LCOV - code coverage report
Current view: top level - gcc/cp - decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.8 % 9880 9368
Test Date: 2026-12-05 16:10:02 Functions: 98.0 % 245 240
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Process declarations and variables for the C++ compiler.
       2              :    Copyright (C) 1988-2026 Free Software Foundation, Inc.
       3              :    Contributed by Michael Tiemann (tiemann@cygnus.com)
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify
       8              : it under the terms of the GNU General Public License as published by
       9              : the Free Software Foundation; either version 3, or (at your option)
      10              : any later version.
      11              : 
      12              : GCC is distributed in the hope that it will be useful,
      13              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15              : GNU General Public License for more details.
      16              : 
      17              : You should have received a copy of the GNU General Public License
      18              : along with GCC; see the file COPYING3.  If not see
      19              : <http://www.gnu.org/licenses/>.  */
      20              : 
      21              : 
      22              : /* Process declarations and symbol lookup for C++ front end.
      23              :    Also constructs types; the standard scalar types at initialization,
      24              :    and structure, union, array and enum types when they are declared.  */
      25              : 
      26              : /* ??? not all decl nodes are given the most useful possible
      27              :    line numbers.  For example, the CONST_DECLs for enum values.  */
      28              : 
      29              : #include "config.h"
      30              : #include "system.h"
      31              : #include "coretypes.h"
      32              : #include "target.h"
      33              : #include "c-family/c-target.h"
      34              : #include "cp-tree.h"
      35              : #include "timevar.h"
      36              : #include "stringpool.h"
      37              : #include "cgraph.h"
      38              : #include "stor-layout.h"
      39              : #include "varasm.h"
      40              : #include "attribs.h"
      41              : #include "flags.h"
      42              : #include "tree-iterator.h"
      43              : #include "decl.h"
      44              : #include "intl.h"
      45              : #include "toplev.h"
      46              : #include "c-family/c-objc.h"
      47              : #include "c-family/c-pragma.h"
      48              : #include "c-family/c-ubsan.h"
      49              : #include "cp/cp-name-hint.h"
      50              : #include "debug.h"
      51              : #include "plugin.h"
      52              : #include "builtins.h"
      53              : #include "gimplify.h"
      54              : #include "asan.h"
      55              : #include "gcc-rich-location.h"
      56              : #include "langhooks.h"
      57              : #include "context.h"  /* For 'g'.  */
      58              : #include "omp-general.h"
      59              : #include "omp-offload.h"  /* For offload_vars.  */
      60              : #include "opts.h"
      61              : #include "langhooks-def.h"  /* For lhd_simulate_record_decl  */
      62              : #include "coroutines.h"
      63              : #include "contracts.h"
      64              : #include "gcc-urlifier.h"
      65              : #include "diagnostic-highlight-colors.h"
      66              : #include "pretty-print-markup.h"
      67              : 
      68              : /* Possible cases of bad specifiers type used by bad_specifiers. */
      69              : enum bad_spec_place {
      70              :   BSP_VAR,    /* variable */
      71              :   BSP_PARM,   /* parameter */
      72              :   BSP_TYPE,   /* type */
      73              :   BSP_FIELD   /* field */
      74              : };
      75              : 
      76              : static const char *redeclaration_error_message (tree, tree);
      77              : 
      78              : static bool decl_jump_unsafe (tree);
      79              : static bool decl_instrument_init_bypass_p (tree);
      80              : static void require_complete_types_for_parms (tree);
      81              : static tree grok_reference_init (tree, tree, tree, int);
      82              : static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
      83              :                          int, int, int, bool, int, tree, location_t);
      84              : static void check_static_variable_definition (tree, tree);
      85              : static void record_unknown_type (tree, const char *);
      86              : static int member_function_or_else (tree, tree, enum overload_flags);
      87              : static tree local_variable_p_walkfn (tree *, int *, void *);
      88              : static tree lookup_and_check_tag (enum tag_types, tree, TAG_how, bool);
      89              : static void maybe_deduce_size_from_array_init (tree, tree);
      90              : static void layout_var_decl (tree);
      91              : static tree check_initializer (tree, tree, int, vec<tree, va_gc> **);
      92              : static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
      93              : static void copy_type_enum (tree , tree);
      94              : static void check_function_type (tree, tree);
      95              : static void begin_destructor_body (void);
      96              : static void record_key_method_defined (tree);
      97              : static tree create_array_type_for_decl (tree, tree, tree, location_t);
      98              : static tree get_atexit_node (void);
      99              : static tree get_dso_handle_node (void);
     100              : static tree start_cleanup_fn (tree, bool, bool);
     101              : static void end_cleanup_fn (void);
     102              : static tree cp_make_fname_decl (location_t, tree, int);
     103              : static void initialize_predefined_identifiers (void);
     104              : static tree check_special_function_return_type
     105              :        (special_function_kind, tree, tree, int, const cp_declarator**,
     106              :         const location_t*);
     107              : static tree push_cp_library_fn (enum tree_code, tree, int);
     108              : static tree build_cp_library_fn (tree, enum tree_code, tree, int);
     109              : static void store_parm_decls (tree);
     110              : static void initialize_local_var (tree, tree, bool);
     111              : static void expand_static_init (tree, tree);
     112              : static location_t smallest_type_location (const cp_decl_specifier_seq*);
     113              : static bool identify_goto (tree, location_t, const location_t *,
     114              :                            enum diagnostics::kind, bool);
     115              : 
     116              : /* The following symbols are subsumed in the cp_global_trees array, and
     117              :    listed here individually for documentation purposes.
     118              : 
     119              :    C++ extensions
     120              :         tree wchar_decl_node;
     121              : 
     122              :         tree vtable_entry_type;
     123              :         tree delta_type_node;
     124              :         tree __t_desc_type_node;
     125              : 
     126              :         tree class_type_node;
     127              :         tree unknown_type_node;
     128              : 
     129              :    Array type `vtable_entry_type[]'
     130              : 
     131              :         tree vtbl_type_node;
     132              :         tree vtbl_ptr_type_node;
     133              : 
     134              :    Namespaces,
     135              : 
     136              :         tree std_node;
     137              :         tree std_meta_node;
     138              :         tree abi_node;
     139              : 
     140              :    A FUNCTION_DECL which can call `abort'.  Not necessarily the
     141              :    one that the user will declare, but sufficient to be called
     142              :    by routines that want to abort the program.
     143              : 
     144              :         tree abort_fndecl;
     145              : 
     146              :    Used by RTTI
     147              :         tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
     148              :         tree tinfo_var_id;  */
     149              : 
     150              : tree cp_global_trees[CPTI_MAX];
     151              : 
     152              : /* A list of objects which have constructors or destructors
     153              :    which reside in namespace scope.  The decl is stored in
     154              :    the TREE_VALUE slot and the initializer is stored
     155              :    in the TREE_PURPOSE slot.  */
     156              : tree static_aggregates;
     157              : 
     158              : /* Like static_aggregates, but for thread_local variables.  */
     159              : tree tls_aggregates;
     160              : 
     161              : /* A hash-map mapping from variable decls to the dynamic initializer for
     162              :    the decl.  This is currently only used by OpenMP.  */
     163              : decl_tree_map *dynamic_initializers;
     164              : 
     165              : /* -- end of C++ */
     166              : 
     167              : /* A node for the integer constant 2.  */
     168              : 
     169              : tree integer_two_node;
     170              : 
     171              : /* vector of static decls.  */
     172              : vec<tree, va_gc> *static_decls;
     173              : 
     174              : /* vector of keyed classes.  */
     175              : vec<tree, va_gc> *keyed_classes;
     176              : 
     177              : /* Used in the direct_goto vector of named_label_use_entry for
     178              :    addresses of the LABEL_DECLs within GOTO_EXPR or asm goto
     179              :    for forward jumps.  */
     180              : 
     181              : struct GTY(()) named_label_fwd_direct_goto {
     182              :   tree *GTY((skip)) direct_goto;
     183              : };
     184              : 
     185              : /* Used in the direct_goto vector of named_label_use_entry for
     186              :    addresses of the LABEL_DECLs within GOTO_EXPR or asm goto
     187              :    for backward jumps.  */
     188              : 
     189              : struct GTY(()) named_label_bck_direct_goto {
     190              :   tree *GTY((skip)) direct_goto;
     191              :   /* Number of the decl_instrument_init_bypass_p decls in bad_decls vector
     192              :      at the time this backward goto has been seen.  */
     193              :   unsigned n_bad_decls;
     194              : };
     195              : 
     196              : /* Used only for jumps to as-yet undefined labels, since jumps to
     197              :    defined labels can have their validity checked immediately.  */
     198              : 
     199              : struct GTY((chain_next ("%h.next"))) named_label_use_entry {
     200              :   struct named_label_use_entry *next;
     201              :   /* The binding level to which this entry is *currently* attached.
     202              :      This is initially the binding level in which the goto appeared,
     203              :      but is modified as scopes are closed.  */
     204              :   cp_binding_level *binding_level;
     205              :   /* The head of the names list that was current when the goto appeared,
     206              :      or the inner scope popped.  These are the decls that will *not* be
     207              :      skipped when jumping to the label.  */
     208              :   tree names_in_scope;
     209              :   /* If the use is a possible destination of a computed goto, a vec of decls
     210              :      that aren't destroyed, filled in by poplevel_named_label_1.  */
     211              :   vec<tree, va_gc> *computed_goto;
     212              :   /* If the use is a destination of normal goto, a vec of addresses of
     213              :      LABEL_DECLs that might need changing for !!flag_auto_var_init
     214              :      forward jumps across vacuous initializers.  */
     215              :   vec<named_label_fwd_direct_goto, va_gc> *direct_goto;
     216              :   /* The location of the goto, for error reporting.  */
     217              :   location_t o_goto_locus;
     218              :   /* True if an OpenMP structured block scope has been closed since
     219              :      the goto appeared.  This means that the branch from the label will
     220              :      illegally exit an OpenMP scope.  */
     221              :   bool in_omp_scope;
     222              : };
     223              : 
     224              : /* A list of all LABEL_DECLs in the function that have names.  Here so
     225              :    we can clear out their names' definitions at the end of the
     226              :    function, and so we can check the validity of jumps to these labels.  */
     227              : 
     228              : struct GTY((for_user)) named_label_entry {
     229              : 
     230              :   tree name;  /* Name of decl. */
     231              : 
     232              :   tree label_decl; /* LABEL_DECL, unless deleted local label. */
     233              : 
     234              :   named_label_entry *outer; /* Outer shadowed chain.  */
     235              : 
     236              :   /* The binding level to which the label is *currently* attached.
     237              :      This is initially set to the binding level in which the label
     238              :      is defined, but is modified as scopes are closed.  */
     239              :   cp_binding_level *binding_level;
     240              : 
     241              :   /* The head of the names list that was current when the label was
     242              :      defined, or the inner scope popped.  These are the decls that will
     243              :      be skipped when jumping to the label.  */
     244              :   tree names_in_scope;
     245              : 
     246              :   /* A vector of all decls from all binding levels that would be
     247              :      crossed by a backward branch to the label.  */
     248              :   vec<tree, va_gc> *bad_decls;
     249              : 
     250              :   /* A list of uses of the label, before the label is defined.  */
     251              :   named_label_use_entry *uses;
     252              : 
     253              :   /* If the use is a destination of normal goto, a vec of addresses of
     254              :      LABEL_DECLs that might need changing for !!flag_auto_var_init
     255              :      backward jumps across vacuous initializers.  */
     256              :   vec<named_label_bck_direct_goto, va_gc> *direct_goto;
     257              : 
     258              :   /* Locus of &&label if addressed is set or the copy of the first
     259              :      goto label otherwise.  */
     260              :   location_t goto_locus;
     261              : 
     262              :   /* If ambiguous is set, this is the locus of the second LABEL_DECL with the
     263              :      same name.  */
     264              :   location_t other_label_locus;
     265              : 
     266              :   /* True if we've seen &&label.  Apparently we can't use TREE_ADDRESSABLE for
     267              :      this, it has a more specific meaning for LABEL_DECL.  */
     268              :   bool addressed : 1;
     269              : 
     270              :   /* The following bits are set after the label is defined, and are
     271              :      updated as scopes are popped.  They indicate that a jump to the
     272              :      label will illegally enter a scope of the given flavor.  */
     273              :   bool in_try_scope : 1;
     274              :   bool in_catch_scope : 1;
     275              :   bool in_omp_scope : 1;
     276              :   bool in_transaction_scope : 1;
     277              :   bool in_constexpr_if : 1;
     278              :   bool in_consteval_if : 1;
     279              :   bool in_stmt_expr : 1;
     280              : 
     281              :   /* True if bad_decls chain contains any decl_jump_unsafe decls
     282              :      (rather than just decl_instrument_init_bypass_p).  */
     283              :   bool has_bad_decls : 1;
     284              : 
     285              :   /* Marks the case where multiple labels in the same function
     286              :      have the same name in C++29 or later.  goto or && isn't allowed on
     287              :      those.  */
     288              :   bool ambiguous : 1;
     289              : };
     290              : 
     291              : #define named_labels cp_function_chain->x_named_labels
     292              : 
     293              : /* The number of function bodies which we are currently processing.
     294              :    (Zero if we are at namespace scope, one inside the body of a
     295              :    function, two inside the body of a function in a local class, etc.)  */
     296              : int function_depth;
     297              : 
     298              : /* Whether the exception-specifier is part of a function type (i.e. C++17).  */
     299              : bool flag_noexcept_type;
     300              : 
     301              : /* States indicating how grokdeclarator() should handle declspecs marked
     302              :    with __attribute__((deprecated)).  An object declared as
     303              :    __attribute__((deprecated)) suppresses warnings of uses of other
     304              :    deprecated items.  */
     305              : enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
     306              : 
     307              : 
     308              : /* A list of VAR_DECLs whose type was incomplete at the time the
     309              :    variable was declared.  */
     310              : 
     311              : struct GTY(()) incomplete_var {
     312              :   tree decl;
     313              :   tree incomplete_type;
     314              : };
     315              : 
     316              : 
     317              : static GTY(()) vec<incomplete_var, va_gc> *incomplete_vars;
     318              : 
     319              : /* Returns the kind of template specialization we are currently
     320              :    processing, given that it's declaration contained N_CLASS_SCOPES
     321              :    explicit scope qualifications.  */
     322              : 
     323              : tmpl_spec_kind
     324    258034652 : current_tmpl_spec_kind (int n_class_scopes)
     325              : {
     326    258034652 :   int n_template_parm_scopes = 0;
     327    258034652 :   int seen_specialization_p = 0;
     328    258034652 :   int innermost_specialization_p = 0;
     329    258034652 :   cp_binding_level *b;
     330              : 
     331              :   /* Scan through the template parameter scopes.  */
     332    258034652 :   for (b = current_binding_level;
     333    322080716 :        b->kind == sk_template_parms;
     334     64046064 :        b = b->level_chain)
     335              :     {
     336              :       /* If we see a specialization scope inside a parameter scope,
     337              :          then something is wrong.  That corresponds to a declaration
     338              :          like:
     339              : 
     340              :             template <class T> template <> ...
     341              : 
     342              :          which is always invalid since [temp.expl.spec] forbids the
     343              :          specialization of a class member template if the enclosing
     344              :          class templates are not explicitly specialized as well.  */
     345     64046064 :       if (b->explicit_spec_p)
     346              :         {
     347      1524540 :           if (n_template_parm_scopes == 0)
     348              :             innermost_specialization_p = 1;
     349              :           else
     350         1109 :             seen_specialization_p = 1;
     351              :         }
     352     62521524 :       else if (seen_specialization_p == 1)
     353              :         return tsk_invalid_member_spec;
     354              : 
     355     64046064 :       ++n_template_parm_scopes;
     356              :     }
     357              : 
     358              :   /* Handle explicit instantiations.  */
     359    258034652 :   if (processing_explicit_instantiation)
     360              :     {
     361      2006566 :       if (n_template_parm_scopes != 0)
     362              :         /* We've seen a template parameter list during an explicit
     363              :            instantiation.  For example:
     364              : 
     365              :              template <class T> template void f(int);
     366              : 
     367              :            This is erroneous.  */
     368              :         return tsk_invalid_expl_inst;
     369              :       else
     370      2006566 :         return tsk_expl_inst;
     371              :     }
     372              : 
     373    256028086 :   if (n_template_parm_scopes < n_class_scopes)
     374              :     /* We've not seen enough template headers to match all the
     375              :        specialized classes present.  For example:
     376              : 
     377              :          template <class T> void R<T>::S<T>::f(int);
     378              : 
     379              :        This is invalid; there needs to be one set of template
     380              :        parameters for each class.  */
     381              :     return tsk_insufficient_parms;
     382    256028086 :   else if (n_template_parm_scopes == n_class_scopes)
     383              :     /* We're processing a non-template declaration (even though it may
     384              :        be a member of a template class.)  For example:
     385              : 
     386              :          template <class T> void S<T>::f(int);
     387              : 
     388              :        The `class T' matches the `S<T>', leaving no template headers
     389              :        corresponding to the `f'.  */
     390              :     return tsk_none;
     391     55756249 :   else if (n_template_parm_scopes > n_class_scopes + 1)
     392              :     /* We've got too many template headers.  For example:
     393              : 
     394              :          template <> template <class T> void f (T);
     395              : 
     396              :        There need to be more enclosing classes.  */
     397              :     return tsk_excessive_parms;
     398              :   else
     399              :     /* This must be a template.  It's of the form:
     400              : 
     401              :          template <class T> template <class U> void S<T>::f(U);
     402              : 
     403              :        This is a specialization if the innermost level was a
     404              :        specialization; otherwise it's just a definition of the
     405              :        template.  */
     406     55756249 :     return innermost_specialization_p ? tsk_expl_spec : tsk_template;
     407              : }
     408              : 
     409              : /* Exit the current scope.  */
     410              : 
     411              : void
     412    101669701 : finish_scope (void)
     413              : {
     414    101669701 :   poplevel (0, 0, 0);
     415    101669701 : }
     416              : 
     417              : /* When a label goes out of scope, check to see if that label was used
     418              :    in a valid manner, and issue any appropriate warnings or errors.  */
     419              : 
     420              : static void
     421        22402 : check_label_used (tree label)
     422              : {
     423        22402 :   if (!processing_template_decl)
     424              :     {
     425        21741 :       if (DECL_INITIAL (label) == NULL_TREE)
     426              :         {
     427           53 :           location_t location;
     428              : 
     429           53 :           error ("label %q+D used but not defined", label);
     430           53 :           location = input_location;
     431              :             /* FIXME want (LOCATION_FILE (input_location), (line)0) */
     432              :           /* Avoid crashing later.  */
     433           53 :           define_label (location, DECL_NAME (label));
     434              :         }
     435              :       else
     436        21688 :         warn_for_unused_label (label);
     437              :     }
     438        22402 : }
     439              : 
     440              : /* Helper function to sort named label entries in a vector by DECL_UID.  */
     441              : 
     442              : static int
     443       255814 : sort_labels (const void *a, const void *b)
     444              : {
     445       255814 :   tree label1 = *(tree const *) a;
     446       255814 :   tree label2 = *(tree const *) b;
     447              : 
     448              :   /* DECL_UIDs can never be equal.  */
     449       255814 :   return DECL_UID (label1) > DECL_UID (label2) ? -1 : +1;
     450              : }
     451              : 
     452              : static void adjust_backward_goto (named_label_entry *, tree_stmt_iterator);
     453              : static named_label_entry *lookup_label_1 (tree, bool);
     454              : 
     455              : /* Helper of pop_labels, called through cp_walk_tree.  Adjust
     456              :    LABEL_EXPRs of named labels, if they are targets of backwards
     457              :    gotos jumping across vacuous initialization for
     458              :    !!flag_auto_var_init.  */
     459              : 
     460              : static tree
     461         2909 : adjust_backward_gotos (tree *tp, int *walk_subtrees, void *data)
     462              : {
     463         2909 :   tree t = *tp;
     464         2909 :   switch (TREE_CODE (t))
     465              :     {
     466            3 :     case LABEL_EXPR:
     467              :       /* In rare cases LABEL_EXPR can appear as the only substatement
     468              :          of some other statement, e.g. if body etc.  In that case, we know
     469              :          there can't be an older if (0) wrapper with artificial initializers
     470              :          before it.  Replace the LABEL_EXPR statement with a STATEMENT_LIST
     471              :          and insert the LABEL_EXPR into it, later on if (0) will be added
     472              :          before that.  */
     473            3 :       if (DECL_NAME (LABEL_EXPR_LABEL (t)))
     474              :         {
     475            3 :           named_label_entry *ent
     476            3 :             = lookup_label_1 (DECL_NAME (LABEL_EXPR_LABEL (t)), false);
     477            3 :           if (ent->direct_goto
     478            3 :               && (!ent->ambiguous || ent->label_decl == LABEL_EXPR_LABEL (t)))
     479              :             {
     480            3 :               *tp = alloc_stmt_list ();
     481            3 :               append_to_statement_list_force (t, tp);
     482            3 :               adjust_backward_goto (ent, tsi_last (*tp));
     483              :             }
     484              :         }
     485            3 :       *walk_subtrees = 0;
     486            3 :       break;
     487          141 :     case STATEMENT_LIST:
     488          141 :       {
     489          141 :         tree_stmt_iterator i;
     490          141 :         *walk_subtrees = 0;
     491              :         /* In the common case, LABEL_EXPRs appear inside of a STATEMENT_LIST.
     492              :            In that case pass the stmt iterator to adjust_backward_goto, so
     493              :            that it can insert if (0) wrapper artificial initializers before
     494              :            it or reuse the existing ones.  */
     495          915 :         for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
     496          774 :           if (TREE_CODE (tsi_stmt (i)) != LABEL_EXPR)
     497          737 :             cp_walk_tree (tsi_stmt_ptr (i), adjust_backward_gotos,
     498              :                           data, (hash_set<tree> *) data);
     499           37 :           else if (DECL_NAME (LABEL_EXPR_LABEL (tsi_stmt (i))))
     500              :             {
     501           16 :               named_label_entry *ent
     502           16 :                 = lookup_label_1 (DECL_NAME (LABEL_EXPR_LABEL (tsi_stmt (i))),
     503              :                                   false);
     504           16 :               if (ent->direct_goto
     505           16 :                   && (!ent->ambiguous
     506            0 :                       || ent->label_decl == LABEL_EXPR_LABEL (tsi_stmt (i))))
     507           16 :                 adjust_backward_goto (ent, i);
     508              :             }
     509          141 :         break;
     510              :       }
     511         2765 :     default:
     512         2765 :       if (TYPE_P (t))
     513            4 :         *walk_subtrees = 0;
     514              :     }
     515         2909 :   return NULL_TREE;
     516              : }
     517              : 
     518              : /* At the end of a function, all labels declared within the function
     519              :    go out of scope.  BLOCK is the top-level block for the
     520              :    function.  */
     521              : 
     522              : static void
     523    166967325 : pop_labels (tree block)
     524              : {
     525    166967325 :   if (!named_labels)
     526    166962429 :     return;
     527              : 
     528              :   /* We need to add the labels to the block chain, so debug
     529              :      information is emitted.  But, we want the order to be stable so
     530              :      need to sort them first.  Otherwise the debug output could be
     531              :      randomly ordered.  I guess it's mostly stable, unless the hash
     532              :      table implementation changes.  */
     533         4896 :   auto_vec<tree, 32> labels (named_labels->elements ());
     534         4896 :   hash_table<named_label_hash>::iterator end (named_labels->end ());
     535              : 
     536         4896 :   if (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
     537          808 :       && !processing_template_decl)
     538              :     {
     539         4462 :       for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
     540              :         {
     541         2948 :           named_label_entry *ent = *iter;
     542         2948 :           if (ent->direct_goto)
     543              :             {
     544            4 :               hash_set<tree> pset;
     545            4 :               cp_walk_tree (&DECL_SAVED_TREE (current_function_decl),
     546              :                             adjust_backward_gotos, &pset, &pset);
     547            4 :               break;
     548            4 :             }
     549              :         }
     550              :     }
     551              : 
     552        27026 :   for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
     553              :     {
     554        22130 :       named_label_entry *ent = *iter;
     555              : 
     556        22130 :       gcc_checking_assert (!ent->outer);
     557        22130 :       if (ent->label_decl)
     558        21944 :         labels.quick_push (ent->label_decl);
     559        22130 :       ggc_free (ent);
     560              :     }
     561         4896 :   named_labels = NULL;
     562         4896 :   labels.qsort (sort_labels);
     563              : 
     564        26840 :   while (labels.length ())
     565              :     {
     566        21944 :       tree label = labels.pop ();
     567        21944 :       tree last = label;
     568              : 
     569        22183 :       while (DECL_CHAIN (last))
     570              :         {
     571          239 :           check_label_used (DECL_CHAIN (last));
     572          239 :           last = DECL_CHAIN (last);
     573              :         }
     574              : 
     575        21944 :       DECL_CHAIN (last) = BLOCK_VARS (block);
     576        21944 :       BLOCK_VARS (block) = label;
     577              : 
     578        21944 :       check_label_used (label);
     579              :     }
     580         4896 : }
     581              : 
     582              : /* At the end of a block with local labels, restore the outer definition.  */
     583              : 
     584              : static void
     585          219 : pop_local_label (tree id, tree label)
     586              : {
     587          219 :   check_label_used (label);
     588          219 :   named_label_entry **slot = named_labels->find_slot_with_hash
     589          219 :     (id, IDENTIFIER_HASH_VALUE (id), NO_INSERT);
     590          219 :   named_label_entry *ent = *slot;
     591              : 
     592          219 :   if (ent->outer)
     593              :     ent = ent->outer;
     594              :   else
     595              :     {
     596          198 :       ent = ggc_cleared_alloc<named_label_entry> ();
     597          198 :       ent->name = id;
     598              :     }
     599          219 :   *slot = ent;
     600          219 : }
     601              : 
     602              : /* The following two routines are used to interface to Objective-C++.
     603              :    The binding level is purposely treated as an opaque type.  */
     604              : 
     605              : void *
     606            0 : objc_get_current_scope (void)
     607              : {
     608            0 :   return current_binding_level;
     609              : }
     610              : 
     611              : /* The following routine is used by the NeXT-style SJLJ exceptions;
     612              :    variables get marked 'volatile' so as to not be clobbered by
     613              :    _setjmp()/_longjmp() calls.  All variables in the current scope,
     614              :    as well as parent scopes up to (but not including) ENCLOSING_BLK
     615              :    shall be thusly marked.  */
     616              : 
     617              : void
     618            0 : objc_mark_locals_volatile (void *enclosing_blk)
     619              : {
     620            0 :   cp_binding_level *scope;
     621              : 
     622            0 :   for (scope = current_binding_level;
     623            0 :        scope && scope != enclosing_blk;
     624            0 :        scope = scope->level_chain)
     625              :     {
     626            0 :       tree decl;
     627              : 
     628            0 :       for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
     629            0 :         objc_volatilize_decl (decl);
     630              : 
     631              :       /* Do not climb up past the current function.  */
     632            0 :       if (scope->kind == sk_function_parms)
     633              :         break;
     634              :     }
     635            0 : }
     636              : 
     637              : /* True if B is the level for the condition of a constexpr if.  */
     638              : 
     639              : static bool
     640      1811875 : level_for_constexpr_if (cp_binding_level *b)
     641              : {
     642      1805965 :   return (b->kind == sk_cond && b->this_entity
     643          309 :           && TREE_CODE (b->this_entity) == IF_STMT
     644      1812184 :           && IF_STMT_CONSTEXPR_P (b->this_entity));
     645              : }
     646              : 
     647              : /* True if B is the level for the condition of a consteval if.  */
     648              : 
     649              : static bool
     650      1811851 : level_for_consteval_if (cp_binding_level *b)
     651              : {
     652      1805941 :   return (b->kind == sk_cond && b->this_entity
     653          285 :           && TREE_CODE (b->this_entity) == IF_STMT
     654      1812136 :           && IF_STMT_CONSTEVAL_P (b->this_entity));
     655              : }
     656              : 
     657              : /* True if T is a non-static VAR_DECL that has a non-trivial destructor.
     658              :    See [stmt.dcl]/2.  */
     659              : 
     660              : static bool
     661           28 : automatic_var_with_nontrivial_dtor_p (const_tree t)
     662              : {
     663           28 :   if (error_operand_p (t))
     664              :     return false;
     665              : 
     666           22 :   return (VAR_P (t)
     667           22 :           && decl_storage_duration (const_cast<tree> (t)) == dk_auto
     668           44 :           && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t)));
     669              : }
     670              : 
     671              : /* Update data for defined and undefined labels when leaving a scope.  */
     672              : 
     673              : int
     674       236586 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
     675              : {
     676       236586 :   named_label_entry *ent = *slot;
     677       236586 :   cp_binding_level *obl = bl->level_chain;
     678              : 
     679       236586 :   if (ent->binding_level == bl)
     680              :     {
     681        13461 :       tree decl;
     682              : 
     683              :       /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
     684              :          TREE_LISTs representing OVERLOADs, so be careful.  */
     685        20711 :       for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
     686         7323 :                                                      ? DECL_CHAIN (decl)
     687           73 :                                                      : TREE_CHAIN (decl)))
     688         7250 :         if (decl_jump_unsafe (decl))
     689              :           {
     690         3505 :             vec_safe_push (ent->bad_decls, decl);
     691         3505 :             ent->has_bad_decls = true;
     692              :           }
     693         3745 :         else if (decl_instrument_init_bypass_p (decl))
     694          605 :           vec_safe_push (ent->bad_decls, decl);
     695              : 
     696        13461 :       ent->binding_level = obl;
     697        13461 :       ent->names_in_scope = obl->names;
     698        13461 :       switch (bl->kind)
     699              :         {
     700           42 :         case sk_try:
     701           42 :           ent->in_try_scope = true;
     702           42 :           break;
     703           27 :         case sk_catch:
     704           27 :           ent->in_catch_scope = true;
     705           27 :           break;
     706          324 :         case sk_omp:
     707          324 :           ent->in_omp_scope = true;
     708          324 :           break;
     709            3 :         case sk_transaction:
     710            3 :           ent->in_transaction_scope = true;
     711            3 :           break;
     712           48 :         case sk_stmt_expr:
     713           48 :           ent->in_stmt_expr = true;
     714           48 :           break;
     715         6221 :         case sk_block:
     716         6221 :           if (level_for_constexpr_if (obl))
     717           15 :             ent->in_constexpr_if = true;
     718         6206 :           else if (level_for_consteval_if (obl))
     719           30 :             ent->in_consteval_if = true;
     720              :           break;
     721              :         default:
     722              :           break;
     723              :         }
     724              :     }
     725       223125 :   else if (ent->uses)
     726              :     {
     727              :       struct named_label_use_entry *use;
     728              : 
     729        27728 :       for (use = ent->uses; use ; use = use->next)
     730        18576 :         if (use->binding_level == bl)
     731              :           {
     732         6563 :             if (auto &cg = use->computed_goto)
     733              :               {
     734           57 :                 if (bl->kind == sk_catch)
     735            3 :                   vec_safe_push (cg, get_identifier ("catch"));
     736           66 :                 for (tree d = use->names_in_scope; d; d = DECL_CHAIN (d))
     737            9 :                   if (automatic_var_with_nontrivial_dtor_p (d))
     738            6 :                     vec_safe_push (cg, d);
     739              :               }
     740              : 
     741         6563 :             use->binding_level = obl;
     742         6563 :             use->names_in_scope = obl->names;
     743         6563 :             if (bl->kind == sk_omp)
     744           12 :               use->in_omp_scope = true;
     745              :           }
     746              :     }
     747              : 
     748       236586 :   return 1;
     749              : }
     750              : 
     751              : /* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
     752              :    when errors were reported, except for -Werror-unused-but-set-*.  */
     753              : static int unused_but_set_errorcount;
     754              : 
     755              : /* Exit a binding level.
     756              :    Pop the level off, and restore the state of the identifier-decl mappings
     757              :    that were in effect when this level was entered.
     758              : 
     759              :    If KEEP == 1, this level had explicit declarations, so
     760              :    and create a "block" (a BLOCK node) for the level
     761              :    to record its declarations and subblocks for symbol table output.
     762              : 
     763              :    If FUNCTIONBODY is nonzero, this level is the body of a function,
     764              :    so create a block as if KEEP were set and also clear out all
     765              :    label names.
     766              : 
     767              :    If REVERSE is nonzero, reverse the order of decls before putting
     768              :    them into the BLOCK.  */
     769              : 
     770              : tree
     771    703029195 : poplevel (int keep, int reverse, int functionbody)
     772              : {
     773    703029195 :   tree link;
     774              :   /* The chain of decls was accumulated in reverse order.
     775              :      Put it into forward order, just for cleanliness.  */
     776    703029195 :   tree decls;
     777    703029195 :   tree subblocks;
     778    703029195 :   tree block;
     779    703029195 :   tree decl;
     780    703029195 :   scope_kind kind;
     781              : 
     782    703029195 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     783    703029464 :  restart:
     784              : 
     785    703029464 :   block = NULL_TREE;
     786              : 
     787    703029464 :   gcc_assert (current_binding_level->kind != sk_class
     788              :               && current_binding_level->kind != sk_namespace);
     789              : 
     790    703029464 :   if (current_binding_level->kind == sk_cleanup)
     791              :     functionbody = 0;
     792    703029464 :   subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
     793              : 
     794    703029464 :   gcc_assert (!vec_safe_length (current_binding_level->class_shadowed));
     795              : 
     796              :   /* We used to use KEEP == 2 to indicate that the new block should go
     797              :      at the beginning of the list of blocks at this binding level,
     798              :      rather than the end.  This hack is no longer used.  */
     799    703029464 :   gcc_assert (keep == 0 || keep == 1);
     800              : 
     801    703029464 :   if (current_binding_level->keep)
     802      8646178 :     keep = 1;
     803              : 
     804              :   /* Any uses of undefined labels, and any defined labels, now operate
     805              :      under constraints of next binding contour.  */
     806    703029464 :   if (cfun && !functionbody && named_labels)
     807        56594 :     named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
     808       293180 :                    (current_binding_level);
     809              : 
     810              :   /* Get the decls in the order they were written.
     811              :      Usually current_binding_level->names is in reverse order.
     812              :      But parameter decls were previously put in forward order.  */
     813              : 
     814    703029464 :   decls = current_binding_level->names;
     815    703029464 :   if (reverse)
     816              :     {
     817    386194702 :       decls = nreverse (decls);
     818    386194702 :       current_binding_level->names = decls;
     819              :     }
     820              : 
     821              :   /* If there were any declarations or structure tags in that level,
     822              :      or if this level is a function body,
     823              :      create a BLOCK to record them for the life of this function.  */
     824    703029464 :   block = NULL_TREE;
     825              :   /* Avoid function body block if possible.  */
     826    745587716 :   if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
     827              :     keep = 0;
     828    660471482 :   else if (keep == 1 || functionbody)
     829    210858981 :     block = make_node (BLOCK);
     830    210858981 :   if (block != NULL_TREE)
     831              :     {
     832    210858981 :       BLOCK_VARS (block) = decls;
     833    210858981 :       BLOCK_SUBBLOCKS (block) = subblocks;
     834              :     }
     835              : 
     836              :   /* In each subblock, record that this is its superior.  */
     837    703029464 :   if (keep >= 0)
     838    789478367 :     for (link = subblocks; link; link = BLOCK_CHAIN (link))
     839     86448903 :       BLOCK_SUPERCONTEXT (link) = block;
     840              : 
     841              :   /* Before we remove the declarations first check for unused variables.  */
     842    703029464 :   if ((warn_unused_variable || warn_unused_but_set_variable)
     843      6799898 :       && current_binding_level->kind != sk_template_parms
     844      5728322 :       && !processing_template_decl)
     845      6569369 :     for (tree d = get_local_decls (); d; d = TREE_CHAIN (d))
     846              :       {
     847              :         /* There are cases where D itself is a TREE_LIST.  See in
     848              :            push_local_binding where the list of decls returned by
     849              :            getdecls is built.  */
     850      3327842 :         tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
     851      3327842 :         decl = strip_using_decl (udecl);
     852              : 
     853      3327842 :         tree type = TREE_TYPE (decl);
     854      3327842 :         if (VAR_P (decl)
     855       388627 :             && (!TREE_USED (decl) || !DECL_READ_P (decl))
     856         3627 :             && !DECL_IN_SYSTEM_HEADER (udecl)
     857              :             /* For structured bindings, consider only real variables, not
     858              :                subobjects.  */
     859         3615 :             && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
     860         3390 :                 : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
     861              :             /* Don't warn about name-independent declarations.  */
     862          911 :             && !name_independent_decl_p (decl)
     863          755 :             && type != error_mark_node
     864      3332178 :             && (!CLASS_TYPE_P (type)
     865           51 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
     866            3 :                 || lookup_attribute ("warn_unused",
     867            3 :                                      TYPE_ATTRIBUTES (TREE_TYPE (decl)))))
     868              :           {
     869          721 :             if (!TREE_USED (decl))
     870              :               {
     871          317 :                 if (TREE_CODE (udecl) == USING_DECL)
     872            3 :                   warning_at (DECL_SOURCE_LOCATION (udecl),
     873            3 :                               OPT_Wunused_variable,
     874              :                               "unused using-declaration %qD", udecl);
     875          314 :                 else if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     876            3 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     877            3 :                               OPT_Wunused_variable,
     878              :                               "unused structured binding declaration");
     879              :                 else
     880          311 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     881          311 :                               OPT_Wunused_variable, "unused variable %qD", decl);
     882          317 :                 suppress_warning (decl, OPT_Wunused_variable);
     883              :               }
     884          404 :             else if (DECL_CONTEXT (decl) == current_function_decl
     885              :                      // For -Wunused-but-set-variable leave references alone.
     886          380 :                      && !TYPE_REF_P (TREE_TYPE (decl))
     887          784 :                      && errorcount == unused_but_set_errorcount)
     888              :               {
     889          371 :                 if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     890           12 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     891           12 :                               OPT_Wunused_but_set_variable_, "structured "
     892              :                               "binding declaration set but not used");
     893              :                 else
     894          359 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     895          359 :                               OPT_Wunused_but_set_variable_,
     896              :                               "variable %qD set but not used", decl);
     897          371 :                 unused_but_set_errorcount = errorcount;
     898              :               }
     899              :           }
     900              :       }
     901              : 
     902              :   /* Remove declarations for all the DECLs in this level.  */
     903   1420122293 :   for (link = decls; link; link = TREE_CHAIN (link))
     904              :     {
     905    717092829 :       tree name;
     906    717092829 :       if (TREE_CODE (link) == TREE_LIST)
     907              :         {
     908     13813648 :           decl = TREE_VALUE (link);
     909     13813648 :           name = TREE_PURPOSE (link);
     910     13813648 :           gcc_checking_assert (name);
     911              :         }
     912              :       else
     913              :         {
     914    703279181 :           decl = link;
     915    703279181 :           name = DECL_NAME (decl);
     916              :         }
     917              : 
     918              :       /* Remove the binding.  */
     919    717092829 :       if (TREE_CODE (decl) == LABEL_DECL)
     920          219 :         pop_local_label (name, decl);
     921              :       else
     922    717092610 :         pop_local_binding (name, decl);
     923              :     }
     924              : 
     925              :   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
     926    703029464 :   for (link = current_binding_level->type_shadowed;
     927    957625744 :        link; link = TREE_CHAIN (link))
     928    254596280 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
     929              : 
     930              :   /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
     931              :      list if a `using' declaration put them there.  The debugging
     932              :      back ends won't understand OVERLOAD, so we remove them here.
     933              :      Because the BLOCK_VARS are (temporarily) shared with
     934              :      CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
     935              :      popped all the bindings.  Also remove undeduced 'auto' decls,
     936              :      which LTO doesn't understand, and can't have been used by anything.  */
     937    703029464 :   if (block)
     938              :     {
     939    210858981 :       tree* d;
     940              : 
     941    554831893 :       for (d = &BLOCK_VARS (block); *d; )
     942              :         {
     943    343972912 :           if (TREE_CODE (*d) == TREE_LIST
     944    343972912 :               || (!processing_template_decl
     945    108854017 :                   && undeduced_auto_decl (*d)))
     946     13813700 :             *d = TREE_CHAIN (*d);
     947              :           else
     948    330159212 :             d = &DECL_CHAIN (*d);
     949              :         }
     950              :     }
     951              : 
     952              :   /* If the level being exited is the top level of a function,
     953              :      check over all the labels.  */
     954    703029464 :   if (functionbody)
     955              :     {
     956    166967325 :       if (block)
     957              :         {
     958              :           /* Since this is the top level block of a function, the vars are
     959              :              the function's parameters.  Don't leave them in the BLOCK
     960              :              because they are found in the FUNCTION_DECL instead.  */
     961    124409343 :           BLOCK_VARS (block) = 0;
     962    124409343 :           pop_labels (block);
     963              :         }
     964              :       else
     965     42557982 :         pop_labels (subblocks);
     966              :     }
     967              : 
     968    703029464 :   kind = current_binding_level->kind;
     969    703029464 :   if (kind == sk_cleanup)
     970              :     {
     971          269 :       tree stmt;
     972              : 
     973              :       /* If this is a temporary binding created for a cleanup, then we'll
     974              :          have pushed a statement list level.  Pop that, create a new
     975              :          BIND_EXPR for the block, and insert it into the stream.  */
     976          269 :       stmt = pop_stmt_list (current_binding_level->statement_list);
     977          269 :       stmt = c_build_bind_expr (input_location, block, stmt);
     978          269 :       add_stmt (stmt);
     979              :     }
     980              : 
     981    703029464 :   leave_scope ();
     982    703029464 :   if (functionbody)
     983              :     {
     984              :       /* The current function is being defined, so its DECL_INITIAL
     985              :          should be error_mark_node.  */
     986    166967325 :       gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
     987    209525307 :       DECL_INITIAL (current_function_decl) = block ? block : subblocks;
     988    166967325 :       if (subblocks)
     989              :         {
     990     80994883 :           if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl)
     991     52888303 :               && BLOCK_SUBBLOCKS (subblocks))
     992      1386268 :             BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
     993              :           else
     994     41171984 :             BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
     995              :         }
     996              :     }
     997    536062139 :   else if (block)
     998     86449638 :     current_binding_level->blocks
     999    172899276 :       = block_chainon (current_binding_level->blocks, block);
    1000              : 
    1001              :   /* If we did not make a block for the level just exited,
    1002              :      any blocks made for inner levels
    1003              :      (since they cannot be recorded as subblocks in that level)
    1004              :      must be carried forward so they will later become subblocks
    1005              :      of something else.  */
    1006    449612501 :   else if (subblocks)
    1007           18 :     current_binding_level->blocks
    1008           36 :       = block_chainon (current_binding_level->blocks, subblocks);
    1009              : 
    1010              :   /* Each and every BLOCK node created here in `poplevel' is important
    1011              :      (e.g. for proper debugging information) so if we created one
    1012              :      earlier, mark it as "used".  */
    1013    703029464 :   if (block)
    1014    210858981 :     TREE_USED (block) = 1;
    1015              : 
    1016              :   /* All temporary bindings created for cleanups are popped silently.  */
    1017    703029464 :   if (kind == sk_cleanup)
    1018          269 :     goto restart;
    1019              : 
    1020   1406058390 :   return block;
    1021    703029195 : }
    1022              : 
    1023              : /* Call wrapup_globals_declarations for the globals in NAMESPACE.  */
    1024              : /* Diagnose odr-used extern inline variables without definitions
    1025              :    in the current TU.  */
    1026              : 
    1027              : int
    1028       147945 : wrapup_namespace_globals ()
    1029              : {
    1030       147945 :   if (vec<tree, va_gc> *statics = static_decls)
    1031              :     {
    1032     18235959 :       for (tree decl : *statics)
    1033              :         {
    1034              :           /* Rewrite the REFLECT_EXPR with 0 so that the ME can process it.  */
    1035     18114524 :           if (flag_reflection && DECL_INITIAL (decl))
    1036       311069 :             rewrite_null_reflection (DECL_INITIAL (decl));
    1037              : 
    1038     18114524 :           if (warn_unused_function
    1039      1014867 :               && TREE_CODE (decl) == FUNCTION_DECL
    1040       765494 :               && DECL_INITIAL (decl) == 0
    1041         7625 :               && DECL_EXTERNAL (decl)
    1042         7613 :               && !TREE_PUBLIC (decl)
    1043           34 :               && !DECL_ARTIFICIAL (decl)
    1044           34 :               && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
    1045            9 :               && !warning_suppressed_p (decl, OPT_Wunused)
    1046     19129391 :               && warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_function,
    1047              :                              "%qF declared %<static%> but never defined",
    1048              :                              decl))
    1049            6 :                 suppress_warning (decl, OPT_Wunused);
    1050              : 
    1051     18114524 :           if (VAR_P (decl)
    1052      5962725 :               && DECL_EXTERNAL (decl)
    1053              :               /* We mark consteval-only variables DECL_EXTERNAL, but
    1054              :                   extern constexpr inline std::meta::info i{};
    1055              :                  is a definition (the extern is redundant).  */
    1056      2040237 :               && !DECL_INITIAL (decl)
    1057      2039062 :               && DECL_INLINE_VAR_P (decl)
    1058     18114553 :               && DECL_ODR_USED (decl))
    1059            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    1060              :                       "odr-used inline variable %qD is not defined", decl);
    1061              :         }
    1062              : 
    1063              :       /* Clear out the list, so we don't rescan next time.  */
    1064       121435 :       static_decls = NULL;
    1065              : 
    1066              :       /* Write out any globals that need to be output.  */
    1067       121435 :       return wrapup_global_declarations (statics->address (),
    1068       121435 :                                          statics->length ());
    1069              :     }
    1070              :   return 0;
    1071              : }
    1072              : 
    1073              : /* In C++, you don't have to write `struct S' to refer to `S'; you
    1074              :    can just use `S'.  We accomplish this by creating a TYPE_DECL as
    1075              :    if the user had written `typedef struct S S'.  Create and return
    1076              :    the TYPE_DECL for TYPE.  */
    1077              : 
    1078              : tree
    1079    187767590 : create_implicit_typedef (tree name, tree type)
    1080              : {
    1081    187767590 :   tree decl;
    1082              : 
    1083    187767590 :   decl = build_decl (input_location, TYPE_DECL, name, type);
    1084    187767590 :   DECL_ARTIFICIAL (decl) = 1;
    1085              :   /* There are other implicit type declarations, like the one *within*
    1086              :      a class that allows you to write `S::S'.  We must distinguish
    1087              :      amongst these.  */
    1088    187767590 :   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
    1089    187767590 :   TYPE_NAME (type) = decl;
    1090    187767590 :   TYPE_STUB_DECL (type) = decl;
    1091              : 
    1092    187767590 :   return decl;
    1093              : }
    1094              : 
    1095              : /* Function-scope local entities that need discriminators.  Each entry
    1096              :    is a {decl,name} pair.  VAR_DECLs for anon unions get their name
    1097              :    smashed, so we cannot rely on DECL_NAME.  */
    1098              : 
    1099              : static GTY((deletable)) vec<tree, va_gc> *local_entities;
    1100              : 
    1101              : /* Determine the mangling discriminator of local DECL.  There are
    1102              :    generally very few of these in any particular function.  */
    1103              : 
    1104              : void
    1105       759683 : determine_local_discriminator (tree decl, tree name)
    1106              : {
    1107       759683 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    1108       759683 :   retrofit_lang_decl (decl);
    1109       759683 :   tree ctx = DECL_CONTEXT (decl);
    1110       759683 :   size_t nelts = vec_safe_length (local_entities);
    1111       759683 :   if (name == NULL_TREE)
    1112       759414 :     name = (TREE_CODE (decl) == TYPE_DECL
    1113      1237825 :             && TYPE_UNNAMED_P (TREE_TYPE (decl))
    1114      1373894 :             ? NULL_TREE : DECL_NAME (decl));
    1115     22487931 :   for (size_t i = 0; i < nelts; i += 2)
    1116              :     {
    1117     21728932 :       tree *pair = &(*local_entities)[i];
    1118     21728932 :       tree d = pair[0];
    1119     21728932 :       tree n = pair[1];
    1120     21728932 :       gcc_checking_assert (d != decl);
    1121     21728932 :       if (name == n
    1122      3898001 :           && TREE_CODE (decl) == TREE_CODE (d)
    1123     25626924 :           && ctx == DECL_CONTEXT (d))
    1124              :         {
    1125          684 :           tree disc = integer_one_node;
    1126          684 :           if (DECL_DISCRIMINATOR (d))
    1127          377 :             disc = build_int_cst (TREE_TYPE (disc),
    1128          377 :                                   TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
    1129          684 :           DECL_DISCRIMINATOR (decl) = disc;
    1130              :           /* Replace the saved decl.  */
    1131          684 :           pair[0] = decl;
    1132          684 :           decl = NULL_TREE;
    1133          684 :           break;
    1134              :         }
    1135              :     }
    1136              : 
    1137       759683 :   if (decl)
    1138              :     {
    1139       758999 :       vec_safe_reserve (local_entities, 2);
    1140       758999 :       local_entities->quick_push (decl);
    1141       758999 :       local_entities->quick_push (name);
    1142              :     }
    1143       759683 : }
    1144              : 
    1145              : 
    1146              : /* True if DECL is a constrained hidden friend as per [temp.friend]/9:
    1147              : 
    1148              :    A non-template friend declaration with a requires-clause shall be a
    1149              :    definition. A friend function template with a constraint that depends on a
    1150              :    template parameter from an enclosing template shall be a definition. Such a
    1151              :    constrained friend function or function template declaration does not
    1152              :    declare the same function or function template as a declaration in any other
    1153              :    scope.
    1154              : 
    1155              :    The ABI calls this a "member-like constrained friend" and mangles it like a
    1156              :    member function to avoid collisions.  */
    1157              : 
    1158              : bool
    1159   2577381826 : member_like_constrained_friend_p (tree decl)
    1160              : {
    1161   2577381826 :   return (TREE_CODE (decl) == FUNCTION_DECL
    1162    886162029 :           && DECL_UNIQUE_FRIEND_P (decl)
    1163    293337060 :           && DECL_FRIEND_CONTEXT (decl)
    1164    128991312 :           && get_constraints (decl)
    1165     18761802 :           && CLASSTYPE_IMPLICIT_INSTANTIATION (DECL_FRIEND_CONTEXT (decl))
    1166   2586740805 :           && (!DECL_TEMPLATE_INFO (decl)
    1167      9358979 :               || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
    1168         8543 :               || (uses_outer_template_parms_in_constraints
    1169         8543 :                   (most_general_template (decl)))));
    1170              : }
    1171              : 
    1172              : /* Returns true if functions FN1 and FN2 have equivalent trailing
    1173              :    requires clauses.  */
    1174              : 
    1175              : static bool
    1176     72437109 : function_requirements_equivalent_p (tree newfn, tree oldfn)
    1177              : {
    1178              :   /* [temp.friend]/9 "Such a constrained friend function does not declare the
    1179              :      same function as a declaration in any other scope."  So no need to
    1180              :      actually compare the requirements.  */
    1181     72437109 :   if (member_like_constrained_friend_p (newfn)
    1182     72437109 :       || member_like_constrained_friend_p (oldfn))
    1183              :     return false;
    1184              : 
    1185              :   /* Compare only trailing requirements.  */
    1186     72436988 :   tree reqs1 = get_trailing_function_requirements (newfn);
    1187     72436988 :   tree reqs2 = get_trailing_function_requirements (oldfn);
    1188     72436988 :   if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
    1189              :     return false;
    1190              : 
    1191              :   /* Substitution is needed when friends are involved.  */
    1192     72301805 :   reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
    1193     72301805 :   reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
    1194              : 
    1195     72301805 :   return cp_tree_equal (reqs1, reqs2);
    1196              : }
    1197              : 
    1198              : /* Two functions of the same name correspond [basic.scope.scope] if
    1199              : 
    1200              :    + both declare functions with the same non-object-parameter-type-list,
    1201              :    equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
    1202              :    specified in [temp.friend]), and, if both are non-static members, they have
    1203              :    corresponding object parameters, or
    1204              : 
    1205              :    + both declare function templates with equivalent
    1206              :    non-object-parameter-type-lists, return types (if any), template-heads, and
    1207              :    trailing requires-clauses (if any), and, if both are non-static members,
    1208              :    they have corresponding object parameters.
    1209              : 
    1210              :    This is a subset of decls_match: it identifies declarations that cannot be
    1211              :    overloaded with one another.  This function does not consider DECL_NAME.  */
    1212              : 
    1213              : bool
    1214   1570772839 : fns_correspond (tree newdecl, tree olddecl)
    1215              : {
    1216   1570772839 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1217              :     return false;
    1218              : 
    1219   1460400798 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1220              :     {
    1221   1459037076 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1222              :         return 0;
    1223    346846305 :       newdecl = DECL_TEMPLATE_RESULT (newdecl);
    1224    346846305 :       olddecl = DECL_TEMPLATE_RESULT (olddecl);
    1225              :     }
    1226              : 
    1227    348210027 :   tree f1 = TREE_TYPE (newdecl);
    1228    348210027 :   tree f2 = TREE_TYPE (olddecl);
    1229              : 
    1230    348210027 :   int rq1 = type_memfn_rqual (f1);
    1231    348210027 :   int rq2 = type_memfn_rqual (f2);
    1232              : 
    1233              :   /* If only one is a non-static member function, ignore ref-quals.  */
    1234    348210027 :   if (TREE_CODE (f1) != TREE_CODE (f2))
    1235              :     rq1 = rq2;
    1236              :   /* Two non-static member functions have corresponding object parameters if:
    1237              :      + exactly one is an implicit object member function with no ref-qualifier
    1238              :      and the types of their object parameters ([dcl.fct]), after removing
    1239              :      top-level references, are the same, or
    1240              :      + their object parameters have the same type.  */
    1241              :   /* ??? We treat member functions of different classes as corresponding even
    1242              :      though that means the object parameters have different types.  */
    1243    348210027 :   else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
    1244            0 :     rq1 = rq2;
    1245              : 
    1246    348210027 :   bool types_match = rq1 == rq2;
    1247              : 
    1248    348210027 :   if (types_match)
    1249              :     {
    1250    348210027 :       tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1251    348210027 :       tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    1252    348210027 :       types_match = compparms (p1, p2);
    1253              :     }
    1254              : 
    1255              :   /* Two function declarations match if either has a requires-clause
    1256              :      then both have a requires-clause and their constraints-expressions
    1257              :      are equivalent.  */
    1258    348210027 :   if (types_match && flag_concepts)
    1259     42923715 :     types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1260              : 
    1261              :   return types_match;
    1262              : }
    1263              : 
    1264              : /* Subroutine of duplicate_decls: return truthvalue of whether
    1265              :    or not types of these decls match.
    1266              : 
    1267              :    For C++, we must compare the parameter list so that `int' can match
    1268              :    `int&' in a parameter position, but `int&' is not confused with
    1269              :    `const int&'.  */
    1270              : 
    1271              : int
    1272    819498658 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
    1273              : {
    1274    869816033 :   int types_match;
    1275              : 
    1276    869816033 :   if (newdecl == olddecl)
    1277              :     return 1;
    1278              : 
    1279    869697673 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1280              :     /* If the two DECLs are not even the same kind of thing, we're not
    1281              :        interested in their types.  */
    1282              :     return 0;
    1283              : 
    1284    458807573 :   gcc_assert (DECL_P (newdecl));
    1285              : 
    1286    458807573 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1287              :     {
    1288              :       /* Specializations of different templates are different functions
    1289              :          even if they have the same type.  */
    1290    303212579 :       tree t1 = (DECL_USE_TEMPLATE (newdecl)
    1291    303212579 :                  ? DECL_TI_TEMPLATE (newdecl)
    1292       648399 :                  : NULL_TREE);
    1293    303212579 :       tree t2 = (DECL_USE_TEMPLATE (olddecl)
    1294    303212579 :                  ? DECL_TI_TEMPLATE (olddecl)
    1295      4135566 :                  : NULL_TREE);
    1296    303212579 :       if (t1 != t2)
    1297              :         return 0;
    1298              : 
    1299    299725329 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1300    299725329 :           && ! (DECL_EXTERN_C_P (newdecl)
    1301      3003574 :                 && DECL_EXTERN_C_P (olddecl)))
    1302              :         return 0;
    1303              : 
    1304              :       /* A new declaration doesn't match a built-in one unless it
    1305              :          is also extern "C".  */
    1306    277891963 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1307    277891963 :           && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
    1308              :         return 0;
    1309              : 
    1310    277229954 :       tree f1 = TREE_TYPE (newdecl);
    1311    277229954 :       tree f2 = TREE_TYPE (olddecl);
    1312    277229954 :       if (TREE_CODE (f1) != TREE_CODE (f2))
    1313              :         return 0;
    1314              : 
    1315              :       /* A declaration with deduced return type should use its pre-deduction
    1316              :          type for declaration matching.  */
    1317    277051342 :       tree r2 = fndecl_declared_return_type (olddecl);
    1318    277051342 :       tree r1 = fndecl_declared_return_type (newdecl);
    1319              : 
    1320              :       /* For memchr et al, allow const void* return type (as specified by C++)
    1321              :          when we expect void* (as in C).  */
    1322    277051342 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1323      6643342 :           && DECL_EXTERN_C_P (olddecl)
    1324      4083939 :           && !same_type_p (r1, r2)
    1325           70 :           && TREE_CODE (r1) == POINTER_TYPE
    1326           15 :           && TREE_CODE (r2) == POINTER_TYPE
    1327    277051354 :           && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
    1328              :         r2 = r1;
    1329              : 
    1330    277051342 :       tree p1 = TYPE_ARG_TYPES (f1);
    1331    277051342 :       tree p2 = TYPE_ARG_TYPES (f2);
    1332              : 
    1333    277051342 :       if (same_type_p (r1, r2))
    1334              :         {
    1335    177503976 :           if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
    1336    177503944 :               && fndecl_built_in_p (olddecl))
    1337              :             {
    1338           50 :               types_match = self_promoting_args_p (p1);
    1339           50 :               if (p1 == void_list_node)
    1340            3 :                 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
    1341              :             }
    1342              :           else
    1343    177503838 :             types_match =
    1344    177503838 :               compparms (p1, p2)
    1345     29996655 :               && type_memfn_rqual (f1) == type_memfn_rqual (f2)
    1346    207500097 :               && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
    1347      1253083 :                   || comp_type_attributes (TREE_TYPE (newdecl),
    1348      1253083 :                                            TREE_TYPE (olddecl)) != 0);
    1349              :         }
    1350              :       else
    1351              :         types_match = 0;
    1352              : 
    1353              :       /* Two function declarations match if either has a requires-clause
    1354              :          then both have a requires-clause and their constraints-expressions
    1355              :          are equivalent.  */
    1356     29996288 :       if (types_match && flag_concepts)
    1357     29513362 :         types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1358              : 
    1359              :       /* The decls dont match if they correspond to two different versions
    1360              :          of the same function.   Disallow extern "C" functions to be
    1361              :          versions for now.  */
    1362     29996288 :       if (types_match
    1363     29794148 :           && !DECL_EXTERN_C_P (newdecl)
    1364     21423718 :           && !DECL_EXTERN_C_P (olddecl)
    1365     51416235 :           && disjoint_version_decls (newdecl, olddecl))
    1366              :         {
    1367         8880 :           if (record_versions)
    1368         8793 :             maybe_version_functions (newdecl, olddecl);
    1369              :           return 0;
    1370              :         }
    1371              :     }
    1372    155594994 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1373              :     {
    1374    153779202 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1375              :         return 0;
    1376              : 
    1377     50318954 :       tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1378     50318954 :       tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1379              : 
    1380     50318954 :       if (TREE_CODE (newres) != TREE_CODE (oldres))
    1381              :         return 0;
    1382              : 
    1383              :       /* Two template types match if they are the same. Otherwise, compare
    1384              :          the underlying declarations.  */
    1385     50318945 :       if (TREE_CODE (newres) == TYPE_DECL)
    1386         1570 :         types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
    1387              :       else
    1388              :         types_match = decls_match (newres, oldres);
    1389              :     }
    1390              :   else
    1391              :     {
    1392              :       /* Need to check scope for variable declaration (VAR_DECL).
    1393              :          For typedef (TYPE_DECL), scope is ignored.  */
    1394      1815792 :       if (VAR_P (newdecl)
    1395      1216167 :           && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1396              :           /* [dcl.link]
    1397              :              Two declarations for an object with C language linkage
    1398              :              with the same name (ignoring the namespace that qualify
    1399              :              it) that appear in different namespace scopes refer to
    1400              :              the same object.  */
    1401      2007738 :           && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
    1402              :         return 0;
    1403              : 
    1404      1623894 :       if (TREE_TYPE (newdecl) == error_mark_node)
    1405            0 :         types_match = TREE_TYPE (olddecl) == error_mark_node;
    1406      1623894 :       else if (TREE_TYPE (olddecl) == NULL_TREE)
    1407            0 :         types_match = TREE_TYPE (newdecl) == NULL_TREE;
    1408      1623894 :       else if (TREE_TYPE (newdecl) == NULL_TREE)
    1409              :         types_match = 0;
    1410              :       else
    1411      1623894 :         types_match = comptypes (TREE_TYPE (newdecl),
    1412      1623894 :                                  TREE_TYPE (olddecl),
    1413              :                                  COMPARE_REDECLARATION);
    1414              :     }
    1415              : 
    1416              :   return types_match;
    1417              : }
    1418              : 
    1419              : /* Mark DECL as versioned if it isn't already.  */
    1420              : 
    1421              : void
    1422        17676 : maybe_mark_function_versioned (tree decl)
    1423              : {
    1424        17676 :   if (!DECL_FUNCTION_VERSIONED (decl))
    1425              :     {
    1426              :       /* We need to insert function version now to make sure the correct
    1427              :          pre-mangled assembler name is recorded.  */
    1428         1068 :       cgraph_node *node = cgraph_node::get_create (decl);
    1429              : 
    1430         1068 :       if (!node->function_version ())
    1431         1068 :         node->insert_new_function_version ();
    1432              : 
    1433         1068 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    1434              :       /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
    1435              :          to include the version marker.  */
    1436         1068 :       if (DECL_ASSEMBLER_NAME_SET_P (decl))
    1437         1062 :         mangle_decl (decl);
    1438              :     }
    1439        17676 : }
    1440              : 
    1441              : /* NEWDECL and OLDDECL have identical signatures.  If they are
    1442              :    different versions adjust them, record function versions, and return
    1443              :    true.  */
    1444              : 
    1445              : bool
    1446       207538 : maybe_version_functions (tree newdecl, tree olddecl)
    1447              : {
    1448       207538 :   if (!disjoint_version_decls (newdecl, olddecl))
    1449              :     return false;
    1450              : 
    1451         8820 :   maybe_mark_function_versioned (olddecl);
    1452         8820 :   if (DECL_LOCAL_DECL_P (olddecl))
    1453              :     {
    1454           18 :       olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
    1455           18 :       maybe_mark_function_versioned (olddecl);
    1456              :     }
    1457              : 
    1458         8820 :   maybe_mark_function_versioned (newdecl);
    1459         8820 :   if (DECL_LOCAL_DECL_P (newdecl))
    1460              :     {
    1461              :       /* Unfortunately, we can get here before pushdecl naturally calls
    1462              :          push_local_extern_decl_alias, so we need to call it directly.  */
    1463           18 :       if (!DECL_LOCAL_DECL_ALIAS (newdecl))
    1464            6 :         push_local_extern_decl_alias (newdecl);
    1465           18 :       newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
    1466           18 :       maybe_mark_function_versioned (newdecl);
    1467              :     }
    1468              : 
    1469              :   /* Add the new version to the function version structure.  */
    1470         8820 :   cgraph_node *fn_node = cgraph_node::get_create (olddecl);
    1471         8820 :   cgraph_function_version_info *fn_v = fn_node->function_version ();
    1472         8820 :   if (!fn_v)
    1473           15 :     fn_v = fn_node->insert_new_function_version ();
    1474              : 
    1475         8820 :   cgraph_node::add_function_version (fn_v, newdecl);
    1476              : 
    1477         8820 :   return true;
    1478              : }
    1479              : 
    1480              : /* If NEWDECL is `static' and an `extern' was seen previously,
    1481              :    warn about it.  OLDDECL is the previous declaration.
    1482              : 
    1483              :    Note that this does not apply to the C++ case of declaring
    1484              :    a variable `extern const' and then later `const'.
    1485              : 
    1486              :    Don't complain about built-in functions, since they are beyond
    1487              :    the user's control.  */
    1488              : 
    1489              : void
    1490     20294285 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
    1491              : {
    1492     20294285 :   if (TREE_CODE (newdecl) == TYPE_DECL
    1493              :       || TREE_CODE (newdecl) == TEMPLATE_DECL
    1494              :       || TREE_CODE (newdecl) == CONST_DECL
    1495              :       || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1496     20294273 :     return;
    1497              : 
    1498              :   /* Don't get confused by static member functions; that's a different
    1499              :      use of `static'.  */
    1500              :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    1501     15601504 :       && DECL_STATIC_FUNCTION_P (newdecl))
    1502              :     return;
    1503              : 
    1504              :   /* If the old declaration was `static', or the new one isn't, then
    1505              :      everything is OK.  */
    1506     15934236 :   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
    1507              :     return;
    1508              : 
    1509              :   /* It's OK to declare a builtin function as `static'.  */
    1510           12 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1511           12 :       && DECL_ARTIFICIAL (olddecl))
    1512              :     return;
    1513              : 
    1514           12 :   auto_diagnostic_group d;
    1515           12 :   if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1516              :                  "%qD was declared %<extern%> and later %<static%>", newdecl))
    1517           12 :     inform (DECL_SOURCE_LOCATION (olddecl),
    1518              :             "previous declaration of %qD", olddecl);
    1519           12 : }
    1520              : 
    1521              : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
    1522              :    function templates.  If their exception specifications do not
    1523              :    match, issue a diagnostic.  */
    1524              : 
    1525              : static void
    1526     19731073 : check_redeclaration_exception_specification (tree new_decl,
    1527              :                                              tree old_decl)
    1528              : {
    1529     19731073 :   tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1530     19731073 :   tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1531              : 
    1532              :   /* Two default specs are equivalent, don't force evaluation.  */
    1533      7621515 :   if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
    1534     19876685 :       && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
    1535              :     return;
    1536              : 
    1537     19721150 :   if (!type_dependent_expression_p (old_decl))
    1538              :     {
    1539     12104917 :       maybe_instantiate_noexcept (new_decl);
    1540     12104917 :       maybe_instantiate_noexcept (old_decl);
    1541              :     }
    1542     19721150 :   new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1543     19721150 :   old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1544              : 
    1545              :   /* [except.spec]
    1546              : 
    1547              :      If any declaration of a function has an exception-specification,
    1548              :      all declarations, including the definition and an explicit
    1549              :      specialization, of that function shall have an
    1550              :      exception-specification with the same set of type-ids.  */
    1551     19721150 :   if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
    1552     15760827 :       && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
    1553     35481892 :       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
    1554              :     {
    1555          329 :       const char *const msg
    1556              :         = G_("declaration of %qF has a different exception specifier");
    1557          329 :       bool complained = true;
    1558          329 :       location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
    1559          329 :       auto_diagnostic_group d;
    1560              : 
    1561              :       /* Be permissive about C++98 vs C++11 operator new declarations.  */
    1562          658 :       bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
    1563            1 :                          && CP_DECL_CONTEXT (new_decl) == global_namespace
    1564          331 :                          && (nothrow_spec_p (new_exceptions)
    1565            1 :                              == nothrow_spec_p (old_exceptions)));
    1566              : 
    1567          329 :       if (DECL_IN_SYSTEM_HEADER (old_decl)
    1568          329 :           && (global_new || DECL_EXTERN_C_P (old_decl)))
    1569              :         /* Don't fuss about the C library; the C library functions are not
    1570              :            specified to have exception specifications (just behave as if they
    1571              :            have them), but some implementations include them.  */
    1572          233 :         complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
    1573           96 :       else if (!flag_exceptions)
    1574              :         /* We used to silently permit mismatched eh specs with
    1575              :            -fno-exceptions, so only complain if -pedantic.  */
    1576            3 :         complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
    1577           93 :       else if (!new_exceptions || global_new)
    1578              :         /* Reduce to pedwarn for omitted exception specification.  No warning
    1579              :            flag for this; silence the warning by correcting the code.  */
    1580           18 :         complained = pedwarn (new_loc, 0, msg, new_decl);
    1581              :       else
    1582           75 :         error_at (new_loc, msg, new_decl);
    1583              : 
    1584          329 :       if (complained)
    1585           99 :         inform (DECL_SOURCE_LOCATION (old_decl),
    1586              :                 "from previous declaration %qF", old_decl);
    1587              : 
    1588              :       /* Copy the old exception specification if new_decl has none.  Unless the
    1589              :          old decl is extern "C", as obscure code might depend on the type of
    1590              :          the new declaration (e.g. noexcept-type19.C).  */
    1591          329 :       if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
    1592           17 :         TREE_TYPE (new_decl)
    1593           34 :           = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
    1594          329 :     }
    1595              : }
    1596              : 
    1597              : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
    1598              :    Otherwise issue diagnostics.  */
    1599              : 
    1600              : bool
    1601     20294811 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
    1602              : {
    1603     20294811 :   old_decl = STRIP_TEMPLATE (old_decl);
    1604     20294811 :   new_decl = STRIP_TEMPLATE (new_decl);
    1605     20294811 :   if (!VAR_OR_FUNCTION_DECL_P (old_decl)
    1606     20243407 :       || !VAR_OR_FUNCTION_DECL_P (new_decl))
    1607              :     return true;
    1608     20243407 :   if (DECL_DECLARED_CONSTEXPR_P (old_decl)
    1609     20243407 :       == DECL_DECLARED_CONSTEXPR_P (new_decl))
    1610              :     {
    1611     20092103 :       if (TREE_CODE (old_decl) != FUNCTION_DECL)
    1612              :         return true;
    1613     39462976 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1614     19731488 :           == DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1615              :         return true;
    1616              :     }
    1617       151310 :   if (TREE_CODE (old_decl) == FUNCTION_DECL)
    1618              :     {
    1619              :       /* With -fimplicit-constexpr, ignore changes in the constexpr
    1620              :          keyword.  */
    1621           71 :       if (flag_implicit_constexpr
    1622           71 :           && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
    1623            0 :               == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
    1624              :         return true;
    1625           71 :       if (fndecl_built_in_p (old_decl))
    1626              :         {
    1627              :           /* Hide a built-in declaration.  */
    1628            0 :           DECL_DECLARED_CONSTEXPR_P (old_decl)
    1629            0 :             = DECL_DECLARED_CONSTEXPR_P (new_decl);
    1630            0 :           if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1631            0 :             SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
    1632              :           return true;
    1633              :         }
    1634              :       /* 7.1.5 [dcl.constexpr]
    1635              :          Note: An explicit specialization can differ from the template
    1636              :          declaration with respect to the constexpr specifier.  */
    1637           71 :       if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
    1638           71 :           && DECL_TEMPLATE_SPECIALIZATION (new_decl))
    1639              :         return true;
    1640              : 
    1641           42 :       const char *kind = "constexpr";
    1642           42 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1643           72 :           || DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1644              :         kind = "consteval";
    1645           42 :       auto_diagnostic_group d;
    1646           42 :       error_at (DECL_SOURCE_LOCATION (new_decl),
    1647              :                 "redeclaration %qD differs in %qs "
    1648              :                 "from previous declaration", new_decl,
    1649              :                 kind);
    1650           42 :       inform (DECL_SOURCE_LOCATION (old_decl),
    1651              :               "previous declaration %qD", old_decl);
    1652           42 :       return false;
    1653           42 :     }
    1654              :   return true;
    1655              : }
    1656              : 
    1657              : /* DECL is a redeclaration of a function or function template.  If
    1658              :    it does have default arguments issue a diagnostic.  Note: this
    1659              :    function is used to enforce the requirements in C++11 8.3.6 about
    1660              :    no default arguments in redeclarations.  */
    1661              : 
    1662              : static void
    1663     11816958 : check_redeclaration_no_default_args (tree decl)
    1664              : {
    1665     11816958 :   gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
    1666              : 
    1667     11816958 :   for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
    1668     34739186 :        t && t != void_list_node; t = TREE_CHAIN (t))
    1669     22922285 :     if (TREE_PURPOSE (t))
    1670              :       {
    1671           57 :         permerror (DECL_SOURCE_LOCATION (decl),
    1672              :                    "redeclaration of %q#D may not have default "
    1673              :                    "arguments", decl);
    1674           57 :         return;
    1675              :       }
    1676              : }
    1677              : 
    1678              : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
    1679              :    in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
    1680              :    the TEMPLATE_DECLs in case of function templates).  This function is used
    1681              :    to enforce the final part of C++17 11.3.6/4, about a single declaration:
    1682              :    "If a friend declaration specifies a default argument expression, that
    1683              :    declaration shall be a definition and shall be the only declaration of
    1684              :    the function or function template in the translation unit."  */
    1685              : 
    1686              : static void
    1687      7385875 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
    1688              : {
    1689     14053102 :   if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
    1690              :     return;
    1691              : 
    1692      1851673 :   for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
    1693      1851673 :          t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1694      4896589 :        t1 && t1 != void_list_node;
    1695      3044916 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1696      4328987 :     if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
    1697      8689332 :         || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
    1698              :       {
    1699           36 :         auto_diagnostic_group d;
    1700           36 :         if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1701              :                        "friend declaration of %q#D specifies default "
    1702              :                        "arguments and isn%'t the only declaration", newdecl))
    1703           36 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1704              :                   "previous declaration of %q#D", olddecl);
    1705           36 :         return;
    1706           36 :       }
    1707              : }
    1708              : 
    1709              : /* Merge tree bits that correspond to attributes noreturn, nothrow,
    1710              :    const,  malloc, and pure from NEWDECL with those of OLDDECL.  */
    1711              : 
    1712              : static void
    1713     19165478 : merge_attribute_bits (tree newdecl, tree olddecl)
    1714              : {
    1715     19165478 :   TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    1716     19165478 :   TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
    1717     19165478 :   TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
    1718     19165478 :   TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
    1719     19165478 :   TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    1720     19165478 :   TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
    1721     19165478 :   DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    1722     19165478 :   DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
    1723     19165478 :   DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    1724     19165478 :   DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
    1725     19165478 :   DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
    1726     19165478 :   DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
    1727     19165478 :   TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
    1728     19165478 :   TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
    1729     19165478 :   TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
    1730     19165478 :   TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
    1731     19165478 :   DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    1732     19165478 :   DECL_NO_LIMIT_STACK (olddecl) |= DECL_NO_LIMIT_STACK (newdecl);
    1733     38330956 :   DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    1734     19165478 :     |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    1735     38330956 :   DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl)
    1736     19165478 :     |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl);
    1737     19165478 :   DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
    1738     19165478 :   DECL_IS_NOVOPS (olddecl) |= DECL_IS_NOVOPS (newdecl);
    1739     19165478 : }
    1740              : 
    1741              : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)                   \
    1742              :                           && lookup_attribute ("gnu_inline",          \
    1743              :                                                DECL_ATTRIBUTES (fn)))
    1744              : 
    1745              : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
    1746              :    ambiguates olddecl.  Returns true if an error occurs.  */
    1747              : 
    1748              : static bool
    1749    149646647 : duplicate_function_template_decls (tree newdecl, tree olddecl)
    1750              : {
    1751    149646647 :   tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1752    149646647 :   tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1753              :   /* Function template declarations can be differentiated by parameter
    1754              :      and return type.  */
    1755    149646647 :   if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
    1756    149646647 :                  TYPE_ARG_TYPES (TREE_TYPE (newres)))
    1757    149646647 :        && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
    1758              :                        TREE_TYPE (TREE_TYPE (olddecl))))
    1759              :     {
    1760              :       /* ... and also by their template-heads and requires-clauses.  */
    1761         7381 :       if (template_heads_equivalent_p (newdecl, olddecl)
    1762         7381 :           && function_requirements_equivalent_p (newres, oldres))
    1763              :         {
    1764            0 :           auto_diagnostic_group d;
    1765            0 :           error ("ambiguating new declaration %q+#D", newdecl);
    1766            0 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1767              :                   "old declaration %q#D", olddecl);
    1768            0 :           return true;
    1769            0 :         }
    1770              : 
    1771              :       /* FIXME: The types are the same but the are differences
    1772              :          in either the template heads or function requirements.
    1773              :          We should be able to diagnose a set of common errors
    1774              :          stemming from these declarations. For example:
    1775              : 
    1776              :            template<typename T> requires C void f(...);
    1777              :            template<typename T> void f(...) requires C;
    1778              : 
    1779              :          These are functionally equivalent but not equivalent.  */
    1780              :     }
    1781              : 
    1782              :   return false;
    1783              : }
    1784              : 
    1785              : /* OLD_PARMS is the innermost set of template parameters for some template
    1786              :    declaration, and NEW_PARMS is the corresponding set of template parameters
    1787              :    for a redeclaration of that template.  Merge the default arguments within
    1788              :    these two sets of parameters.  OLDDECL is the origin of OLD_PARMS.  */
    1789              : 
    1790              : bool
    1791      9244979 : merge_default_template_args (tree new_parms, tree old_parms, tree olddecl)
    1792              : {
    1793      9244979 :   bool class_p = DECL_IMPLICIT_TYPEDEF_P (STRIP_TEMPLATE (olddecl));
    1794              : 
    1795      9244979 :   gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
    1796              :                        == TREE_VEC_LENGTH (old_parms));
    1797     26106061 :   for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
    1798              :     {
    1799     16861106 :       tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
    1800     16861106 :       tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
    1801     16861106 :       tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
    1802     16861106 :       tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
    1803     16861106 :       if (error_operand_p (new_parm) || error_operand_p (old_parm))
    1804              :         return false;
    1805       238053 :       if (new_default != NULL_TREE && old_default != NULL_TREE
    1806     16862208 :           && !(redefinable_import_p (olddecl)
    1807          542 :                && cp_tree_equal (new_default, old_default)))
    1808              :         {
    1809           21 :           auto_diagnostic_group d;
    1810           21 :           error ("redefinition of default argument for %q+#D", new_parm);
    1811           21 :           inform (DECL_SOURCE_LOCATION (old_parm),
    1812              :                   "original definition appeared here");
    1813           21 :           return false;
    1814           21 :         }
    1815     16861082 :       else if (new_default != NULL_TREE)
    1816              :         /* Update the previous template parameters (which are the ones
    1817              :            that will really count) with the new default value.  */
    1818       238032 :         old_default = new_default;
    1819     16623050 :       else if (class_p && old_default != NULL_TREE)
    1820              :         /* Update the new parameters, too; they'll be used as the
    1821              :            parameters for any members.  */
    1822      1030960 :         new_default = old_default;
    1823              :     }
    1824              :   return true;
    1825              : }
    1826              : 
    1827              : /* Helper function for duplicate_decls and push_local_extern_decl_alias.
    1828              :    Merge parameter attributes and names between NEWDECL and OLDDECL.
    1829              :    NEW_DEFINES_FUNCTION and TYPES_MATCH argument like variables in
    1830              :    duplicate_decls, EXTERN_ALIAS false for duplicate_decls and true for
    1831              :    push_local_extern_decl_alias.  */
    1832              : 
    1833              : void
    1834     15601693 : merge_decl_arguments (tree newdecl, tree olddecl, bool new_defines_function,
    1835              :                       bool types_match, bool extern_alias)
    1836              : {
    1837     15601693 :   tree oldarg, newarg, type = NULL_TREE;
    1838     15601693 :   tree first_user_parm = NULL_TREE;
    1839     15601693 :   if (extern_alias)
    1840          189 :     first_user_parm = FUNCTION_FIRST_USER_PARM (newdecl);
    1841     15601693 :   for (oldarg = DECL_ARGUMENTS (olddecl), newarg = DECL_ARGUMENTS (newdecl);
    1842     43731336 :        oldarg && newarg;
    1843     28129643 :        oldarg = DECL_CHAIN (oldarg), newarg = DECL_CHAIN (newarg))
    1844              :     {
    1845     28129643 :       DECL_ATTRIBUTES (newarg)
    1846     28129643 :         = (*targetm.merge_decl_attributes) (oldarg, newarg);
    1847     28129643 :       if (lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (newarg))
    1848     28129712 :           && !lookup_attribute (NULL, "indeterminate",
    1849           69 :                                 DECL_ATTRIBUTES (oldarg)))
    1850              :         {
    1851           18 :           auto_diagnostic_group d;
    1852           18 :           error_at (DECL_SOURCE_LOCATION (newarg),
    1853              :                     "%<indeterminate%> attribute not specified for parameter "
    1854              :                     "%qD on the first declaration of its function", newarg);
    1855           18 :           inform (DECL_SOURCE_LOCATION (oldarg), "earlier declaration");
    1856           18 :         }
    1857              :       /* ??? Should attributes propagate out from a block extern?  If so,
    1858              :          we should do that for the function itself, not just parameters.  */
    1859     28129643 :       if (!extern_alias || flag_reflection)
    1860     28129476 :         DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    1861     28129643 :       if (!flag_reflection)
    1862     27712105 :         continue;
    1863              :       /* For extern_alias set DECL_HAS_DEFAULT_ARGUMENT_P on oldarg
    1864              :          if the local extern has a default argument for that parameter.  */
    1865       417538 :       if (extern_alias)
    1866              :         {
    1867           36 :           if (newarg == first_user_parm)
    1868           12 :             type = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1869           24 :           else if (type)
    1870           24 :             type = TREE_CHAIN (type);
    1871           72 :           if (type && TREE_PURPOSE (type))
    1872            4 :             DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
    1873              :         }
    1874              :       else
    1875              :         {
    1876              :           /* Otherwise propagate the flag.  */
    1877       417502 :           if (DECL_HAS_DEFAULT_ARGUMENT_P (oldarg))
    1878            0 :             DECL_HAS_DEFAULT_ARGUMENT_P (newarg) = 1;
    1879       417502 :           if (DECL_HAS_DEFAULT_ARGUMENT_P (newarg))
    1880            0 :             DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
    1881              :         }
    1882              :       /* Merge names for std::meta::has_identifier and
    1883              :          std::meta::{,u8}identifier_of purposes.  If they are different and
    1884              :          both oldarg and newarg are named, add flag to force that
    1885              :          std::meta::has_identifier returns false.  If one is named and one is
    1886              :          unnamed, if neither is a olddecl nor newdecl is definition, propagate
    1887              :          DECL_NAME to both.  Otherwise stash the old name into "old parm name"
    1888              :          artificial attribute.  */
    1889       417538 :       if (DECL_NAME (oldarg) != DECL_NAME (newarg))
    1890              :         {
    1891        46654 :           if (DECL_NAME (oldarg) && DECL_NAME (newarg))
    1892              :             {
    1893              :               /* Different names.  */
    1894        10500 :               MULTIPLE_NAMES_PARM_P (oldarg) = 1;
    1895        10500 :               MULTIPLE_NAMES_PARM_P (newarg) = 1;
    1896              :             }
    1897        36154 :           else if (!new_defines_function
    1898        36154 :                    && types_match
    1899        36154 :                    && DECL_INITIAL (olddecl) == NULL_TREE)
    1900              :             {
    1901              :               /* For 2 non-definitions with matching types, one is named and
    1902              :                  one unnamed, propagate name to both.  */
    1903         6840 :               if (DECL_NAME (oldarg))
    1904         5736 :                 DECL_NAME (newarg) = DECL_NAME (oldarg);
    1905              :               else
    1906         1104 :                 DECL_NAME (oldarg) = DECL_NAME (newarg);
    1907              :             }
    1908              :           /* Depending on which PARM_DECL we'll keep, look at the other
    1909              :              PARM_DECL's name.  */
    1910        29314 :           else if (tree name = ((new_defines_function || !types_match)
    1911        29314 :                                 ? DECL_NAME (oldarg) : DECL_NAME (newarg)))
    1912              :             {
    1913          240 :               tree opn = lookup_attribute ("old parm name",
    1914          240 :                                            DECL_ATTRIBUTES (oldarg));
    1915          240 :               if (opn)
    1916              :                 {
    1917            4 :                   if (TREE_VALUE (TREE_VALUE (opn)) == name)
    1918              :                     /* Name already in "old parm name" attribute.  */;
    1919              :                   else
    1920              :                     {
    1921              :                       /* Different names.  */
    1922            0 :                       MULTIPLE_NAMES_PARM_P (oldarg) = 1;
    1923            0 :                       MULTIPLE_NAMES_PARM_P (newarg) = 1;
    1924              :                     }
    1925              :                 }
    1926              :               else
    1927              :                 {
    1928              :                   /* Save name into attribute.  */
    1929          236 :                   DECL_ATTRIBUTES (newarg)
    1930          236 :                     = tree_cons (get_identifier ("old parm name"),
    1931              :                                  tree_cons (NULL_TREE, name, NULL_TREE),
    1932          236 :                                  DECL_ATTRIBUTES (newarg));
    1933          236 :                   DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    1934              :                 }
    1935              :             }
    1936        29074 :           else if (extern_alias)
    1937            2 :             DECL_NAME (newarg) = DECL_NAME (oldarg);
    1938              :         }
    1939              :     }
    1940     15601693 : }
    1941              : 
    1942              : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
    1943              :    If the redeclaration is invalid, a diagnostic is issued, and the
    1944              :    error_mark_node is returned.  Otherwise, OLDDECL is returned.
    1945              : 
    1946              :    If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
    1947              :    returned.
    1948              : 
    1949              :    HIDING is true if the new decl is being hidden.  WAS_HIDDEN is true
    1950              :    if the old decl was hidden.
    1951              : 
    1952              :    Hidden decls can be anticipated builtins, injected friends, or
    1953              :    (coming soon) injected from a local-extern decl.   */
    1954              : 
    1955              : tree
    1956    335292421 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
    1957              : {
    1958    335438169 :   unsigned olddecl_uid = DECL_UID (olddecl);
    1959    335438169 :   int types_match = 0;
    1960    335438169 :   int new_defines_function = 0;
    1961    335438169 :   tree new_template_info;
    1962    335438169 :   location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
    1963    335438169 :   location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
    1964              : 
    1965    335438169 :   if (newdecl == olddecl)
    1966              :     return olddecl;
    1967              : 
    1968    334596322 :   types_match = decls_match (newdecl, olddecl);
    1969              : 
    1970              :   /* If either the type of the new decl or the type of the old decl is an
    1971              :      error_mark_node, then that implies that we have already issued an
    1972              :      error (earlier) for some bogus type specification, and in that case,
    1973              :      it is rather pointless to harass the user with yet more error message
    1974              :      about the same declaration, so just pretend the types match here.  */
    1975    334596322 :   if (TREE_TYPE (newdecl) == error_mark_node
    1976    334596322 :       || TREE_TYPE (olddecl) == error_mark_node)
    1977              :     return error_mark_node;
    1978              : 
    1979    334596293 :   bool mod_redefinable = redefinable_import_p (olddecl);
    1980              : 
    1981              :   /* Check for redeclaration and other discrepancies.  */
    1982    334596293 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1983    334596293 :       && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    1984              :     {
    1985      6409818 :       if (TREE_CODE (newdecl) != FUNCTION_DECL)
    1986              :         {
    1987              :           /* Avoid warnings redeclaring built-ins which have not been
    1988              :              explicitly declared.  */
    1989       196457 :           if (was_hidden)
    1990              :             {
    1991       196299 :               if (TREE_PUBLIC (newdecl)
    1992       196299 :                   && CP_DECL_CONTEXT (newdecl) == global_namespace)
    1993           18 :                 warning_at (newdecl_loc,
    1994           18 :                             OPT_Wbuiltin_declaration_mismatch,
    1995              :                             "built-in function %qD declared as non-function",
    1996              :                             newdecl);
    1997              :               return NULL_TREE;
    1998              :             }
    1999              : 
    2000              :           /* If you declare a built-in or predefined function name as static,
    2001              :              the old definition is overridden, but optionally warn this was a
    2002              :              bad choice of name.  */
    2003          158 :           if (! TREE_PUBLIC (newdecl))
    2004              :             {
    2005          158 :               warning_at (newdecl_loc,
    2006          158 :                           OPT_Wshadow,
    2007          158 :                           fndecl_built_in_p (olddecl)
    2008              :                           ? G_("shadowing built-in function %q#D")
    2009              :                           : G_("shadowing library function %q#D"), olddecl);
    2010              :               /* Discard the old built-in function.  */
    2011          158 :               return NULL_TREE;
    2012              :             }
    2013              :           /* If the built-in is not ansi, then programs can override
    2014              :              it even globally without an error.  */
    2015            0 :           else if (! fndecl_built_in_p (olddecl))
    2016            0 :             warning_at (newdecl_loc, 0,
    2017              :                         "library function %q#D redeclared as non-function %q#D",
    2018              :                         olddecl, newdecl);
    2019              :           else
    2020            0 :             error_at (newdecl_loc,
    2021              :                       "declaration of %q#D conflicts with built-in "
    2022              :                       "declaration %q#D", newdecl, olddecl);
    2023              :           return NULL_TREE;
    2024              :         }
    2025      6213361 :       else if (!types_match)
    2026              :         {
    2027              :           /* Avoid warnings redeclaring built-ins which have not been
    2028              :              explicitly declared.  */
    2029      2253038 :           if (was_hidden)
    2030              :             {
    2031       807958 :               tree t1, t2;
    2032              : 
    2033              :               /* A new declaration doesn't match a built-in one unless it
    2034              :                  is also extern "C".  */
    2035       807958 :               gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
    2036       807958 :               gcc_assert (DECL_EXTERN_C_P (olddecl));
    2037       807958 :               if (!DECL_EXTERN_C_P (newdecl))
    2038              :                 return NULL_TREE;
    2039              : 
    2040       145949 :               for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2041       145949 :                    t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    2042       251039 :                    t1 || t2;
    2043       105090 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    2044              :                 {
    2045       251021 :                   if (!t1 || !t2)
    2046              :                     break;
    2047              :                   /* FILE, tm types are not known at the time
    2048              :                      we create the builtins.  */
    2049       772809 :                   for (unsigned i = 0;
    2050      1023668 :                        i < sizeof (builtin_structptr_types)
    2051              :                            / sizeof (builtin_structptr_type);
    2052              :                        ++i)
    2053       918572 :                     if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
    2054              :                       {
    2055       145763 :                         tree t = TREE_VALUE (t1);
    2056              : 
    2057       145763 :                         if (TYPE_PTR_P (t)
    2058       291526 :                             && TYPE_IDENTIFIER (TREE_TYPE (t))
    2059       145763 :                             == get_identifier (builtin_structptr_types[i].str)
    2060       291511 :                             && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
    2061              :                           {
    2062       145748 :                             tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    2063              : 
    2064       145748 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl))
    2065       145748 :                               = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
    2066       145748 :                             types_match = decls_match (newdecl, olddecl);
    2067       145748 :                             if (types_match)
    2068              :                               return duplicate_decls (newdecl, olddecl,
    2069              :                                                       hiding, was_hidden);
    2070            0 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
    2071              :                           }
    2072           15 :                         goto next_arg;
    2073              :                       }
    2074              : 
    2075       105096 :                   if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    2076              :                     break;
    2077       105090 :                 next_arg:;
    2078              :                 }
    2079              : 
    2080          201 :               warning_at (newdecl_loc,
    2081          201 :                           OPT_Wbuiltin_declaration_mismatch,
    2082              :                           "declaration of %q#D conflicts with built-in "
    2083              :                           "declaration %q#D", newdecl, olddecl);
    2084              :             }
    2085      1445080 :           else if ((DECL_EXTERN_C_P (newdecl)
    2086           15 :                     && DECL_EXTERN_C_P (olddecl))
    2087      2890145 :                    || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2088      1445065 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
    2089              :             {
    2090              :               /* Don't really override olddecl for __* prefixed builtins
    2091              :                  except for __[^b]*_chk, the compiler might be using those
    2092              :                  explicitly.  */
    2093           15 :               if (fndecl_built_in_p (olddecl))
    2094              :                 {
    2095           15 :                   tree id = DECL_NAME (olddecl);
    2096           15 :                   const char *name = IDENTIFIER_POINTER (id);
    2097           15 :                   size_t len;
    2098              : 
    2099           15 :                   if (name[0] == '_'
    2100           15 :                       && name[1] == '_'
    2101           30 :                       && (startswith (name + 2, "builtin_")
    2102            6 :                           || (len = strlen (name)) <= strlen ("___chk")
    2103            6 :                           || memcmp (name + len - strlen ("_chk"),
    2104              :                                      "_chk", strlen ("_chk") + 1) != 0))
    2105              :                     {
    2106           15 :                       if (DECL_INITIAL (newdecl))
    2107              :                         {
    2108            6 :                           error_at (newdecl_loc,
    2109              :                                     "definition of %q#D ambiguates built-in "
    2110              :                                     "declaration %q#D", newdecl, olddecl);
    2111            6 :                           return error_mark_node;
    2112              :                         }
    2113            9 :                       auto_diagnostic_group d;
    2114            9 :                       if (permerror (newdecl_loc,
    2115              :                                      "new declaration %q#D ambiguates built-in"
    2116              :                                      " declaration %q#D", newdecl, olddecl)
    2117            9 :                           && flag_permissive)
    2118            3 :                         inform (newdecl_loc,
    2119              :                                 "ignoring the %q#D declaration", newdecl);
    2120            9 :                       return flag_permissive ? olddecl : error_mark_node;
    2121            9 :                     }
    2122              :                 }
    2123              : 
    2124              :               /* A near match; override the builtin.  */
    2125              : 
    2126            0 :               if (TREE_PUBLIC (newdecl))
    2127            0 :                 warning_at (newdecl_loc,
    2128            0 :                             OPT_Wbuiltin_declaration_mismatch,
    2129              :                             "new declaration %q#D ambiguates built-in "
    2130              :                             "declaration %q#D", newdecl, olddecl);
    2131              :               else
    2132            0 :                 warning (OPT_Wshadow,
    2133              :                          fndecl_built_in_p (olddecl)
    2134              :                          ? G_("shadowing built-in function %q#D")
    2135              :                          : G_("shadowing library function %q#D"), olddecl);
    2136              :             }
    2137              :           else
    2138              :             /* Discard the old built-in function.  */
    2139              :             return NULL_TREE;
    2140              : 
    2141              :           /* Replace the old RTL to avoid problems with inlining.  */
    2142          201 :           COPY_DECL_RTL (newdecl, olddecl);
    2143              :         }
    2144              :       else
    2145              :         {
    2146              :           /* Even if the types match, prefer the new declarations type
    2147              :              for built-ins which have not been explicitly declared,
    2148              :              for exception lists, etc...  */
    2149      3960323 :           tree type = TREE_TYPE (newdecl);
    2150      3960323 :           tree attribs = (*targetm.merge_type_attributes)
    2151      3960323 :             (TREE_TYPE (olddecl), type);
    2152              : 
    2153      3960323 :           type = cp_build_type_attribute_variant (type, attribs);
    2154      3960323 :           TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
    2155              :         }
    2156              : 
    2157              :       /* If a function is explicitly declared "throw ()", propagate that to
    2158              :          the corresponding builtin.  */
    2159      3960524 :       if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
    2160      3792163 :           && was_hidden
    2161      3792120 :           && TREE_NOTHROW (newdecl)
    2162      7486585 :           && !TREE_NOTHROW (olddecl))
    2163              :         {
    2164        27924 :           enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
    2165        27924 :           tree tmpdecl = builtin_decl_explicit (fncode);
    2166        27924 :           if (tmpdecl && tmpdecl != olddecl && types_match)
    2167        27924 :             TREE_NOTHROW (tmpdecl)  = 1;
    2168              :         }
    2169              : 
    2170              :       /* Whether or not the builtin can throw exceptions has no
    2171              :          bearing on this declarator.  */
    2172      3960524 :       TREE_NOTHROW (olddecl) = 0;
    2173              : 
    2174      3960524 :       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
    2175              :         {
    2176              :           /* If a builtin function is redeclared as `static', merge
    2177              :              the declarations, but make the original one static.  */
    2178            3 :           DECL_THIS_STATIC (olddecl) = 1;
    2179            3 :           TREE_PUBLIC (olddecl) = 0;
    2180              : 
    2181              :           /* Make the old declaration consistent with the new one so
    2182              :              that all remnants of the builtin-ness of this function
    2183              :              will be banished.  */
    2184            3 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    2185            3 :           COPY_DECL_RTL (newdecl, olddecl);
    2186              :         }
    2187              :     }
    2188    328186475 :   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    2189              :     {
    2190              :       /* C++ Standard, 3.3, clause 4:
    2191              :          "[Note: a namespace name or a class template name must be unique
    2192              :          in its declarative region (7.3.2, clause 14). ]"  */
    2193     73232117 :       if (TREE_CODE (olddecl) == NAMESPACE_DECL
    2194     73232090 :           || TREE_CODE (newdecl) == NAMESPACE_DECL)
    2195              :         /* Namespace conflicts with not namespace.  */;
    2196     35828715 :       else if (DECL_TYPE_TEMPLATE_P (olddecl)
    2197    109060793 :                || DECL_TYPE_TEMPLATE_P (newdecl))
    2198              :         /* Class template conflicts.  */;
    2199     73232072 :       else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
    2200     35828715 :                 && DECL_TEMPLATE_RESULT (olddecl)
    2201     35828715 :                 && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
    2202    109060781 :                || (TREE_CODE (newdecl) == TEMPLATE_DECL
    2203     37354636 :                    && DECL_TEMPLATE_RESULT (newdecl)
    2204     37354636 :                    && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
    2205              :         /* Variable template conflicts.  */;
    2206     73232063 :       else if (concept_definition_p (olddecl)
    2207    146464120 :                || concept_definition_p (newdecl))
    2208              :         /* Concept conflicts.  */;
    2209     73232051 :       else if ((TREE_CODE (newdecl) == FUNCTION_DECL
    2210     35867722 :                 && DECL_FUNCTION_TEMPLATE_P (olddecl))
    2211     73271070 :                || (TREE_CODE (olddecl) == FUNCTION_DECL
    2212     37354649 :                    && DECL_FUNCTION_TEMPLATE_P (newdecl)))
    2213              :         {
    2214              :           /* One is a function and the other is a template
    2215              :              function.  */
    2216     73183315 :           if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
    2217              :             return NULL_TREE;
    2218              : 
    2219              :           /* There can only be one!  */
    2220        57535 :           auto_diagnostic_group d;
    2221        57535 :           if (TREE_CODE (newdecl) == TEMPLATE_DECL
    2222        57535 :               && check_raw_literal_operator (olddecl))
    2223            3 :             error_at (newdecl_loc,
    2224              :                       "literal operator %q#D conflicts with"
    2225              :                       " raw literal operator", newdecl);
    2226        57532 :           else if (check_raw_literal_operator (newdecl))
    2227            3 :             error_at (newdecl_loc,
    2228              :                       "raw literal operator %q#D conflicts with"
    2229              :                       " literal operator template", newdecl);
    2230              :           else
    2231              :             return NULL_TREE;
    2232              : 
    2233            6 :           inform (olddecl_loc, "previous declaration %q#D", olddecl);
    2234            6 :           return error_mark_node;
    2235        57535 :         }
    2236        48736 :       else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
    2237              :         /* A structured binding must be unique in its declarative region.  */;
    2238        39175 :       else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2239        48733 :                || DECL_IMPLICIT_TYPEDEF_P (newdecl))
    2240              :         /* One is an implicit typedef, that's ok.  */
    2241              :         return NULL_TREE;
    2242              : 
    2243          153 :       auto_diagnostic_group d;
    2244          153 :       error ("%q#D redeclared as different kind of entity", newdecl);
    2245          153 :       inform (olddecl_loc, "previous declaration %q#D", olddecl);
    2246              : 
    2247          153 :       return error_mark_node;
    2248          153 :     }
    2249    254954358 :   else if (!types_match)
    2250              :     {
    2251    238586058 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
    2252              :         /* These are certainly not duplicate declarations; they're
    2253              :            from different scopes.  */
    2254              :         return NULL_TREE;
    2255              : 
    2256    238585414 :       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2257              :         {
    2258    149647736 :           tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    2259    149647736 :           tree newres = DECL_TEMPLATE_RESULT (newdecl);
    2260              : 
    2261              :           /* The name of a class template may not be declared to refer to
    2262              :              any other template, class, function, object, namespace, value,
    2263              :              or type in the same scope.  */
    2264    149647736 :           if (TREE_CODE (oldres) == TYPE_DECL
    2265    149646665 :               || TREE_CODE (newres) == TYPE_DECL)
    2266              :             {
    2267              :               /* E.g. cstddef __byte_operand.  Alternatively we could find a
    2268              :                  mergeable definition in lookup_elaborated_type, but we'd still
    2269              :                  need to push it into scope in the current TU.  */
    2270         1074 :               if (mod_redefinable
    2271         2139 :                   && (DECL_IMPLICIT_TYPEDEF_P (oldres)
    2272         1065 :                       == DECL_IMPLICIT_TYPEDEF_P (newres)))
    2273         1059 :                 goto return_old;
    2274              : 
    2275           15 :               auto_diagnostic_group d;
    2276           15 :               error_at (newdecl_loc,
    2277              :                         "conflicting declaration of template %q#D", newdecl);
    2278           15 :               inform (olddecl_loc,
    2279              :                       "previous declaration %q#D", olddecl);
    2280           15 :               return error_mark_node;
    2281           15 :             }
    2282              : 
    2283    149646662 :           else if (TREE_CODE (oldres) == FUNCTION_DECL
    2284    149646647 :                    && TREE_CODE (newres) == FUNCTION_DECL)
    2285              :             {
    2286    149646647 :               if (duplicate_function_template_decls (newdecl, olddecl))
    2287            0 :                 return error_mark_node;
    2288              :               return NULL_TREE;
    2289              :             }
    2290           15 :           else if (mod_redefinable
    2291            6 :                    && TREE_CODE (oldres) == VAR_DECL
    2292            6 :                    && TREE_CODE (newres) == VAR_DECL
    2293            6 :                    && !DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2294            6 :                    && template_heads_equivalent_p (newdecl, olddecl)
    2295            6 :                    && undeduced_auto_decl (newdecl)
    2296           21 :                    && !undeduced_auto_decl (olddecl))
    2297              :             /* A variable template imported with a deduced type is being
    2298              :                redeclared with an as-yet undeduced placeholder type.  Keep
    2299              :                the imported declaration, as we do for non-template
    2300              :                variables below.  */
    2301            6 :             goto return_old;
    2302              :           return NULL_TREE;
    2303              :         }
    2304     88937678 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2305              :         {
    2306     88936917 :           if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
    2307              :             {
    2308           57 :               auto_diagnostic_group d;
    2309           57 :               error_at (newdecl_loc,
    2310              :                         "conflicting declaration of C function %q#D",
    2311              :                         newdecl);
    2312           57 :               inform (olddecl_loc,
    2313              :                       "previous declaration %q#D", olddecl);
    2314           57 :               return error_mark_node;
    2315           57 :             }
    2316              :           /* For function versions, params and types match, but they
    2317              :              are not ambiguous.  */
    2318     88936860 :           else if (((!DECL_FUNCTION_VERSIONED (newdecl)
    2319     88928526 :                      && !DECL_FUNCTION_VERSIONED (olddecl))
    2320         8379 :                     || !same_type_p (fndecl_declared_return_type (newdecl),
    2321              :                                      fndecl_declared_return_type (olddecl)))
    2322              :                    /* Let constrained hidden friends coexist for now, we'll
    2323              :                       check satisfaction later.  */
    2324     88928481 :                    && !member_like_constrained_friend_p (newdecl)
    2325     81378640 :                    && !member_like_constrained_friend_p (olddecl)
    2326              :                    // The functions have the same parameter types.
    2327     79637353 :                    && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2328     79637353 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
    2329              :                    // And the same constraints.
    2330     88936929 :                    && equivalently_constrained (newdecl, olddecl))
    2331              :             {
    2332           69 :               auto_diagnostic_group d;
    2333           69 :               error_at (newdecl_loc,
    2334              :                         "ambiguating new declaration of %q#D", newdecl);
    2335           69 :               inform (olddecl_loc,
    2336              :                       "old declaration %q#D", olddecl);
    2337           69 :               return error_mark_node;
    2338           69 :             }
    2339              :           else
    2340              :             return NULL_TREE;
    2341              :         }
    2342          761 :       else if (mod_redefinable
    2343          609 :                && TREE_CODE (newdecl) == TYPE_DECL
    2344         1971 :                && (DECL_IMPLICIT_TYPEDEF_P (newdecl)
    2345          605 :                    == DECL_IMPLICIT_TYPEDEF_P (olddecl)))
    2346              :         /* Can also get here with e.g. typedef class {...} foo.  */
    2347          605 :         goto return_old;
    2348          156 :       else if (mod_redefinable
    2349            4 :                && TREE_CODE (newdecl) == VAR_DECL
    2350            4 :                && undeduced_auto_decl (newdecl)
    2351          160 :                && !undeduced_auto_decl (olddecl))
    2352              :         /* We don't have fndecl_declared_return_type for vars.  */
    2353            4 :         goto return_old;
    2354              :       else
    2355              :         {
    2356          152 :           auto_diagnostic_group d;
    2357          152 :           error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
    2358          152 :           inform (olddecl_loc,
    2359              :                   "previous declaration as %q#D", olddecl);
    2360          152 :           return error_mark_node;
    2361          152 :         }
    2362              :     }
    2363     16368300 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2364     16368300 :            && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
    2365              :     {
    2366              :       /* OMP UDRs are never duplicates. */
    2367           33 :       gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
    2368           33 :       auto_diagnostic_group d;
    2369           33 :       error_at (newdecl_loc,
    2370              :                 "redeclaration of %<pragma omp declare reduction%>");
    2371           33 :       inform (olddecl_loc,
    2372              :               "previous %<pragma omp declare reduction%> declaration");
    2373           33 :       return error_mark_node;
    2374           33 :     }
    2375     16368267 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2376     16368267 :             && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
    2377          281 :                  && (!DECL_TEMPLATE_INFO (newdecl)
    2378          281 :                      || (DECL_TI_TEMPLATE (newdecl)
    2379          281 :                          != DECL_TI_TEMPLATE (olddecl))))
    2380     11641265 :                 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2381       565918 :                     && (!DECL_TEMPLATE_INFO (olddecl)
    2382       565918 :                         || (DECL_TI_TEMPLATE (olddecl)
    2383       565918 :                             != DECL_TI_TEMPLATE (newdecl))))))
    2384              :     /* It's OK to have a template specialization and a non-template
    2385              :        with the same type, or to have specializations of two
    2386              :        different templates with the same type.  Note that if one is a
    2387              :        specialization, and the other is an instantiation of the same
    2388              :        template, that we do not exit at this point.  That situation
    2389              :        can occur if we instantiate a template class, and then
    2390              :        specialize one of its methods.  This situation is valid, but
    2391              :        the declarations must be merged in the usual way.  */
    2392              :     return NULL_TREE;
    2393     16368267 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2394     16368267 :            && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
    2395       648035 :                 && !DECL_USE_TEMPLATE (newdecl))
    2396     11641265 :                || (DECL_TEMPLATE_INSTANTIATION (newdecl)
    2397        82398 :                    && !DECL_USE_TEMPLATE (olddecl))))
    2398              :     /* One of the declarations is a template instantiation, and the
    2399              :        other is not a template at all.  That's OK.  */
    2400              :     return NULL_TREE;
    2401     16368267 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    2402              :     {
    2403              :       /* In [namespace.alias] we have:
    2404              : 
    2405              :            In a declarative region, a namespace-alias-definition can be
    2406              :            used to redefine a namespace-alias declared in that declarative
    2407              :            region to refer only to the namespace to which it already
    2408              :            refers.
    2409              : 
    2410              :          Therefore, if we encounter a second alias directive for the same
    2411              :          alias, we can just ignore the second directive.  */
    2412           31 :       if (DECL_NAMESPACE_ALIAS (newdecl)
    2413           31 :           && (DECL_NAMESPACE_ALIAS (newdecl)
    2414           28 :               == DECL_NAMESPACE_ALIAS (olddecl)))
    2415           22 :         goto return_old;
    2416              : 
    2417              :       /* Leave it to update_binding to merge or report error.  */
    2418              :       return NULL_TREE;
    2419              :     }
    2420              :   /* Check if the two decls are non-mergeable versioned decls.  */
    2421     16368236 :   else if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2422              :            && diagnose_versioned_decls (olddecl, newdecl))
    2423              :     return error_mark_node;
    2424              :   else
    2425              :     {
    2426     16368236 :       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
    2427     16368236 :       if (errmsg)
    2428              :         {
    2429          623 :           auto_diagnostic_group d;
    2430          623 :           error_at (newdecl_loc, errmsg, newdecl);
    2431          623 :           if (DECL_NAME (olddecl) != NULL_TREE)
    2432          623 :             inform (olddecl_loc,
    2433          623 :                     (DECL_INITIAL (olddecl) && namespace_bindings_p ())
    2434              :                     ? G_("%q#D previously defined here")
    2435              :                     : G_("%q#D previously declared here"), olddecl);
    2436          623 :           if (cxx_dialect >= cxx26
    2437          149 :               && DECL_NAME (newdecl)
    2438          149 :               && id_equal (DECL_NAME (newdecl), "_")
    2439          636 :               && !name_independent_decl_p (newdecl))
    2440              :             {
    2441           13 :               if (TREE_CODE (newdecl) == PARM_DECL)
    2442            2 :                 inform (newdecl_loc,
    2443              :                         "parameter declaration is not name-independent");
    2444           11 :               else if (DECL_DECOMPOSITION_P (newdecl))
    2445              :                 {
    2446            3 :                   if (at_namespace_scope_p ())
    2447            2 :                     inform (newdecl_loc,
    2448              :                             "structured binding at namespace scope is not "
    2449              :                             "name-independent");
    2450            1 :                   else if (TREE_STATIC (newdecl))
    2451            1 :                     inform (newdecl_loc,
    2452              :                             "static structured binding is not "
    2453              :                             "name-independent");
    2454            0 :                   else if (DECL_EXTERNAL (newdecl))
    2455            0 :                     inform (newdecl_loc,
    2456              :                             "extern structured binding is not "
    2457              :                             "name-independent");
    2458              :                 }
    2459            8 :               else if (at_class_scope_p ()
    2460            0 :                        && VAR_P (newdecl)
    2461            8 :                        && TREE_STATIC (newdecl))
    2462            0 :                 inform (newdecl_loc,
    2463              :                         "static data member is not name-independent");
    2464            8 :               else if (VAR_P (newdecl) && at_namespace_scope_p ())
    2465            3 :                 inform (newdecl_loc,
    2466              :                         "variable at namespace scope is not name-independent");
    2467            5 :               else if (VAR_P (newdecl) && TREE_STATIC (newdecl))
    2468            3 :                 inform (newdecl_loc,
    2469              :                         "static variable is not name-independent");
    2470            2 :               else if (VAR_P (newdecl) && DECL_EXTERNAL (newdecl))
    2471            0 :                 inform (newdecl_loc,
    2472              :                         "extern variable is not name-independent");
    2473              :             }
    2474          623 :           return error_mark_node;
    2475          623 :         }
    2476     16367613 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2477     11641025 :                && DECL_INITIAL (olddecl) != NULL_TREE
    2478        19897 :                && !prototype_p (TREE_TYPE (olddecl))
    2479     16367613 :                && prototype_p (TREE_TYPE (newdecl)))
    2480              :         {
    2481              :           /* Prototype decl follows defn w/o prototype.  */
    2482            0 :           auto_diagnostic_group d;
    2483            0 :           if (warning_at (newdecl_loc, 0,
    2484              :                           "prototype specified for %q#D", newdecl))
    2485            0 :             inform (olddecl_loc,
    2486              :                     "previous non-prototype definition here");
    2487            0 :         }
    2488     15856377 :       else if (VAR_OR_FUNCTION_DECL_P (olddecl)
    2489     28008638 :                && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
    2490              :         {
    2491              :           /* [dcl.link]
    2492              :              If two declarations of the same function or object
    2493              :              specify different linkage-specifications ..., the program
    2494              :              is ill-formed.... Except for functions with C++ linkage,
    2495              :              a function declaration without a linkage specification
    2496              :              shall not precede the first linkage specification for
    2497              :              that function.  A function can be declared without a
    2498              :              linkage specification after an explicit linkage
    2499              :              specification has been seen; the linkage explicitly
    2500              :              specified in the earlier declaration is not affected by
    2501              :              such a function declaration.
    2502              : 
    2503              :              DR 563 raises the question why the restrictions on
    2504              :              functions should not also apply to objects.  Older
    2505              :              versions of G++ silently ignore the linkage-specification
    2506              :              for this example:
    2507              : 
    2508              :                namespace N {
    2509              :                  extern int i;
    2510              :                  extern "C" int i;
    2511              :                }
    2512              : 
    2513              :              which is clearly wrong.  Therefore, we now treat objects
    2514              :              like functions.  */
    2515         1773 :           if (current_lang_depth () == 0)
    2516              :             {
    2517              :               /* There is no explicit linkage-specification, so we use
    2518              :                  the linkage from the previous declaration.  */
    2519         1761 :               retrofit_lang_decl (newdecl);
    2520         1761 :               SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    2521              :             }
    2522              :           else
    2523              :             {
    2524           12 :               auto_diagnostic_group d;
    2525           12 :               error_at (newdecl_loc,
    2526              :                         "conflicting declaration of %q#D with %qL linkage",
    2527           12 :                         newdecl, DECL_LANGUAGE (newdecl));
    2528           12 :               inform (olddecl_loc,
    2529              :                       "previous declaration with %qL linkage",
    2530           12 :                       DECL_LANGUAGE (olddecl));
    2531           12 :             }
    2532              :         }
    2533              : 
    2534     16367613 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
    2535              :         ;
    2536     15698332 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2537              :         {
    2538              :           /* Note: free functions, as TEMPLATE_DECLs, are handled below.  */
    2539     13826895 :           if (DECL_FUNCTION_MEMBER_P (olddecl)
    2540     10992718 :               && (/* grokfndecl passes member function templates too
    2541              :                      as FUNCTION_DECLs.  */
    2542      8336937 :                   DECL_TEMPLATE_INFO (olddecl)
    2543              :                   /* C++11 8.3.6/6.
    2544              :                      Default arguments for a member function of a class
    2545              :                      template shall be specified on the initial declaration
    2546              :                      of the member function within the class template.  */
    2547       701872 :                   || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
    2548              :             {
    2549      7714110 :               if (!mod_redefinable)
    2550      7713224 :                 check_redeclaration_no_default_args (newdecl);
    2551              : 
    2552      7714110 :               if (DECL_TEMPLATE_INFO (olddecl)
    2553      7714110 :                   && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
    2554              :                 {
    2555      2308232 :                   tree new_parms = DECL_TEMPLATE_INFO (newdecl)
    2556      2308232 :                     ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
    2557      2308232 :                     : INNERMOST_TEMPLATE_PARMS (current_template_parms);
    2558      2308232 :                   tree old_parms
    2559      2308232 :                     = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
    2560      2308232 :                   merge_default_template_args (new_parms, old_parms, olddecl);
    2561              :                 }
    2562              :             }
    2563              :           else
    2564              :             {
    2565      3278608 :               tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    2566      3278608 :               tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    2567      3278608 :               int i = 1;
    2568              : 
    2569     11816126 :               for (; t1 && t1 != void_list_node;
    2570      5258910 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
    2571      5260739 :                 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
    2572              :                   {
    2573          111 :                     if (!cp_tree_equal (TREE_PURPOSE (t1),
    2574          111 :                                         TREE_PURPOSE (t2)))
    2575              :                       {
    2576           30 :                         auto_diagnostic_group d;
    2577           30 :                         error_at (newdecl_loc,
    2578              :                                   "default argument given for parameter %d "
    2579              :                                   "of %q#D", i, newdecl);
    2580           30 :                         inform (olddecl_loc,
    2581              :                                 "previous specification in %q#D here",
    2582              :                                 olddecl);
    2583           30 :                       }
    2584           81 :                     else if (!mod_redefinable)
    2585              :                       {
    2586           24 :                         auto_diagnostic_group d;
    2587           24 :                         if (permerror (newdecl_loc,
    2588              :                                        "default argument given for parameter "
    2589              :                                        "%d of %q#D", i, newdecl))
    2590           24 :                           inform (olddecl_loc,
    2591              :                                   "previous specification in %q#D here",
    2592              :                                   olddecl);
    2593           24 :                       }
    2594              :                   }
    2595              : 
    2596              :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2597              :                  argument expression, that declaration... shall be the only
    2598              :                  declaration of the function or function template in the
    2599              :                  translation unit."  */
    2600      3278608 :               check_no_redeclaration_friend_default_args (olddecl, newdecl);
    2601              :             }
    2602              :         }
    2603              :     }
    2604              : 
    2605              :   /* Do not merge an implicit typedef with an explicit one.  In:
    2606              : 
    2607              :        class A;
    2608              :        ...
    2609              :        typedef class A A __attribute__ ((foo));
    2610              : 
    2611              :      the attribute should apply only to the typedef.  */
    2612     20328137 :   if (TREE_CODE (olddecl) == TYPE_DECL
    2613     20328137 :       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2614        50382 :           || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
    2615              :     return NULL_TREE;
    2616              : 
    2617     20294351 :   if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
    2618              :     return NULL_TREE;
    2619              : 
    2620     20294339 :   if (!validate_constexpr_redeclaration (olddecl, newdecl))
    2621           30 :     return error_mark_node;
    2622              : 
    2623     20294309 :   if (modules_p ()
    2624        74958 :       && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
    2625     20341016 :       && TREE_CODE (olddecl) != NAMESPACE_DECL)
    2626              :     {
    2627        46707 :       if (!module_may_redeclare (olddecl, newdecl))
    2628           24 :         return error_mark_node;
    2629              : 
    2630        46683 :       if (!hiding)
    2631              :         {
    2632              :           /* The old declaration should match the exportingness of the new
    2633              :              declaration.  But hidden friend declarations just keep the
    2634              :              exportingness of the old declaration; see CWG2588.  */
    2635        42011 :           tree not_tmpl = STRIP_TEMPLATE (olddecl);
    2636        42011 :           if (DECL_LANG_SPECIFIC (not_tmpl)
    2637        41887 :               && DECL_MODULE_ATTACH_P (not_tmpl)
    2638              :               /* Typedefs are not entities and so are OK to be redeclared
    2639              :                  as exported: see [module.interface]/p6.  */
    2640        42202 :               && TREE_CODE (olddecl) != TYPE_DECL)
    2641              :             {
    2642          179 :               if (DECL_MODULE_EXPORT_P (newdecl)
    2643          179 :                   && !DECL_MODULE_EXPORT_P (not_tmpl))
    2644              :                 {
    2645           15 :                   auto_diagnostic_group d;
    2646           15 :                   error ("conflicting exporting for declaration %qD", newdecl);
    2647           15 :                   inform (olddecl_loc,
    2648              :                           "previously declared here without exporting");
    2649           15 :                 }
    2650              :             }
    2651        41832 :           else if (DECL_MODULE_EXPORT_P (newdecl))
    2652        10476 :             DECL_MODULE_EXPORT_P (not_tmpl) = true;
    2653              :         }
    2654              :     }
    2655              : 
    2656              :   /* We have committed to returning OLDDECL at this point.  */
    2657              : 
    2658              :   /* If new decl is `static' and an `extern' was seen previously,
    2659              :      warn about it.  */
    2660     20294285 :   warn_extern_redeclared_static (newdecl, olddecl);
    2661              : 
    2662              :   /* True to merge attributes between the declarations, false to
    2663              :      set OLDDECL's attributes to those of NEWDECL (for template
    2664              :      explicit specializations that specify their own attributes
    2665              :      independent of those specified for the primary template).  */
    2666     20294285 :   bool merge_attr;
    2667     40588570 :   merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
    2668     15601504 :                 || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2669     20860188 :                 || DECL_TEMPLATE_SPECIALIZATION (olddecl));
    2670              : 
    2671     20294285 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2672              :     {
    2673     15601504 :       if (merge_attr)
    2674              :         {
    2675     15035867 :           {
    2676     15035867 :             auto_diagnostic_group d;
    2677     15035867 :             if (diagnose_mismatched_attributes (olddecl, newdecl))
    2678           36 :               inform (olddecl_loc, DECL_INITIAL (olddecl)
    2679              :                       ? G_("previous definition of %qD here")
    2680              :                       : G_("previous declaration of %qD here"), olddecl);
    2681     15035867 :           }
    2682              : 
    2683              :           /* [dcl.attr.noreturn]: The first declaration of a function shall
    2684              :              specify the noreturn attribute if any declaration of that function
    2685              :              specifies the noreturn attribute.  */
    2686     15035867 :           tree a;
    2687     15035867 :           if (TREE_THIS_VOLATILE (newdecl)
    2688        98557 :               && !TREE_THIS_VOLATILE (olddecl)
    2689              :               /* This applies to [[noreturn]] only, not its GNU variants.  */
    2690           76 :               && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
    2691           54 :               && cxx11_attribute_p (a)
    2692     15035888 :               && get_attribute_namespace (a) == NULL_TREE)
    2693              :             {
    2694            9 :               auto_diagnostic_group d;
    2695            9 :               error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
    2696              :                         "but its first declaration was not", newdecl);
    2697            9 :               inform (olddecl_loc, "previous declaration of %qD", olddecl);
    2698            9 :             }
    2699              :         }
    2700              : 
    2701              :       /* Now that functions must hold information normally held
    2702              :          by field decls, there is extra work to do so that
    2703              :          declaration information does not get destroyed during
    2704              :          definition.  */
    2705     15601504 :       if (DECL_VINDEX (olddecl))
    2706       158554 :         DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
    2707     15601504 :       if (DECL_CONTEXT (olddecl))
    2708     15601504 :         DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    2709     15601504 :       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
    2710     15601504 :       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2711     15601504 :       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
    2712     15601504 :       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
    2713     15601504 :       DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
    2714     15601504 :       DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
    2715     15601504 :       DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
    2716     15601504 :       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
    2717     15601504 :       DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
    2718     15601504 :         |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
    2719     15601504 :       if (DECL_OVERLOADED_OPERATOR_P (olddecl))
    2720      2774531 :         DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
    2721      5549062 :           = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
    2722     15601504 :       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
    2723              : 
    2724     15601504 :       if (new_defines_function && mod_redefinable
    2725     15601504 :           && DECL_INITIAL (olddecl))
    2726              :         {
    2727         4082 :           if (GNU_INLINE_P (STRIP_TEMPLATE (olddecl))
    2728         2297 :               && !GNU_INLINE_P (STRIP_TEMPLATE (newdecl)))
    2729              :             /* Normal out-of-line redefinition of gnu_inline.  */
    2730              :             mod_redefinable = false;
    2731              :           else
    2732              :             new_defines_function = false;
    2733              :         }
    2734              : 
    2735     15601504 :       check_redecl_contract (newdecl, olddecl);
    2736              : 
    2737              :       /* Optionally warn about more than one declaration for the same
    2738              :          name, but don't warn about a function declaration followed by a
    2739              :          definition.  */
    2740           27 :       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
    2741           27 :           && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
    2742              :           /* Don't warn about extern decl followed by definition.  */
    2743           27 :           && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
    2744              :           /* Don't warn if at least one is/was hidden.  */
    2745           27 :           && !(hiding || was_hidden)
    2746              :           /* Don't warn about declaration followed by specialization.  */
    2747     15601516 :           && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2748            9 :               || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
    2749              :         {
    2750            6 :           auto_diagnostic_group d;
    2751            6 :           if (warning_at (newdecl_loc,
    2752            6 :                           OPT_Wredundant_decls,
    2753              :                           "redundant redeclaration of %qD in same scope",
    2754              :                           newdecl))
    2755            6 :             inform (olddecl_loc,
    2756              :                     "previous declaration of %qD", olddecl);
    2757            6 :         }
    2758              : 
    2759              :       /* [dcl.fct.def.delete] A deleted definition of a function shall be the
    2760              :          first declaration of the function or, for an explicit specialization
    2761              :          of a function template, the first declaration of that
    2762              :          specialization.  */
    2763     15601504 :       if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
    2764       648035 :             && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
    2765              :         {
    2766     15035867 :           if (DECL_DELETED_FN (newdecl)
    2767     15035867 :               && !(mod_redefinable
    2768           22 :                    && DECL_DELETED_FN (olddecl)))
    2769              :             {
    2770           21 :               auto_diagnostic_group d;
    2771           21 :               if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
    2772              :                            "is not first declaration", newdecl))
    2773           21 :                 inform (olddecl_loc,
    2774              :                         "previous declaration of %qD", olddecl);
    2775           21 :             }
    2776     15035867 :           DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
    2777     15035867 :           if (DECL_DELETED_FN (olddecl)
    2778           28 :               && DECL_INITIAL (olddecl)
    2779     15035873 :               && TREE_CODE (DECL_INITIAL (olddecl)) == STRING_CST)
    2780            3 :             DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2781              :         }
    2782              :     }
    2783              : 
    2784              :   /* Deal with C++: must preserve virtual function table size.  */
    2785     20294285 :   if (TREE_CODE (olddecl) == TYPE_DECL)
    2786              :     {
    2787        50379 :       tree newtype = TREE_TYPE (newdecl);
    2788        50379 :       tree oldtype = TREE_TYPE (olddecl);
    2789              : 
    2790        50379 :       if (newtype != error_mark_node && oldtype != error_mark_node
    2791       100758 :           && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
    2792       138669 :         CLASSTYPE_FRIEND_CLASSES (newtype)
    2793        46223 :           = CLASSTYPE_FRIEND_CLASSES (oldtype);
    2794              : 
    2795        50379 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2796              :     }
    2797              : 
    2798              :   /* Copy all the DECL_... slots specified in the new decl except for
    2799              :      any that we copy here from the old type.  */
    2800     20294285 :   if (merge_attr)
    2801     19728648 :     DECL_ATTRIBUTES (newdecl)
    2802     39457296 :       = (*targetm.merge_decl_attributes) (olddecl, newdecl);
    2803              :   else
    2804       565637 :     DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    2805              : 
    2806              :   /* Transfer purviewness and importingness to the old decl.  */
    2807     20294285 :   transfer_defining_module (olddecl, newdecl);
    2808              : 
    2809     20294285 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2810              :     {
    2811      4131166 :       tree old_result = DECL_TEMPLATE_RESULT (olddecl);
    2812      4131166 :       tree new_result = DECL_TEMPLATE_RESULT (newdecl);
    2813      4131166 :       TREE_TYPE (olddecl) = TREE_TYPE (old_result);
    2814              : 
    2815              :       /* The new decl should not already have gathered any
    2816              :          specializations.  */
    2817      4131166 :       gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
    2818              : 
    2819              :       /* Make sure the contracts are equivalent.  */
    2820      4131166 :       check_redecl_contract (newdecl, olddecl);
    2821              : 
    2822      4131166 :       DECL_ATTRIBUTES (old_result)
    2823      4131166 :         = (*targetm.merge_decl_attributes) (old_result, new_result);
    2824              : 
    2825      4131166 :       if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2826              :         {
    2827      4129794 :           if (DECL_SOURCE_LOCATION (newdecl)
    2828      4129794 :               != DECL_SOURCE_LOCATION (olddecl))
    2829              :             {
    2830              :               /* Per C++11 8.3.6/4, default arguments cannot be added in
    2831              :                  later declarations of a function template.  */
    2832      4107267 :               if (!mod_redefinable)
    2833      4103734 :                 check_redeclaration_no_default_args (newdecl);
    2834              :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2835              :                  argument expression, that declaration... shall be the only
    2836              :                  declaration of the function or function template in the
    2837              :                  translation unit."  */
    2838      4107267 :               check_no_redeclaration_friend_default_args
    2839      4107267 :                 (old_result, new_result);
    2840              : 
    2841      4107267 :               tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
    2842      4107267 :               tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
    2843      4107267 :               merge_default_template_args (new_parms, old_parms, olddecl);
    2844              :             }
    2845      4129794 :           if (!DECL_UNIQUE_FRIEND_P (new_result))
    2846      3023908 :             DECL_UNIQUE_FRIEND_P (old_result) = false;
    2847              : 
    2848      4129794 :           check_default_args (newdecl);
    2849              : 
    2850      8259576 :           if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
    2851      4129794 :               && DECL_INITIAL (new_result))
    2852              :             {
    2853           24 :               mod_redefinable = false;
    2854           24 :               if (DECL_INITIAL (old_result))
    2855           12 :                 DECL_UNINLINABLE (old_result) = 1;
    2856              :               else
    2857           12 :                 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
    2858           24 :               DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
    2859           72 :               DECL_NOT_REALLY_EXTERN (old_result)
    2860           24 :                 = DECL_NOT_REALLY_EXTERN (new_result);
    2861           48 :               DECL_INTERFACE_KNOWN (old_result)
    2862           24 :                 = DECL_INTERFACE_KNOWN (new_result);
    2863           24 :               DECL_DECLARED_INLINE_P (old_result)
    2864           24 :                 = DECL_DECLARED_INLINE_P (new_result);
    2865           24 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2866           24 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2867              :             }
    2868              :           else
    2869              :             {
    2870      4129770 :               DECL_DECLARED_INLINE_P (old_result)
    2871      4129770 :                 |= DECL_DECLARED_INLINE_P (new_result);
    2872      4129770 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2873      4129770 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2874      4129770 :               check_redeclaration_exception_specification (newdecl, olddecl);
    2875              : 
    2876      4129770 :               merge_attribute_bits (new_result, old_result);
    2877              :             }
    2878              :         }
    2879              : 
    2880              :       /* If the new declaration is a definition, update the file and
    2881              :          line information on the declaration, and also make
    2882              :          the old declaration the same definition.  */
    2883      4131166 :       if (DECL_INITIAL (new_result) != NULL_TREE
    2884      4131166 :           && !(DECL_INITIAL (old_result)
    2885              :                && mod_redefinable))
    2886              :         {
    2887      5604016 :           DECL_SOURCE_LOCATION (olddecl)
    2888      5604016 :             = DECL_SOURCE_LOCATION (old_result)
    2889      2802008 :             = DECL_SOURCE_LOCATION (newdecl);
    2890      2802008 :           DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
    2891      2802008 :           if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2892              :             {
    2893      2802008 :               update_contract_arguments (new_result, old_result);
    2894              : 
    2895      2802008 :               DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
    2896     10094069 :               for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
    2897      7292061 :                 DECL_CONTEXT (p) = old_result;
    2898              : 
    2899      5604016 :               if (tree fc = DECL_FRIEND_CONTEXT (new_result))
    2900           18 :                 SET_DECL_FRIEND_CONTEXT (old_result, fc);
    2901              :             }
    2902              :         }
    2903              : 
    2904              :       /* FIXME we can't goto return_old here without removing newdecl from more
    2905              :          hash tables.  */
    2906              :       return olddecl;
    2907              :     }
    2908              : 
    2909     16163119 :   if (types_match)
    2910              :     {
    2911     16162918 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2912     15601303 :         check_redeclaration_exception_specification (newdecl, olddecl);
    2913              : 
    2914              :       /* Automatically handles default parameters.  */
    2915     16162918 :       tree oldtype = TREE_TYPE (olddecl);
    2916     16162918 :       tree newtype;
    2917              : 
    2918              :       /* For typedefs use the old type, as the new type's DECL_NAME points
    2919              :          at newdecl, which will be ggc_freed.  */
    2920     16162918 :       if (TREE_CODE (newdecl) == TYPE_DECL)
    2921              :         {
    2922              :           /* But NEWTYPE might have an attribute, honor that.  */
    2923        50379 :           tree tem = TREE_TYPE (newdecl);
    2924        50379 :           newtype = oldtype;
    2925              : 
    2926        50379 :           if (TYPE_USER_ALIGN (tem))
    2927              :             {
    2928           70 :               if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2929            6 :                 SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2930           70 :               TYPE_USER_ALIGN (newtype) = true;
    2931              :             }
    2932              : 
    2933              :           /* And remove the new type from the variants list.  */
    2934        50379 :           if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2935              :             {
    2936           24 :               tree remove = TREE_TYPE (newdecl);
    2937           24 :               if (TYPE_MAIN_VARIANT (remove) == remove)
    2938              :                 {
    2939            9 :                   gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2940              :                   /* If remove is the main variant, no need to remove that
    2941              :                      from the list.  One of the DECL_ORIGINAL_TYPE
    2942              :                      variants, e.g. created for aligned attribute, might still
    2943              :                      refer to the newdecl TYPE_DECL though, so remove that one
    2944              :                      in that case.  */
    2945            9 :                   if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
    2946            6 :                     if (orig != remove)
    2947            6 :                       for (tree t = TYPE_MAIN_VARIANT (orig); t;
    2948            0 :                            t = TYPE_MAIN_VARIANT (t))
    2949            6 :                         if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2950              :                           {
    2951           12 :                             TYPE_NEXT_VARIANT (t)
    2952            6 :                               = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2953            6 :                             break;
    2954              :                           }
    2955              :                 }
    2956              :               else
    2957           15 :                 for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2958            0 :                      t = TYPE_NEXT_VARIANT (t))
    2959           15 :                   if (TYPE_NEXT_VARIANT (t) == remove)
    2960              :                     {
    2961           15 :                       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2962           15 :                       break;
    2963              :                     }
    2964              :             }
    2965              :         }
    2966     16112539 :       else if (merge_attr)
    2967     15546902 :         newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
    2968              :       else
    2969       565637 :         newtype = TREE_TYPE (newdecl);
    2970              : 
    2971     16162918 :       if (VAR_P (newdecl))
    2972              :         {
    2973       511236 :           DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
    2974              :           /* For already initialized vars, TREE_READONLY could have been
    2975              :              cleared in cp_finish_decl, because the var needs runtime
    2976              :              initialization or destruction.  Make sure not to set
    2977              :              TREE_READONLY on it again.  */
    2978       511236 :           if (DECL_INITIALIZED_P (olddecl)
    2979         2021 :               && !DECL_EXTERNAL (olddecl)
    2980       511999 :               && !TREE_READONLY (olddecl))
    2981          167 :             TREE_READONLY (newdecl) = 0;
    2982       511236 :           DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
    2983      1022472 :           DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
    2984       511236 :             |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
    2985       511236 :           if (DECL_DEPENDENT_INIT_P (olddecl))
    2986       108096 :             SET_DECL_DEPENDENT_INIT_P (newdecl, true);
    2987      1022472 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
    2988       511236 :             |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
    2989       511236 :           DECL_DECLARED_CONSTEXPR_P (newdecl)
    2990       511236 :             |= DECL_DECLARED_CONSTEXPR_P (olddecl);
    2991      1022472 :           DECL_DECLARED_CONSTINIT_P (newdecl)
    2992       511236 :             |= DECL_DECLARED_CONSTINIT_P (olddecl);
    2993              : 
    2994              :           /* Merge the threadprivate attribute from OLDDECL into NEWDECL.  */
    2995       511236 :           if (DECL_LANG_SPECIFIC (olddecl)
    2996      1018866 :               && CP_DECL_THREADPRIVATE_P (olddecl))
    2997              :             {
    2998              :               /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed.  */
    2999           41 :               retrofit_lang_decl (newdecl);
    3000           41 :               CP_DECL_THREADPRIVATE_P (newdecl) = 1;
    3001              :             }
    3002              :         }
    3003              : 
    3004              :       /* An explicit specialization of a function template or of a member
    3005              :          function of a class template can be declared transaction_safe
    3006              :          independently of whether the corresponding template entity is declared
    3007              :          transaction_safe. */
    3008         1207 :       if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
    3009         1072 :           && DECL_TEMPLATE_INSTANTIATION (olddecl)
    3010           78 :           && DECL_TEMPLATE_SPECIALIZATION (newdecl)
    3011           54 :           && tx_safe_fn_type_p (newtype)
    3012     16162918 :           && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
    3013            0 :         newtype = tx_unsafe_fn_variant (newtype);
    3014              : 
    3015     16162918 :       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
    3016              : 
    3017     16162918 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3018     15601303 :         check_default_args (newdecl);
    3019              : 
    3020              :       /* Lay the type out, unless already done.  */
    3021     16162918 :       if (! same_type_p (newtype, oldtype)
    3022          370 :           && TREE_TYPE (newdecl) != error_mark_node
    3023     16163288 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    3024          287 :         layout_type (TREE_TYPE (newdecl));
    3025              : 
    3026     16162918 :       if ((VAR_P (newdecl)
    3027     15651682 :            || TREE_CODE (newdecl) == PARM_DECL
    3028     15651682 :            || TREE_CODE (newdecl) == RESULT_DECL
    3029     15651682 :            || TREE_CODE (newdecl) == FIELD_DECL
    3030     15651682 :            || TREE_CODE (newdecl) == TYPE_DECL)
    3031     16213297 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    3032       394824 :         layout_decl (newdecl, 0);
    3033              : 
    3034              :       /* Merge deprecatedness.  */
    3035     16162918 :       if (TREE_DEPRECATED (newdecl))
    3036        11628 :         TREE_DEPRECATED (olddecl) = 1;
    3037              : 
    3038              :       /* Merge unavailability.  */
    3039     16162918 :       if (TREE_UNAVAILABLE (newdecl))
    3040            3 :         TREE_UNAVAILABLE (olddecl) = 1;
    3041              : 
    3042              :       /* Preserve function specific target and optimization options */
    3043     16162918 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3044              :         {
    3045     15601303 :           if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    3046     15601303 :               && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    3047            0 :             DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    3048            0 :               = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    3049              : 
    3050     15601303 :           if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    3051     15601303 :               && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    3052           55 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    3053           55 :               = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    3054              : 
    3055     15601303 :           if (!DECL_UNIQUE_FRIEND_P (olddecl))
    3056     15070391 :             DECL_UNIQUE_FRIEND_P (newdecl) = false;
    3057              :         }
    3058              :       else
    3059              :         {
    3060              :           /* Merge the const type qualifier.  */
    3061       561615 :           if (TREE_READONLY (newdecl))
    3062       152784 :             TREE_READONLY (olddecl) = 1;
    3063              :           /* Merge the volatile type qualifier.  */
    3064       561615 :           if (TREE_THIS_VOLATILE (newdecl))
    3065            5 :             TREE_THIS_VOLATILE (olddecl) = 1;
    3066              :         }
    3067              : 
    3068              :       /* Merge the initialization information.  */
    3069     16162918 :       if (DECL_INITIAL (olddecl) != NULL_TREE
    3070     16162918 :           && (DECL_INITIAL (newdecl) == NULL_TREE
    3071         2325 :               || mod_redefinable))
    3072              :         {
    3073       189930 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    3074       189930 :           DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    3075       189930 :           if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3076              :             {
    3077        19813 :               DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    3078        19813 :               DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    3079              :             }
    3080              :         }
    3081              : 
    3082     16162918 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3083              :         {
    3084     15601303 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    3085     15601303 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    3086     15601303 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    3087     15601303 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    3088        56880 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    3089     15601303 :           DECL_LOOPING_CONST_OR_PURE_P (newdecl)
    3090     15601303 :             |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
    3091     15601303 :           DECL_IS_REPLACEABLE_OPERATOR (newdecl)
    3092     15601303 :             |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
    3093              : 
    3094     15601303 :           if (merge_attr)
    3095     15035666 :             merge_attribute_bits (newdecl, olddecl);
    3096              :           else
    3097              :             {
    3098              :               /* Merge the noreturn bit.  */
    3099       565637 :               TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    3100       565637 :               TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    3101       565637 :               TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    3102       565637 :               DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
    3103       565637 :               DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
    3104              :             }
    3105              :           /* Keep the old RTL.  */
    3106     15601303 :           COPY_DECL_RTL (olddecl, newdecl);
    3107              :         }
    3108       561615 :       else if (VAR_P (newdecl)
    3109       561615 :                && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
    3110              :         {
    3111              :           /* Keep the old RTL.  We cannot keep the old RTL if the old
    3112              :              declaration was for an incomplete object and the new
    3113              :              declaration is not since many attributes of the RTL will
    3114              :              change.  */
    3115       511162 :           COPY_DECL_RTL (olddecl, newdecl);
    3116              :         }
    3117              :     }
    3118              :   /* If cannot merge, then use the new type and qualifiers,
    3119              :      and don't preserve the old rtl.  */
    3120              :   else
    3121              :     {
    3122              :       /* Clean out any memory we had of the old declaration.  */
    3123          201 :       tree oldstatic = value_member (olddecl, static_aggregates);
    3124          201 :       if (oldstatic)
    3125            0 :         TREE_VALUE (oldstatic) = error_mark_node;
    3126              : 
    3127          201 :       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
    3128          201 :       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    3129          201 :       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    3130          201 :       TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    3131          201 :       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
    3132              :     }
    3133              : 
    3134              :   /* Merge the storage class information.  */
    3135     16163119 :   merge_weak (newdecl, olddecl);
    3136              : 
    3137     16163119 :   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
    3138     16163119 :   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    3139     16163119 :   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
    3140     16163119 :   if (! DECL_EXTERNAL (olddecl))
    3141        55761 :     DECL_EXTERNAL (newdecl) = 0;
    3142     16163119 :   if (! DECL_COMDAT (olddecl))
    3143      6956971 :     DECL_COMDAT (newdecl) = 0;
    3144              : 
    3145     16163119 :   if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
    3146              :     {
    3147           78 :       if (!DECL_LOCAL_DECL_P (olddecl))
    3148              :         /* This can happen if olddecl was brought in from the
    3149              :            enclosing namespace via a using-decl.  The new decl is
    3150              :            then not a block-scope extern at all.  */
    3151            3 :         DECL_LOCAL_DECL_P (newdecl) = false;
    3152              :       else
    3153              :         {
    3154           75 :           retrofit_lang_decl (newdecl);
    3155           75 :           tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
    3156           75 :             = DECL_LOCAL_DECL_ALIAS (olddecl);
    3157           75 :           if (alias != error_mark_node)
    3158              :             {
    3159           72 :               DECL_ATTRIBUTES (alias)
    3160           72 :                 = (*targetm.merge_decl_attributes) (alias, newdecl);
    3161           72 :               if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3162           42 :                 merge_attribute_bits (newdecl, alias);
    3163              :             }
    3164              :         }
    3165              :     }
    3166              : 
    3167     16163119 :   new_template_info = NULL_TREE;
    3168     16163119 :   if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
    3169              :     {
    3170     16109143 :       bool new_redefines_gnu_inline = false;
    3171              : 
    3172     16109143 :       if (new_defines_function
    3173     16109143 :           && ((DECL_INTERFACE_KNOWN (olddecl)
    3174         1277 :                && TREE_CODE (olddecl) == FUNCTION_DECL)
    3175      9396352 :               || (TREE_CODE (olddecl) == TEMPLATE_DECL
    3176            0 :                   && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
    3177              :                       == FUNCTION_DECL))))
    3178         2554 :         new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
    3179              : 
    3180              :       if (!new_redefines_gnu_inline)
    3181              :         {
    3182     16109065 :           DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
    3183     16109065 :           DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
    3184     16109065 :           DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
    3185              :         }
    3186              : 
    3187     16109143 :       if (TREE_CODE (newdecl) != TYPE_DECL)
    3188              :         {
    3189     16109079 :           DECL_TEMPLATE_INSTANTIATED (newdecl)
    3190     16109079 :             |= DECL_TEMPLATE_INSTANTIATED (olddecl);
    3191     16109079 :           DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
    3192              : 
    3193              :           /* If the OLDDECL is an instantiation and/or specialization,
    3194              :              then the NEWDECL must be too.  But, it may not yet be marked
    3195              :              as such if the caller has created NEWDECL, but has not yet
    3196              :              figured out that it is a redeclaration.  */
    3197     16109079 :           if (!DECL_USE_TEMPLATE (newdecl))
    3198     15460376 :             DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
    3199              : 
    3200     16109079 :           if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
    3201     15542762 :             DECL_INITIALIZED_IN_CLASS_P (newdecl)
    3202     31085524 :               |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
    3203              :         }
    3204              : 
    3205              :       /* Don't really know how much of the language-specific
    3206              :          values we should copy from old to new.  */
    3207     16109143 :       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
    3208              : 
    3209     16109143 :       if (LANG_DECL_HAS_MIN (newdecl))
    3210              :         {
    3211     16109143 :           DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
    3212     16109143 :           if (DECL_TEMPLATE_INFO (newdecl))
    3213              :             {
    3214       648736 :               new_template_info = DECL_TEMPLATE_INFO (newdecl);
    3215       648736 :               if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    3216       648736 :                   && DECL_TEMPLATE_SPECIALIZATION (newdecl))
    3217              :                 /* Remember the presence of explicit specialization args.  */
    3218      1131280 :                 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
    3219      1131280 :                   = TINFO_USED_TEMPLATE_ID (new_template_info);
    3220              :             }
    3221              : 
    3222              :           /* We don't want to copy template info from a non-templated friend
    3223              :              (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now.  */
    3224     16109143 :           gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
    3225              :                                || !non_templated_friend_p (olddecl));
    3226     16109143 :           DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
    3227              :         }
    3228              : 
    3229     16109143 :       if (DECL_DECLARES_FUNCTION_P (newdecl))
    3230              :         {
    3231              :           /* Only functions have these fields.  */
    3232     15601504 :           DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
    3233     15601504 :           DECL_BEFRIENDING_CLASSES (newdecl)
    3234     15601504 :             = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
    3235     15601504 :                        DECL_BEFRIENDING_CLASSES (olddecl));
    3236              :           /* DECL_THUNKS is only valid for virtual functions,
    3237              :              otherwise it is a DECL_FRIEND_CONTEXT.  */
    3238     15601504 :           if (DECL_VIRTUAL_P (newdecl))
    3239       631834 :             SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
    3240     29939340 :           else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
    3241       382113 :             SET_DECL_FRIEND_CONTEXT (olddecl, fc);
    3242              :         }
    3243       507639 :       else if (VAR_P (newdecl))
    3244              :         {
    3245              :           /* Only variables have this field.  */
    3246       507575 :           if (VAR_HAD_UNKNOWN_BOUND (olddecl))
    3247          198 :             SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
    3248              :         }
    3249              :     }
    3250              : 
    3251     16163119 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3252              :     {
    3253     15601504 :       merge_decl_arguments (newdecl, olddecl, new_defines_function,
    3254              :                             types_match, false);
    3255              : 
    3256     15601504 :       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    3257     15601504 :           && !DECL_TEMPLATE_INSTANTIATION (newdecl))
    3258              :         {
    3259              :           /* If newdecl is not a specialization, then it is not a
    3260              :              template-related function at all.  And that means that we
    3261              :              should have exited above, returning 0.  */
    3262       565637 :           gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
    3263              : 
    3264       565637 :           if (DECL_ODR_USED (olddecl))
    3265              :             /* From [temp.expl.spec]:
    3266              : 
    3267              :                If a template, a member template or the member of a class
    3268              :                template is explicitly specialized then that
    3269              :                specialization shall be declared before the first use of
    3270              :                that specialization that would cause an implicit
    3271              :                instantiation to take place, in every translation unit in
    3272              :                which such a use occurs.  */
    3273            0 :             error ("explicit specialization of %qD after first use",
    3274              :                       olddecl);
    3275              : 
    3276       565637 :           SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
    3277       565637 :           DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
    3278      1131121 :                                    && DECL_NONGNU_INLINE_P (newdecl));
    3279              : 
    3280              :           /* Don't propagate visibility from the template to the
    3281              :              specialization here.  We'll do that in determine_visibility if
    3282              :              appropriate.  */
    3283       565637 :           DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
    3284              : 
    3285              :           /* [temp.expl.spec/14] We don't inline explicit specialization
    3286              :              just because the primary template says so.  */
    3287       565637 :           gcc_assert (!merge_attr);
    3288              : 
    3289       565637 :           DECL_DECLARED_INLINE_P (olddecl)
    3290       565637 :             = DECL_DECLARED_INLINE_P (newdecl);
    3291              : 
    3292       565637 :           DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3293       565637 :             = DECL_DISREGARD_INLINE_LIMITS (newdecl);
    3294              : 
    3295       565637 :           DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
    3296              :         }
    3297     15035867 :       else if (new_defines_function && DECL_INITIAL (olddecl))
    3298              :         {
    3299              :           /* Never inline re-defined extern inline functions.
    3300              :              FIXME: this could be better handled by keeping both
    3301              :              function as separate declarations.  */
    3302           78 :           DECL_UNINLINABLE (newdecl) = 1;
    3303              :         }
    3304              :       else
    3305              :         {
    3306     15035789 :           if (DECL_PENDING_INLINE_P (olddecl))
    3307              :             {
    3308            6 :               DECL_PENDING_INLINE_P (newdecl) = 1;
    3309            6 :               DECL_PENDING_INLINE_INFO (newdecl)
    3310           12 :                 = DECL_PENDING_INLINE_INFO (olddecl);
    3311              :             }
    3312     15035783 :           else if (DECL_PENDING_INLINE_P (newdecl))
    3313              :             ;
    3314     15035783 :           else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
    3315     15035783 :             DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
    3316     30071566 :               = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
    3317              : 
    3318     15035789 :           DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
    3319              : 
    3320     45107367 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    3321     30071578 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    3322              : 
    3323     30071578 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3324     15035789 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3325     15035789 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3326     29594643 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3327              :         }
    3328              : 
    3329              :       /* Preserve abstractness on cloned [cd]tors.  */
    3330     15601504 :       DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
    3331              : 
    3332              :       /* Update newdecl's parms to point at olddecl.  */
    3333     49600644 :       for (tree parm = DECL_ARGUMENTS (newdecl); parm;
    3334     33999140 :            parm = DECL_CHAIN (parm))
    3335     33999140 :         DECL_CONTEXT (parm) = olddecl;
    3336              : 
    3337     15601504 :       if (! types_match)
    3338              :         {
    3339          201 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    3340          201 :           COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
    3341          201 :           COPY_DECL_RTL (newdecl, olddecl);
    3342              :         }
    3343     15601504 :       if (! types_match || new_defines_function)
    3344              :         {
    3345              :           /* Update the contracts to reflect the new parameter names. */
    3346      9397830 :           update_contract_arguments (newdecl, olddecl);
    3347              : 
    3348              :           /* Mark the old PARM_DECLs in case std::meta::parameters_of has
    3349              :              been called on the old declaration and reflections of those
    3350              :              arguments are held across this point and used later.
    3351              :              Such PARM_DECLs are no longer present in
    3352              :              DECL_ARGUMENTS (DECL_CONTEXT (oldarg)) chain.  */
    3353      9397830 :           for (tree oldarg = DECL_ARGUMENTS (olddecl);
    3354     32946784 :                oldarg; oldarg = DECL_CHAIN (oldarg))
    3355     23548954 :             OLD_PARM_DECL_P (oldarg) = 1;
    3356              : 
    3357              :           /* These need to be copied so that the names are available.
    3358              :              Note that if the types do match, we'll preserve inline
    3359              :              info and other bits, but if not, we won't.  */
    3360      9397830 :           DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
    3361      9397830 :           DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
    3362              :         }
    3363              :       /* If redeclaring a builtin function, it stays built in
    3364              :          if newdecl is a gnu_inline definition, or if newdecl is just
    3365              :          a declaration.  */
    3366     15601504 :       if (fndecl_built_in_p (olddecl)
    3367     15658082 :           && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
    3368              :         {
    3369      4046123 :           copy_decl_built_in_function (newdecl, olddecl);
    3370              :           /* If we're keeping the built-in definition, keep the rtl,
    3371              :              regardless of declaration matches.  */
    3372      4046123 :           COPY_DECL_RTL (olddecl, newdecl);
    3373      4046123 :           if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3374              :             {
    3375      4046117 :               enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3376      4046117 :               if (builtin_decl_explicit_p (fncode))
    3377              :                 {
    3378              :                   /* A compatible prototype of these builtin functions
    3379              :                      is seen, assume the runtime implements it with
    3380              :                      the expected semantics.  */
    3381      4046117 :                   switch (fncode)
    3382              :                     {
    3383        10101 :                     case BUILT_IN_STPCPY:
    3384        10101 :                       set_builtin_decl_implicit_p (fncode, true);
    3385        10101 :                       break;
    3386      4036016 :                     default:
    3387      4036016 :                       set_builtin_decl_declared_p (fncode, true);
    3388      4036016 :                       break;
    3389              :                     }
    3390              :                 }
    3391              : 
    3392      4046117 :               copy_attributes_to_builtin (newdecl);
    3393              :             }
    3394              :         }
    3395     15601504 :       if (new_defines_function)
    3396              :         /* If defining a function declared with other language
    3397              :            linkage, use the previously declared language linkage.  */
    3398      9397629 :         SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    3399      6203875 :       else if (types_match)
    3400              :         {
    3401      6203674 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3402              :           /* Don't clear out the arguments if we're just redeclaring a
    3403              :              function.  */
    3404      6203674 :           if (DECL_ARGUMENTS (olddecl))
    3405      2120800 :               DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
    3406              :         }
    3407              :     }
    3408       561615 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    3409            0 :     NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
    3410              : 
    3411              :   /* Now preserve various other info from the definition.  */
    3412     16163119 :   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
    3413     16163119 :   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
    3414     16163119 :   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3415     16163119 :   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    3416              : 
    3417              :   /* Warn about conflicting visibility specifications.  */
    3418     16163119 :   if (DECL_VISIBILITY_SPECIFIED (olddecl)
    3419      5633556 :       && DECL_VISIBILITY_SPECIFIED (newdecl)
    3420     16174895 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    3421              :     {
    3422           12 :       auto_diagnostic_group d;
    3423           12 :       if (warning_at (newdecl_loc, OPT_Wattributes,
    3424              :                       "%qD: visibility attribute ignored because it "
    3425              :                       "conflicts with previous declaration", newdecl))
    3426           12 :         inform (olddecl_loc,
    3427              :                 "previous declaration of %qD", olddecl);
    3428           12 :     }
    3429              :   /* Choose the declaration which specified visibility.  */
    3430     16163119 :   if (DECL_VISIBILITY_SPECIFIED (olddecl))
    3431              :     {
    3432      5633556 :       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    3433      5633556 :       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    3434              :     }
    3435              :   /* Init priority used to be merged from newdecl to olddecl by the memcpy,
    3436              :      so keep this behavior.  */
    3437     16163119 :   if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
    3438              :     {
    3439           10 :       SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
    3440           10 :       DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
    3441              :     }
    3442              :   /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED.  */
    3443     16163119 :   if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    3444              :     {
    3445           54 :       SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    3446           54 :       DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    3447              :     }
    3448     16163065 :   else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    3449     16163065 :       && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    3450            3 :     DECL_USER_ALIGN (newdecl) = 1;
    3451              : 
    3452     16163119 :   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3453     32326238 :   if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    3454     16163119 :       > DECL_WARN_IF_NOT_ALIGN (newdecl))
    3455            0 :     SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    3456              :                                 DECL_WARN_IF_NOT_ALIGN (olddecl));
    3457     16163119 :   if (TREE_CODE (newdecl) == FIELD_DECL)
    3458            0 :     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
    3459              : 
    3460              :   /* Merge module entity mapping information.  */
    3461     16163119 :   if (DECL_LANG_SPECIFIC (olddecl)
    3462     32272713 :       && (DECL_MODULE_ENTITY_P (olddecl)
    3463     16104962 :           || DECL_MODULE_KEYED_DECLS_P (olddecl)))
    3464              :     {
    3465         4632 :       retrofit_lang_decl (newdecl);
    3466         4632 :       DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
    3467         4632 :       DECL_MODULE_KEYED_DECLS_P (newdecl) = DECL_MODULE_KEYED_DECLS_P (olddecl);
    3468              :     }
    3469              : 
    3470              :   /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
    3471              :      with that from NEWDECL below.  */
    3472     16163119 :   if (DECL_LANG_SPECIFIC (olddecl))
    3473              :     {
    3474     16109594 :       gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
    3475              :                            != DECL_LANG_SPECIFIC (newdecl));
    3476     16109594 :       ggc_free (DECL_LANG_SPECIFIC (olddecl));
    3477              :     }
    3478              : 
    3479              :   /* Merge the USED information.  */
    3480     16163119 :   if (TREE_USED (olddecl))
    3481       506754 :     TREE_USED (newdecl) = 1;
    3482     15656365 :   else if (TREE_USED (newdecl))
    3483           62 :     TREE_USED (olddecl) = 1;
    3484              : 
    3485     16163119 :   if (VAR_P (newdecl))
    3486              :     {
    3487       511236 :       if (DECL_READ_P (olddecl))
    3488        43741 :         DECL_READ_P (newdecl) = 1;
    3489       467495 :       else if (DECL_READ_P (newdecl))
    3490            3 :         DECL_READ_P (olddecl) = 1;
    3491              :     }
    3492              : 
    3493     16163119 :   if (DECL_PRESERVE_P (olddecl))
    3494           48 :     DECL_PRESERVE_P (newdecl) = 1;
    3495     16163071 :   else if (DECL_PRESERVE_P (newdecl))
    3496           75 :     DECL_PRESERVE_P (olddecl) = 1;
    3497              : 
    3498              :   /* Merge the DECL_FUNCTION_VERSIONED information.  newdecl will be copied
    3499              :      to olddecl and deleted.  */
    3500     16163119 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3501     31764623 :       && DECL_FUNCTION_VERSIONED (olddecl))
    3502              :     {
    3503              :       /* Set the flag for newdecl so that it gets copied to olddecl.  */
    3504          258 :       DECL_FUNCTION_VERSIONED (newdecl) = 1;
    3505              :       /* newdecl will be purged after copying to olddecl and is no longer
    3506              :          a version.  */
    3507          258 :       cgraph_node::delete_function_version_by_decl (newdecl);
    3508              :     }
    3509              : 
    3510     16163119 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3511              :     {
    3512     15601504 :       int function_size;
    3513     15601504 :       struct symtab_node *snode = symtab_node::get (olddecl);
    3514              : 
    3515     15601504 :       function_size = sizeof (struct tree_decl_common);
    3516              : 
    3517     15601504 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3518              :               (char *) newdecl + sizeof (struct tree_common),
    3519              :               function_size - sizeof (struct tree_common));
    3520              : 
    3521     15601504 :       memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3522              :               (char *) newdecl + sizeof (struct tree_decl_common),
    3523              :               sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
    3524              : 
    3525              :       /* Preserve symtab node mapping.  */
    3526     15601504 :       olddecl->decl_with_vis.symtab_node = snode;
    3527              : 
    3528     15601504 :       if (new_template_info)
    3529              :         /* If newdecl is a template instantiation, it is possible that
    3530              :            the following sequence of events has occurred:
    3531              : 
    3532              :            o A friend function was declared in a class template.  The
    3533              :            class template was instantiated.
    3534              : 
    3535              :            o The instantiation of the friend declaration was
    3536              :            recorded on the instantiation list, and is newdecl.
    3537              : 
    3538              :            o Later, however, instantiate_class_template called pushdecl
    3539              :            on the newdecl to perform name injection.  But, pushdecl in
    3540              :            turn called duplicate_decls when it discovered that another
    3541              :            declaration of a global function with the same name already
    3542              :            existed.
    3543              : 
    3544              :            o Here, in duplicate_decls, we decided to clobber newdecl.
    3545              : 
    3546              :            If we're going to do that, we'd better make sure that
    3547              :            olddecl, and not newdecl, is on the list of
    3548              :            instantiations so that if we try to do the instantiation
    3549              :            again we won't get the clobbered declaration.  */
    3550       648334 :         reregister_specialization (newdecl,
    3551              :                                    new_template_info,
    3552              :                                    olddecl);
    3553              :     }
    3554              :   else
    3555              :     {
    3556       561615 :       size_t size = tree_code_size (TREE_CODE (newdecl));
    3557              : 
    3558       561615 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3559              :               (char *) newdecl + sizeof (struct tree_common),
    3560              :               sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3561              : 
    3562       561615 :       switch (TREE_CODE (newdecl))
    3563              :         {
    3564       561615 :         case LABEL_DECL:
    3565       561615 :         case VAR_DECL:
    3566       561615 :         case RESULT_DECL:
    3567       561615 :         case PARM_DECL:
    3568       561615 :         case FIELD_DECL:
    3569       561615 :         case TYPE_DECL:
    3570       561615 :         case CONST_DECL:
    3571       561615 :           {
    3572       561615 :             struct symtab_node *snode = NULL;
    3573              : 
    3574       561615 :             if (VAR_P (newdecl)
    3575       561615 :                 && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
    3576            3 :                     || DECL_EXTERNAL (olddecl)))
    3577       511236 :               snode = symtab_node::get (olddecl);
    3578       561615 :             memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3579              :                     (char *) newdecl + sizeof (struct tree_decl_common),
    3580              :                     size - sizeof (struct tree_decl_common)
    3581       561615 :                     + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3582       561615 :             if (VAR_P (newdecl))
    3583       511236 :               olddecl->decl_with_vis.symtab_node = snode;
    3584              :           }
    3585              :           break;
    3586            0 :         default:
    3587            0 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3588              :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3589              :                   sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
    3590            0 :                   + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3591            0 :           break;
    3592              :         }
    3593              :     }
    3594              : 
    3595     16163119 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3596              :     {
    3597     16112740 :       if (DECL_EXTERNAL (olddecl)
    3598       512614 :           || TREE_PUBLIC (olddecl)
    3599     16112810 :           || TREE_STATIC (olddecl))
    3600              :         {
    3601              :           /* Merge the section attribute.
    3602              :              We want to issue an error if the sections conflict but that must be
    3603              :              done later in decl_attributes since we are called before attributes
    3604              :              are assigned.  */
    3605     16112740 :           if (DECL_SECTION_NAME (newdecl) != NULL)
    3606            7 :             set_decl_section_name (olddecl, newdecl);
    3607              : 
    3608     16112740 :           if (DECL_ONE_ONLY (newdecl))
    3609              :             {
    3610            0 :               struct symtab_node *oldsym, *newsym;
    3611            0 :               oldsym = symtab_node::get_create (olddecl);
    3612            0 :               newsym = symtab_node::get (newdecl);
    3613            0 :               oldsym->set_comdat_group (newsym->get_comdat_group ());
    3614              :             }
    3615              :         }
    3616              : 
    3617     16112740 :       if (VAR_P (newdecl)
    3618     16112740 :           && CP_DECL_THREAD_LOCAL_P (newdecl))
    3619              :         {
    3620          418 :           CP_DECL_THREAD_LOCAL_P (olddecl) = true;
    3621          418 :           if (!processing_template_decl)
    3622          385 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3623              :         }
    3624              :     }
    3625              : 
    3626     16163119 :   DECL_UID (olddecl) = olddecl_uid;
    3627              : 
    3628              :   /* NEWDECL contains the merged attribute lists.
    3629              :      Update OLDDECL to be the same.  */
    3630     16163119 :   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    3631              : 
    3632              :   /* NEWDECL's TLS model was chosen for NEWDECL alone, which may not have
    3633              :      been weak until merge_weak.  */
    3634     16163119 :   if (VAR_P (olddecl)
    3635       511236 :       && CP_DECL_THREAD_LOCAL_P (olddecl)
    3636          459 :       && DECL_WEAK (olddecl)
    3637     16163131 :       && !processing_template_decl)
    3638           12 :     weak_decl_tls_model (olddecl);
    3639              : 
    3640              :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3641              :     so that encode_section_info has a chance to look at the new decl
    3642              :     flags and attributes.  */
    3643     16163119 :   if (DECL_RTL_SET_P (olddecl)
    3644     16163134 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3645           15 :           || (VAR_P (olddecl)
    3646           15 :               && TREE_STATIC (olddecl))))
    3647           15 :     make_decl_rtl (olddecl);
    3648              : 
    3649              :   /* The NEWDECL will no longer be needed.  Because every out-of-class
    3650              :      declaration of a member results in a call to duplicate_decls,
    3651              :      freeing these nodes represents in a significant savings.
    3652              : 
    3653              :      Before releasing the node, be sore to remove function from symbol
    3654              :      table that might have been inserted there to record comdat group.
    3655              :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3656              :      structure is shared in between newdecl and oldecl.  */
    3657     16163119 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3658     15601504 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3659     16163119 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3660              :     {
    3661     16112740 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3662     16112740 :       if (snode)
    3663          413 :         snode->remove ();
    3664              :     }
    3665              : 
    3666     16163119 :   if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3667              :     {
    3668     15601504 :       tree clone;
    3669     16142599 :       FOR_EACH_CLONE (clone, olddecl)
    3670              :         {
    3671       541095 :           DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
    3672       541095 :           DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
    3673              :         }
    3674              :     }
    3675              : 
    3676       561615 :  return_old:
    3677              :   /* Remove the associated constraints for newdecl, if any, before
    3678              :      reclaiming memory. */
    3679     16164815 :   if (flag_concepts)
    3680     15900712 :     remove_constraints (newdecl);
    3681              : 
    3682     16164815 :   if (flag_contracts)
    3683              :     /* Remove the specifiers, and then remove the decl from the lookup.  */
    3684      1576193 :     remove_decl_with_fn_contracts_specifiers (newdecl);
    3685              : 
    3686              :   /* And similarly for any module tracking data.  */
    3687     16164815 :   if (modules_p ())
    3688        53084 :     remove_defining_module (newdecl);
    3689              : 
    3690     16164815 :   ggc_free (newdecl);
    3691              : 
    3692     16164815 :   return olddecl;
    3693              : }
    3694              : 
    3695              : /* Return zero if the declaration NEWDECL is valid
    3696              :    when the declaration OLDDECL (assumed to be for the same name)
    3697              :    has already been seen.
    3698              :    Otherwise return an error message format string with a %s
    3699              :    where the identifier should go.  */
    3700              : 
    3701              : static const char *
    3702     16368236 : redeclaration_error_message (tree newdecl, tree olddecl)
    3703              : {
    3704     16368747 :   if (redefinable_import_p (olddecl))
    3705              :     return NULL;
    3706              : 
    3707     16360254 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    3708              :     {
    3709              :       /* Because C++ can put things into name space for free,
    3710              :          constructs like "typedef struct foo { ... } foo"
    3711              :          would look like an erroneous redeclaration.  */
    3712        84676 :       if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
    3713              :         return NULL;
    3714              :       else
    3715            0 :         return G_("redefinition of %q#D");
    3716              :     }
    3717     16275578 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3718              :     {
    3719              :       /* If this is a pure function, its olddecl will actually be
    3720              :          the original initialization to `0' (which we force to call
    3721              :          abort()).  Don't complain about redefinition in this case.  */
    3722     23276126 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
    3723     11638081 :           && DECL_INITIAL (olddecl) == NULL_TREE)
    3724              :         return NULL;
    3725              : 
    3726              :       /* If both functions come from different namespaces, this is not
    3727              :          a redeclaration - this is a conflict with a used function.  */
    3728     23276096 :       if (DECL_NAMESPACE_SCOPE_P (olddecl)
    3729      2843226 :           && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
    3730     11638051 :           && ! decls_match (olddecl, newdecl))
    3731              :         return G_("%qD conflicts with used function");
    3732              : 
    3733              :       /* We'll complain about linkage mismatches in
    3734              :          warn_extern_redeclared_static.  */
    3735              : 
    3736              :       /* Defining the same name twice is no good.  */
    3737     11638048 :       if (decl_defined_p (olddecl)
    3738     11638048 :           && decl_defined_p (newdecl))
    3739              :         {
    3740          303 :           if (DECL_NAME (olddecl) == NULL_TREE)
    3741              :             return G_("%q#D not declared in class");
    3742          441 :           else if (!GNU_INLINE_P (olddecl)
    3743          387 :                    || GNU_INLINE_P (newdecl))
    3744              :             return G_("redefinition of %q#D");
    3745              :         }
    3746              : 
    3747     13498631 :       if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
    3748              :         {
    3749      1809474 :           bool olda = GNU_INLINE_P (olddecl);
    3750      1809474 :           bool newa = GNU_INLINE_P (newdecl);
    3751              : 
    3752      1809474 :           if (olda != newa)
    3753              :             {
    3754           15 :               if (newa)
    3755              :                 return G_("%q+D redeclared inline with "
    3756              :                           "%<gnu_inline%> attribute");
    3757              :               else
    3758            9 :                 return G_("%q+D redeclared inline without "
    3759              :                           "%<gnu_inline%> attribute");
    3760              :             }
    3761              :         }
    3762              : 
    3763              :       /* [class.compare.default]: A definition of a comparison operator as
    3764              :          defaulted that appears in a class shall be the first declaration of
    3765              :          that function.  */
    3766     11637811 :       special_function_kind sfk = special_function_p (olddecl);
    3767     11637811 :       if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
    3768              :         return G_("comparison operator %q+D defaulted after "
    3769              :                   "its first declaration");
    3770              : 
    3771     11637808 :       check_abi_tag_redeclaration
    3772     11637808 :         (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
    3773     11637808 :          lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
    3774              : 
    3775     11637808 :       return NULL;
    3776              :     }
    3777      4637515 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    3778              :     {
    3779      4126802 :       tree nt, ot;
    3780              : 
    3781      4126802 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
    3782              :         return G_("redefinition of %q#D");
    3783              : 
    3784      4126796 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
    3785          511 :         return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
    3786          511 :                                             DECL_TEMPLATE_RESULT (olddecl));
    3787              : 
    3788      4126285 :       if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
    3789              :         return NULL;
    3790              : 
    3791      4126273 :       nt = DECL_TEMPLATE_RESULT (newdecl);
    3792      4126273 :       if (DECL_TEMPLATE_INFO (nt))
    3793       992108 :         nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
    3794      4126273 :       ot = DECL_TEMPLATE_RESULT (olddecl);
    3795      4126273 :       if (DECL_TEMPLATE_INFO (ot))
    3796      4126273 :         ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
    3797      6928011 :       if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
    3798      4126312 :           && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
    3799              :         return G_("redefinition of %q#D");
    3800              : 
    3801      6702271 :       if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
    3802              :         {
    3803      1877668 :           bool olda = GNU_INLINE_P (ot);
    3804      1877668 :           bool newa = GNU_INLINE_P (nt);
    3805              : 
    3806      1877668 :           if (olda != newa)
    3807              :             {
    3808            0 :               if (newa)
    3809              :                 return G_("%q+D redeclared inline with "
    3810              :                           "%<gnu_inline%> attribute");
    3811              :               else
    3812            0 :                 return G_("%q+D redeclared inline without "
    3813              :                           "%<gnu_inline%> attribute");
    3814              :             }
    3815              :         }
    3816              : 
    3817              :       /* Core issue #226 (C++11):
    3818              : 
    3819              :            If a friend function template declaration specifies a
    3820              :            default template-argument, that declaration shall be a
    3821              :            definition and shall be the only declaration of the
    3822              :            function template in the translation unit.  */
    3823      4126258 :       if ((cxx_dialect != cxx98)
    3824      4110763 :           && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
    3825      4334876 :           && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
    3826              :                                        /*is_primary=*/true,
    3827              :                                        /*is_partial=*/false,
    3828              :                                        /*is_friend_decl=*/2))
    3829            3 :         return G_("redeclaration of friend %q#D "
    3830              :                   "may not have default template arguments");
    3831              : 
    3832              :       return NULL;
    3833              :     }
    3834       510713 :   else if (VAR_P (newdecl)
    3835       510629 :            && (CP_DECL_THREAD_LOCAL_P (newdecl)
    3836       510629 :                != CP_DECL_THREAD_LOCAL_P (olddecl))
    3837       510760 :            && (! DECL_LANG_SPECIFIC (olddecl)
    3838           44 :                || ! CP_DECL_THREADPRIVATE_P (olddecl)
    3839           41 :                || CP_DECL_THREAD_LOCAL_P (newdecl)))
    3840              :     {
    3841              :       /* Only variables can be thread-local, and all declarations must
    3842              :          agree on this property.  */
    3843            6 :       if (CP_DECL_THREAD_LOCAL_P (newdecl))
    3844              :         return G_("thread-local declaration of %q#D follows "
    3845              :                   "non-thread-local declaration");
    3846              :       else
    3847            3 :         return G_("non-thread-local declaration of %q#D follows "
    3848              :                   "thread-local declaration");
    3849              :     }
    3850       510707 :   else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
    3851              :     {
    3852              :       /* The objects have been declared at namespace scope.  If either
    3853              :          is a member of an anonymous union, then this is an invalid
    3854              :          redeclaration.  For example:
    3855              : 
    3856              :            int i;
    3857              :            union { int i; };
    3858              : 
    3859              :            is invalid.  */
    3860       510471 :       if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
    3861      1021011 :           || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
    3862              :         return G_("redeclaration of %q#D");
    3863              :       /* If at least one declaration is a reference, there is no
    3864              :          conflict.  For example:
    3865              : 
    3866              :            int i = 3;
    3867              :            extern int i;
    3868              : 
    3869              :          is valid.  */
    3870       510537 :       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
    3871              :         return NULL;
    3872              : 
    3873              :       /* Static data member declared outside a class definition
    3874              :          if the variable is defined within the class with constexpr
    3875              :          specifier is declaration rather than definition (and
    3876              :          deprecated).  */
    3877         2829 :       if (cxx_dialect >= cxx17
    3878         2756 :           && VAR_P (olddecl)
    3879         2700 :           && DECL_CLASS_SCOPE_P (olddecl)
    3880         2658 :           && DECL_DECLARED_CONSTEXPR_P (olddecl)
    3881         5475 :           && !DECL_INITIAL (newdecl))
    3882              :         {
    3883         2646 :           DECL_EXTERNAL (newdecl) = 1;
    3884              :           /* For now, only warn with explicit -Wdeprecated.  */
    3885         2646 :           if (OPTION_SET_P (warn_deprecated))
    3886              :             {
    3887           40 :               auto_diagnostic_group d;
    3888           40 :               if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
    3889              :                                 "redundant redeclaration of %<constexpr%> "
    3890              :                                 "static data member %qD", newdecl))
    3891            4 :                 inform (DECL_SOURCE_LOCATION (olddecl),
    3892              :                           "previous declaration of %qD", olddecl);
    3893           40 :             }
    3894              :           return NULL;
    3895              :         }
    3896              : 
    3897              :       /* Reject two definitions.  */
    3898              :       return G_("redefinition of %q#D");
    3899              :     }
    3900              :   else
    3901              :     {
    3902              :       /* Objects declared with block scope:  */
    3903              :       /* Reject two definitions, and reject a definition
    3904              :          together with an external reference.  */
    3905          155 :       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
    3906          155 :         return G_("redeclaration of %q#D");
    3907              :       return NULL;
    3908              :     }
    3909              : }
    3910              : 
    3911              : 
    3912              : /* Hash and equality functions for the named_label table.  */
    3913              : 
    3914              : hashval_t
    3915        86896 : named_label_hash::hash (const value_type entry)
    3916              : {
    3917        86896 :   return IDENTIFIER_HASH_VALUE (entry->name);
    3918              : }
    3919              : 
    3920              : bool
    3921        83558 : named_label_hash::equal (const value_type entry, compare_type name)
    3922              : {
    3923        83558 :   return name == entry->name;
    3924              : }
    3925              : 
    3926              : /* Look for a label named ID in the current function.  If one cannot
    3927              :    be found, create one.  Return the named_label_entry, or NULL on
    3928              :    failure.  */
    3929              : 
    3930              : static named_label_entry *
    3931        26127 : lookup_label_1 (tree id, bool making_local_p)
    3932              : {
    3933        26127 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    3934              : 
    3935              :   /* You can't use labels at global scope.  */
    3936        26127 :   if (current_function_decl == NULL_TREE)
    3937              :     {
    3938            3 :       error ("label %qE referenced outside of any function", id);
    3939            3 :       return NULL;
    3940              :     }
    3941              : 
    3942        26124 :   if (!named_labels)
    3943         4912 :     named_labels = hash_table<named_label_hash>::create_ggc (13);
    3944              : 
    3945        26124 :   hashval_t hash = IDENTIFIER_HASH_VALUE (id);
    3946        26124 :   named_label_entry **slot
    3947        26124 :     = named_labels->find_slot_with_hash (id, hash, INSERT);
    3948        26124 :   named_label_entry *old = *slot;
    3949              : 
    3950        26124 :   if (old && old->label_decl)
    3951              :     {
    3952         3929 :       if (!making_local_p)
    3953              :         return old;
    3954              : 
    3955           21 :       if (old->binding_level == current_binding_level)
    3956              :         {
    3957            0 :           auto_diagnostic_group d;
    3958            0 :           error ("local label %qE conflicts with existing label", id);
    3959            0 :           inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
    3960            0 :           return NULL;
    3961            0 :         }
    3962              :     }
    3963              : 
    3964              :   /* We are making a new decl, create or reuse the named_label_entry  */
    3965        22237 :   named_label_entry *ent = NULL;
    3966           33 :   if (old && !old->label_decl)
    3967              :     ent = old;
    3968              :   else
    3969              :     {
    3970        22204 :       ent = ggc_cleared_alloc<named_label_entry> ();
    3971        22204 :       ent->name = id;
    3972        22204 :       ent->outer = old;
    3973        22204 :       *slot = ent;
    3974              :     }
    3975              : 
    3976              :   /* Now create the LABEL_DECL.  */
    3977        22216 :   tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
    3978              : 
    3979        22216 :   DECL_CONTEXT (decl) = current_function_decl;
    3980        22216 :   SET_DECL_MODE (decl, VOIDmode);
    3981        22216 :   if (making_local_p)
    3982              :     {
    3983          219 :       C_DECLARED_LABEL_FLAG (decl) = true;
    3984          219 :       DECL_CHAIN (decl) = current_binding_level->names;
    3985          219 :       current_binding_level->names = decl;
    3986              :     }
    3987              : 
    3988        22216 :   ent->label_decl = decl;
    3989              : 
    3990        22216 :   return ent;
    3991        26127 : }
    3992              : 
    3993              : /* Wrapper for lookup_label_1.  */
    3994              : 
    3995              : tree
    3996         3196 : lookup_label (tree id)
    3997              : {
    3998         3196 :   named_label_entry *ent = lookup_label_1 (id, false);
    3999         3196 :   if (ent && ent->label_decl)
    4000              :     {
    4001         3193 :       if (LABEL_DECL_IN_TEMPLATE_FOR_P (ent->label_decl))
    4002              :         {
    4003           24 :           auto_diagnostic_group d;
    4004           24 :           error ("reference to a label %qD inside of "
    4005              :                  "%<template for%> body", ent->label_decl);
    4006           24 :           inform (DECL_SOURCE_LOCATION (ent->label_decl),
    4007              :                   "definition of the label");
    4008           24 :         }
    4009         3169 :       else if (ent->ambiguous)
    4010              :         {
    4011            6 :           auto_diagnostic_group d;
    4012            6 :           error ("reference to an ambiguous label %qD", ent->label_decl);
    4013            6 :           inform (DECL_SOURCE_LOCATION (ent->label_decl),
    4014              :                   "definition of the first label");
    4015            6 :           inform (ent->other_label_locus,
    4016              :                   "definition of the second label");
    4017            6 :         }
    4018         3193 :       return ent->label_decl;
    4019              :     }
    4020              :   return NULL_TREE;
    4021              : }
    4022              : 
    4023              : /* Look for a label named ID in the current function and return it if it
    4024              :    exists (or has just been referenced in some forward goto or &&label),
    4025              :    otherwise return NULL.  Don't report any errors.  */
    4026              : 
    4027              : tree
    4028           56 : maybe_lookup_label (tree id)
    4029              : {
    4030           56 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    4031              : 
    4032           56 :   if (current_function_decl == NULL_TREE || !named_labels)
    4033              :     return NULL_TREE;
    4034              : 
    4035           56 :   hashval_t hash = IDENTIFIER_HASH_VALUE (id);
    4036           56 :   named_label_entry **slot
    4037           56 :     = named_labels->find_slot_with_hash (id, hash, NO_INSERT);
    4038           56 :   if (slot != NULL)
    4039           38 :     return (*slot)->label_decl;
    4040              :   return NULL_TREE;
    4041           56 : }
    4042              : 
    4043              : /* Remember that we've seen &&ID.  */
    4044              : 
    4045              : void
    4046          283 : mark_label_addressed (tree id)
    4047              : {
    4048          283 :   named_label_entry *ent = lookup_label_1 (id, false);
    4049          283 :   if (!ent->addressed)
    4050              :     {
    4051          223 :       ent->addressed = true;
    4052          223 :       ent->goto_locus = input_location;
    4053              :     }
    4054          283 : }
    4055              : 
    4056              : tree
    4057          219 : declare_local_label (tree id)
    4058              : {
    4059          219 :   named_label_entry *ent = lookup_label_1 (id, true);
    4060          219 :   return ent ? ent->label_decl : NULL_TREE;
    4061              : }
    4062              : 
    4063              : /* Returns true if it is ill-formed to jump past the declaration of DECL.  */
    4064              : 
    4065              : static bool
    4066      3011571 : decl_jump_unsafe (tree decl)
    4067              : {
    4068              :   /* [stmt.dcl]/3: A program that jumps from a point where a local variable
    4069              :      with automatic storage duration is not in scope to a point where it is
    4070              :      in scope is ill-formed unless the variable has scalar type, class type
    4071              :      with a trivial default constructor and a trivial destructor, a
    4072              :      cv-qualified version of one of these types, or an array of one of the
    4073              :      preceding types and is declared without an initializer (8.5).  */
    4074      3011571 :   tree type = TREE_TYPE (decl);
    4075              : 
    4076      3011571 :   return (type != error_mark_node
    4077      3011541 :           && VAR_P (decl)
    4078        17389 :           && !TREE_STATIC (decl)
    4079      3028824 :           && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    4080        13695 :               || variably_modified_type_p (type, NULL_TREE)));
    4081              : }
    4082              : 
    4083              : /* Returns true if decl is an automatic variable with vacuous initialization
    4084              :    except when it is [[indeterminate]] or [[gnu::uninitialized]].
    4085              :    Jumps across such initialization need to be instrumented for
    4086              :    !!flag_auto_var_init.  */
    4087              : 
    4088              : static bool
    4089      3008004 : decl_instrument_init_bypass_p (tree decl)
    4090              : {
    4091      3008004 :   tree type = TREE_TYPE (decl);
    4092              : 
    4093      3008004 :   return (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    4094      2245356 :           && !processing_template_decl
    4095      2245009 :           && type != error_mark_node
    4096      2244991 :           && VAR_P (decl)
    4097         1240 :           && !TREE_STATIC (decl)
    4098         1219 :           && !DECL_EXTERNAL (decl)
    4099         2410 :           && !(DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    4100         1205 :                || variably_modified_type_p (type, NULL_TREE))
    4101         1205 :           && !lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (decl))
    4102         1205 :           && !lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))
    4103      3009209 :           && !DECL_HAS_VALUE_EXPR_P (decl));
    4104              : }
    4105              : 
    4106              : /* Build .DEFERRED_INIT call for DECL.  */
    4107              : 
    4108              : static tree
    4109          142 : build_deferred_init_call (tree decl)
    4110              : {
    4111          142 :   tree decl_size_arg = TYPE_SIZE_UNIT (TREE_TYPE (decl));
    4112          284 :   tree init_type_arg = build_int_cst (integer_type_node,
    4113          142 :                                       (int) flag_auto_var_init);
    4114          142 :   location_t loc = DECL_SOURCE_LOCATION (decl);
    4115          142 :   tree decl_name;
    4116              : 
    4117          142 :   if (DECL_NAME (decl))
    4118          142 :     decl_name = build_string_literal (DECL_NAME (decl));
    4119              :   else
    4120              :     {
    4121            0 :       char decl_name_anonymous[3 + (HOST_BITS_PER_INT + 2) / 3];
    4122            0 :       sprintf (decl_name_anonymous, "D.%u", DECL_UID (decl));
    4123            0 :       decl_name = build_string_literal (decl_name_anonymous);
    4124              :     }
    4125              : 
    4126          142 :   tree call = build_call_expr_internal_loc (loc, IFN_DEFERRED_INIT,
    4127          142 :                                             TREE_TYPE (decl), 3,
    4128              :                                             decl_size_arg, init_type_arg,
    4129              :                                             decl_name);
    4130          142 :   tree ret = build2_loc (loc, MODIFY_EXPR, void_type_node, decl, call);
    4131          142 :   return build_stmt (loc, EXPR_STMT, ret);
    4132              : }
    4133              : 
    4134              : /* Emit before ITER (and any labels/case labels before it) code like
    4135              :    if (0)
    4136              :      {
    4137              :        l1:
    4138              :         v4 = .DEFERRED_INIT (sizeof (v4), ?, "v4");
    4139              :         v3 = .DEFERRED_INIT (sizeof (v3), ?, "v3");
    4140              :         v2 = .DEFERRED_INIT (sizeof (v2), ?, "v2");
    4141              :         v1 = .DEFERRED_INIT (sizeof (v1), ?, "v1");
    4142              :      }
    4143              :    and return l1 label, or if it already exists, assert it has the
    4144              :    .DEFERRED_INIT calls for the right decls in the right order and
    4145              :    amend it, either by adding extra labels in between or further
    4146              :    ,DEFERRED_INIT calls before the first label and extra label before
    4147              :    that.  If CASE_LABEL is non-NULL, emit that CASE_LABEL_EXPR instead
    4148              :    of adding a label.  DECLS points to an array of NDECLS VAR_DECLs
    4149              :    which should be initialized.  */
    4150              : 
    4151              : static tree
    4152          129 : maybe_add_deferred_init_calls (tree_stmt_iterator iter, tree case_label,
    4153              :                                tree *decls, unsigned ndecls)
    4154              : {
    4155          129 :   tree lab = NULL_TREE;
    4156          193 :   for (; !tsi_end_p (iter); tsi_prev (&iter))
    4157              :     {
    4158          187 :       switch (TREE_CODE (tsi_stmt (iter)))
    4159              :         {
    4160           64 :         case LABEL_EXPR:
    4161           64 :         case CASE_LABEL_EXPR:
    4162           64 :         case DEBUG_BEGIN_STMT:
    4163           64 :           continue;
    4164              :         default:
    4165              :           break;
    4166              :         }
    4167              :       break;
    4168              :     }
    4169          129 :   if (!tsi_end_p (iter)
    4170          123 :       && TREE_CODE (tsi_stmt (iter)) == IF_STMT
    4171          206 :       && IF_STMT_VACUOUS_INIT_P (tsi_stmt (iter)))
    4172              :     {
    4173              :       /* Found IF_STMT added for this or some adjacent
    4174              :          LABEL_EXPR/CASE_LABEL_EXPR by an earlier call to this function.
    4175              :          The decls are ordered so that we can always reuse it.  Sometimes
    4176              :          by no modifications at all and just returning the right label
    4177              :          which was added already before, sometimes by adding a label in
    4178              :          between two previously added .DEFERRED_INIT calls and sometimes
    4179              :          by adding extra statements (.DEFERRED_INIT calls and LABEL_EXPR
    4180              :          before that) before the statements in IF_STMT body.  */
    4181           71 :       tree then_clause = THEN_CLAUSE (tsi_stmt (iter));
    4182           71 :       iter = tsi_last (then_clause);
    4183           71 :       bool add = false;
    4184          452 :       for (unsigned int i = 0; i < ndecls; ++i)
    4185              :         {
    4186          310 :           tree decl = decls[i];
    4187          310 :           if (!add)
    4188              :             {
    4189              :               /* Skip over labels/case labels after .DEFERRED_INIT for the
    4190              :                  DECL we are looking for.  */
    4191          399 :               while (!tsi_end_p (iter)
    4192          399 :                      && (TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR
    4193          286 :                          || (TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR
    4194           26 :                              && !case_label)))
    4195          119 :                 tsi_prev (&iter);
    4196          280 :               if (tsi_end_p (iter))
    4197              :                 {
    4198              :                   /* Reached the start, we'll need to prepend further
    4199              :                      statements.  */
    4200           20 :                   add = true;
    4201           20 :                   iter = tsi_start (then_clause);
    4202              :                 }
    4203              :               else
    4204              :                 {
    4205              :                   /* Found something, assert it is .DEFERRED_INIT for
    4206              :                      DECL.  */
    4207          260 :                   tree t = tsi_stmt (iter);
    4208          260 :                   gcc_checking_assert (TREE_CODE (t) == EXPR_STMT);
    4209          260 :                   t = EXPR_STMT_EXPR (t);
    4210          260 :                   gcc_checking_assert (TREE_CODE (t) == MODIFY_EXPR
    4211              :                                        && TREE_OPERAND (t, 0) == decl
    4212              :                                        && (TREE_CODE (TREE_OPERAND (t, 1))
    4213              :                                            == CALL_EXPR));
    4214          260 :                   t = TREE_OPERAND (t, 1);
    4215          260 :                   gcc_checking_assert (CALL_EXPR_FN (t) == NULL_TREE
    4216              :                                        && (CALL_EXPR_IFN (t)
    4217              :                                            == IFN_DEFERRED_INIT));
    4218          260 :                   tsi_prev (&iter);
    4219              :                 }
    4220              :             }
    4221          280 :           if (add)
    4222              :             {
    4223              :               /* If reached the start in this or some earlier iteration,
    4224              :                  prepend .DEFERRED_INIT call for DECL.  */
    4225           50 :               tree t = build_deferred_init_call (decl);
    4226           50 :               STMT_IS_FULL_EXPR_P (t) = 1;
    4227           50 :               tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
    4228              :             }
    4229              :         }
    4230           71 :       if (!add)
    4231              :         {
    4232              :           /* If .DEFERRED_INIT calls for all the decls were already there,
    4233              :              skip over case labels and if we find a LABEL_EXPR, return
    4234              :              its label.  */
    4235           63 :           while (!tsi_end_p (iter)
    4236           63 :                  && !case_label
    4237          117 :                  && TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR)
    4238           12 :             tsi_prev (&iter);
    4239           51 :           if (tsi_end_p (iter))
    4240              :             {
    4241              :               /* Only case labels were found and we are looking for normal
    4242              :                  label, we'll need to add it.  */
    4243            0 :               add = true;
    4244            0 :               iter = tsi_start (then_clause);
    4245              :             }
    4246           51 :           else if (!case_label
    4247           51 :                    && TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR)
    4248              :             /* Return existing label.  */
    4249           21 :             lab = LABEL_EXPR_LABEL (tsi_stmt (iter));
    4250              :           else
    4251              :             {
    4252              :               /* We'll need to add a LABEL_EXPR or move CASE_LABEL_EXPR.  */
    4253           30 :               gcc_checking_assert (case_label
    4254              :                                    || (TREE_CODE (tsi_stmt (iter))
    4255              :                                        == EXPR_STMT));
    4256           30 :               add = true;
    4257           30 :               tsi_next (&iter);
    4258           30 :               gcc_checking_assert (!tsi_end_p (iter));
    4259              :             }
    4260              :         }
    4261           21 :       if (add)
    4262              :         {
    4263           50 :           tree t;
    4264           50 :           if (case_label)
    4265              :             t = case_label;
    4266              :           else
    4267              :             {
    4268           41 :               lab = create_artificial_label (UNKNOWN_LOCATION);
    4269           41 :               t = build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab);
    4270              :             }
    4271           50 :           tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
    4272              :         }
    4273              :     }
    4274              :   else
    4275              :     {
    4276              :       /* No IF_STMT created by this function found.  Create it all
    4277              :          from scratch, so a LABEL_EXPR (or moved CASE_LABEL_EXPR)
    4278              :          followed by .DEFERRED_INIT calls inside of a new if (0).  */
    4279           58 :       tree new_then = push_stmt_list ();
    4280           58 :       if (!case_label)
    4281              :         {
    4282           23 :           lab = create_artificial_label (UNKNOWN_LOCATION);
    4283           23 :           add_stmt (build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab));
    4284              :         }
    4285              :       else
    4286           35 :         add_stmt (case_label);
    4287          150 :       for (unsigned int i = ndecls; i; --i)
    4288           92 :         add_stmt (build_deferred_init_call (decls[i - 1]));
    4289           58 :       new_then = pop_stmt_list (new_then);
    4290           58 :       tree stmt = build4 (IF_STMT, void_type_node, boolean_false_node,
    4291              :                           new_then, void_node, NULL_TREE);
    4292           58 :       IF_STMT_VACUOUS_INIT_P (stmt) = 1;
    4293           58 :       if (tsi_end_p (iter))
    4294              :         {
    4295            6 :           iter = tsi_start (iter.container);
    4296            6 :           tsi_link_before (&iter, stmt, TSI_SAME_STMT);
    4297              :         }
    4298              :       else
    4299           52 :         tsi_link_after (&iter, stmt, TSI_CONTINUE_LINKING);
    4300              :     }
    4301          129 :   return lab;
    4302              : }
    4303              : 
    4304              : /* Adjust backward gotos to named label ENT if they jump over vacuous
    4305              :    initializers if !!flag_auto_var_init.  ITER is the location of
    4306              :    LABEL_EXPR for that named label.  */
    4307              : 
    4308              : static void
    4309           19 : adjust_backward_goto (named_label_entry *ent, tree_stmt_iterator iter)
    4310              : {
    4311           19 :   auto_vec<tree, 4> decls;
    4312           19 :   unsigned int i, max_cnt = ent->direct_goto->last ().n_bad_decls;
    4313           19 :   tree decl;
    4314          107 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, i, decl)
    4315           88 :     if (!decl_jump_unsafe (decl))
    4316              :       {
    4317           88 :         gcc_checking_assert (decl_instrument_init_bypass_p (decl));
    4318           88 :         decls.safe_push (decl);
    4319          176 :         if (decls.length () == max_cnt)
    4320              :           break;
    4321              :       }
    4322           19 :   named_label_bck_direct_goto *dgoto;
    4323           19 :   unsigned last = 0;
    4324           19 :   tree lab = NULL_TREE;
    4325          103 :   FOR_EACH_VEC_SAFE_ELT_REVERSE (ent->direct_goto, i, dgoto)
    4326              :     {
    4327           46 :       if (dgoto->n_bad_decls != last)
    4328              :         {
    4329           40 :           last = dgoto->n_bad_decls;
    4330           80 :           lab = maybe_add_deferred_init_calls (iter, NULL_TREE,
    4331              :                                                decls.address (), last);
    4332              :         }
    4333           46 :       *dgoto->direct_goto = lab;
    4334              :     }
    4335           19 : }
    4336              : 
    4337              : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
    4338              :    to the user.  */
    4339              : 
    4340              : static bool
    4341          297 : identify_goto (tree decl, location_t loc, const location_t *locus,
    4342              :                enum diagnostics::kind diag_kind, bool computed)
    4343              : {
    4344          297 :   if (computed)
    4345           43 :     diag_kind = diagnostics::kind::warning;
    4346          297 :   auto_diagnostic_group d;
    4347          297 :   bool complained
    4348          384 :     = emit_diagnostic (diag_kind, loc, 0,
    4349              :                        decl ? G_("jump to label %qD")
    4350              :                        : G_("jump to case label"), decl);
    4351          297 :   if (complained && locus)
    4352              :     {
    4353          210 :       if (computed)
    4354           43 :         inform (*locus, "  as a possible target of computed goto");
    4355              :       else
    4356          167 :         inform (*locus, "  from here");
    4357              :     }
    4358          594 :   return complained;
    4359          297 : }
    4360              : 
    4361              : /* Check that a single previously seen jump to a newly defined label
    4362              :    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
    4363              :    the jump context; NAMES are the names in scope in LEVEL at the jump
    4364              :    context; LOCUS is the source position of the jump or 0.  COMPUTED
    4365              :    is a vec of decls if the jump is a computed goto.  DIRECT_GOTO is a
    4366              :    vec of pointers to LABEL_DECLs that might need adjusting if vacuous
    4367              :    initializations are crossed for !!flag_auto_var_init.  CASE_LABEL is
    4368              :    CASE_LABEL_EXPR to be moved if needed for the check_switch_goto case.
    4369              :    Returns non-zero if all is well, 2 if any vacuous initializers were
    4370              :    crossed.  */
    4371              : 
    4372              : static int
    4373      1835653 : check_previous_goto_1 (tree decl, cp_binding_level *level, tree names,
    4374              :                        bool exited_omp, const location_t *locus,
    4375              :                        vec<tree, va_gc> *computed,
    4376              :                        vec<named_label_fwd_direct_goto, va_gc> *direct_goto,
    4377              :                        tree case_label)
    4378              : {
    4379      1835653 :   auto_diagnostic_group d;
    4380      1835653 :   cp_binding_level *b;
    4381      1835653 :   bool complained = false;
    4382      1835653 :   int identified = 0;
    4383      1835653 :   bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
    4384      1835653 :   bool saw_ceif = false, saw_se = false;
    4385      1835653 :   auto_vec<tree> vacuous_decls;
    4386      1835653 :   bool vacuous_inits = false;
    4387              : 
    4388      1835653 :   if (exited_omp)
    4389              :     {
    4390           12 :       complained = identify_goto (decl, input_location, locus,
    4391              :                                   diagnostics::kind::error,
    4392              :                                   computed);
    4393           12 :       if (complained)
    4394           12 :         inform (input_location, "  exits OpenMP structured block");
    4395              :       saw_omp = true;
    4396              :       identified = 2;
    4397              :     }
    4398              : 
    4399      3641590 :   for (b = current_binding_level; b ; b = b->level_chain)
    4400              :     {
    4401      3641590 :       tree new_decls, old_decls = (b == level ? names : NULL_TREE);
    4402              : 
    4403      6645626 :       for (new_decls = b->names; new_decls != old_decls;
    4404      5997365 :            new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
    4405      2993329 :                         : TREE_CHAIN (new_decls)))
    4406              :         {
    4407      3004036 :           bool problem = decl_jump_unsafe (new_decls);
    4408      3004036 :           if (! problem)
    4409              :             {
    4410      3003987 :               if (decl_instrument_init_bypass_p (new_decls))
    4411              :                 {
    4412          328 :                   if (direct_goto || case_label)
    4413          257 :                     vacuous_decls.safe_push (new_decls);
    4414              :                   vacuous_inits = true;
    4415              :                 }
    4416      3003987 :               continue;
    4417              :             }
    4418              : 
    4419           49 :           if (!identified)
    4420              :             {
    4421           49 :               complained = identify_goto (decl, input_location, locus,
    4422              :                                           diagnostics::kind::error,
    4423              :                                           computed);
    4424           49 :               identified = 2;
    4425              :             }
    4426           49 :           if (complained)
    4427           49 :             inform (DECL_SOURCE_LOCATION (new_decls),
    4428              :                     "  crosses initialization of %q#D", new_decls);
    4429              :         }
    4430              : 
    4431      3641590 :       if (b == level)
    4432              :         break;
    4433              : 
    4434      1805937 :       const char *inf = NULL;
    4435      1805937 :       location_t loc = input_location;
    4436      1805937 :       switch (b->kind)
    4437              :         {
    4438            3 :         case sk_try:
    4439            3 :           if (!saw_eh)
    4440              :             inf = G_("  enters %<try%> block");
    4441              :           saw_eh = true;
    4442              :           break;
    4443              : 
    4444            9 :         case sk_catch:
    4445            9 :           if (!saw_eh)
    4446              :             inf = G_("  enters %<catch%> block");
    4447              :           saw_eh = true;
    4448              :           break;
    4449              : 
    4450          102 :         case sk_omp:
    4451          102 :           if (!saw_omp)
    4452              :             inf = G_("  enters OpenMP structured block");
    4453              :           saw_omp = true;
    4454              :           break;
    4455              : 
    4456            3 :         case sk_transaction:
    4457            3 :           if (!saw_tm)
    4458              :             inf = G_("  enters synchronized or atomic statement");
    4459              :           saw_tm = true;
    4460              :           break;
    4461              : 
    4462           18 :         case sk_stmt_expr:
    4463           18 :           if (!saw_se)
    4464              :             inf = G_("  enters statement expression");
    4465              :           saw_se = true;
    4466              :           break;
    4467              : 
    4468      1805657 :         case sk_block:
    4469      1805657 :           if (!saw_cxif && level_for_constexpr_if (b->level_chain))
    4470              :             {
    4471            9 :               inf = G_("  enters %<constexpr if%> statement");
    4472            9 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    4473              :               saw_cxif = true;
    4474              :             }
    4475      1805648 :           else if (!saw_ceif && level_for_consteval_if (b->level_chain))
    4476              :             {
    4477           18 :               inf = G_("  enters %<consteval if%> statement");
    4478           18 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    4479              :               saw_ceif = true;
    4480              :             }
    4481              :           break;
    4482              : 
    4483              :         default:
    4484              :           break;
    4485              :         }
    4486              : 
    4487           27 :       if (inf)
    4488              :         {
    4489          141 :           if (identified < 2)
    4490          141 :             complained = identify_goto (decl, input_location, locus,
    4491              :                                         diagnostics::kind::error,
    4492              :                                         computed);
    4493          141 :           identified = 2;
    4494          141 :           if (complained)
    4495          141 :             inform (loc, inf);
    4496              :         }
    4497              :     }
    4498              : 
    4499      1835653 :   if (!vec_safe_is_empty (computed))
    4500              :     {
    4501            9 :       if (!identified)
    4502            6 :         complained = identify_goto (decl, input_location, locus,
    4503              :                                     diagnostics::kind::error,
    4504              :                                     computed);
    4505            9 :       identified = 2;
    4506            9 :       if (complained)
    4507           18 :         for (tree d : computed)
    4508              :           {
    4509            9 :             if (DECL_P (d))
    4510            6 :               inform (DECL_SOURCE_LOCATION (d), "  does not destroy %qD", d);
    4511            3 :             else if (d == get_identifier ("catch"))
    4512            3 :               inform (*locus, "  does not clean up handled exception");
    4513              :           }
    4514              :     }
    4515              : 
    4516      1835745 :   if (!vacuous_decls.is_empty () && !seen_error ())
    4517              :     {
    4518           89 :       tree_stmt_iterator iter = tsi_last (cur_stmt_list);
    4519           89 :       if (case_label)
    4520              :         {
    4521           44 :           gcc_checking_assert (tsi_stmt (iter) == case_label);
    4522           44 :           tsi_delink (&iter);
    4523           44 :           iter = tsi_last (cur_stmt_list);
    4524              :         }
    4525           89 :       tree lab = maybe_add_deferred_init_calls (iter, case_label,
    4526              :                                                 vacuous_decls.address (),
    4527              :                                                 vacuous_decls.length ());
    4528           89 :       if (lab)
    4529              :         {
    4530              :           unsigned int i;
    4531              :           named_label_fwd_direct_goto *dgoto;
    4532          179 :           FOR_EACH_VEC_SAFE_ELT (direct_goto, i, dgoto)
    4533           45 :             *dgoto->direct_goto = lab;
    4534              :         }
    4535              :     }
    4536              : 
    4537      1835653 :   if (identified)
    4538              :     return 0;
    4539      1835445 :   return vacuous_inits ? 2 : 1;
    4540      1835653 : }
    4541              : 
    4542              : static void
    4543         2167 : check_previous_goto (tree decl, struct named_label_use_entry *use)
    4544              : {
    4545         2167 :   check_previous_goto_1 (decl, use->binding_level,
    4546              :                          use->names_in_scope, use->in_omp_scope,
    4547         2167 :                          &use->o_goto_locus, use->computed_goto,
    4548              :                          use->direct_goto, NULL_TREE);
    4549         2167 :   vec_free (use->direct_goto);
    4550         2167 : }
    4551              : 
    4552              : static int
    4553      1833486 : check_switch_goto (cp_binding_level *level, tree case_label)
    4554              : {
    4555      1833486 :   return check_previous_goto_1 (NULL_TREE, level, level->names,
    4556      1833486 :                                 false, NULL, nullptr, nullptr, case_label);
    4557              : }
    4558              : 
    4559              : /* Check that a new jump to a label ENT is OK.  DECLP is a pointer
    4560              :    to a LABEL_DECL for direct gotos and NULL for computed gotos.  */
    4561              : 
    4562              : void
    4563         3062 : check_goto_1 (named_label_entry *ent, tree *declp)
    4564              : {
    4565         3062 :   auto_diagnostic_group d;
    4566         3062 :   tree decl = ent->label_decl;
    4567         3062 :   bool computed = declp == NULL;
    4568              : 
    4569         3062 :   if (ent->goto_locus == UNKNOWN_LOCATION)
    4570         1918 :     ent->goto_locus = input_location;
    4571              : 
    4572              :   /* If the label hasn't been defined yet, defer checking.  */
    4573         3062 :   if (! DECL_INITIAL (decl))
    4574              :     {
    4575              :       /* Don't bother creating another use if the last goto had the
    4576              :          same data, and will therefore create the same set of errors.  */
    4577         2349 :       if (ent->uses
    4578          706 :           && ent->uses->binding_level == current_binding_level
    4579           63 :           && ent->uses->names_in_scope == current_binding_level->names)
    4580              :         {
    4581           63 :           if (declp
    4582           57 :               && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    4583           12 :               && !processing_template_decl)
    4584           10 :             vec_safe_push (ent->uses->direct_goto,
    4585           10 :                            named_label_fwd_direct_goto { declp });
    4586              :           return;
    4587              :         }
    4588              : 
    4589         2286 :       named_label_use_entry *new_use
    4590         2286 :         = ggc_alloc<named_label_use_entry> ();
    4591         2286 :       new_use->binding_level = current_binding_level;
    4592         2286 :       new_use->names_in_scope = current_binding_level->names;
    4593         2286 :       new_use->o_goto_locus = input_location;
    4594         2286 :       new_use->in_omp_scope = false;
    4595         2286 :       new_use->computed_goto = computed ? make_tree_vector () : nullptr;
    4596         2286 :       new_use->direct_goto = nullptr;
    4597         2286 :       if (declp
    4598         2195 :           && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    4599          423 :           && !processing_template_decl)
    4600          348 :         vec_safe_push (new_use->direct_goto,
    4601          348 :                        named_label_fwd_direct_goto { declp });
    4602              : 
    4603         2286 :       new_use->next = ent->uses;
    4604         2286 :       ent->uses = new_use;
    4605         2286 :       return;
    4606              :     }
    4607              : 
    4608          713 :   bool saw_catch = false, complained = false;
    4609          713 :   int identified = 0;
    4610          713 :   tree bad;
    4611          713 :   unsigned ix;
    4612          713 :   unsigned n_bad_decls = 0;
    4613              : 
    4614          713 :   if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
    4615          698 :       || ent->in_constexpr_if || ent->in_consteval_if
    4616          692 :       || ent->in_omp_scope || ent->in_stmt_expr
    4617          674 :       || ent->has_bad_decls)
    4618              :     {
    4619           52 :       enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
    4620           52 :       if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
    4621           37 :           || ent->in_consteval_if || ent->in_transaction_scope
    4622           31 :           || ent->in_omp_scope || ent->in_stmt_expr)
    4623           39 :         diag_kind = diagnostics::kind::error;
    4624           52 :       complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4625              :                                   &input_location, diag_kind, computed);
    4626           52 :       identified = 1 + (diag_kind == diagnostics::kind::error);
    4627              :     }
    4628              : 
    4629          910 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
    4630              :     {
    4631          197 :       bool problem = decl_jump_unsafe (bad);
    4632          197 :       if (!problem)
    4633              :         {
    4634          184 :           gcc_checking_assert (decl_instrument_init_bypass_p (bad));
    4635          184 :           n_bad_decls++;
    4636          184 :           continue;
    4637              :         }
    4638              : 
    4639           13 :       if (DECL_ARTIFICIAL (bad))
    4640              :         {
    4641              :           /* Can't skip init of __exception_info.  */
    4642            0 :           if (identified == 1)
    4643              :             {
    4644            0 :               complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4645              :                                           &input_location,
    4646              :                                           diagnostics::kind::error,
    4647              :                                           computed);
    4648            0 :               identified = 2;
    4649              :             }
    4650            0 :           if (complained)
    4651            0 :             inform (DECL_SOURCE_LOCATION (bad), "  enters %<catch%> block");
    4652              :           saw_catch = true;
    4653              :         }
    4654           13 :       else if (complained)
    4655           13 :         inform (DECL_SOURCE_LOCATION (bad),
    4656              :                 "  skips initialization of %q#D", bad);
    4657              :     }
    4658              : 
    4659          713 :   if (complained)
    4660              :     {
    4661           52 :       if (ent->in_try_scope)
    4662            9 :         inform (input_location, "  enters %<try%> block");
    4663           43 :       else if (ent->in_catch_scope && !saw_catch)
    4664            3 :         inform (input_location, "  enters %<catch%> block");
    4665           40 :       else if (ent->in_transaction_scope)
    4666            3 :         inform (input_location, "  enters synchronized or atomic statement");
    4667           37 :       else if (ent->in_constexpr_if)
    4668            3 :         inform (input_location, "  enters %<constexpr if%> statement");
    4669           34 :       else if (ent->in_consteval_if)
    4670            3 :         inform (input_location, "  enters %<consteval if%> statement");
    4671           31 :       else if (ent->in_stmt_expr)
    4672           15 :         inform (input_location, "  enters statement expression");
    4673              :     }
    4674              : 
    4675          713 :   if (ent->in_omp_scope)
    4676              :     {
    4677            3 :       if (complained)
    4678            3 :         inform (input_location, "  enters OpenMP structured block");
    4679              :     }
    4680          710 :   else if (flag_openmp)
    4681           42 :     for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4682              :       {
    4683           42 :         if (b == ent->binding_level)
    4684              :           break;
    4685           36 :         if (b->kind == sk_omp)
    4686              :           {
    4687           21 :             if (identified < 2)
    4688              :               {
    4689           42 :                 complained = identify_goto (decl,
    4690           21 :                                             DECL_SOURCE_LOCATION (decl),
    4691              :                                             &input_location,
    4692              :                                             diagnostics::kind::error,
    4693              :                                             computed);
    4694           21 :                 identified = 2;
    4695              :               }
    4696           21 :             if (complained)
    4697           21 :               inform (input_location, "  exits OpenMP structured block");
    4698              :             break;
    4699              :           }
    4700              :       }
    4701              : 
    4702              :   /* Warn if a computed goto might involve a local variable going out of scope
    4703              :      without being cleaned up.  */
    4704          713 :   if (computed)
    4705              :     {
    4706           89 :       auto level = ent->binding_level;
    4707           89 :       auto names = ent->names_in_scope;
    4708           89 :       for (auto b = current_binding_level; ; b = b->level_chain)
    4709              :         {
    4710          165 :           if (b->kind == sk_catch)
    4711              :             {
    4712            6 :               if (!identified)
    4713              :                 {
    4714            6 :                   complained
    4715            6 :                     = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4716              :                                      &input_location, diagnostics::kind::error,
    4717              :                                      computed);
    4718            6 :                   identified = 2;
    4719              :                 }
    4720            6 :               if (complained)
    4721            6 :                 inform (input_location,
    4722              :                         "  does not clean up handled exception");
    4723              :             }
    4724          165 :           tree end = b == level ? names : NULL_TREE;
    4725          184 :           for (tree d = b->names; d != end; d = DECL_CHAIN (d))
    4726              :             {
    4727           19 :               if (automatic_var_with_nontrivial_dtor_p (d))
    4728              :                 {
    4729           10 :                   if (!identified)
    4730              :                     {
    4731           10 :                       complained
    4732           10 :                         = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4733              :                                          &input_location, diagnostics::kind::error,
    4734              :                                          computed);
    4735           10 :                       identified = 2;
    4736              :                     }
    4737           10 :                   if (complained)
    4738           10 :                     inform (DECL_SOURCE_LOCATION (d),
    4739              :                             "  does not destroy %qD", d);
    4740              :                 }
    4741              :             }
    4742          165 :           if (b == level)
    4743              :             break;
    4744           76 :         }
    4745              :     }
    4746              : 
    4747          713 :   if (n_bad_decls && declp)
    4748           46 :     vec_safe_push (ent->direct_goto,
    4749           46 :                    named_label_bck_direct_goto { declp, n_bad_decls });
    4750         3062 : }
    4751              : 
    4752              : /* Check that a new jump to a label *DECLP is OK.  Called by
    4753              :    finish_goto_stmt.  */
    4754              : 
    4755              : void
    4756         3016 : check_goto (tree *declp)
    4757              : {
    4758         3016 :   if (!named_labels)
    4759              :     return;
    4760         3001 :   tree decl = *declp;
    4761         3001 :   if (TREE_CODE (decl) != LABEL_DECL)
    4762              :     {
    4763              :       /* We don't know where a computed goto is jumping,
    4764              :          so check all addressable labels.  */
    4765          345 :       for (auto iter = named_labels->begin ();
    4766          470 :            iter != named_labels->end ();
    4767          220 :            ++iter)
    4768              :         {
    4769          220 :           auto ent = *iter;
    4770          220 :           if (ent->addressed)
    4771          186 :             check_goto_1 (ent, NULL);
    4772              :         }
    4773              :     }
    4774              :   else
    4775              :     {
    4776         2876 :       hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
    4777         2876 :       named_label_entry **slot
    4778         2876 :         = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
    4779         2876 :       named_label_entry *ent = *slot;
    4780         2876 :       check_goto_1 (ent, declp);
    4781              :     }
    4782              : }
    4783              : 
    4784              : /* Check that a return is ok wrt OpenMP structured blocks.
    4785              :    Called by finish_return_stmt.  Returns true if all is well.  */
    4786              : 
    4787              : bool
    4788       288117 : check_omp_return (void)
    4789              : {
    4790       854096 :   for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4791       854096 :     if (b->kind == sk_omp)
    4792              :       {
    4793           15 :         error ("invalid exit from OpenMP structured block");
    4794           15 :         return false;
    4795              :       }
    4796       854081 :     else if (b->kind == sk_function_parms)
    4797              :       break;
    4798              :   return true;
    4799              : }
    4800              : 
    4801              : /* Define a label, specifying the location in the source file.
    4802              :    Return the LABEL_DECL node for the label.  */
    4803              : 
    4804              : tree
    4805        22410 : define_label (location_t location, tree name)
    4806              : {
    4807        22410 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    4808              : 
    4809              :   /* After labels, make any new cleanups in the function go into their
    4810              :      own new (temporary) binding contour.  */
    4811        22410 :   for (cp_binding_level *p = current_binding_level;
    4812        37006 :        p->kind != sk_function_parms;
    4813        14596 :        p = p->level_chain)
    4814        14596 :     p->more_cleanups_ok = 0;
    4815              : 
    4816        22410 :   named_label_entry *ent = lookup_label_1 (name, false);
    4817        22410 :   tree decl = ent->label_decl;
    4818              : 
    4819        22410 :   if (DECL_INITIAL (decl) != NULL_TREE)
    4820              :     {
    4821          271 :       if (cxx_dialect <= cxx26 || C_DECLARED_LABEL_FLAG (decl))
    4822              :         {
    4823           32 :           error ("duplicate label %qD", decl);
    4824           32 :           return error_mark_node;
    4825              :         }
    4826              :       /* For C++29 and later, allow duplicate labels, but reject
    4827              :          goto or && on those.  Don't allow duplicate labels when
    4828              :          __label__ extension is used though.  */
    4829          239 :       if (!ent->ambiguous)
    4830              :         {
    4831           96 :           if (ent->goto_locus != UNKNOWN_LOCATION
    4832          105 :               && !LABEL_DECL_IN_TEMPLATE_FOR_P (decl))
    4833              :             {
    4834            3 :               auto_diagnostic_group d;
    4835            3 :               error_at (ent->goto_locus,
    4836              :                         "reference to an ambiguous label %qD", decl);
    4837            3 :               inform (DECL_SOURCE_LOCATION (decl),
    4838              :                       "definition of the first label");
    4839            3 :               inform (location, "definition of the second label");
    4840            3 :             }
    4841           96 :           ent->other_label_locus = location;
    4842           96 :           ent->ambiguous = 1;
    4843              :         }
    4844          239 :       decl = build_decl (location, LABEL_DECL, name, void_type_node);
    4845          239 :       DECL_CONTEXT (decl) = current_function_decl;
    4846          239 :       SET_DECL_MODE (decl, VOIDmode);
    4847          239 :       DECL_INITIAL (decl) = error_mark_node;
    4848          239 :       DECL_CHAIN (decl) = DECL_CHAIN (ent->label_decl);
    4849          239 :       DECL_CHAIN (ent->label_decl) = decl;
    4850          239 :       return decl;
    4851              :     }
    4852              :   else
    4853              :     {
    4854              :       /* Mark label as having been defined.  */
    4855        22139 :       DECL_INITIAL (decl) = error_mark_node;
    4856              :       /* Say where in the source.  */
    4857        22139 :       DECL_SOURCE_LOCATION (decl) = location;
    4858              : 
    4859        22139 :       if (in_expansion_stmt)
    4860              :         {
    4861           24 :           if (ent->goto_locus != UNKNOWN_LOCATION)
    4862              :             {
    4863            8 :               auto_diagnostic_group d;
    4864            8 :               error_at (ent->goto_locus,
    4865              :                         "reference to a label %qD inside of "
    4866              :                         "%<template for%> body", decl);
    4867            8 :               inform (location,
    4868              :                       "definition of the label");
    4869            8 :             }
    4870           24 :           LABEL_DECL_IN_TEMPLATE_FOR_P (decl) = 1;
    4871              :         }
    4872              : 
    4873        22139 :       ent->binding_level = current_binding_level;
    4874        22139 :       ent->names_in_scope = current_binding_level->names;
    4875              : 
    4876        24306 :       for (named_label_use_entry *use = ent->uses; use; use = use->next)
    4877         2167 :         check_previous_goto (decl, use);
    4878        22139 :       ent->uses = NULL;
    4879              :     }
    4880              : 
    4881        22139 :   return decl;
    4882        22410 : }
    4883              : 
    4884              : struct cp_switch
    4885              : {
    4886              :   cp_binding_level *level;
    4887              :   struct cp_switch *next;
    4888              :   /* The SWITCH_STMT being built.  */
    4889              :   tree switch_stmt;
    4890              :   /* A splay-tree mapping the low element of a case range to the high
    4891              :      element, or NULL_TREE if there is no high element.  Used to
    4892              :      determine whether or not a new case label duplicates an old case
    4893              :      label.  We need a tree, rather than simply a hash table, because
    4894              :      of the GNU case range extension.  */
    4895              :   splay_tree cases;
    4896              :   /* Remember whether a default: case label has been seen.  */
    4897              :   bool has_default_p;
    4898              :   /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT.  */
    4899              :   bool break_stmt_seen_p;
    4900              :   /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
    4901              :      where BREAK_STMT doesn't belong to the SWITCH_STMT.  */
    4902              :   bool in_loop_body_p;
    4903              : };
    4904              : 
    4905              : /* A stack of the currently active switch statements.  The innermost
    4906              :    switch statement is on the top of the stack.  There is no need to
    4907              :    mark the stack for garbage collection because it is only active
    4908              :    during the processing of the body of a function, and we never
    4909              :    collect at that point.  */
    4910              : 
    4911              : static struct cp_switch *switch_stack;
    4912              : 
    4913              : /* Called right after a switch-statement condition is parsed.
    4914              :    SWITCH_STMT is the switch statement being parsed.  */
    4915              : 
    4916              : void
    4917       736224 : push_switch (tree switch_stmt)
    4918              : {
    4919       736224 :   struct cp_switch *p = XNEW (struct cp_switch);
    4920       736224 :   p->level = current_binding_level;
    4921       736224 :   p->next = switch_stack;
    4922       736224 :   p->switch_stmt = switch_stmt;
    4923       736224 :   p->cases = splay_tree_new (case_compare, NULL, NULL);
    4924       736224 :   p->has_default_p = false;
    4925       736224 :   p->break_stmt_seen_p = false;
    4926       736224 :   p->in_loop_body_p = false;
    4927       736224 :   switch_stack = p;
    4928       736224 : }
    4929              : 
    4930              : void
    4931       736224 : pop_switch (void)
    4932              : {
    4933       736224 :   struct cp_switch *cs = switch_stack;
    4934              : 
    4935              :   /* Emit warnings as needed.  */
    4936       736224 :   location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
    4937       736224 :   tree cond = SWITCH_STMT_COND (cs->switch_stmt);
    4938       736224 :   const bool bool_cond_p
    4939       736224 :     = (SWITCH_STMT_TYPE (cs->switch_stmt)
    4940       736224 :        && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
    4941       736224 :   if (!processing_template_decl)
    4942       302688 :     c_do_switch_warnings (cs->cases, switch_location,
    4943       302688 :                           SWITCH_STMT_TYPE (cs->switch_stmt), cond,
    4944              :                           bool_cond_p);
    4945              : 
    4946              :   /* For the benefit of block_may_fallthru remember if the switch body
    4947              :      case labels cover all possible values and if there are break; stmts.  */
    4948       736224 :   if (cs->has_default_p
    4949       736224 :       || (!processing_template_decl
    4950        42671 :           && c_switch_covers_all_cases_p (cs->cases,
    4951        42671 :                                           SWITCH_STMT_TYPE (cs->switch_stmt))))
    4952       547704 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
    4953       736224 :   if (!cs->break_stmt_seen_p)
    4954       382324 :     SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
    4955              :   /* Now that we're done with the switch warnings, set the switch type
    4956              :      to the type of the condition if the index type was of scoped enum type.
    4957              :      (Such types don't participate in the integer promotions.)  We do this
    4958              :      because of bit-fields whose declared type is a scoped enum type:
    4959              :      gimplification will use the lowered index type, but convert the
    4960              :      case values to SWITCH_STMT_TYPE, which would have been the declared type
    4961              :      and verify_gimple_switch doesn't accept that.  */
    4962       736224 :   if (is_bitfield_expr_with_lowered_type (cond))
    4963        33342 :     SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
    4964       736224 :   gcc_assert (!cs->in_loop_body_p);
    4965       736224 :   splay_tree_delete (cs->cases);
    4966       736224 :   switch_stack = switch_stack->next;
    4967       736224 :   free (cs);
    4968       736224 : }
    4969              : 
    4970              : /* Note that a BREAK_STMT is about to be added.  If it is inside of
    4971              :    a SWITCH_STMT and not inside of a loop body inside of it, note
    4972              :    in switch_stack we've seen a BREAK_STMT.  */
    4973              : 
    4974              : void
    4975      4891481 : note_break_stmt (void)
    4976              : {
    4977      4891481 :   if (switch_stack && !switch_stack->in_loop_body_p)
    4978      2757755 :     switch_stack->break_stmt_seen_p = true;
    4979      4891481 : }
    4980              : 
    4981              : /* Note the start of processing of an iteration statement's body.
    4982              :    The note_break_stmt function will do nothing while processing it.
    4983              :    Return a flag that should be passed to note_iteration_stmt_body_end.  */
    4984              : 
    4985              : bool
    4986     18435587 : note_iteration_stmt_body_start (void)
    4987              : {
    4988     18435587 :   if (!switch_stack)
    4989              :     return false;
    4990       195099 :   bool ret = switch_stack->in_loop_body_p;
    4991       195099 :   switch_stack->in_loop_body_p = true;
    4992       195099 :   return ret;
    4993              : }
    4994              : 
    4995              : /* Note the end of processing of an iteration statement's body.  */
    4996              : 
    4997              : void
    4998     18435587 : note_iteration_stmt_body_end (bool prev)
    4999              : {
    5000     18435587 :   if (switch_stack)
    5001       195099 :     switch_stack->in_loop_body_p = prev;
    5002     18435587 : }
    5003              : 
    5004              : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
    5005              :    condition.  Note that if TYPE and VALUE are already integral we don't
    5006              :    really do the conversion because the language-independent
    5007              :    warning/optimization code will work better that way.  */
    5008              : 
    5009              : static tree
    5010      3666636 : case_conversion (tree type, tree value)
    5011              : {
    5012      3666636 :   if (value == NULL_TREE)
    5013              :     return value;
    5014              : 
    5015      1573476 :   value = mark_rvalue_use (value);
    5016              : 
    5017      1573476 :   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    5018      1124760 :     type = type_promotes_to (type);
    5019              : 
    5020      1573476 :   tree ovalue = value;
    5021              :   /* The constant-expression VALUE shall be a converted constant expression
    5022              :      of the adjusted type of the switch condition, which doesn't allow
    5023              :      narrowing conversions.  */
    5024      1573476 :   value = build_converted_constant_expr (type, value, tf_warning_or_error);
    5025              : 
    5026      1573476 :   if (cxx_dialect >= cxx11
    5027      1573476 :       && (SCOPED_ENUM_P (type)
    5028      1121648 :           || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
    5029              :     /* Use the converted value.  */;
    5030              :   else
    5031              :     /* The already integral case.  */
    5032              :     value = ovalue;
    5033              : 
    5034      1573476 :   return cxx_constant_value (value);
    5035              : }
    5036              : 
    5037              : /* Note that we've seen a definition of a case label, and complain if this
    5038              :    is a bad place for one.  */
    5039              : 
    5040              : tree
    5041      5986172 : finish_case_label (location_t loc, tree low_value, tree high_value)
    5042              : {
    5043      5986172 :   tree cond, r;
    5044      5986172 :   cp_binding_level *p;
    5045      5986172 :   tree type;
    5046              : 
    5047      5986172 :   if (low_value == NULL_TREE && high_value == NULL_TREE)
    5048       547668 :     switch_stack->has_default_p = true;
    5049              : 
    5050      5986172 :   if (processing_template_decl)
    5051              :     {
    5052      4152731 :       tree label;
    5053              : 
    5054              :       /* For templates, just add the case label; we'll do semantic
    5055              :          analysis at instantiation-time.  But diagnose case labels
    5056              :          in expansion statements with switch outside of it here.  */
    5057      4152731 :       if (in_expansion_stmt)
    5058          735 :         for (cp_binding_level *b = current_binding_level;
    5059         1470 :              b != switch_stack->level; b = b->level_chain)
    5060          767 :           if (b->kind == sk_template_for && b->this_entity)
    5061              :             {
    5062           32 :               auto_diagnostic_group d;
    5063           32 :               error ("jump to case label");
    5064           32 :               inform (EXPR_LOCATION (b->this_entity),
    5065              :                       "  enters %<template for%> statement");
    5066           32 :               return error_mark_node;
    5067           32 :             }
    5068      4152699 :       label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
    5069      4152699 :       return add_stmt (build_case_label (low_value, high_value, label));
    5070              :     }
    5071              : 
    5072              :   /* Find the condition on which this switch statement depends.  */
    5073      1833441 :   cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
    5074      1833441 :   if (cond && TREE_CODE (cond) == TREE_LIST)
    5075            0 :     cond = TREE_VALUE (cond);
    5076              : 
    5077      1833441 :   int chk_switch_goto = check_switch_goto (switch_stack->level, NULL_TREE);
    5078      1833441 :   if (!chk_switch_goto)
    5079           87 :     return error_mark_node;
    5080              : 
    5081      1833354 :   type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
    5082      1833354 :   if (type == error_mark_node)
    5083              :     return error_mark_node;
    5084              : 
    5085      1833318 :   low_value = case_conversion (type, low_value);
    5086      1833318 :   high_value = case_conversion (type, high_value);
    5087              : 
    5088      1833318 :   r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
    5089              : 
    5090      1833318 :   if (r != error_mark_node && chk_switch_goto == 2)
    5091           45 :     check_switch_goto (switch_stack->level, r);
    5092              : 
    5093              :   /* After labels, make any new cleanups in the function go into their
    5094              :      own new (temporary) binding contour.  */
    5095      1833318 :   for (p = current_binding_level;
    5096      7726054 :        p->kind != sk_function_parms;
    5097      5892736 :        p = p->level_chain)
    5098      5892736 :     p->more_cleanups_ok = 0;
    5099              : 
    5100              :   return r;
    5101              : }
    5102              : 
    5103              : struct typename_info {
    5104              :   tree scope;
    5105              :   tree name;
    5106              :   tree template_id;
    5107              :   tag_types tag_type;
    5108              : };
    5109              : 
    5110              : struct typename_hasher : ggc_ptr_hash<tree_node>
    5111              : {
    5112              :   typedef typename_info *compare_type;
    5113              : 
    5114              :   /* Hash a TYPENAME_TYPE.  */
    5115              : 
    5116              :   static hashval_t
    5117    479283232 :   hash (tree context, tree fullname)
    5118              :   {
    5119    479283232 :     hashval_t hash = 0;
    5120    479283232 :     hash = iterative_hash_hashval_t (TYPE_HASH (context), hash);
    5121              :     /* FULLNAME could be a template-id, so use iterative_hash_template_arg here.
    5122              :        And might as well set comparing_specializations for stronger hashing.  */
    5123    479283232 :     ++comparing_specializations;
    5124    479283232 :     hash = iterative_hash_template_arg (fullname, hash);
    5125    479283232 :     --comparing_specializations;
    5126    479283232 :     return hash;
    5127              :   }
    5128              : 
    5129              :   static hashval_t
    5130     64976240 :   hash (const typename_info *ti)
    5131              :   {
    5132     64976240 :     return typename_hasher::hash (ti->scope, ti->template_id);
    5133              :   }
    5134              : 
    5135              :   static hashval_t
    5136    414306992 :   hash (tree t)
    5137              :   {
    5138    414306992 :     return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
    5139              :   }
    5140              : 
    5141              :   /* Compare two TYPENAME_TYPEs.  */
    5142              : 
    5143              :   static bool
    5144    484773954 :   equal (tree t1, const typename_info *t2)
    5145              :   {
    5146    484773954 :     return (TYPE_IDENTIFIER (t1) == t2->name
    5147    162980234 :             && TYPE_CONTEXT (t1) == t2->scope
    5148     34161477 :             && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
    5149    518217279 :             && get_typename_tag (t1) == t2->tag_type);
    5150              :   }
    5151              : };
    5152              : 
    5153              : /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
    5154              :    the type of `T', NAME is the IDENTIFIER_NODE for `t'.
    5155              : 
    5156              :    Returns the new TYPENAME_TYPE.  */
    5157              : 
    5158              : static GTY (()) hash_table<typename_hasher> *typename_htab;
    5159              : 
    5160              : tree
    5161     64976240 : build_typename_type (tree context, tree name, tree fullname,
    5162              :                      enum tag_types tag_type)
    5163              : {
    5164     64976240 :   typename_info ti;
    5165              : 
    5166     64976240 :   if (typename_htab == NULL)
    5167        20034 :     typename_htab = hash_table<typename_hasher>::create_ggc (61);
    5168              : 
    5169     64976240 :   ti.scope = FROB_CONTEXT (context);
    5170     64976240 :   ti.name = name;
    5171     64976240 :   ti.template_id = fullname;
    5172     64976240 :   ti.tag_type = tag_type;
    5173     64976240 :   hashval_t hash = typename_hasher::hash (&ti);
    5174              : 
    5175              :   /* See if we already have this type.  */
    5176     64976240 :   tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
    5177     64976240 :   tree t = *e;
    5178     64976240 :   if (*e)
    5179              :     t = *e;
    5180              :   else
    5181              :     {
    5182              :       /* Build the TYPENAME_TYPE.  */
    5183     32751199 :       t = cxx_make_type (TYPENAME_TYPE);
    5184     32751199 :       TYPE_CONTEXT (t) = ti.scope;
    5185     32751199 :       TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
    5186     32751199 :       set_typename_tag (t, ti.tag_type);
    5187              : 
    5188              :       /* Build the corresponding TYPE_DECL.  */
    5189     32751199 :       tree d = build_decl (input_location, TYPE_DECL, name, t);
    5190     32751199 :       TYPE_NAME (t) = d;
    5191     32751199 :       TYPE_STUB_DECL (t) = d;
    5192     32751199 :       DECL_CONTEXT (d) = ti.scope;
    5193     32751199 :       DECL_ARTIFICIAL (d) = 1;
    5194              : 
    5195              :       /* Store it in the hash table.  */
    5196     32751199 :       *e = t;
    5197              : 
    5198              :       /* TYPENAME_TYPEs must always be compared structurally, because
    5199              :          they may or may not resolve down to another type depending on
    5200              :          the currently open classes. */
    5201     32751199 :       SET_TYPE_STRUCTURAL_EQUALITY (t);
    5202              :     }
    5203              : 
    5204     64976240 :   return t;
    5205              : }
    5206              : 
    5207              : /* Resolve `typename CONTEXT::NAME'.  TAG_TYPE indicates the tag
    5208              :    provided to name the type.  Returns an appropriate type, unless an
    5209              :    error occurs, in which case error_mark_node is returned.  If we
    5210              :    locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
    5211              :    return that, rather than the _TYPE it corresponds to, in other
    5212              :    cases we look through the type decl.  If TF_ERROR is set, complain
    5213              :    about errors, otherwise be quiet.  */
    5214              : 
    5215              : tree
    5216    275777590 : make_typename_type (tree context, tree name, enum tag_types tag_type,
    5217              :                     tsubst_flags_t complain)
    5218              : {
    5219    275777590 :   tree fullname;
    5220    275777590 :   tree t;
    5221    275777590 :   bool want_template;
    5222              : 
    5223    275777590 :   if (name == error_mark_node
    5224    275777584 :       || context == NULL_TREE
    5225    275777584 :       || context == error_mark_node)
    5226              :     return error_mark_node;
    5227              : 
    5228    275777568 :   if (TYPE_P (name))
    5229              :     {
    5230            0 :       if (!(TYPE_LANG_SPECIFIC (name)
    5231            0 :             && (CLASSTYPE_IS_TEMPLATE (name)
    5232            0 :                 || CLASSTYPE_USE_TEMPLATE (name))))
    5233            0 :         name = TYPE_IDENTIFIER (name);
    5234              :       else
    5235              :         /* Create a TEMPLATE_ID_EXPR for the type.  */
    5236            0 :         name = build_nt (TEMPLATE_ID_EXPR,
    5237            0 :                          CLASSTYPE_TI_TEMPLATE (name),
    5238            0 :                          CLASSTYPE_TI_ARGS (name));
    5239              :     }
    5240    275777568 :   else if (TREE_CODE (name) == TYPE_DECL)
    5241            0 :     name = DECL_NAME (name);
    5242              : 
    5243    275777568 :   fullname = name;
    5244              : 
    5245    275777568 :   if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    5246              :     {
    5247      5393297 :       name = TREE_OPERAND (name, 0);
    5248      5393297 :       if (DECL_TYPE_TEMPLATE_P (name))
    5249            0 :         name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
    5250      5393297 :       if (TREE_CODE (name) != IDENTIFIER_NODE)
    5251              :         {
    5252            0 :           if (complain & tf_error)
    5253            0 :             error ("%qD is not a type", name);
    5254            0 :           return error_mark_node;
    5255              :         }
    5256              :     }
    5257    275777568 :   if (TREE_CODE (name) == TEMPLATE_DECL)
    5258              :     {
    5259            0 :       if (complain & tf_error)
    5260            0 :         error ("%qD used without template arguments", name);
    5261            0 :       return error_mark_node;
    5262              :     }
    5263    275777568 :   else if (is_overloaded_fn (name))
    5264              :     {
    5265            3 :       if (complain & tf_error)
    5266            3 :         error ("%qD is a function, not a type", name);
    5267            3 :       return error_mark_node;
    5268              :     }
    5269    275777565 :   gcc_assert (identifier_p (name));
    5270    275777565 :   gcc_assert (TYPE_P (context));
    5271              : 
    5272    275777565 :   if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
    5273              :     /* This can happen for C++17 variadic using (c++/88986).  */;
    5274    262378286 :   else if (!MAYBE_CLASS_TYPE_P (context))
    5275              :     {
    5276            6 :       if (complain & tf_error)
    5277            6 :         error ("%q#T is not a class", context);
    5278            6 :       return error_mark_node;
    5279              :     }
    5280              : 
    5281              :   /* When the CONTEXT is a dependent type,  NAME could refer to a
    5282              :      dependent base class of CONTEXT.  But look inside it anyway
    5283              :      if CONTEXT is a currently open scope, in case it refers to a
    5284              :      member of the current instantiation or a non-dependent base;
    5285              :      lookup will stop when we hit a dependent base.  */
    5286    275777559 :   if (!dependent_scope_p (context))
    5287              :     {
    5288              :       /* We generally don't ignore non-types during TYPENAME_TYPE lookup
    5289              :          (as per [temp.res.general]/3), unless
    5290              :            - the tag corresponds to a class-key or 'enum' so
    5291              :              [basic.lookup.elab] applies, or
    5292              :            - the tag corresponds to scope_type or tf_qualifying_scope is
    5293              :              set so [basic.lookup.qual]/1 applies, or
    5294              :            - we're inside a base-specifier so [class.derived.general]/2 applies;
    5295              :              the tag will already be class_type in that case.
    5296              :          TODO: If we'd set/track the scope_type tag thoroughly on all
    5297              :          TYPENAME_TYPEs that are followed by :: then we wouldn't need the
    5298              :          tf_qualifying_scope flag.  */
    5299    431371626 :       bool want_type = (tag_type != none_type && tag_type != typename_type)
    5300    215685813 :         || (complain & tf_qualifying_scope);
    5301    215685813 :       t = lookup_member (context, name, /*protect=*/2, want_type, complain);
    5302              :     }
    5303              :   else
    5304              :     t = NULL_TREE;
    5305              : 
    5306    275777559 :   if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
    5307     60092767 :     return build_typename_type (context, name, fullname, tag_type);
    5308              : 
    5309    215684792 :   want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
    5310              : 
    5311    215684792 :   if (!t)
    5312              :     {
    5313     19602335 :       if (complain & tf_error)
    5314              :         {
    5315          223 :           if (!COMPLETE_TYPE_P (context))
    5316           18 :             cxx_incomplete_type_error (NULL_TREE, context);
    5317              :           else
    5318          409 :             error (want_template ? G_("no class template named %q#T in %q#T")
    5319              :                    : G_("no type named %q#T in %q#T"), name, context);
    5320              :         }
    5321     19602335 :       return error_mark_node;
    5322              :     }
    5323              : 
    5324              :   /* Pull out the template from an injected-class-name (or multiple).  */
    5325    196082457 :   if (want_template)
    5326      3437912 :     t = maybe_get_template_decl_from_type_decl (t);
    5327              : 
    5328    196082457 :   if (TREE_CODE (t) == TREE_LIST)
    5329              :     {
    5330            3 :       if (complain & tf_error)
    5331              :         {
    5332            3 :           auto_diagnostic_group d;
    5333            3 :           error ("lookup of %qT in %qT is ambiguous", name, context);
    5334            3 :           print_candidates (input_location, t);
    5335            3 :         }
    5336            3 :       return error_mark_node;
    5337              :     }
    5338              : 
    5339    196082454 :   if (want_template && !DECL_TYPE_TEMPLATE_P (t))
    5340              :     {
    5341            6 :       if (complain & tf_error)
    5342            6 :         error ("%<typename %T::%D%> names %q#T, which is not a class template",
    5343              :                context, name, t);
    5344            6 :       return error_mark_node;
    5345              :     }
    5346    196082448 :   if (!want_template && TREE_CODE (t) != TYPE_DECL)
    5347              :     {
    5348         2187 :       if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
    5349         4377 :           && DECL_TYPE_TEMPLATE_P (t))
    5350              :         /* The caller permits this typename-specifier to name a template
    5351              :            (because it appears in a CTAD-enabled context).  */;
    5352              :       else
    5353              :         {
    5354           23 :           if (complain & tf_error)
    5355           17 :             error ("%<typename %T::%D%> names %q#D, which is not a type",
    5356              :                    context, name, t);
    5357           23 :           return error_mark_node;
    5358              :         }
    5359              :     }
    5360              : 
    5361    196082425 :   if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
    5362              :                                             context, complain))
    5363           42 :     return error_mark_node;
    5364              : 
    5365    196082383 :   if (!want_template && DECL_TYPE_TEMPLATE_P (t))
    5366         2176 :     return make_template_placeholder (t);
    5367              : 
    5368    196080207 :   if (want_template)
    5369              :     {
    5370      3437906 :       t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
    5371              :                                  NULL_TREE, context,
    5372              :                                  complain | tf_user);
    5373      3437906 :       if (t == error_mark_node)
    5374              :         return error_mark_node;
    5375      3437901 :       t = TYPE_NAME (t);
    5376              :     }
    5377              : 
    5378    196080202 :   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
    5379      2380120 :     t = TREE_TYPE (t);
    5380              : 
    5381    196080202 :   maybe_record_typedef_use (t);
    5382              : 
    5383    196080202 :   return t;
    5384              : }
    5385              : 
    5386              : /* Resolve `CONTEXT::template NAME'.  Returns a TEMPLATE_DECL if the name
    5387              :    can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
    5388              :    in which case error_mark_node is returned.
    5389              : 
    5390              :    If PARM_LIST is non-NULL, also make sure that the template parameter
    5391              :    list of TEMPLATE_DECL matches.
    5392              : 
    5393              :    If COMPLAIN zero, don't complain about any errors that occur.  */
    5394              : 
    5395              : tree
    5396       185941 : make_unbound_class_template (tree context, tree name, tree parm_list,
    5397              :                              tsubst_flags_t complain)
    5398              : {
    5399       185941 :   if (TYPE_P (name))
    5400            0 :     name = TYPE_IDENTIFIER (name);
    5401       185941 :   else if (DECL_P (name))
    5402            0 :     name = DECL_NAME (name);
    5403       185941 :   gcc_assert (identifier_p (name));
    5404              : 
    5405       185941 :   if (!dependent_type_p (context)
    5406       185941 :       || currently_open_class (context))
    5407              :     {
    5408        92088 :       tree tmpl = NULL_TREE;
    5409              : 
    5410        92088 :       if (MAYBE_CLASS_TYPE_P (context))
    5411        92082 :         tmpl = lookup_field (context, name, 0, false);
    5412              : 
    5413        92082 :       if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
    5414            3 :         tmpl = maybe_get_template_decl_from_type_decl (tmpl);
    5415              : 
    5416        92076 :       if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
    5417              :         {
    5418           12 :           if (complain & tf_error)
    5419            9 :             error ("no class template named %q#T in %q#T", name, context);
    5420           12 :           return error_mark_node;
    5421              :         }
    5422              : 
    5423        92076 :       if (parm_list
    5424        92076 :           && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
    5425              :         {
    5426            0 :           if (complain & tf_error)
    5427              :             {
    5428            0 :               auto_diagnostic_group d;
    5429            0 :               error ("template parameters do not match template %qD", tmpl);
    5430            0 :               inform (DECL_SOURCE_LOCATION (tmpl),
    5431              :                       "%qD declared here", tmpl);
    5432            0 :             }
    5433            0 :           return error_mark_node;
    5434              :         }
    5435              : 
    5436        92076 :       if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
    5437              :                                           complain))
    5438            0 :         return error_mark_node;
    5439              : 
    5440              :       return tmpl;
    5441              :     }
    5442              : 
    5443        93853 :   return make_unbound_class_template_raw (context, name, parm_list);
    5444              : }
    5445              : 
    5446              : /* Build an UNBOUND_CLASS_TEMPLATE.  */
    5447              : 
    5448              : tree
    5449        93905 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
    5450              : {
    5451              :   /* Build the UNBOUND_CLASS_TEMPLATE.  */
    5452        93905 :   tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
    5453        93905 :   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
    5454        93905 :   TREE_TYPE (t) = NULL_TREE;
    5455        93905 :   SET_TYPE_STRUCTURAL_EQUALITY (t);
    5456              : 
    5457              :   /* Build the corresponding TEMPLATE_DECL.  */
    5458        93905 :   tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
    5459        93905 :   TYPE_NAME (t) = d;
    5460        93905 :   TYPE_STUB_DECL (t) = d;
    5461        93905 :   DECL_CONTEXT (d) = TYPE_CONTEXT (t);
    5462        93905 :   DECL_ARTIFICIAL (d) = 1;
    5463        93905 :   DECL_TEMPLATE_PARMS (d) = parm_list;
    5464              : 
    5465        93905 :   return t;
    5466              : }
    5467              : 
    5468              : 
    5469              : 
    5470              : /* Push the declarations of builtin types into the global namespace.
    5471              :    RID_INDEX is the index of the builtin type in the array
    5472              :    RID_POINTERS.  NAME is the name used when looking up the builtin
    5473              :    type.  TYPE is the _TYPE node for the builtin type.
    5474              : 
    5475              :    The calls to set_global_binding below should be
    5476              :    eliminated.  Built-in types should not be looked up name; their
    5477              :    names are keywords that the parser can recognize.  However, there
    5478              :    is code in c-common.cc that uses identifier_global_value to look up
    5479              :    built-in types by name.  */
    5480              : 
    5481              : void
    5482      4259257 : record_builtin_type (enum rid rid_index,
    5483              :                      const char* name,
    5484              :                      tree type)
    5485              : {
    5486      4259257 :   tree decl = NULL_TREE;
    5487              : 
    5488      4259257 :   if (name)
    5489              :     {
    5490      2513799 :       tree tname = get_identifier (name);
    5491      2513799 :       tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
    5492      2513799 :       DECL_ARTIFICIAL (tdecl) = 1;
    5493      2513799 :       set_global_binding (tdecl);
    5494      2513799 :       decl = tdecl;
    5495              :     }
    5496              : 
    5497      4259257 :   if ((int) rid_index < (int) RID_MAX)
    5498      2615079 :     if (tree rname = ridpointers[(int) rid_index])
    5499      1999035 :       if (!decl || DECL_NAME (decl) != rname)
    5500              :         {
    5501      1437436 :           tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
    5502      1437436 :           DECL_ARTIFICIAL (rdecl) = 1;
    5503      1437436 :           set_global_binding (rdecl);
    5504      1437436 :           if (!decl)
    5505              :             decl = rdecl;
    5506              :         }
    5507              : 
    5508      3951235 :   if (decl)
    5509              :     {
    5510      3643213 :       if (!TYPE_NAME (type))
    5511      3027169 :         TYPE_NAME (type) = decl;
    5512      3643213 :       debug_hooks->type_decl (decl, 0);
    5513              :     }
    5514      4259257 : }
    5515              : 
    5516              : /* Push a type into the namespace so that the back ends ignore it.  */
    5517              : 
    5518              : static void
    5519       308022 : record_unknown_type (tree type, const char* name)
    5520              : {
    5521       308022 :   tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
    5522              :                                     TYPE_DECL, get_identifier (name), type));
    5523              :   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
    5524       308022 :   DECL_IGNORED_P (decl) = 1;
    5525       308022 :   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    5526       308022 :   TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
    5527       308022 :   SET_TYPE_ALIGN (type, 1);
    5528       308022 :   TYPE_USER_ALIGN (type) = 0;
    5529       308022 :   SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
    5530       308022 : }
    5531              : 
    5532              : /* Create all the predefined identifiers.  */
    5533              : 
    5534              : static void
    5535       102674 : initialize_predefined_identifiers (void)
    5536              : {
    5537       102674 :   struct predefined_identifier
    5538              :   {
    5539              :     const char *name; /* Name.  */
    5540              :     tree *node;  /* Node to store it in.  */
    5541              :     cp_identifier_kind kind;  /* Kind of identifier.  */
    5542              :   };
    5543              : 
    5544              :   /* A table of identifiers to create at startup.  */
    5545       102674 :   static const predefined_identifier predefined_identifiers[] = {
    5546              :     {"C++", &lang_name_cplusplus, cik_normal},
    5547              :     {"C", &lang_name_c, cik_normal},
    5548              :     /* Some of these names have a trailing space so that it is
    5549              :        impossible for them to conflict with names written by users.  */
    5550              :     {"__ct ", &ctor_identifier, cik_ctor},
    5551              :     {"__ct_base ", &base_ctor_identifier, cik_ctor},
    5552              :     {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
    5553              :     {"__dt ", &dtor_identifier, cik_dtor},
    5554              :     {"__dt_base ", &base_dtor_identifier, cik_dtor},
    5555              :     {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
    5556              :     {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
    5557              :     {"__conv_op ", &conv_op_identifier, cik_conv_op},
    5558              :     {"__in_chrg", &in_charge_identifier, cik_normal},
    5559              :     {"__as_base ", &as_base_identifier, cik_normal},
    5560              :     {"this", &this_identifier, cik_normal},
    5561              :     {"__delta", &delta_identifier, cik_normal},
    5562              :     {"__pfn", &pfn_identifier, cik_normal},
    5563              :     {"_vptr", &vptr_identifier, cik_normal},
    5564              :     {"__vtt_parm", &vtt_parm_identifier, cik_normal},
    5565              :     {"::", &global_identifier, cik_normal},
    5566              :       /* The demangler expects anonymous namespaces to be called
    5567              :          something starting with '_GLOBAL__N_'.  It no longer needs
    5568              :          to be unique to the TU.  */
    5569              :     {"_GLOBAL__N_1", &anon_identifier, cik_normal},
    5570              :     {"auto", &auto_identifier, cik_normal},
    5571              :     {"decltype(auto)", &decltype_auto_identifier, cik_normal},
    5572              :     {"initializer_list", &init_list_identifier, cik_normal},
    5573              :     {"__for_range ", &for_range__identifier, cik_normal},
    5574              :     {"__for_begin ", &for_begin__identifier, cik_normal},
    5575              :     {"__for_end ", &for_end__identifier, cik_normal},
    5576              :     {"__for_range", &for_range_identifier, cik_normal},
    5577              :     {"__for_begin", &for_begin_identifier, cik_normal},
    5578              :     {"__for_end", &for_end_identifier, cik_normal},
    5579              :     {"abi_tag", &abi_tag_identifier, cik_normal},
    5580              :     {"aligned", &aligned_identifier, cik_normal},
    5581              :     {"begin", &begin_identifier, cik_normal},
    5582              :     {"end", &end_identifier, cik_normal},
    5583              :     {"get", &get__identifier, cik_normal},
    5584              :     {"gnu", &gnu_identifier, cik_normal},
    5585              :     {"tuple_element", &tuple_element_identifier, cik_normal},
    5586              :     {"tuple_size", &tuple_size_identifier, cik_normal},
    5587              :     {"type", &type_identifier, cik_normal},
    5588              :     {"value", &value_identifier, cik_normal},
    5589              :     {"_FUN", &fun_identifier, cik_normal},
    5590              :     {"__closure", &closure_identifier, cik_normal},
    5591              :     {"heap uninit", &heap_uninit_identifier, cik_normal},
    5592              :     {"heap ", &heap_identifier, cik_normal},
    5593              :     {"heap deleted", &heap_deleted_identifier, cik_normal},
    5594              :     {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
    5595              :     {"heap []", &heap_vec_identifier, cik_normal},
    5596              :     {"omp", &omp_identifier, cik_normal},
    5597              :     {"internal ", &internal_identifier, cik_normal},
    5598              :     {"annotation ", &annotation_identifier, cik_normal},
    5599              :     {NULL, NULL, cik_normal}
    5600              :   };
    5601              : 
    5602      5031026 :   for (const predefined_identifier *pid = predefined_identifiers;
    5603      5031026 :        pid->name; ++pid)
    5604              :     {
    5605      4928352 :       *pid->node = get_identifier (pid->name);
    5606              :       /* Some of these identifiers already have a special kind.  */
    5607      4928352 :       if (pid->kind != cik_normal)
    5608       821392 :         set_identifier_kind (*pid->node, pid->kind);
    5609              :     }
    5610       102674 : }
    5611              : 
    5612              : /* Build a specific variant of operator new.  */
    5613              : 
    5614              : static void
    5615       183846 : cxx_build_operator_new (tree newtype)
    5616              : {
    5617       183846 :   tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    5618       183846 :   DECL_IS_MALLOC (opnew) = 1;
    5619       183846 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    5620       183846 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    5621       183846 :   opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    5622       183846 :   DECL_IS_MALLOC (opnew) = 1;
    5623       183846 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    5624       183846 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    5625       183846 : }
    5626              : 
    5627              : /* Build a specific variant of operator delete.  */
    5628              : 
    5629              : static void
    5630       347524 : cxx_build_operator_delete (tree deltype)
    5631              : {
    5632       347524 :   tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    5633       347524 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    5634       347524 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    5635       347524 :   opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    5636       347524 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    5637       347524 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    5638       347524 : }
    5639              : 
    5640              : /* Declare all variants of operator new and delete.  */
    5641              : 
    5642              : static void
    5643       102674 : cxx_init_operator_new_delete_decls (void)
    5644              : {
    5645       102674 :   tree newattrs, extvisattr;
    5646       102674 :   tree newtype, deltype;
    5647       102674 :   tree ptr_ftype_sizetype;
    5648       102674 :   tree new_eh_spec;
    5649       102674 :   tree void_ftype_ptr = build_function_type_list (void_type_node,
    5650              :                                                   ptr_type_node, NULL_TREE);
    5651       102674 :   void_ftype_ptr
    5652       102674 :     = build_exception_variant (void_ftype_ptr, empty_except_spec);
    5653              : 
    5654       102674 :   ptr_ftype_sizetype
    5655       102674 :     = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
    5656       102674 :   if (cxx_dialect == cxx98)
    5657              :     {
    5658        14360 :       tree bad_alloc_id;
    5659        14360 :       tree bad_alloc_type_node;
    5660        14360 :       tree bad_alloc_decl;
    5661              : 
    5662        14360 :       push_nested_namespace (std_node);
    5663        14360 :       bad_alloc_id = get_identifier ("bad_alloc");
    5664        14360 :       bad_alloc_type_node = make_class_type (RECORD_TYPE);
    5665        14360 :       TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
    5666        14360 :       bad_alloc_decl
    5667        14360 :         = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
    5668        14360 :       DECL_CONTEXT (bad_alloc_decl) = current_namespace;
    5669        14360 :       TREE_PUBLIC (bad_alloc_decl) = true;
    5670        14360 :       pop_nested_namespace (std_node);
    5671              : 
    5672        14360 :       new_eh_spec
    5673        14360 :         = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
    5674              :     }
    5675              :   else
    5676        88314 :     new_eh_spec = noexcept_false_spec;
    5677              : 
    5678       102674 :   extvisattr = build_tree_list (get_identifier ("externally_visible"),
    5679              :                                 NULL_TREE);
    5680       102674 :   newattrs = tree_cons (get_identifier ("alloc_size"),
    5681              :                         build_tree_list (NULL_TREE, integer_one_node),
    5682              :                         extvisattr);
    5683       102674 :   newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
    5684       102674 :   newtype = build_exception_variant (newtype, new_eh_spec);
    5685       102674 :   deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
    5686       102674 :   deltype = build_exception_variant (deltype, empty_except_spec);
    5687       102674 :   cxx_build_operator_new (newtype);
    5688       102674 :   cxx_build_operator_delete (deltype);
    5689       102674 :   if (flag_sized_deallocation)
    5690              :     {
    5691              :       /* Also push the sized deallocation variants:
    5692              :            void operator delete(void*, std::size_t) throw();
    5693              :            void operator delete[](void*, std::size_t) throw();  */
    5694        82513 :       tree void_ftype_ptr_size
    5695        82513 :         = build_function_type_list (void_type_node, ptr_type_node,
    5696              :                                     size_type_node, NULL_TREE);
    5697        82513 :       deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
    5698              :                                                  extvisattr);
    5699        82513 :       deltype = build_exception_variant (deltype, empty_except_spec);
    5700        82513 :       cxx_build_operator_delete (deltype);
    5701              :     }
    5702              : 
    5703       102674 :   if (aligned_new_threshold)
    5704              :     {
    5705        81172 :       push_nested_namespace (std_node);
    5706        81172 :       tree align_id = get_identifier ("align_val_t");
    5707        81172 :       align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
    5708              :                                     NULL_TREE, /*scoped*/true, NULL);
    5709        81172 :       pop_nested_namespace (std_node);
    5710              : 
    5711              :       /* operator new (size_t, align_val_t); */
    5712        81172 :       newtype = build_function_type_list (ptr_type_node, size_type_node,
    5713              :                                           align_type_node, NULL_TREE);
    5714        81172 :       newtype = cp_build_type_attribute_variant (newtype, newattrs);
    5715        81172 :       newtype = build_exception_variant (newtype, new_eh_spec);
    5716        81172 :       cxx_build_operator_new (newtype);
    5717              : 
    5718              :       /* operator delete (void *, align_val_t); */
    5719        81172 :       deltype = build_function_type_list (void_type_node, ptr_type_node,
    5720              :                                           align_type_node, NULL_TREE);
    5721        81172 :       deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    5722        81172 :       deltype = build_exception_variant (deltype, empty_except_spec);
    5723        81172 :       cxx_build_operator_delete (deltype);
    5724              : 
    5725        81172 :       if (flag_sized_deallocation)
    5726              :         {
    5727              :           /* operator delete (void *, size_t, align_val_t); */
    5728        81165 :           deltype = build_function_type_list (void_type_node, ptr_type_node,
    5729              :                                               size_type_node, align_type_node,
    5730              :                                               NULL_TREE);
    5731        81165 :           deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    5732        81165 :           deltype = build_exception_variant (deltype, empty_except_spec);
    5733        81165 :           cxx_build_operator_delete (deltype);
    5734              :         }
    5735              :     }
    5736       102674 : }
    5737              : 
    5738              : /* Create the predefined scalar types of C,
    5739              :    and some nodes representing standard constants (0, 1, (void *)0).
    5740              :    Initialize the global binding level.
    5741              :    Make definitions for built-in primitive functions.  */
    5742              : 
    5743              : void
    5744       102674 : cxx_init_decl_processing (void)
    5745              : {
    5746       102674 :   tree void_ftype;
    5747              : 
    5748              :   /* Create all the identifiers we need.  */
    5749       102674 :   initialize_predefined_identifiers ();
    5750              : 
    5751              :   /* Create the global variables.  */
    5752       102674 :   push_to_top_level ();
    5753              : 
    5754       102674 :   current_function_decl = NULL_TREE;
    5755       102674 :   current_binding_level = NULL;
    5756              :   /* Enter the global namespace.  */
    5757       102674 :   gcc_assert (global_namespace == NULL_TREE);
    5758       102674 :   global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
    5759              :                                       void_type_node);
    5760       102674 :   TREE_PUBLIC (global_namespace) = true;
    5761       102674 :   DECL_MODULE_EXPORT_P (global_namespace) = true;
    5762       102674 :   DECL_CONTEXT (global_namespace)
    5763       102674 :     = build_translation_unit_decl (get_identifier (main_input_filename));
    5764              :   /* Remember whether we want the empty class passing ABI change warning
    5765              :      in this TU.  */
    5766       102674 :   TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
    5767       127988 :     = warn_abi && abi_version_crosses (12);
    5768       102674 :   debug_hooks->register_main_translation_unit
    5769       102674 :     (DECL_CONTEXT (global_namespace));
    5770       102674 :   begin_scope (sk_namespace, global_namespace);
    5771       102674 :   current_namespace = global_namespace;
    5772              : 
    5773       102674 :   if (flag_visibility_ms_compat)
    5774            6 :     default_visibility = VISIBILITY_HIDDEN;
    5775              : 
    5776              :   /* Initially, C.  */
    5777       102674 :   current_lang_name = lang_name_c;
    5778              : 
    5779              :   /* Create the `std' namespace.  */
    5780       102674 :   push_namespace (get_identifier ("std"));
    5781       102674 :   std_node = current_namespace;
    5782       102674 :   pop_namespace ();
    5783              : 
    5784       102674 :   flag_noexcept_type = (cxx_dialect >= cxx17);
    5785              : 
    5786       102674 :   c_common_nodes_and_builtins ();
    5787              : 
    5788              :   /* Call the target stack_protect_guard hook if the stack protection
    5789              :      guard is declared as a global symbol.  */
    5790       102674 :   if (targetm.stack_protect_guard_symbol_p ())
    5791           24 :     pushdecl (targetm.stack_protect_guard ());
    5792              : 
    5793       102674 :   tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
    5794       102674 :   tree decl
    5795       102674 :     = add_builtin_function ("__builtin_is_constant_evaluated",
    5796              :                             bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    5797              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5798       102674 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5799              : 
    5800              :   /* The concrete return type of __builtin_source_location is
    5801              :      const std::source_location::__impl*, but we can't form the type
    5802              :      at this point.  So we initially declare it with an auto return
    5803              :      type which we then "deduce" from require_deduced_type upon first use.  */
    5804       102674 :   tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
    5805       102674 :   decl = add_builtin_function ("__builtin_source_location",
    5806              :                                auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
    5807              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5808       102674 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5809              : 
    5810       102674 :   tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
    5811              :                                                         NULL_TREE);
    5812       102674 :   decl
    5813       102674 :     = add_builtin_function ("__builtin_is_corresponding_member",
    5814              :                             bool_vaftype,
    5815              :                             CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
    5816              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5817       102674 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5818              : 
    5819       102674 :   decl
    5820       102674 :     = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
    5821              :                             bool_vaftype,
    5822              :                             CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
    5823              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5824       102674 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5825              : 
    5826       102674 :   if (cxx_dialect >= cxx26)
    5827              :     {
    5828        25819 :       tree void_ptrintftype
    5829        25819 :         = build_function_type_list (void_type_node, ptr_type_node,
    5830              :                                     integer_type_node, NULL_TREE);
    5831        25819 :       decl = add_builtin_function ("__builtin_eh_ptr_adjust_ref",
    5832              :                                    void_ptrintftype,
    5833              :                                    CP_BUILT_IN_EH_PTR_ADJUST_REF,
    5834              :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5835        25819 :       set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5836              : 
    5837              :       /* Similar case to __builtin_source_location above.  The concrete
    5838              :          return type is std::exception_ptr, but we can't form the type
    5839              :          at this point, so it is deduced later.  */
    5840        25819 :       decl = add_builtin_function ("__builtin_current_exception",
    5841              :                                    auto_ftype, CP_BUILT_IN_CURRENT_EXCEPTION,
    5842              :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5843        25819 :       set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5844              : 
    5845        25819 :       tree int_ftype = build_function_type_list (integer_type_node, NULL_TREE);
    5846        25819 :       decl = add_builtin_function ("__builtin_uncaught_exceptions",
    5847              :                                    int_ftype, CP_BUILT_IN_UNCAUGHT_EXCEPTIONS,
    5848              :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5849        25819 :       set_call_expr_flags (decl, ECF_PURE | ECF_NOTHROW | ECF_LEAF);
    5850              :     }
    5851              : 
    5852       102674 :   decl
    5853       102674 :     = add_builtin_function ("__builtin_is_string_literal",
    5854              :                             bool_vaftype,
    5855              :                             CP_BUILT_IN_IS_STRING_LITERAL,
    5856              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5857       102674 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5858              : 
    5859       102674 :   tree void_vaintftype = build_varargs_function_type_list (void_type_node,
    5860              :                                                            integer_type_node,
    5861              :                                                            NULL_TREE);
    5862       102674 :   decl = add_builtin_function ("__builtin_constexpr_diag",
    5863              :                                void_vaintftype,
    5864              :                                CP_BUILT_IN_CONSTEXPR_DIAG,
    5865              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5866       102674 :   set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5867              : 
    5868       102674 :   decl = add_builtin_function ("__builtin_is_within_lifetime",
    5869              :                                bool_vaftype, CP_BUILT_IN_IS_WITHIN_LIFETIME,
    5870              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5871       102674 :   set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5872       102674 :   SET_DECL_IMMEDIATE_FUNCTION_P (decl);
    5873              : 
    5874       102674 :   tree void_vaftype = build_varargs_function_type_list (void_type_node,
    5875              :                                                         NULL_TREE);
    5876       102674 :   decl = add_builtin_function ("__builtin_start_lifetime",
    5877              :                                void_vaftype, CP_BUILT_IN_START_LIFETIME,
    5878              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5879       102674 :   set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5880              : 
    5881       102674 :   integer_two_node = build_int_cst (integer_type_node, 2);
    5882              : 
    5883              :   /* Guess at the initial static decls size.  */
    5884       102674 :   vec_alloc (static_decls, 500);
    5885              : 
    5886              :   /* ... and keyed classes.  */
    5887       102674 :   vec_alloc (keyed_classes, 100);
    5888              : 
    5889       102674 :   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
    5890       102674 :   truthvalue_type_node = boolean_type_node;
    5891       102674 :   truthvalue_false_node = boolean_false_node;
    5892       102674 :   truthvalue_true_node = boolean_true_node;
    5893              : 
    5894       102674 :   empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
    5895       102674 :   noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
    5896       102674 :   noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
    5897       102674 :   noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
    5898              :                                             NULL_TREE);
    5899              : 
    5900              : #if 0
    5901              :   record_builtin_type (RID_MAX, NULL, string_type_node);
    5902              : #endif
    5903              : 
    5904       102674 :   delta_type_node = ptrdiff_type_node;
    5905       102674 :   vtable_index_type = ptrdiff_type_node;
    5906              : 
    5907       102674 :   vtt_parm_type = build_pointer_type (const_ptr_type_node);
    5908       102674 :   void_ftype = build_function_type_list (void_type_node, NULL_TREE);
    5909              : 
    5910              :   /* Create the conversion operator marker.  This operator's DECL_NAME
    5911              :      is in the identifier table, so we can use identifier equality to
    5912              :      find it.  */
    5913       102674 :   conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
    5914              :                                     void_ftype);
    5915              : 
    5916              :   /* C++ extensions */
    5917              : 
    5918       102674 :   unknown_type_node = make_node (LANG_TYPE);
    5919       102674 :   record_unknown_type (unknown_type_node, "unknown type");
    5920              : 
    5921              :   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
    5922       102674 :   TREE_TYPE (unknown_type_node) = unknown_type_node;
    5923              : 
    5924              :   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
    5925              :      result.  */
    5926       102674 :   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
    5927       102674 :   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
    5928              : 
    5929       102674 :   init_list_type_node = make_node (LANG_TYPE);
    5930       102674 :   record_unknown_type (init_list_type_node, "init list");
    5931              : 
    5932              :   /* Used when parsing to distinguish parameter-lists () and (void).  */
    5933       102674 :   explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
    5934              : 
    5935       102674 :   {
    5936              :     /* Make sure we get a unique function type, so we can give
    5937              :        its pointer type a name.  (This wins for gdb.) */
    5938       102674 :     tree vfunc_type = make_node (FUNCTION_TYPE);
    5939       102674 :     TREE_TYPE (vfunc_type) = integer_type_node;
    5940       102674 :     TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
    5941       102674 :     layout_type (vfunc_type);
    5942              : 
    5943       102674 :     vtable_entry_type = build_pointer_type (vfunc_type);
    5944              :   }
    5945       102674 :   record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
    5946              : 
    5947       102674 :   vtbl_type_node
    5948       102674 :     = build_cplus_array_type (vtable_entry_type, NULL_TREE);
    5949       102674 :   layout_type (vtbl_type_node);
    5950       102674 :   vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
    5951       102674 :   record_builtin_type (RID_MAX, NULL, vtbl_type_node);
    5952       102674 :   vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
    5953       102674 :   layout_type (vtbl_ptr_type_node);
    5954       102674 :   record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
    5955              : 
    5956       102674 :   push_namespace (get_identifier ("__cxxabiv1"));
    5957       102674 :   abi_node = current_namespace;
    5958       102674 :   pop_namespace ();
    5959              : 
    5960       102674 :   any_targ_node = make_node (LANG_TYPE);
    5961       102674 :   record_unknown_type (any_targ_node, "any type");
    5962              : 
    5963              :   /* Now, C++.  */
    5964       102674 :   current_lang_name = lang_name_cplusplus;
    5965              : 
    5966       102674 :   if (aligned_new_threshold > 1
    5967       102674 :       && !pow2p_hwi (aligned_new_threshold))
    5968              :     {
    5969            0 :       error ("%<-faligned-new=%d%> is not a power of two",
    5970              :              aligned_new_threshold);
    5971            0 :       aligned_new_threshold = 1;
    5972              :     }
    5973       102674 :   if (aligned_new_threshold == -1)
    5974       124162 :     aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
    5975       102674 :   if (aligned_new_threshold == 1)
    5976        81169 :     aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
    5977              : 
    5978              :   /* Ensure attribs.cc is initialized.  */
    5979       102674 :   init_attributes ();
    5980       102674 :   cxx_init_operator_new_delete_decls ();
    5981              : 
    5982              :   /* C++-specific nullptr initialization.  */
    5983       102674 :   if (abi_version_at_least (9))
    5984       102503 :     SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    5985       102674 :   record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
    5986              : 
    5987       102674 :   if (! supports_one_only ())
    5988            0 :     flag_weak = 0;
    5989              : 
    5990       102674 :   abort_fndecl
    5991       102674 :     = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
    5992              :                             ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
    5993       102674 :   if (flag_weak)
    5994              :     /* If no definition is available, resolve references to NULL.  */
    5995       102644 :     declare_weak (abort_fndecl);
    5996              : 
    5997              :   /* Perform other language dependent initializations.  */
    5998       102674 :   init_class_processing ();
    5999       102674 :   init_rtti_processing ();
    6000       102674 :   init_template_processing ();
    6001              : 
    6002       102674 :   if (flag_exceptions)
    6003       101414 :     init_exception_processing ();
    6004              : 
    6005       102674 :   if (flag_contracts)
    6006        25870 :     init_contracts ();
    6007              : 
    6008       102674 :   if (modules_p ())
    6009         5044 :     init_modules (parse_in);
    6010              : 
    6011       102674 :   if (flag_reflection)
    6012         1394 :     init_reflection ();
    6013              : 
    6014       102674 :   make_fname_decl = cp_make_fname_decl;
    6015       102674 :   start_fname_decls ();
    6016              : 
    6017              :   /* Show we use EH for cleanups.  */
    6018       102674 :   if (flag_exceptions)
    6019       101414 :     using_eh_for_cleanups ();
    6020              : 
    6021              :   /* Check that the hardware interference sizes are at least
    6022              :      alignof(max_align_t), as required by the standard.  */
    6023       102674 :   const int max_align = max_align_t_align () / BITS_PER_UNIT;
    6024       102674 :   if (OPTION_SET_P (param_destruct_interfere_size))
    6025              :     {
    6026            0 :       if (param_destruct_interfere_size < max_align)
    6027            0 :         error ("%<--param destructive-interference-size=%d%> is less than "
    6028              :                "%d", param_destruct_interfere_size, max_align);
    6029            0 :       else if (param_destruct_interfere_size < param_l1_cache_line_size)
    6030            0 :         warning (OPT_Winterference_size,
    6031              :                  "%<--param destructive-interference-size=%d%> "
    6032              :                  "is less than %<--param l1-cache-line-size=%d%>",
    6033              :                  param_destruct_interfere_size, param_l1_cache_line_size);
    6034              :     }
    6035       102674 :   else if (param_destruct_interfere_size)
    6036              :     /* Assume the internal value is OK.  */;
    6037            0 :   else if (param_l1_cache_line_size >= max_align)
    6038            0 :     param_destruct_interfere_size = param_l1_cache_line_size;
    6039              :   /* else leave it unset.  */
    6040              : 
    6041       102674 :   if (OPTION_SET_P (param_construct_interfere_size))
    6042              :     {
    6043            0 :       if (param_construct_interfere_size < max_align)
    6044            0 :         error ("%<--param constructive-interference-size=%d%> is less than "
    6045              :                "%d", param_construct_interfere_size, max_align);
    6046            0 :       else if (param_construct_interfere_size > param_l1_cache_line_size
    6047            0 :                && param_l1_cache_line_size >= max_align)
    6048            0 :         warning (OPT_Winterference_size,
    6049              :                  "%<--param constructive-interference-size=%d%> "
    6050              :                  "is greater than %<--param l1-cache-line-size=%d%>",
    6051              :                  param_construct_interfere_size, param_l1_cache_line_size);
    6052              :     }
    6053       102674 :   else if (param_construct_interfere_size)
    6054              :     /* Assume the internal value is OK.  */;
    6055            0 :   else if (param_l1_cache_line_size >= max_align)
    6056            0 :     param_construct_interfere_size = param_l1_cache_line_size;
    6057       102674 : }
    6058              : 
    6059              : /* Enter an abi node in global-module context.  returns a cookie to
    6060              :    give to pop_abi_namespace.  */
    6061              : 
    6062              : unsigned
    6063        58852 : push_abi_namespace (tree node)
    6064              : {
    6065        58852 :   push_nested_namespace (node);
    6066        58852 :   push_visibility ("default", 2);
    6067        58852 :   unsigned flags = module_kind;
    6068        58852 :   module_kind = 0;
    6069        58852 :   return flags;
    6070              : }
    6071              : 
    6072              : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
    6073              :    you.  */
    6074              : 
    6075              : void
    6076        58852 : pop_abi_namespace (unsigned flags, tree node)
    6077              : {
    6078        58852 :   module_kind = flags;
    6079        58852 :   pop_visibility (2);
    6080        58852 :   pop_nested_namespace (node);
    6081        58852 : }
    6082              : 
    6083              : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
    6084              :    the decl, LOC is the location to give the decl, NAME is the
    6085              :    initialization string and TYPE_DEP indicates whether NAME depended
    6086              :    on the type of the function. We make use of that to detect
    6087              :    __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
    6088              :    at the point of first use, so we mustn't push the decl now.  */
    6089              : 
    6090              : static tree
    6091       246680 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
    6092              : {
    6093       246680 :   tree domain = NULL_TREE;
    6094       246680 :   tree init = NULL_TREE;
    6095              : 
    6096       246680 :   if (!(type_dep && current_function_decl && in_template_context))
    6097              :     {
    6098        61004 :       const char *name = NULL;
    6099        61004 :       bool release_name = false;
    6100              : 
    6101        61004 :       if (current_function_decl == NULL_TREE)
    6102              :         name = "top level";
    6103        60990 :       else if (type_dep == 0)
    6104              :         {
    6105              :           /* __FUNCTION__ */
    6106          847 :           name = fname_as_string (type_dep);
    6107          847 :           release_name = true;
    6108              :         }
    6109              :       else
    6110              :         {
    6111              :           /* __PRETTY_FUNCTION__ */
    6112        60143 :           gcc_checking_assert (type_dep == 1);
    6113        60143 :           name = cxx_printable_name (current_function_decl, 2);
    6114              :         }
    6115              : 
    6116        60990 :       if (!release_name)
    6117              :         {
    6118        60157 :           cpp_string cstr = { 0, 0 }, strname;
    6119        60157 :           strname.text
    6120        60157 :             = const_cast <unsigned char *> ((const unsigned char *) name);
    6121        60157 :           strname.len = strlen (name) + 1;
    6122        60157 :           if (cpp_translate_string (parse_in, &strname, &cstr, CPP_STRING,
    6123              :                                     false))
    6124              :             {
    6125        60157 :               name = (const char *) cstr.text;
    6126        60157 :               release_name = true;
    6127              :             }
    6128              :         }
    6129              : 
    6130        61004 :       size_t length = strlen (name);
    6131        61004 :       domain = build_index_type (size_int (length));
    6132        61004 :       init = build_string (length + 1, name);
    6133        61004 :       if (release_name)
    6134        61004 :         free (const_cast<char *> (name));
    6135              :     }
    6136              : 
    6137       246680 :   tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
    6138       246680 :   type = build_cplus_array_type (type, domain);
    6139              : 
    6140       246680 :   if (init)
    6141        61004 :     TREE_TYPE (init) = type;
    6142              :   else
    6143       185676 :     init = error_mark_node;
    6144              : 
    6145       246680 :   tree decl = build_decl (loc, VAR_DECL, id, type);
    6146              : 
    6147       246680 :   TREE_READONLY (decl) = 1;
    6148       246680 :   DECL_ARTIFICIAL (decl) = 1;
    6149       246680 :   DECL_DECLARED_CONSTEXPR_P (decl) = 1;
    6150       246680 :   TREE_STATIC (decl) = 1;
    6151              : 
    6152       246680 :   TREE_USED (decl) = 1;
    6153              : 
    6154       246680 :   SET_DECL_VALUE_EXPR (decl, init);
    6155       246680 :   DECL_HAS_VALUE_EXPR_P (decl) = 1;
    6156              :   /* For decl_constant_var_p.  */
    6157       246680 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    6158              : 
    6159       246680 :   if (current_function_decl)
    6160              :     {
    6161       246666 :       DECL_CONTEXT (decl) = current_function_decl;
    6162       246666 :       decl = pushdecl_outermost_localscope (decl);
    6163       246666 :       if (decl != error_mark_node)
    6164       246663 :         add_decl_expr (decl);
    6165              :       else
    6166            3 :         gcc_assert (seen_error ());
    6167              :     }
    6168              :   else
    6169              :     {
    6170           14 :       DECL_THIS_STATIC (decl) = true;
    6171           14 :       decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
    6172              :     }
    6173              : 
    6174       246680 :   return decl;
    6175              : }
    6176              : 
    6177              : /* Install DECL as a builtin function at current global scope.  Return
    6178              :    the new decl (if we found an existing version).  Also installs it
    6179              :    into ::std, if it's not '_*'.  */
    6180              : 
    6181              : tree
    6182    239233476 : cxx_builtin_function (tree decl)
    6183              : {
    6184    239233476 :   retrofit_lang_decl (decl);
    6185              : 
    6186    239233476 :   DECL_ARTIFICIAL (decl) = 1;
    6187    239233476 :   SET_DECL_LANGUAGE (decl, lang_c);
    6188              :   /* Runtime library routines are, by definition, available in an
    6189              :      external shared object.  */
    6190    239233476 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    6191    239233476 :   DECL_VISIBILITY_SPECIFIED (decl) = 1;
    6192              : 
    6193    239233476 :   tree id = DECL_NAME (decl);
    6194    239233476 :   const char *name = IDENTIFIER_POINTER (id);
    6195    239233476 :   bool hiding = false;
    6196    239233476 :   if (name[0] != '_' || name[1] != '_')
    6197              :     /* In the user's namespace, it must be declared before use.  */
    6198              :     hiding = true;
    6199    200785448 :   else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
    6200    200785448 :            && !startswith (name + 2, "builtin_")
    6201    224690941 :            && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
    6202              :                            "_chk", strlen ("_chk") + 1))
    6203              :     /* Treat __*_chk fortification functions as anticipated as well,
    6204              :        unless they are __builtin_*_chk.  */
    6205              :     hiding = true;
    6206              : 
    6207              :   /* All builtins that don't begin with an '_' should additionally
    6208              :      go in the 'std' namespace.  */
    6209    239233476 :   if (name[0] != '_')
    6210              :     {
    6211     38307570 :       tree std_decl = copy_decl (decl);
    6212              : 
    6213     38307570 :       push_nested_namespace (std_node);
    6214     38307570 :       DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
    6215     38307570 :       pushdecl (std_decl, hiding);
    6216     38307570 :       pop_nested_namespace (std_node);
    6217              :     }
    6218              : 
    6219    239233476 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    6220    239233476 :   decl = pushdecl (decl, hiding);
    6221              : 
    6222    239233476 :   return decl;
    6223              : }
    6224              : 
    6225              : /* Like cxx_builtin_function, but guarantee the function is added to the global
    6226              :    scope.  This is to allow function specific options to add new machine
    6227              :    dependent builtins when the target ISA changes via attribute((target(...)))
    6228              :    which saves space on program startup if the program does not use non-generic
    6229              :    ISAs.  */
    6230              : 
    6231              : tree
    6232       832330 : cxx_builtin_function_ext_scope (tree decl)
    6233              : {
    6234       832330 :   push_nested_namespace (global_namespace);
    6235       832330 :   decl = cxx_builtin_function (decl);
    6236       832330 :   pop_nested_namespace (global_namespace);
    6237              : 
    6238       832330 :   return decl;
    6239              : }
    6240              : 
    6241              : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    6242              : 
    6243              : tree
    6244            0 : cxx_simulate_builtin_function_decl (tree decl)
    6245              : {
    6246            0 :   retrofit_lang_decl (decl);
    6247              : 
    6248            0 :   DECL_ARTIFICIAL (decl) = 1;
    6249            0 :   SET_DECL_LANGUAGE (decl, lang_cplusplus);
    6250            0 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    6251            0 :   return pushdecl (decl);
    6252              : }
    6253              : 
    6254              : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
    6255              :    function.  Not called directly.  */
    6256              : 
    6257              : static tree
    6258      1656904 : build_library_fn (tree name, enum tree_code operator_code, tree type,
    6259              :                   int ecf_flags)
    6260              : {
    6261      1656904 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    6262      1656904 :   DECL_EXTERNAL (fn) = 1;
    6263      1656904 :   TREE_PUBLIC (fn) = 1;
    6264      1656904 :   DECL_ARTIFICIAL (fn) = 1;
    6265      1656904 :   DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
    6266      1656904 :     = OVL_OP_INFO (false, operator_code)->ovl_op_code;
    6267      1656904 :   SET_DECL_LANGUAGE (fn, lang_c);
    6268              :   /* Runtime library routines are, by definition, available in an
    6269              :      external shared object.  */
    6270      1656904 :   DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
    6271      1656904 :   DECL_VISIBILITY_SPECIFIED (fn) = 1;
    6272      1656904 :   set_call_expr_flags (fn, ecf_flags);
    6273      1656904 :   return fn;
    6274              : }
    6275              : 
    6276              : /* Returns the _DECL for a library function with C++ linkage.  */
    6277              : 
    6278              : static tree
    6279      1164421 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
    6280              :                      int ecf_flags)
    6281              : {
    6282      1164421 :   tree fn = build_library_fn (name, operator_code, type, ecf_flags);
    6283      1164421 :   DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
    6284      1164421 :   SET_DECL_LANGUAGE (fn, lang_cplusplus);
    6285      1164421 :   return fn;
    6286              : }
    6287              : 
    6288              : /* Like build_library_fn, but takes a C string instead of an
    6289              :    IDENTIFIER_NODE.  */
    6290              : 
    6291              : tree
    6292       107686 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
    6293              : {
    6294       107686 :   return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
    6295              : }
    6296              : 
    6297              : /* Like build_cp_library_fn, but takes a C string instead of an
    6298              :    IDENTIFIER_NODE.  */
    6299              : 
    6300              : tree
    6301       101681 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
    6302              : {
    6303       101681 :   return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
    6304       101681 :                               ecf_flags);
    6305              : }
    6306              : 
    6307              : /* Like build_library_fn, but also pushes the function so that we will
    6308              :    be able to find it via get_global_binding.  Also, the function
    6309              :    may throw exceptions listed in RAISES.  */
    6310              : 
    6311              : tree
    6312       384797 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
    6313              : {
    6314       384797 :   if (raises)
    6315        42701 :     type = build_exception_variant (type, raises);
    6316              : 
    6317       384797 :   tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
    6318       384797 :   return pushdecl_top_level (fn);
    6319              : }
    6320              : 
    6321              : /* Like build_cp_library_fn, but also pushes the function so that it
    6322              :    will be found by normal lookup.  */
    6323              : 
    6324              : static tree
    6325      1062740 : push_cp_library_fn (enum tree_code operator_code, tree type,
    6326              :                     int ecf_flags)
    6327              : {
    6328      1062740 :   tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
    6329              :                                  operator_code, type, ecf_flags);
    6330      1062740 :   pushdecl (fn);
    6331      1062740 :   if (flag_tm)
    6332         3412 :     apply_tm_attr (fn, get_identifier ("transaction_safe"));
    6333      1062740 :   return fn;
    6334              : }
    6335              : 
    6336              : /* Like push_library_fn, but also note that this function throws
    6337              :    and does not return.  Used for __throw_foo and the like.  */
    6338              : 
    6339              : tree
    6340       112368 : push_throw_library_fn (tree name, tree type)
    6341              : {
    6342       112368 :   tree fn = push_library_fn (name, type, NULL_TREE,
    6343              :                              ECF_NORETURN | ECF_XTHROW | ECF_COLD);
    6344       112368 :   return fn;
    6345              : }
    6346              : 
    6347              : /* When we call finish_struct for an anonymous union, we create
    6348              :    default copy constructors and such.  But, an anonymous union
    6349              :    shouldn't have such things; this function undoes the damage to the
    6350              :    anonymous union type T.
    6351              : 
    6352              :    (The reason that we create the synthesized methods is that we don't
    6353              :    distinguish `union { int i; }' from `typedef union { int i; } U'.
    6354              :    The first is an anonymous union; the second is just an ordinary
    6355              :    union type.)  */
    6356              : 
    6357              : void
    6358       178274 : fixup_anonymous_aggr (tree t)
    6359              : {
    6360              :   /* Wipe out memory of synthesized methods.  */
    6361       178274 :   TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
    6362       178274 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
    6363       178274 :   TYPE_HAS_COPY_CTOR (t) = 0;
    6364       178274 :   TYPE_HAS_CONST_COPY_CTOR (t) = 0;
    6365       178274 :   TYPE_HAS_COPY_ASSIGN (t) = 0;
    6366       178274 :   TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
    6367              : 
    6368              :   /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
    6369              :      invalid members.  */
    6370      1042962 :   for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
    6371              :     {
    6372       864688 :       if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
    6373            0 :         *prev_p = DECL_CHAIN (probe);
    6374              :       else
    6375       864688 :         prev_p = &DECL_CHAIN (probe);
    6376              : 
    6377       864688 :       if (DECL_ARTIFICIAL (probe)
    6378       864688 :           && (!DECL_IMPLICIT_TYPEDEF_P (probe)
    6379        77972 :               || TYPE_ANON_P (TREE_TYPE (probe))))
    6380       293355 :         continue;
    6381              : 
    6382       571333 :       if (TREE_CODE (probe) != FIELD_DECL
    6383       571279 :           || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
    6384              :         {
    6385              :           /* We already complained about static data members in
    6386              :              finish_static_data_member_decl.  */
    6387           66 :           if (!VAR_P (probe))
    6388              :             {
    6389           51 :               auto_diagnostic_group d;
    6390           51 :               if (permerror (DECL_SOURCE_LOCATION (probe),
    6391           51 :                              TREE_CODE (t) == UNION_TYPE
    6392              :                              ? "%q#D invalid; an anonymous union may "
    6393              :                              "only have public non-static data members"
    6394              :                              : "%q#D invalid; an anonymous struct may "
    6395              :                              "only have public non-static data members", probe))
    6396              :                 {
    6397           51 :                   static bool hint;
    6398           51 :                   if (flag_permissive && !hint)
    6399              :                     {
    6400            6 :                       hint = true;
    6401            6 :                       inform (DECL_SOURCE_LOCATION (probe),
    6402              :                               "this flexibility is deprecated and will be "
    6403              :                               "removed");
    6404              :                     }
    6405              :                 }
    6406           51 :             }
    6407              :         }
    6408              :       }
    6409              : 
    6410              :   /* Splice all functions out of CLASSTYPE_MEMBER_VEC.  */
    6411       178274 :   vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
    6412       178274 :   unsigned store = 0;
    6413       529855 :   for (tree elt : vec)
    6414       351581 :     if (!is_overloaded_fn (elt))
    6415       351560 :       (*vec)[store++] = elt;
    6416       178274 :   vec_safe_truncate (vec, store);
    6417              : 
    6418              :   /* Wipe RTTI info.  */
    6419       178274 :   SET_CLASSTYPE_TYPEINFO_VAR (t, NULL_TREE);
    6420              : 
    6421              :   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
    6422              :      assignment operators (because they cannot have these methods themselves).
    6423              :      For anonymous unions this is already checked because they are not allowed
    6424              :      in any union, otherwise we have to check it.  */
    6425       178274 :   if (TREE_CODE (t) != UNION_TYPE)
    6426              :     {
    6427        37989 :       tree field, type;
    6428              : 
    6429        37989 :       if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
    6430              :         {
    6431            9 :           error_at (location_of (t), "anonymous struct with base classes");
    6432              :           /* Avoid ICE after error on anon-struct9.C.  */
    6433            9 :           TYPE_NEEDS_CONSTRUCTING (t) = false;
    6434              :         }
    6435              : 
    6436       152800 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6437       114811 :         if (TREE_CODE (field) == FIELD_DECL)
    6438              :           {
    6439        76721 :             type = TREE_TYPE (field);
    6440        76721 :             if (CLASS_TYPE_P (type))
    6441              :               {
    6442           61 :                 if (TYPE_NEEDS_CONSTRUCTING (type))
    6443            6 :                   error ("member %q+#D with constructor not allowed "
    6444              :                          "in anonymous aggregate", field);
    6445           61 :                 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    6446            0 :                   error ("member %q+#D with destructor not allowed "
    6447              :                          "in anonymous aggregate", field);
    6448           61 :                 if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    6449            0 :                   error ("member %q+#D with copy assignment operator "
    6450              :                          "not allowed in anonymous aggregate", field);
    6451              :               }
    6452              :           }
    6453              :     }
    6454       178274 : }
    6455              : 
    6456              : /* Warn for an attribute located at LOCATION that appertains to the
    6457              :    class type CLASS_TYPE that has not been properly placed after its
    6458              :    class-key, in it class-specifier.  */
    6459              : 
    6460              : void
    6461          117 : warn_misplaced_attr_for_class_type (location_t location,
    6462              :                                     tree class_type)
    6463              : {
    6464          117 :   gcc_assert (OVERLOAD_TYPE_P (class_type));
    6465              : 
    6466          117 :   auto_diagnostic_group d;
    6467          117 :   if (warning_at (location, OPT_Wattributes,
    6468              :                   "attribute ignored in declaration "
    6469              :                   "of %q#T", class_type))
    6470          117 :     inform (location,
    6471              :             "attribute for %q#T must follow the %qs keyword",
    6472              :             class_type, class_key_or_enum_as_string (class_type));
    6473          117 : }
    6474              : 
    6475              : /* Returns the cv-qualifiers that apply to the type specified
    6476              :    by the DECLSPECS.  */
    6477              : 
    6478              : static cv_qualifier
    6479   1076019187 : get_type_quals (const cp_decl_specifier_seq *declspecs)
    6480              : {
    6481   1076019187 :   auto type_quals = TYPE_UNQUALIFIED;
    6482              : 
    6483   1076019187 :   if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    6484    111088726 :     type_quals |= TYPE_QUAL_CONST;
    6485   1076019187 :   if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    6486      1787105 :     type_quals |= TYPE_QUAL_VOLATILE;
    6487   1076019187 :   if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    6488           34 :     type_quals |= TYPE_QUAL_RESTRICT;
    6489              : 
    6490   1076019187 :   return type_quals;
    6491              : }
    6492              : 
    6493              : /* Make sure that a declaration with no declarator is well-formed, i.e.
    6494              :    just declares a tagged type or anonymous union.
    6495              : 
    6496              :    Returns the type declared; or NULL_TREE if none.  */
    6497              : 
    6498              : tree
    6499     38627604 : check_tag_decl (cp_decl_specifier_seq *declspecs,
    6500              :                 bool explicit_type_instantiation_p)
    6501              : {
    6502     38627604 :   int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    6503     38627604 :   int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
    6504              :   /* If a class, struct, or enum type is declared by the DECLSPECS
    6505              :      (i.e, if a class-specifier, enum-specifier, or non-typename
    6506              :      elaborated-type-specifier appears in the DECLSPECS),
    6507              :      DECLARED_TYPE is set to the corresponding type.  */
    6508     38627604 :   tree declared_type = NULL_TREE;
    6509     38627604 :   bool error_p = false;
    6510              : 
    6511     38627604 :   if (declspecs->multiple_types_p)
    6512           26 :     error_at (smallest_type_location (declspecs),
    6513              :               "multiple types in one declaration");
    6514     38627578 :   else if (declspecs->redefined_builtin_type)
    6515              :     {
    6516           21 :       location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
    6517           21 :       if (!in_system_header_at (loc))
    6518            9 :         permerror (loc, "redeclaration of C++ built-in type %qT",
    6519              :                    declspecs->redefined_builtin_type);
    6520              :       return NULL_TREE;
    6521              :     }
    6522              : 
    6523     38627583 :   if (declspecs->type
    6524     38627568 :       && TYPE_P (declspecs->type)
    6525     76875820 :       && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
    6526     38247174 :            && MAYBE_CLASS_TYPE_P (declspecs->type))
    6527      1924576 :           || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
    6528              :     declared_type = declspecs->type;
    6529       380454 :   else if (declspecs->type == error_mark_node)
    6530         1504 :     error_p = true;
    6531              : 
    6532     38627583 :   if (type_uses_auto (declared_type))
    6533              :     {
    6534            8 :       error_at (declspecs->locations[ds_type_spec],
    6535              :                 "%<auto%> can only be specified for variables "
    6536              :                 "or function declarations");
    6537            8 :       return error_mark_node;
    6538              :     }
    6539              : 
    6540     38627575 :   if (declared_type && !OVERLOAD_TYPE_P (declared_type))
    6541              :     declared_type = NULL_TREE;
    6542              : 
    6543     38627575 :   if (!declared_type && !saw_friend && !error_p)
    6544           91 :     permerror (input_location, "declaration does not declare anything");
    6545              :   /* Check for an anonymous union.  */
    6546     38247094 :   else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
    6547    111453016 :            && TYPE_UNNAMED_P (declared_type))
    6548              :     {
    6549              :       /* 7/3 In a simple-declaration, the optional init-declarator-list
    6550              :          can be omitted only when declaring a class (clause 9) or
    6551              :          enumeration (7.2), that is, when the decl-specifier-seq contains
    6552              :          either a class-specifier, an elaborated-type-specifier with
    6553              :          a class-key (9.1), or an enum-specifier.  In these cases and
    6554              :          whenever a class-specifier or enum-specifier is present in the
    6555              :          decl-specifier-seq, the identifiers in these specifiers are among
    6556              :          the names being declared by the declaration (as class-name,
    6557              :          enum-names, or enumerators, depending on the syntax).  In such
    6558              :          cases, and except for the declaration of an unnamed bit-field (9.6),
    6559              :          the decl-specifier-seq shall introduce one or more names into the
    6560              :          program, or shall redeclare a name introduced by a previous
    6561              :          declaration.  [Example:
    6562              :              enum { };                  // ill-formed
    6563              :              typedef class { };         // ill-formed
    6564              :          --end example]  */
    6565       178280 :       if (saw_typedef)
    6566              :         {
    6567            6 :           error_at (declspecs->locations[ds_typedef],
    6568              :                     "missing type-name in typedef-declaration");
    6569            6 :           return NULL_TREE;
    6570              :         }
    6571       178274 :       /* Anonymous unions are objects, so they can have specifiers.  */;
    6572       178274 :       SET_ANON_AGGR_TYPE_P (declared_type);
    6573              : 
    6574       178274 :       if (TREE_CODE (declared_type) != UNION_TYPE)
    6575        37989 :         pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
    6576        37989 :                  OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
    6577              :     }
    6578              : 
    6579              :   else
    6580              :     {
    6581     38449204 :       if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
    6582            9 :         error_at (declspecs->locations[ds_inline],
    6583              :                   "%<inline%> can only be specified for functions");
    6584     38449195 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
    6585            3 :         error_at (declspecs->locations[ds_virtual],
    6586              :                   "%<virtual%> can only be specified for functions");
    6587     38449192 :       else if (saw_friend
    6588     38449192 :                && (!current_class_type
    6589      2167168 :                    || current_scope () != current_class_type))
    6590            0 :         error_at (declspecs->locations[ds_friend],
    6591              :                   "%<friend%> can only be specified inside a class");
    6592     38449192 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
    6593            3 :         error_at (declspecs->locations[ds_explicit],
    6594              :                   "%<explicit%> can only be specified for constructors");
    6595     38449189 :       else if (declspecs->storage_class)
    6596            3 :         error_at (declspecs->locations[ds_storage_class],
    6597              :                   "a storage class can only be specified for objects "
    6598              :                   "and functions");
    6599     38449186 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    6600            9 :         error_at (declspecs->locations[ds_const],
    6601              :                   "%<const%> can only be specified for objects and "
    6602              :                   "functions");
    6603     38449177 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    6604            3 :         error_at (declspecs->locations[ds_volatile],
    6605              :                   "%<volatile%> can only be specified for objects and "
    6606              :                   "functions");
    6607     38449174 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    6608            3 :         error_at (declspecs->locations[ds_restrict],
    6609              :                   "%<__restrict%> can only be specified for objects and "
    6610              :                   "functions");
    6611     38449171 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
    6612            3 :         error_at (declspecs->locations[ds_thread],
    6613              :                   "%<__thread%> can only be specified for objects "
    6614              :                   "and functions");
    6615     38449168 :       else if (saw_typedef)
    6616           24 :         warning_at (declspecs->locations[ds_typedef], 0,
    6617              :                     "%<typedef%> was ignored in this declaration");
    6618     38449144 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
    6619            9 :         error_at (declspecs->locations[ds_constexpr],
    6620              :                   "%qs cannot be used for type declarations", "constexpr");
    6621     38449135 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
    6622            3 :         error_at (declspecs->locations[ds_constinit],
    6623              :                   "%qs cannot be used for type declarations", "constinit");
    6624     38449132 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
    6625            3 :         error_at (declspecs->locations[ds_consteval],
    6626              :                   "%qs cannot be used for type declarations", "consteval");
    6627              :     }
    6628              : 
    6629     38627569 :   if (declspecs->attributes && warn_attributes && declared_type)
    6630              :     {
    6631           30 :       location_t loc;
    6632           24 :       if (!CLASS_TYPE_P (declared_type)
    6633           54 :           || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
    6634              :         /* For a non-template class, use the name location.  */
    6635           21 :         loc = location_of (declared_type);
    6636              :       else
    6637              :         /* For a template class (an explicit instantiation), use the
    6638              :            current location.  */
    6639            9 :         loc = input_location;
    6640              : 
    6641           30 :       if (explicit_type_instantiation_p)
    6642              :         /* [dcl.attr.grammar]/4:
    6643              : 
    6644              :                No attribute-specifier-seq shall appertain to an explicit
    6645              :                instantiation.  */
    6646              :         {
    6647            6 :           auto_diagnostic_group d;
    6648            6 :           if (warning_at (loc, OPT_Wattributes,
    6649              :                           "attribute ignored in explicit instantiation %q#T",
    6650              :                           declared_type))
    6651            6 :             inform (loc,
    6652              :                     "no attribute can be applied to "
    6653              :                     "an explicit instantiation");
    6654            6 :         }
    6655              :       else
    6656           24 :         warn_misplaced_attr_for_class_type (loc, declared_type);
    6657              :     }
    6658              : 
    6659     38627569 :   if (declspecs->std_attributes
    6660           93 :       && declared_type
    6661     38627659 :       && any_nonignored_attribute_p (declspecs->std_attributes))
    6662              :     {
    6663           90 :       auto_diagnostic_group d;
    6664           90 :       if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
    6665              :                       "attribute ignored"))
    6666           90 :         inform (declspecs->locations[ds_std_attribute],
    6667              :                 "an attribute that appertains to a type-specifier is ignored");
    6668           90 :     }
    6669              : 
    6670              :   return declared_type;
    6671              : }
    6672              : 
    6673              : /* Called when a declaration is seen that contains no names to declare.
    6674              :    If its type is a reference to a structure, union or enum inherited
    6675              :    from a containing scope, shadow that tag name for the current scope
    6676              :    with a forward reference.
    6677              :    If its type defines a new named structure or union
    6678              :    or defines an enum, it is valid but we need not do anything here.
    6679              :    Otherwise, it is an error.
    6680              : 
    6681              :    C++: may have to grok the declspecs to learn about static,
    6682              :    complain for anonymous unions.
    6683              : 
    6684              :    Returns the TYPE declared -- or NULL_TREE if none.  */
    6685              : 
    6686              : tree
    6687     33852152 : shadow_tag (cp_decl_specifier_seq *declspecs)
    6688              : {
    6689     33852152 :   tree t = check_tag_decl (declspecs,
    6690              :                            /*explicit_type_instantiation_p=*/false);
    6691              : 
    6692     33852152 :   if (!t)
    6693              :     return NULL_TREE;
    6694              : 
    6695     33850632 :   t = maybe_process_partial_specialization (t);
    6696     33850632 :   if (t == error_mark_node)
    6697              :     return NULL_TREE;
    6698              : 
    6699              :   /* This is where the variables in an anonymous union are
    6700              :      declared.  An anonymous union declaration looks like:
    6701              :      union { ... } ;
    6702              :      because there is no declarator after the union, the parser
    6703              :      sends that declaration here.  */
    6704     33848721 :   if (ANON_AGGR_TYPE_P (t))
    6705              :     {
    6706          392 :       fixup_anonymous_aggr (t);
    6707              : 
    6708          392 :       if (TYPE_FIELDS (t))
    6709              :         {
    6710          392 :           tree decl = grokdeclarator (/*declarator=*/NULL,
    6711              :                                       declspecs, NORMAL, 0, NULL);
    6712          392 :           finish_anon_union (decl);
    6713              :         }
    6714              :     }
    6715              : 
    6716              :   return t;
    6717              : }
    6718              : 
    6719              : /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
    6720              : 
    6721              : tree
    6722    421538718 : groktypename (cp_decl_specifier_seq *type_specifiers,
    6723              :               const cp_declarator *declarator,
    6724              :               bool is_template_arg)
    6725              : {
    6726    421538718 :   tree attrs;
    6727    421538718 :   tree type;
    6728     69643717 :   enum decl_context context
    6729    421538718 :     = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
    6730    421538718 :   attrs = type_specifiers->attributes;
    6731    421538718 :   type_specifiers->attributes = NULL_TREE;
    6732    421538718 :   type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
    6733    421538718 :   if (attrs && type != error_mark_node)
    6734              :     {
    6735          673 :       if (CLASS_TYPE_P (type))
    6736            6 :         warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
    6737              :                  "outside of definition", type);
    6738          667 :       else if (MAYBE_CLASS_TYPE_P (type))
    6739              :         /* A template type parameter or other dependent type.  */
    6740            9 :         warning (OPT_Wattributes, "ignoring attributes applied to dependent "
    6741              :                  "type %qT without an associated declaration", type);
    6742              :       else
    6743          658 :         cplus_decl_attributes (&type, attrs, 0);
    6744              :     }
    6745    421538718 :   return type;
    6746              : }
    6747              : 
    6748              : /* Process a DECLARATOR for a function-scope or namespace-scope
    6749              :    variable or function declaration.
    6750              :    (Function definitions go through start_function; class member
    6751              :    declarations appearing in the body of the class go through
    6752              :    grokfield.)  The DECL corresponding to the DECLARATOR is returned.
    6753              :    If an error occurs, the error_mark_node is returned instead.
    6754              : 
    6755              :    DECLSPECS are the decl-specifiers for the declaration.  INITIALIZED is
    6756              :    SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
    6757              :    for an explicitly defaulted function, or SD_DELETED for an explicitly
    6758              :    deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
    6759              :    implicitly initialized via a default constructor.  It can also be
    6760              :    SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
    6761              :    mark the new decl as DECL_DECOMPOSITION_P.
    6762              : 
    6763              :    ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
    6764              :    declaration.
    6765              : 
    6766              :    The scope represented by the context of the returned DECL is pushed
    6767              :    (if it is not the global namespace) and is assigned to
    6768              :    *PUSHED_SCOPE_P.  The caller is then responsible for calling
    6769              :    pop_scope on *PUSHED_SCOPE_P if it is set.  */
    6770              : 
    6771              : tree
    6772    132207770 : start_decl (const cp_declarator *declarator,
    6773              :             cp_decl_specifier_seq *declspecs,
    6774              :             int initialized,
    6775              :             tree attributes,
    6776              :             tree prefix_attributes,
    6777              :             tree *pushed_scope_p)
    6778              : {
    6779    132207770 :   tree decl;
    6780    132207770 :   tree context;
    6781    132207770 :   bool was_public;
    6782    132207770 :   int flags;
    6783    132207770 :   bool alias;
    6784    132207770 :   tree initial;
    6785              : 
    6786    132207770 :   *pushed_scope_p = NULL_TREE;
    6787              : 
    6788    132207770 :   if (prefix_attributes != error_mark_node)
    6789    132207768 :     attributes = attr_chainon (attributes, prefix_attributes);
    6790              : 
    6791    132207770 :   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
    6792              :                          &attributes);
    6793              : 
    6794    132207770 :   if (decl == NULL_TREE || VOID_TYPE_P (decl)
    6795    132207770 :       || decl == error_mark_node
    6796    132205612 :       || prefix_attributes == error_mark_node)
    6797         2160 :     return error_mark_node;
    6798              : 
    6799    132205610 :   context = CP_DECL_CONTEXT (decl);
    6800    132205610 :   if (context != global_namespace)
    6801     23326263 :     *pushed_scope_p = push_scope (context);
    6802              : 
    6803    132205610 :   if (initialized && TREE_CODE (decl) == TYPE_DECL)
    6804              :     {
    6805           27 :       error_at (DECL_SOURCE_LOCATION (decl),
    6806              :                 "typedef %qD is initialized (use %qs instead)",
    6807              :                 decl, "decltype");
    6808           27 :       return error_mark_node;
    6809              :     }
    6810              : 
    6811    132205583 :   if (flag_contracts
    6812     14995915 :       && TREE_CODE (decl) == FUNCTION_DECL
    6813      4202381 :       && !processing_template_decl
    6814      3401768 :       && DECL_RESULT (decl)
    6815    135600777 :       && is_auto (TREE_TYPE (DECL_RESULT (decl))))
    6816           36 :     if (tree specs = get_fn_contract_specifiers (decl))
    6817           12 :       for (tree ca : tree_vec_range (specs))
    6818            9 :         if (POSTCONDITION_P (ca) && POSTCONDITION_IDENTIFIER (ca))
    6819              :           {
    6820            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    6821              :                       "postconditions with deduced result name types must only"
    6822              :                       " appear on function definitions");
    6823            3 :             return error_mark_node;
    6824              :           }
    6825              :   /* Save the DECL_INITIAL value in case it gets clobbered to assist
    6826              :      with attribute validation.  */
    6827    132205580 :   initial = DECL_INITIAL (decl);
    6828              : 
    6829    132205580 :   if (initialized)
    6830              :     {
    6831     64305250 :       if (! toplevel_bindings_p ()
    6832     64305250 :           && DECL_EXTERNAL (decl))
    6833            3 :         warning (0, "declaration of %q#D has %<extern%> and is initialized",
    6834              :                  decl);
    6835     64305250 :       DECL_EXTERNAL (decl) = 0;
    6836     64305250 :       if (toplevel_bindings_p ())
    6837      7900113 :         TREE_STATIC (decl) = 1;
    6838              :       /* Tell 'cplus_decl_attributes' this is an initialized decl,
    6839              :          even though we might not yet have the initializer expression.  */
    6840     64305250 :       if (!DECL_INITIAL (decl))
    6841     63718995 :         DECL_INITIAL (decl) = error_mark_node;
    6842              :     }
    6843    132205580 :   alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
    6844              : 
    6845    132205580 :   if (alias && TREE_CODE (decl) == FUNCTION_DECL)
    6846         3992 :     record_key_method_defined (decl);
    6847              : 
    6848              :   /* If this is a typedef that names the class for linkage purposes
    6849              :      (7.1.3p8), apply any attributes directly to the type.  */
    6850    132205580 :   if (TREE_CODE (decl) == TYPE_DECL
    6851    132205580 :       && TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl))
    6852              :     flags = ATTR_FLAG_TYPE_IN_PLACE;
    6853              :   else
    6854              :     flags = 0;
    6855              : 
    6856              :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    6857    132205580 :   cplus_decl_attributes (&decl, attributes, flags);
    6858              : 
    6859              :   /* Restore the original DECL_INITIAL that we may have clobbered earlier to
    6860              :      assist with attribute validation.  */
    6861    132205580 :   DECL_INITIAL (decl) = initial;
    6862              : 
    6863              :   /* Dllimported symbols cannot be defined.  Static data members (which
    6864              :      can be initialized in-class and dllimported) go through grokfield,
    6865              :      not here, so we don't need to exclude those decls when checking for
    6866              :      a definition.  */
    6867    132205580 :   if (initialized && DECL_DLLIMPORT_P (decl))
    6868              :     {
    6869            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    6870              :                 "definition of %q#D is marked %<dllimport%>", decl);
    6871            0 :       DECL_DLLIMPORT_P (decl) = 0;
    6872              :     }
    6873              : 
    6874              :   /* If #pragma weak was used, mark the decl weak now.  */
    6875    132205580 :   if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
    6876     48121084 :     maybe_apply_pragma_weak (decl);
    6877              : 
    6878    132205580 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6879     39021813 :       && DECL_DECLARED_INLINE_P (decl)
    6880      3534732 :       && DECL_UNINLINABLE (decl)
    6881    132205580 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    6882              :     {
    6883            0 :       auto_urlify_attributes sentinel;
    6884            0 :       warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6885              :                   "inline function %qD given attribute %qs", decl, "noinline");
    6886            0 :     }
    6887              : 
    6888    132205580 :   if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
    6889              :     {
    6890       865792 :       bool this_tmpl = (current_template_depth
    6891       865792 :                         > template_class_depth (context));
    6892       865792 :       if (VAR_P (decl))
    6893              :         {
    6894       506853 :           tree field = lookup_field (context, DECL_NAME (decl), 0, false);
    6895       506853 :           if (field == NULL_TREE
    6896       506853 :               || !(VAR_P (field) || variable_template_p (field)))
    6897            6 :             error ("%q+#D is not a static data member of %q#T", decl, context);
    6898       506847 :           else if (variable_template_p (field)
    6899       506847 :                    && (DECL_LANG_SPECIFIC (decl)
    6900          149 :                        && DECL_TEMPLATE_SPECIALIZATION (decl)))
    6901              :             /* OK, specialization was already checked.  */;
    6902       506776 :           else if (variable_template_p (field) && !this_tmpl)
    6903              :             {
    6904            3 :               auto_diagnostic_group d;
    6905            3 :               error_at (DECL_SOURCE_LOCATION (decl),
    6906              :                         "non-member-template declaration of %qD", decl);
    6907            3 :               inform (DECL_SOURCE_LOCATION (field), "does not match "
    6908              :                       "member template declaration here");
    6909            3 :               return error_mark_node;
    6910            3 :             }
    6911              :           else
    6912              :             {
    6913       506773 :               if (variable_template_p (field))
    6914           75 :                 field = DECL_TEMPLATE_RESULT (field);
    6915              : 
    6916       506773 :               if (DECL_CONTEXT (field) != context)
    6917              :                 {
    6918            3 :                   if (!same_type_p (DECL_CONTEXT (field), context))
    6919            3 :                     permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
    6920              :                                "to be defined as %<%T::%D%>",
    6921            3 :                                DECL_CONTEXT (field), DECL_NAME (decl),
    6922            3 :                                context, DECL_NAME (decl));
    6923            3 :                   DECL_CONTEXT (decl) = DECL_CONTEXT (field);
    6924              :                 }
    6925              : 
    6926       506773 :               if (modules_p () && !module_may_redeclare (field))
    6927           30 :                 return error_mark_node;
    6928              : 
    6929              :               /* Static data member are tricky; an in-class initialization
    6930              :                  still doesn't provide a definition, so the in-class
    6931              :                  declaration will have DECL_EXTERNAL set, but will have an
    6932              :                  initialization.  Thus, duplicate_decls won't warn
    6933              :                  about this situation, and so we check here.  */
    6934       506743 :               if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
    6935            9 :                 error ("duplicate initialization of %qD", decl);
    6936       506743 :               field = duplicate_decls (decl, field);
    6937       506743 :               if (field == error_mark_node)
    6938              :                 return error_mark_node;
    6939       506687 :               else if (field)
    6940       506687 :                 decl = field;
    6941              :             }
    6942              :         }
    6943              :       else
    6944              :         {
    6945       358951 :           tree field = check_classfn (context, decl,
    6946              :                                       this_tmpl
    6947           12 :                                       ? current_template_parms
    6948              :                                       : NULL_TREE);
    6949       358864 :           if (field && field != error_mark_node
    6950       717803 :               && duplicate_decls (decl, field))
    6951       358864 :             decl = field;
    6952              :         }
    6953              : 
    6954              :       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
    6955       865703 :       DECL_IN_AGGR_P (decl) = 0;
    6956              :       /* Do not mark DECL as an explicit specialization if it was not
    6957              :          already marked as an instantiation; a declaration should
    6958              :          never be marked as a specialization unless we know what
    6959              :          template is being specialized.  */
    6960       865703 :       if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    6961              :         {
    6962       356989 :           SET_DECL_TEMPLATE_SPECIALIZATION (decl);
    6963       356989 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6964       336358 :             DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
    6965       336358 :                                   && DECL_NONGNU_INLINE_P (decl));
    6966              :           else
    6967        20631 :             DECL_COMDAT (decl) = false;
    6968              : 
    6969              :           /* [temp.expl.spec] An explicit specialization of a static data
    6970              :              member of a template is a definition if the declaration
    6971              :              includes an initializer; otherwise, it is a declaration.
    6972              : 
    6973              :              We check for processing_specialization so this only applies
    6974              :              to the new specialization syntax.  */
    6975       356989 :           if (!initialized && processing_specialization)
    6976       356785 :             DECL_EXTERNAL (decl) = 1;
    6977              :         }
    6978              : 
    6979      1222536 :       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
    6980              :           /* Aliases are definitions. */
    6981       865739 :           && !alias)
    6982              :         {
    6983            9 :           permerror (declarator->id_loc,
    6984              :                        "declaration of %q#D outside of class is not definition",
    6985              :                        decl);
    6986              :         }
    6987              :     }
    6988              : 
    6989              :   /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works.  */
    6990    132205491 :   if (initialized == SD_DECOMPOSITION)
    6991       491199 :     fit_decomposition_lang_decl (decl, NULL_TREE);
    6992              : 
    6993    132205491 :   was_public = TREE_PUBLIC (decl);
    6994              : 
    6995    225398604 :   if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
    6996    132791622 :       && current_function_decl)
    6997              :     {
    6998              :       /* A function-scope decl of some namespace-scope decl.  */
    6999        62611 :       DECL_LOCAL_DECL_P (decl) = true;
    7000        62611 :       if (named_module_attach_p ())
    7001            3 :         error_at (declarator->id_loc,
    7002              :                   "block-scope extern declaration %q#D must not be"
    7003              :                   " attached to a named module", decl);
    7004              :     }
    7005              : 
    7006              :   /* Enter this declaration into the symbol table.  Don't push the plain
    7007              :      VAR_DECL for a variable template.  */
    7008    132205491 :   if (!template_parm_scope_p ()
    7009    132205491 :       || !VAR_P (decl))
    7010    127636048 :     decl = maybe_push_decl (decl);
    7011              : 
    7012    132205491 :   if (processing_template_decl)
    7013     84076212 :     decl = push_template_decl (decl);
    7014              : 
    7015    132205491 :   if (decl == error_mark_node)
    7016              :     return error_mark_node;
    7017              : 
    7018    132205038 :   if (VAR_P (decl)
    7019     70600519 :       && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
    7020        70825 :       && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
    7021              :       /* But not templated variables.  */
    7022    132236552 :       && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
    7023              :     {
    7024              :       /* This is a const variable with implicit 'static'.  Set
    7025              :          DECL_THIS_STATIC so we can tell it from variables that are
    7026              :          !TREE_PUBLIC because of the anonymous namespace.  */
    7027        31514 :       gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
    7028        31514 :       DECL_THIS_STATIC (decl) = 1;
    7029              :     }
    7030              : 
    7031     74615749 :   if (current_function_decl && VAR_P (decl)
    7032     61883582 :       && maybe_constexpr_fn (current_function_decl)
    7033    148394332 :       && cxx_dialect < cxx23)
    7034              :     {
    7035     12650604 :       bool ok = false;
    7036     12650604 :       if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
    7037              :         {
    7038            9 :           if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    7039           18 :             error_at (DECL_SOURCE_LOCATION (decl),
    7040              :                       "%qD defined %<thread_local%> in %qs function only "
    7041              :                       "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    7042            9 :                       DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    7043              :                       ? "consteval" : "constexpr");
    7044              :         }
    7045     12650595 :       else if (TREE_STATIC (decl))
    7046              :         {
    7047           74 :           if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    7048           72 :             error_at (DECL_SOURCE_LOCATION (decl),
    7049              :                       "%qD defined %<static%> in %qs function only available "
    7050              :                       "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    7051           36 :                       DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    7052              :                       ? "consteval" : "constexpr");
    7053              :         }
    7054              :       else
    7055              :         ok = true;
    7056           45 :       if (!ok)
    7057           83 :         cp_function_chain->invalid_constexpr = true;
    7058              :     }
    7059              : 
    7060    132205038 :   if (!processing_template_decl && VAR_P (decl))
    7061      8798780 :     start_decl_1 (decl, initialized);
    7062              : 
    7063    132205035 :   return decl;
    7064              : }
    7065              : 
    7066              : /* Process the declaration of a variable DECL.  INITIALIZED is true
    7067              :    iff DECL is explicitly initialized.  (INITIALIZED is false if the
    7068              :    variable is initialized via an implicitly-called constructor.)
    7069              :    This function must be called for ordinary variables (including, for
    7070              :    example, implicit instantiations of templates), but must not be
    7071              :    called for template declarations.  */
    7072              : 
    7073              : void
    7074      8810017 : start_decl_1 (tree decl, bool initialized)
    7075              : {
    7076      8810017 :   gcc_checking_assert (!processing_template_decl);
    7077              : 
    7078      8810017 :   if (error_operand_p (decl))
    7079              :     return;
    7080              : 
    7081      8810002 :   gcc_checking_assert (VAR_P (decl));
    7082              : 
    7083      8810002 :   tree type = TREE_TYPE (decl);
    7084      8810002 :   bool complete_p = COMPLETE_TYPE_P (type);
    7085      8810002 :   bool aggregate_definition_p
    7086      8810002 :     = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
    7087              : 
    7088              :   /* If an explicit initializer is present, or if this is a definition
    7089              :      of an aggregate, then we need a complete type at this point.
    7090              :      (Scalars are always complete types, so there is nothing to
    7091              :      check.)  This code just sets COMPLETE_P; errors (if necessary)
    7092              :      are issued below.  */
    7093      4575316 :   if ((initialized || aggregate_definition_p)
    7094      7769830 :       && !complete_p
    7095      6234640 :       && COMPLETE_TYPE_P (complete_type (type)))
    7096              :     {
    7097       339907 :       complete_p = true;
    7098              :       /* We will not yet have set TREE_READONLY on DECL if the type
    7099              :          was "const", but incomplete, before this point.  But, now, we
    7100              :          have a complete type, so we can try again.  */
    7101       339907 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    7102              :     }
    7103              : 
    7104      8809999 :   if (initialized)
    7105              :     /* Is it valid for this decl to have an initializer at all?  */
    7106              :     {
    7107              :       /* Don't allow initializations for incomplete types except for
    7108              :          arrays which might be completed by the initialization.  */
    7109      7000377 :       if (complete_p)
    7110              :         ;                       /* A complete type is ok.  */
    7111      1319173 :       else if (type_uses_auto (type))
    7112              :         ;                       /* An auto type is ok.  */
    7113       123080 :       else if (TREE_CODE (type) != ARRAY_TYPE)
    7114              :         {
    7115           27 :           auto_diagnostic_group d;
    7116           27 :           error ("variable %q#D has initializer but incomplete type", decl);
    7117           48 :           maybe_suggest_missing_header (input_location,
    7118           27 :                                         TYPE_IDENTIFIER (type),
    7119           27 :                                         CP_TYPE_CONTEXT (type));
    7120           27 :           type = TREE_TYPE (decl) = error_mark_node;
    7121           27 :         }
    7122       123053 :       else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
    7123              :         {
    7124            0 :           if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    7125            0 :             error ("elements of array %q#D have incomplete type", decl);
    7126              :           /* else we already gave an error in start_decl.  */
    7127              :         }
    7128              :     }
    7129      1809622 :   else if (aggregate_definition_p && !complete_p)
    7130              :     {
    7131          241 :       if (type_uses_auto (type))
    7132           71 :         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
    7133              :       else
    7134              :         {
    7135          170 :           auto_diagnostic_group d;
    7136          170 :           error ("aggregate %q#D has incomplete type and cannot be defined",
    7137              :                  decl);
    7138          295 :           maybe_suggest_missing_header (input_location,
    7139          170 :                                         TYPE_IDENTIFIER (type),
    7140          170 :                                         CP_TYPE_CONTEXT (type));
    7141              :           /* Change the type so that assemble_variable will give
    7142              :              DECL an rtl we can live with: (mem (const_int 0)).  */
    7143          170 :           type = TREE_TYPE (decl) = error_mark_node;
    7144          170 :         }
    7145              :     }
    7146              : 
    7147              :   /* Create a new scope to hold this declaration if necessary.
    7148              :      Whether or not a new scope is necessary cannot be determined
    7149              :      until after the type has been completed; if the type is a
    7150              :      specialization of a class template it is not until after
    7151              :      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    7152              :      will be set correctly.  */
    7153      8809999 :   maybe_push_cleanup_level (type);
    7154              : }
    7155              : 
    7156              : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
    7157              :    C++20 P0960.  TYPE is the type of the object we're initializing.  */
    7158              : 
    7159              : tree
    7160          309 : do_aggregate_paren_init (tree init, tree type)
    7161              : {
    7162          309 :   tree val = TREE_VALUE (init);
    7163              : 
    7164          309 :   if (TREE_CHAIN (init) == NULL_TREE)
    7165              :     {
    7166              :       /* If the list has a single element and it's a string literal,
    7167              :          then it's the initializer for the array as a whole.  */
    7168          193 :       if (TREE_CODE (type) == ARRAY_TYPE
    7169          193 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    7170          239 :           && TREE_CODE (tree_strip_any_location_wrapper (val))
    7171              :              == STRING_CST)
    7172              :         return val;
    7173              :       /* Handle non-standard extensions like compound literals.  This also
    7174              :          prevents triggering aggregate parenthesized-initialization in
    7175              :          compiler-generated code for =default.  */
    7176          154 :       else if (same_type_ignoring_top_level_qualifiers_p (type,
    7177          154 :                                                           TREE_TYPE (val)))
    7178              :         return val;
    7179              :     }
    7180              : 
    7181          208 :   init = build_constructor_from_list (init_list_type_node, init);
    7182          208 :   CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    7183          208 :   CONSTRUCTOR_IS_PAREN_INIT (init) = true;
    7184          208 :   return init;
    7185              : }
    7186              : 
    7187              : /* Handle initialization of references.  DECL, TYPE, and INIT have the
    7188              :    same meaning as in cp_finish_decl.  *CLEANUP must be NULL on entry,
    7189              :    but will be set to a new CLEANUP_STMT if a temporary is created
    7190              :    that must be destroyed subsequently.
    7191              : 
    7192              :    Returns an initializer expression to use to initialize DECL, or
    7193              :    NULL if the initialization can be performed statically.
    7194              : 
    7195              :    Quotes on semantics can be found in ARM 8.4.3.  */
    7196              : 
    7197              : static tree
    7198       385852 : grok_reference_init (tree decl, tree type, tree init, int flags)
    7199              : {
    7200       385852 :   if (init == NULL_TREE)
    7201              :     {
    7202           15 :       if ((DECL_LANG_SPECIFIC (decl) == 0
    7203            3 :            || DECL_IN_AGGR_P (decl) == 0)
    7204           18 :           && ! DECL_THIS_EXTERN (decl))
    7205           15 :         error_at (DECL_SOURCE_LOCATION (decl),
    7206              :                   "%qD declared as reference but not initialized", decl);
    7207              :       return NULL_TREE;
    7208              :     }
    7209              : 
    7210       385837 :   tree ttype = TREE_TYPE (type);
    7211       385837 :   if (TREE_CODE (init) == TREE_LIST)
    7212              :     {
    7213              :       /* This handles (C++20 only) code like
    7214              : 
    7215              :            const A& r(1, 2, 3);
    7216              : 
    7217              :          where we treat the parenthesized list as a CONSTRUCTOR.  */
    7218         1262 :       if (TREE_TYPE (init) == NULL_TREE
    7219         1262 :           && CP_AGGREGATE_TYPE_P (ttype)
    7220          102 :           && !DECL_DECOMPOSITION_P (decl)
    7221         1361 :           && (cxx_dialect >= cxx20))
    7222              :         {
    7223              :           /* We don't know yet if we should treat const A& r(1) as
    7224              :              const A& r{1}.  */
    7225           93 :           if (list_length (init) == 1)
    7226              :             {
    7227           72 :               flags |= LOOKUP_AGGREGATE_PAREN_INIT;
    7228           72 :               init = build_x_compound_expr_from_list (init, ELK_INIT,
    7229              :                                                       tf_warning_or_error);
    7230              :             }
    7231              :           /* If the list had more than one element, the code is ill-formed
    7232              :              pre-C++20, so we can build a constructor right away.  */
    7233              :           else
    7234           21 :             init = do_aggregate_paren_init (init, ttype);
    7235              :         }
    7236              :       else
    7237         1169 :         init = build_x_compound_expr_from_list (init, ELK_INIT,
    7238              :                                                 tf_warning_or_error);
    7239              :     }
    7240              : 
    7241       385837 :   if (TREE_CODE (ttype) != ARRAY_TYPE
    7242       385837 :       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
    7243              :     /* Note: default conversion is only called in very special cases.  */
    7244           12 :     init = decay_conversion (init, tf_warning_or_error);
    7245              : 
    7246              :   /* check_initializer handles this for non-reference variables, but for
    7247              :      references we need to do it here or the initializer will get the
    7248              :      incomplete array type and confuse later calls to
    7249              :      cp_complete_array_type.  */
    7250       385837 :   if (TREE_CODE (ttype) == ARRAY_TYPE
    7251        22619 :       && TYPE_DOMAIN (ttype) == NULL_TREE
    7252       385920 :       && (BRACE_ENCLOSED_INITIALIZER_P (init)
    7253           50 :           || TREE_CODE (init) == STRING_CST))
    7254              :     {
    7255           33 :       cp_complete_array_type (&ttype, init, false);
    7256           33 :       if (ttype != TREE_TYPE (type))
    7257           33 :         type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
    7258              :     }
    7259              : 
    7260              :   /* Convert INIT to the reference type TYPE.  This may involve the
    7261              :      creation of a temporary, whose lifetime must be the same as that
    7262              :      of the reference.  If so, a DECL_EXPR for the temporary will be
    7263              :      added just after the DECL_EXPR for DECL.  That's why we don't set
    7264              :      DECL_INITIAL for local references (instead assigning to them
    7265              :      explicitly); we need to allow the temporary to be initialized
    7266              :      first.  */
    7267       385837 :   return initialize_reference (type, init, flags,
    7268       385837 :                                tf_warning_or_error);
    7269              : }
    7270              : 
    7271              : /* Designated initializers in arrays are not supported in GNU C++.
    7272              :    The parser cannot detect this error since it does not know whether
    7273              :    a given brace-enclosed initializer is for a class type or for an
    7274              :    array.  This function checks that CE does not use a designated
    7275              :    initializer.  If it does, an error is issued.  Returns true if CE
    7276              :    is valid, i.e., does not have a designated initializer.  */
    7277              : 
    7278              : bool
    7279    156203694 : check_array_designated_initializer (constructor_elt *ce,
    7280              :                                     unsigned HOST_WIDE_INT index)
    7281              : {
    7282              :   /* Designated initializers for array elements are not supported.  */
    7283    156203694 :   if (ce->index)
    7284              :     {
    7285              :       /* The parser only allows identifiers as designated
    7286              :          initializers.  */
    7287    105447262 :       if (ce->index == error_mark_node)
    7288              :         {
    7289            0 :           error ("name used in a GNU-style designated "
    7290              :                  "initializer for an array");
    7291            0 :           return false;
    7292              :         }
    7293    105447262 :       else if (identifier_p (ce->index))
    7294              :         {
    7295           22 :           error ("name %qD used in a GNU-style designated "
    7296              :                  "initializer for an array", ce->index);
    7297           22 :           ce->index = error_mark_node;
    7298           22 :           return false;
    7299              :         }
    7300              : 
    7301    105447240 :       tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
    7302              :                                                   ce->index, true);
    7303    105447240 :       if (ce_index
    7304    105447237 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
    7305    210894474 :           && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
    7306              :               == INTEGER_CST))
    7307              :         {
    7308              :           /* A C99 designator is OK if it matches the current index.  */
    7309    105447234 :           if (wi::to_wide (ce_index) == index)
    7310              :             {
    7311    105447228 :               ce->index = ce_index;
    7312    105447228 :               return true;
    7313              :             }
    7314              :           else
    7315            6 :             sorry ("non-trivial designated initializers not supported");
    7316              :         }
    7317              :       else
    7318            6 :         error_at (cp_expr_loc_or_input_loc (ce->index),
    7319              :                   "C99 designator %qE is not an integral constant-expression",
    7320              :                   ce->index);
    7321              : 
    7322              :       return false;
    7323              :     }
    7324              : 
    7325              :   return true;
    7326              : }
    7327              : 
    7328              : /* When parsing `int a[] = {1, 2};' we don't know the size of the
    7329              :    array until we finish parsing the initializer.  If that's the
    7330              :    situation we're in, update DECL accordingly.  */
    7331              : 
    7332              : static void
    7333     76384250 : maybe_deduce_size_from_array_init (tree decl, tree init)
    7334              : {
    7335     76384250 :   tree type = TREE_TYPE (decl);
    7336              : 
    7337     76384250 :   if (TREE_CODE (type) == ARRAY_TYPE
    7338       984051 :       && TYPE_DOMAIN (type) == NULL_TREE
    7339     77008279 :       && TREE_CODE (decl) != TYPE_DECL)
    7340              :     {
    7341              :       /* do_default is really a C-ism to deal with tentative definitions.
    7342              :          But let's leave it here to ease the eventual merge.  */
    7343       624029 :       int do_default = !DECL_EXTERNAL (decl);
    7344       624029 :       tree initializer = init ? init : DECL_INITIAL (decl);
    7345       624029 :       int failure = 0;
    7346              : 
    7347              :       /* Check that there are no designated initializers in INIT, as
    7348              :          those are not supported in GNU C++, and as the middle-end
    7349              :          will crash if presented with a non-numeric designated
    7350              :          initializer.  */
    7351       624029 :       if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
    7352              :         {
    7353       149135 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
    7354       149135 :           constructor_elt *ce;
    7355       149135 :           HOST_WIDE_INT i, j = 0;
    7356     49009793 :           FOR_EACH_VEC_SAFE_ELT (v, i, ce)
    7357              :             {
    7358     48861711 :               if (instantiation_dependent_expression_p (ce->index))
    7359     76384250 :                 return;
    7360     48861705 :               if (!check_array_designated_initializer (ce, j))
    7361            1 :                 failure = 1;
    7362              :               /* If an un-designated initializer is type-dependent, we can't
    7363              :                  check brace elision yet.  */
    7364     48861705 :               if (ce->index == NULL_TREE
    7365     48861705 :                   && type_dependent_expression_p (ce->value))
    7366              :                 return;
    7367     48860658 :               if (TREE_CODE (ce->value) == RAW_DATA_CST)
    7368          210 :                 j += RAW_DATA_LENGTH (ce->value);
    7369              :               else
    7370     48860448 :                 ++j;
    7371              :             }
    7372              :         }
    7373              : 
    7374       148082 :       if (failure)
    7375            1 :         TREE_TYPE (decl) = error_mark_node;
    7376              :       else
    7377              :         {
    7378       622975 :           failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
    7379              :                                             do_default);
    7380       622975 :           if (failure == 1)
    7381              :             {
    7382           33 :               error_at (cp_expr_loc_or_loc (initializer,
    7383           30 :                                          DECL_SOURCE_LOCATION (decl)),
    7384              :                         "initializer fails to determine size of %qD", decl);
    7385              :             }
    7386       622945 :           else if (failure == 2)
    7387              :             {
    7388           30 :               if (do_default)
    7389              :                 {
    7390            6 :                   error_at (DECL_SOURCE_LOCATION (decl),
    7391              :                             "array size missing in %qD", decl);
    7392              :                 }
    7393              :               /* If a `static' var's size isn't known, make it extern as
    7394              :                  well as static, so it does not get allocated.  If it's not
    7395              :                  `static', then don't mark it extern; finish_incomplete_decl
    7396              :                  will give it a default size and it will get allocated.  */
    7397           24 :               else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
    7398            0 :                 DECL_EXTERNAL (decl) = 1;
    7399              :             }
    7400       622915 :           else if (failure == 3)
    7401              :             {
    7402            6 :               error_at (DECL_SOURCE_LOCATION (decl),
    7403              :                         "zero-size array %qD", decl);
    7404              :             }
    7405              :         }
    7406              : 
    7407       622976 :       cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
    7408              : 
    7409       622976 :       relayout_decl (decl);
    7410              : 
    7411              :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    7412       622976 :       if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    7413              :         {
    7414          212 :           tree tmpl = template_for_substitution (decl);
    7415          212 :           if (DECL_TEMPLATE_RESULT (tmpl) == decl)
    7416           50 :             TREE_TYPE (tmpl) = TREE_TYPE (decl);
    7417              :         }
    7418              :     }
    7419              : }
    7420              : 
    7421              : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
    7422              :    any appropriate error messages regarding the layout.  */
    7423              : 
    7424              : static void
    7425     65248479 : layout_var_decl (tree decl)
    7426              : {
    7427     65248479 :   tree type;
    7428              : 
    7429     65248479 :   type = TREE_TYPE (decl);
    7430     65248479 :   if (type == error_mark_node)
    7431              :     return;
    7432              : 
    7433              :   /* If we haven't already laid out this declaration, do so now.
    7434              :      Note that we must not call complete type for an external object
    7435              :      because it's type might involve templates that we are not
    7436              :      supposed to instantiate yet.  (And it's perfectly valid to say
    7437              :      `extern X x' for some incomplete type `X'.)  */
    7438     65248432 :   if (!DECL_EXTERNAL (decl))
    7439     54782508 :     complete_type (type);
    7440     65248432 :   if (!DECL_SIZE (decl)
    7441       625673 :       && TREE_TYPE (decl) != error_mark_node
    7442     65874105 :       && complete_or_array_type_p (type))
    7443       472566 :     layout_decl (decl, 0);
    7444              : 
    7445     65248432 :   if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
    7446              :     {
    7447              :       /* An automatic variable with an incomplete type: that is an error.
    7448              :          Don't talk about array types here, since we took care of that
    7449              :          message in grokdeclarator.  */
    7450           17 :       error_at (DECL_SOURCE_LOCATION (decl),
    7451              :                 "storage size of %qD isn%'t known", decl);
    7452           17 :       TREE_TYPE (decl) = error_mark_node;
    7453              :     }
    7454              : #if 0
    7455              :   /* Keep this code around in case we later want to control debug info
    7456              :      based on whether a type is "used".  (jason 1999-11-11) */
    7457              : 
    7458              :   else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
    7459              :     /* Let debugger know it should output info for this type.  */
    7460              :     note_debug_info_needed (ttype);
    7461              : 
    7462              :   if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
    7463              :     note_debug_info_needed (DECL_CONTEXT (decl));
    7464              : #endif
    7465              : 
    7466    120030940 :   if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
    7467     40121295 :       && DECL_SIZE (decl) != NULL_TREE
    7468    105084415 :       && ! TREE_CONSTANT (DECL_SIZE (decl)))
    7469              :     {
    7470            6 :       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    7471            6 :           && !DECL_LOCAL_DECL_P (decl))
    7472            0 :         constant_expression_warning (DECL_SIZE (decl));
    7473              :       else
    7474              :         {
    7475            6 :           error_at (DECL_SOURCE_LOCATION (decl),
    7476              :                     "storage size of %qD isn%'t constant", decl);
    7477            6 :           TREE_TYPE (decl) = error_mark_node;
    7478            6 :           type = error_mark_node;
    7479              :         }
    7480              :     }
    7481              : 
    7482              :   /* If the final element initializes a flexible array field, adjust
    7483              :      the size of the DECL with the initializer based on whether the
    7484              :      DECL is a union or a structure.  */
    7485     65248432 :   if (type != error_mark_node
    7486     65248426 :       && DECL_INITIAL (decl)
    7487     38572304 :       && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    7488      5301757 :       && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
    7489      3562610 :       && DECL_SIZE (decl) != NULL_TREE
    7490      3562610 :       && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    7491      3562610 :       && COMPLETE_TYPE_P (type)
    7492      3562610 :       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
    7493     68811042 :       && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
    7494              :     {
    7495      3562610 :       constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
    7496      3562610 :       if (elt.index)
    7497              :         {
    7498      1345052 :           tree itype = TREE_TYPE (elt.index);
    7499      1345052 :           tree vtype = TREE_TYPE (elt.value);
    7500      1345052 :           if (TREE_CODE (itype) == ARRAY_TYPE
    7501        85262 :               && TYPE_DOMAIN (itype) == NULL
    7502          275 :               && TREE_CODE (vtype) == ARRAY_TYPE
    7503      1345327 :               && COMPLETE_TYPE_P (vtype))
    7504              :             {
    7505              :               /* For a structure, add the size of the initializer to the DECL's
    7506              :                  size.  */
    7507          275 :               if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    7508              :                 {
    7509          260 :                   DECL_SIZE (decl)
    7510          260 :                     = size_binop (PLUS_EXPR, DECL_SIZE (decl),
    7511              :                                   TYPE_SIZE (vtype));
    7512          260 :                   DECL_SIZE_UNIT (decl)
    7513          520 :                     = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    7514              :                                   TYPE_SIZE_UNIT (vtype));
    7515              :                 }
    7516              :               /* For a union, the DECL's size is the maximum of the current size
    7517              :                  and the size of the initializer.  */
    7518              :               else
    7519              :                 {
    7520           15 :                   DECL_SIZE (decl)
    7521           15 :                     = size_binop (MAX_EXPR, DECL_SIZE (decl),
    7522              :                                   TYPE_SIZE (vtype));
    7523           15 :                   DECL_SIZE_UNIT (decl)
    7524           30 :                     = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    7525              :                                   TYPE_SIZE_UNIT (vtype));
    7526              :                 }
    7527              :             }
    7528              :         }
    7529              :     }
    7530              : }
    7531              : 
    7532              : /* If a local static variable is declared in an inline function, or if
    7533              :    we have a weak definition, we must endeavor to create only one
    7534              :    instance of the variable at link-time.  */
    7535              : 
    7536              : void
    7537     80361449 : maybe_commonize_var (tree decl)
    7538              : {
    7539              :   /* Don't mess with __FUNCTION__ and similar.  But do handle structured
    7540              :      bindings.  */
    7541     80361449 :   if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
    7542              :     return;
    7543              : 
    7544              :   /* Static data in a function with comdat linkage also has comdat
    7545              :      linkage.  */
    7546     75035814 :   if ((TREE_STATIC (decl)
    7547     49641261 :        && DECL_FUNCTION_SCOPE_P (decl)
    7548       141180 :        && vague_linkage_p (DECL_CONTEXT (decl)))
    7549    174492919 :       || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
    7550              :     {
    7551     43492413 :       if (flag_weak)
    7552              :         {
    7553              :           /* With weak symbols, we simply make the variable COMDAT;
    7554              :              that will cause copies in multiple translations units to
    7555              :              be merged.  */
    7556     43492386 :           comdat_linkage (decl);
    7557              :         }
    7558              :       else
    7559              :         {
    7560           27 :           if (DECL_INITIAL (decl) == NULL_TREE
    7561           27 :               || DECL_INITIAL (decl) == error_mark_node)
    7562              :             {
    7563              :               /* Without weak symbols, we can use COMMON to merge
    7564              :                  uninitialized variables.  */
    7565           24 :               TREE_PUBLIC (decl) = 1;
    7566           24 :               DECL_COMMON (decl) = 1;
    7567              :             }
    7568              :           else
    7569              :             {
    7570              :               /* While for initialized variables, we must use internal
    7571              :                  linkage -- which means that multiple copies will not
    7572              :                  be merged.  */
    7573            3 :               TREE_PUBLIC (decl) = 0;
    7574            3 :               DECL_COMMON (decl) = 0;
    7575            3 :               DECL_INTERFACE_KNOWN (decl) = 1;
    7576            3 :               const char *msg;
    7577            3 :               if (DECL_INLINE_VAR_P (decl))
    7578              :                 msg = G_("sorry: semantics of inline variable "
    7579              :                          "%q#D are wrong (you%'ll wind up with "
    7580              :                          "multiple copies)");
    7581              :               else
    7582              :                 msg = G_("sorry: semantics of inline function "
    7583              :                          "static data %q#D are wrong (you%'ll wind "
    7584              :                          "up with multiple copies)");
    7585            3 :               auto_diagnostic_group d;
    7586            3 :               if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
    7587              :                               msg, decl))
    7588            3 :                 inform (DECL_SOURCE_LOCATION (decl),
    7589              :                         "you can work around this by removing the initializer");
    7590            3 :             }
    7591              :         }
    7592              :     }
    7593              : }
    7594              : 
    7595              : /* Issue an error message if DECL is an uninitialized const variable.
    7596              :    CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
    7597              :    context from potential_constant_expression.  Returns true if all is well,
    7598              :    false otherwise.  */
    7599              : 
    7600              : bool
    7601      9305360 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
    7602              :                                    tsubst_flags_t complain)
    7603              : {
    7604      9305360 :   tree type = strip_array_types (TREE_TYPE (decl));
    7605              : 
    7606              :   /* ``Unless explicitly declared extern, a const object does not have
    7607              :      external linkage and must be initialized. ($8.4; $12.1)'' ARM
    7608              :      7.1.6 */
    7609      9305360 :   if (VAR_P (decl)
    7610      9305360 :       && !TYPE_REF_P (type)
    7611      9256840 :       && (CP_TYPE_CONST_P (type)
    7612              :           /* C++20 permits trivial default initialization in constexpr
    7613              :              context (P1331R2).  */
    7614      7202573 :           || (cxx_dialect < cxx20
    7615       139069 :               && (constexpr_context_p
    7616       124092 :                   || var_in_constexpr_fn (decl))))
    7617     11376720 :       && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    7618              :     {
    7619       660765 :       tree field = default_init_uninitialized_part (type);
    7620       660765 :       if (!field)
    7621              :         return true;
    7622              : 
    7623         5130 :       auto_diagnostic_group d;
    7624         5130 :       bool show_notes = true;
    7625              : 
    7626         5130 :       if (!constexpr_context_p || cxx_dialect >= cxx20)
    7627              :         {
    7628          188 :           if (CP_TYPE_CONST_P (type))
    7629              :             {
    7630           90 :               if (complain & tf_error)
    7631           84 :                 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
    7632              :                                         "uninitialized %<const %D%>", decl);
    7633              :             }
    7634              :           else
    7635              :             {
    7636           98 :               if (!is_instantiation_of_constexpr (current_function_decl)
    7637           98 :                   && (complain & tf_error))
    7638           21 :                 error_at (DECL_SOURCE_LOCATION (decl),
    7639              :                           "uninitialized variable %qD in %<constexpr%> "
    7640              :                           "function", decl);
    7641              :               else
    7642              :                 show_notes = false;
    7643           98 :               cp_function_chain->invalid_constexpr = true;
    7644              :             }
    7645              :         }
    7646         4942 :       else if (complain & tf_error)
    7647            2 :         error_at (DECL_SOURCE_LOCATION (decl),
    7648              :                   "uninitialized variable %qD in %<constexpr%> context",
    7649              :                   decl);
    7650              : 
    7651         5130 :       if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
    7652              :         {
    7653           62 :           tree defaulted_ctor;
    7654              : 
    7655           62 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    7656              :                   "%q#T has no user-provided default constructor", type);
    7657           62 :           defaulted_ctor = in_class_defaulted_default_constructor (type);
    7658           62 :           if (defaulted_ctor)
    7659           33 :             inform (DECL_SOURCE_LOCATION (defaulted_ctor),
    7660              :                     "constructor is not user-provided because it is "
    7661              :                     "explicitly defaulted in the class body");
    7662           62 :           inform (DECL_SOURCE_LOCATION (field),
    7663              :                   "and the implicitly-defined constructor does not "
    7664              :                   "initialize %q#D", field);
    7665              :         }
    7666              : 
    7667         5130 :       return false;
    7668         5130 :     }
    7669              : 
    7670              :   return true;
    7671              : }
    7672              : 
    7673              : /* Structure holding the current initializer being processed by reshape_init.
    7674              :    CUR is a pointer to the current element being processed, END is a pointer
    7675              :    after the last element present in the initializer and RAW_IDX is index into
    7676              :    RAW_DATA_CST if that is CUR elt.  */
    7677              : struct reshape_iter
    7678              : {
    7679              :   constructor_elt *cur;
    7680              :   constructor_elt *end;
    7681              :   unsigned raw_idx;
    7682              : };
    7683              : 
    7684              : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
    7685              : static tree reshape_single_init (tree, tree, tsubst_flags_t);
    7686              : 
    7687              : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    7688              :    returned is the next FIELD_DECL (possibly FIELD itself) that can be
    7689              :    initialized as if for an aggregate class.  If there are no more such fields,
    7690              :    the return value will be NULL.  */
    7691              : 
    7692              : tree
    7693     15676476 : next_aggregate_field (tree field)
    7694              : {
    7695     15676476 :   while (field
    7696     64944506 :          && (TREE_CODE (field) != FIELD_DECL
    7697      9833220 :              || DECL_UNNAMED_BIT_FIELD (field)
    7698      9833059 :              || (DECL_ARTIFICIAL (field)
    7699              :                  /* In C++17, aggregates can have bases.  */
    7700       216539 :                  && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
    7701     49268030 :     field = DECL_CHAIN (field);
    7702              : 
    7703     15676476 :   return field;
    7704              : }
    7705              : 
    7706              : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    7707              :    returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
    7708              :    to a subobject.  If there are no more such fields, the return value will be
    7709              :    NULL.  */
    7710              : 
    7711              : tree
    7712     67374600 : next_subobject_field (tree field)
    7713              : {
    7714     67374600 :   while (field
    7715    885501047 :          && (TREE_CODE (field) != FIELD_DECL
    7716     30022414 :              || DECL_UNNAMED_BIT_FIELD (field)
    7717     30022275 :              || (DECL_ARTIFICIAL (field)
    7718      8320464 :                  && !DECL_FIELD_IS_BASE (field)
    7719      1796844 :                  && !DECL_VIRTUAL_P (field))))
    7720    818126447 :     field = DECL_CHAIN (field);
    7721              : 
    7722     67374600 :   return field;
    7723              : }
    7724              : 
    7725              : /* Return true for [dcl.init.list] direct-list-initialization from
    7726              :    single element of enumeration with a fixed underlying type.  */
    7727              : 
    7728              : bool
    7729    188797432 : is_direct_enum_init (tree type, tree init)
    7730              : {
    7731    188797432 :   if (cxx_dialect >= cxx17
    7732    186745724 :       && TREE_CODE (type) == ENUMERAL_TYPE
    7733      7636647 :       && ENUM_FIXED_UNDERLYING_TYPE_P (type)
    7734      5240523 :       && TREE_CODE (init) == CONSTRUCTOR
    7735       453415 :       && CONSTRUCTOR_IS_DIRECT_INIT (init)
    7736       231007 :       && CONSTRUCTOR_NELTS (init) == 1
    7737          223 :       && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
    7738              :       /* DR 2374: The single element needs to be implicitly
    7739              :          convertible to the underlying type of the enum.  */
    7740          223 :       && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
    7741    188797653 :       && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
    7742          221 :                           TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
    7743          221 :                           CONSTRUCTOR_ELT (init, 0)->value,
    7744              :                           LOOKUP_IMPLICIT, tf_none))
    7745              :     return true;
    7746              :   return false;
    7747              : }
    7748              : 
    7749              : /* Helper function for reshape_init*.  Split first element of
    7750              :    RAW_DATA_CST or return NULL for other elements.  Set *INC_CUR
    7751              :    to true if the whole d->cur has been consumed.  */
    7752              : 
    7753              : static tree
    7754     62679696 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
    7755              : {
    7756     62679696 :   *inc_cur = true;
    7757     62679696 :   if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
    7758              :     return NULL_TREE;
    7759        30720 :   tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
    7760        30720 :   if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
    7761        30588 :     *inc_cur = false;
    7762              :   else
    7763          132 :     d->raw_idx = 0;
    7764              :   return ret;
    7765              : }
    7766              : 
    7767              : /* Wrapper around that which for RAW_DATA_CST in INIT
    7768              :    (as well as in D->cur->value) peels off the first element
    7769              :    of the raw data and returns it, otherwise increments
    7770              :    D->cur and returns INIT.  */
    7771              : 
    7772              : static tree
    7773     62679679 : consume_init (tree init, reshape_iter *d)
    7774              : {
    7775     62679679 :   bool inc_cur;
    7776     62679679 :   if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    7777        30720 :     init = raw_init;
    7778     62679679 :   if (inc_cur)
    7779     62649091 :     d->cur++;
    7780     62679679 :   return init;
    7781              : }
    7782              : 
    7783              : /* Subroutine of reshape_init_array and reshape_init_vector, which does
    7784              :    the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
    7785              :    INTEGER_CST representing the size of the array minus one (the maximum index),
    7786              :    or NULL_TREE if the array was declared without specifying the size. D is
    7787              :    the iterator within the constructor.  */
    7788              : 
    7789              : static tree
    7790       468800 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
    7791              :                       tree first_initializer_p, bool vector_p,
    7792              :                       tsubst_flags_t complain)
    7793              : {
    7794       468800 :   tree new_init;
    7795       468800 :   bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
    7796       468800 :   unsigned HOST_WIDE_INT max_index_cst = 0;
    7797       468800 :   unsigned HOST_WIDE_INT index;
    7798              : 
    7799              :   /* The initializer for an array is always a CONSTRUCTOR.  If this is the
    7800              :      outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
    7801              :      to build a new one.  But don't reuse if not complaining; if this is
    7802              :      tentative, we might also reshape to another type (95319).  */
    7803       468800 :   bool reuse = (first_initializer_p
    7804       409714 :                 && (complain & tf_error)
    7805       408429 :                 && !CP_AGGREGATE_TYPE_P (elt_type)
    7806       813059 :                 && !TREE_SIDE_EFFECTS (first_initializer_p));
    7807       128302 :   if (reuse)
    7808              :     new_init = first_initializer_p;
    7809              :   else
    7810       128302 :     new_init = build_constructor (init_list_type_node, NULL);
    7811              : 
    7812       468800 :   if (sized_array_p)
    7813              :     {
    7814       279362 :       poly_uint64 midx;
    7815              :       /* Minus 1 is used for zero sized arrays.  */
    7816       279362 :       if (integer_all_onesp (max_index))
    7817           24 :         return new_init;
    7818              : 
    7819       279338 :       if (tree_fits_poly_uint64_p (max_index))
    7820       279338 :         midx = tree_to_poly_uint64 (max_index);
    7821              :       /* sizetype is sign extended, not zero extended.  */
    7822              :       else
    7823            0 :         midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
    7824              : 
    7825              :       /* For VLA vectors, we restrict the number of elements in the constructor
    7826              :          to lower bound of the VLA elements.  */
    7827       279338 :       max_index_cst = constant_lower_bound (midx);
    7828              :     }
    7829              : 
    7830       468776 :   constructor_elt *first_cur = d->cur;
    7831              :   /* Loop until there are no more initializers.  */
    7832     57092200 :   for (index = 0;
    7833     57092200 :        d->cur != d->end && (!sized_array_p || index <= max_index_cst);
    7834              :        ++index)
    7835              :     {
    7836     56623605 :       tree elt_init;
    7837     56623605 :       constructor_elt *old_cur = d->cur;
    7838     56623605 :       unsigned int old_raw_idx = d->raw_idx;
    7839     56623605 :       bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
    7840              : 
    7841     56623605 :       if (d->cur->index)
    7842      5894952 :         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7843     56623605 :       check_array_designated_initializer (d->cur, index);
    7844     56623605 :       if (TREE_CODE (d->cur->value) == RAW_DATA_CST
    7845        32752 :           && (TREE_CODE (elt_type) == INTEGER_TYPE
    7846        10233 :               || is_byte_access_type (elt_type))
    7847        22519 :           && TYPE_PRECISION (elt_type) == CHAR_BIT
    7848         1858 :           && (!sized_array_p || index < max_index_cst)
    7849     56625451 :           && !vector_p)
    7850              :         {
    7851          526 :           elt_init = d->cur->value;
    7852          526 :           unsigned int off = d->raw_idx;
    7853          526 :           unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
    7854          526 :           if (!sized_array_p || len <= max_index_cst - index + 1)
    7855              :             {
    7856          517 :               d->cur++;
    7857          517 :               d->raw_idx = 0;
    7858              :             }
    7859              :           else
    7860              :             {
    7861            9 :               len = max_index_cst - index + 1;
    7862            9 :               d->raw_idx += len;
    7863              :             }
    7864          526 :           if (!reuse || off || d->cur == old_cur)
    7865              :             {
    7866           27 :               elt_init = copy_node (elt_init);
    7867           27 :               RAW_DATA_LENGTH (elt_init) = len;
    7868           27 :               RAW_DATA_POINTER (elt_init) += off;
    7869              :             }
    7870          526 :           TREE_TYPE (elt_init) = elt_type;
    7871              :         }
    7872     56623079 :       else if (d->cur->index)
    7873              :         {
    7874      5894727 :           elt_init = reshape_single_init (elt_type, d->cur->value, complain);
    7875      5894727 :           d->cur++;
    7876              :         }
    7877              :       else
    7878     50728352 :         elt_init = reshape_init_r (elt_type, d,
    7879              :                                    /*first_initializer_p=*/NULL_TREE,
    7880              :                                    complain);
    7881     56623605 :       if (elt_init == error_mark_node)
    7882              :         return error_mark_node;
    7883     56623427 :       tree idx = size_int (index);
    7884     56623427 :       if (reuse && old_raw_data_cst && d->cur == old_cur)
    7885              :         {
    7886              :           /* We need to stop reusing as some RAW_DATA_CST in the original
    7887              :              ctor had to be split.  */
    7888           72 :           new_init = build_constructor (init_list_type_node, NULL);
    7889           72 :           if (index)
    7890              :             {
    7891           72 :               vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
    7892           72 :               memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
    7893           72 :                       (d->cur - first_cur)
    7894              :                       * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
    7895           72 :               if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
    7896              :                 {
    7897              :                   unsigned int j;
    7898              :                   tree nidx, nval;
    7899            4 :                   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
    7900              :                                             j, nidx, nval)
    7901            4 :                     if (nidx)
    7902              :                       {
    7903            4 :                         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
    7904            4 :                         (void) nval;
    7905            4 :                         break;
    7906              :                       }
    7907              :                 }
    7908              :             }
    7909              :           reuse = false;
    7910              :         }
    7911     56623359 :       if (reuse)
    7912              :         {
    7913     55095330 :           old_cur->index = idx;
    7914     55095330 :           old_cur->value = elt_init;
    7915              :         }
    7916              :       else
    7917      1528097 :         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    7918              :                                 idx, elt_init);
    7919     56623427 :       if (!TREE_CONSTANT (elt_init))
    7920       196857 :         TREE_CONSTANT (new_init) = false;
    7921              : 
    7922              :       /* This can happen with an invalid initializer (c++/54501).  */
    7923     56623427 :       if (d->cur == old_cur
    7924        32082 :           && !sized_array_p
    7925        14085 :           && d->raw_idx == old_raw_idx)
    7926              :         break;
    7927              : 
    7928     56623424 :       if (TREE_CODE (elt_init) == RAW_DATA_CST)
    7929          526 :         index += RAW_DATA_LENGTH (elt_init) - 1;
    7930              :     }
    7931              : 
    7932              :   return new_init;
    7933              : }
    7934              : 
    7935              : /* Subroutine of reshape_init_r, processes the initializers for arrays.
    7936              :    Parameters are the same of reshape_init_r.  */
    7937              : 
    7938              : static tree
    7939       418861 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
    7940              :                     tsubst_flags_t complain)
    7941              : {
    7942       418861 :   tree max_index = NULL_TREE;
    7943              : 
    7944       418861 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    7945              : 
    7946       418861 :   if (TYPE_DOMAIN (type))
    7947       229469 :     max_index = array_type_nelts_minus_one (type);
    7948              : 
    7949       418861 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7950       418861 :                                first_initializer_p, false, complain);
    7951              : }
    7952              : 
    7953              : /* Subroutine of reshape_init_r, processes the initializers for vectors.
    7954              :    Parameters are the same of reshape_init_r.  */
    7955              : 
    7956              : static tree
    7957        49939 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
    7958              : {
    7959        49939 :   tree max_index = NULL_TREE;
    7960              : 
    7961        49939 :   gcc_assert (VECTOR_TYPE_P (type));
    7962              : 
    7963        49939 :   if (COMPOUND_LITERAL_P (d->cur->value))
    7964              :     {
    7965            0 :       tree value = d->cur->value;
    7966            0 :       if (!same_type_p (TREE_TYPE (value), type))
    7967              :         {
    7968            0 :           if (complain & tf_error)
    7969            0 :             error ("invalid type %qT as initializer for a vector of type %qT",
    7970            0 :                    TREE_TYPE (d->cur->value), type);
    7971            0 :           value = error_mark_node;
    7972              :         }
    7973            0 :       ++d->cur;
    7974            0 :       return value;
    7975              :     }
    7976              : 
    7977              :   /* For a vector, we initialize it as an array of the appropriate size.  */
    7978        49939 :   if (VECTOR_TYPE_P (type))
    7979        49939 :     max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
    7980              : 
    7981        49939 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7982        49939 :                                NULL_TREE, true, complain);
    7983              : }
    7984              : 
    7985              : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
    7986              :    INIT, in isolation from any designator or other initializers.  */
    7987              : 
    7988              : static tree
    7989      6547418 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
    7990              : {
    7991              :   /* We could also implement this by wrapping init in a new CONSTRUCTOR and
    7992              :      calling reshape_init, but this way can just live on the stack.  */
    7993      6547418 :   constructor_elt elt = { /*index=*/NULL_TREE, init };
    7994      6547418 :   reshape_iter iter = { &elt, &elt + 1, 0 };
    7995      6547418 :   return reshape_init_r (type, &iter,
    7996              :                          /*first_initializer_p=*/NULL_TREE,
    7997      6547418 :                          complain);
    7998              : }
    7999              : 
    8000              : /* Subroutine of reshape_init_r, processes the initializers for classes
    8001              :    or union. Parameters are the same of reshape_init_r.  */
    8002              : 
    8003              : static tree
    8004      3780880 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
    8005              :                     tsubst_flags_t complain)
    8006              : {
    8007      3780880 :   tree field;
    8008      3780880 :   tree new_init;
    8009              : 
    8010      3780880 :   gcc_assert (CLASS_TYPE_P (type));
    8011              : 
    8012              :   /* The initializer for a class is always a CONSTRUCTOR.  */
    8013      3780880 :   new_init = build_constructor (init_list_type_node, NULL);
    8014              : 
    8015      3780880 :   int binfo_idx = -1;
    8016      3780880 :   tree binfo = TYPE_BINFO (type);
    8017      3780880 :   tree base_binfo = NULL_TREE;
    8018      3780880 :   if (cxx_dialect >= cxx17 && uses_template_parms (type))
    8019              :     {
    8020              :       /* We get here from maybe_aggr_guide for C++20 class template argument
    8021              :          deduction.  In this case we need to look through the binfo because a
    8022              :          template doesn't have base fields.  */
    8023         2781 :       binfo_idx = 0;
    8024         2781 :       BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
    8025              :     }
    8026           86 :   if (base_binfo)
    8027              :     field = base_binfo;
    8028              :   else
    8029      3780794 :     field = next_aggregate_field (TYPE_FIELDS (type));
    8030              : 
    8031      3780794 :   if (!field)
    8032              :     {
    8033              :       /* [dcl.init.aggr]
    8034              : 
    8035              :         An initializer for an aggregate member that is an
    8036              :         empty class shall have the form of an empty
    8037              :         initializer-list {}.  */
    8038          322 :       if (!first_initializer_p)
    8039              :         {
    8040          268 :           if (complain & tf_error)
    8041           13 :             error ("initializer for %qT must be brace-enclosed", type);
    8042          268 :           return error_mark_node;
    8043              :         }
    8044              :       return new_init;
    8045              :     }
    8046              : 
    8047              :   /* For C++29 designated initializers we do modify d->cur->index in place
    8048              :      to cache name lookup results.  Make sure to undo it before returning.  */
    8049      3780558 :   struct designator_undo {
    8050              :     constructor_elt *start, *end;
    8051      3780619 :     void undo ()
    8052              :     {
    8053      3780770 :       while (start != end)
    8054              :         {
    8055          151 :           start->index = DECL_NAME (start->index);
    8056          151 :           ++start;
    8057              :         }
    8058      3780619 :       start = end = nullptr;
    8059      3780619 :     }
    8060      3780558 :     ~designator_undo () { undo (); }
    8061      3780558 :   } desig_undo = { nullptr, nullptr };
    8062              : 
    8063              :   /* For C++20 CTAD, handle pack expansions in the base list.  */
    8064      3780558 :   tree last_was_pack_expansion = NULL_TREE;
    8065      3780558 :   bool first_desig = true;
    8066              : 
    8067              :   /* Loop through the initializable fields, gathering initializers.  */
    8068     11307310 :   while (d->cur != d->end)
    8069              :     {
    8070      7634580 :       tree field_init;
    8071      7634580 :       constructor_elt *old_cur = d->cur;
    8072      7634580 :       unsigned old_raw_idx = d->raw_idx;
    8073      7634580 :       bool direct_desig = false;
    8074              : 
    8075              :       /* Handle C++20 designated initializers.  */
    8076      7634580 :       if (d->cur->index)
    8077              :         {
    8078       653027 :           if (d->cur->index == error_mark_node)
    8079              :             return error_mark_node;
    8080              : 
    8081       653020 :           if (TREE_CODE (d->cur->index) == FIELD_DECL)
    8082              :             {
    8083          181 :               CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    8084          181 :               direct_desig = true;
    8085          181 :               field = d->cur->index;
    8086              :             }
    8087       652839 :           else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    8088              :             {
    8089       652833 :               if (first_desig && cxx_dialect >= cxx20)
    8090              :                 {
    8091       309278 :                   if (CONSTRUCTOR_NELTS (new_init))
    8092              :                     {
    8093          117 :                       constructor_elt *last
    8094          117 :                         = &CONSTRUCTOR_ELTS (new_init)->last ();
    8095          117 :                       if (last->index == NULL_TREE
    8096          117 :                           || TREE_CODE (last->index) != FIELD_DECL
    8097          234 :                           || !DECL_FIELD_IS_BASE (last->index))
    8098              :                         {
    8099           25 :                           if (complain & tf_error)
    8100           25 :                             error ("last non-designated initializer clause "
    8101              :                                    "does not appertain to a base class "
    8102              :                                    "subobject");
    8103           25 :                           return error_mark_node;
    8104              :                         }
    8105              :                     }
    8106              :                   first_desig = false;
    8107              :                 }
    8108       652808 :               CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    8109       652808 :               field = get_class_binding (type, d->cur->index);
    8110       652808 :               direct_desig = true;
    8111       652808 :               if (!field && cxx_dialect >= cxx29)
    8112           44 :                 field = lookup_member (type, d->cur->index, /*protect=*/2,
    8113              :                                        /*want_type=*/false, complain);
    8114              :             }
    8115              :           else
    8116              :             {
    8117            6 :               if (complain & tf_error)
    8118            6 :                 error ("%<[%E] =%> used in a GNU-style designated initializer"
    8119              :                        " for class %qT", d->cur->index, type);
    8120            6 :               return error_mark_node;
    8121              :             }
    8122              : 
    8123          257 :           if (!field && ANON_AGGR_TYPE_P (type))
    8124              :             /* Apparently the designator isn't for a member of this anonymous
    8125              :                struct, so head back to the enclosing class.  */
    8126              :             break;
    8127              : 
    8128       652986 :           if (!field || TREE_CODE (field) != FIELD_DECL)
    8129              :             {
    8130           43 :               if (complain & tf_error)
    8131              :                 {
    8132           28 :                   if (field && TREE_CODE (field) == TREE_LIST)
    8133              :                     {
    8134            5 :                       auto_diagnostic_group g;
    8135            5 :                       error ("request for member %qD is ambiguous",
    8136            5 :                              d->cur->index);
    8137            5 :                       print_candidates (input_location, field);
    8138            5 :                     }
    8139              :                   else
    8140           23 :                     error ("%qT has no non-static data member named %qD", type,
    8141           23 :                            d->cur->index);
    8142              :                 }
    8143           43 :               return error_mark_node;
    8144              :             }
    8145              : 
    8146              :           /* If the element is an anonymous union object and the initializer
    8147              :              list is a designated-initializer-list, the anonymous union object
    8148              :              is initialized by the designated-initializer-list { D }, where D
    8149              :              is the designated-initializer-clause naming a member of the
    8150              :              anonymous union object.  */
    8151       652943 :           tree ictx = DECL_CONTEXT (field);
    8152       652943 :           if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
    8153              :             {
    8154              :               /* Find the anon aggr that is a direct member of TYPE.  */
    8155          266 :               while (ANON_AGGR_TYPE_P (ictx))
    8156              :                 {
    8157          154 :                   tree cctx = TYPE_CONTEXT (ictx);
    8158          154 :                   if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
    8159          140 :                     goto found;
    8160              :                   ictx = cctx;
    8161              :                 }
    8162              : 
    8163              :               /* In C++29 a designator can name a member of a base; in that
    8164              :                  case, go through the designators and replace ids with _DECLs
    8165              :                  to record the lookup for the most-derived class.  */
    8166          112 :               if (cxx_dialect >= cxx29)
    8167              :                 {
    8168          110 :                   tree ibinfo = lookup_base (type, ictx, ba_unique, NULL,
    8169              :                                              complain);
    8170          110 :                   if (!ibinfo)
    8171              :                     /* The designator names a field outside this base class,
    8172              :                        so we're done.  */
    8173              :                     break;
    8174           61 :                   else if (ibinfo != error_mark_node)
    8175              :                     {
    8176           74 :                       while (BINFO_INHERITANCE_CHAIN (ibinfo) != binfo)
    8177              :                         ibinfo = BINFO_INHERITANCE_CHAIN (ibinfo);
    8178           61 :                       ictx = TREE_TYPE (ibinfo);
    8179              : 
    8180           61 :                       desig_undo.undo ();
    8181              : 
    8182           61 :                       if (d->cur->index != field)
    8183              :                         {
    8184           47 :                           d->cur->index = field;
    8185           47 :                           desig_undo.start = d->cur;
    8186              :                         }
    8187           61 :                       constructor_elt *e = d->cur + 1;
    8188          228 :                       for (; e != d->end; ++e)
    8189              :                         {
    8190          173 :                           if (e->index == NULL_TREE
    8191          173 :                               || e->index == error_mark_node)
    8192              :                             break;
    8193          167 :                           if (desig_undo.start)
    8194              :                             {
    8195          104 :                               gcc_assert (TREE_CODE (e->index)
    8196              :                                           == IDENTIFIER_NODE);
    8197          104 :                               field = lookup_member (type, e->index,
    8198              :                                                      /*protect=*/2,
    8199              :                                                      /*want_type=*/false,
    8200              :                                                      tf_none);
    8201          104 :                               if (!field || TREE_CODE (field) != FIELD_DECL)
    8202              :                                 break;
    8203              :                             }
    8204              :                           else
    8205              :                             {
    8206           63 :                               gcc_assert (TREE_CODE (e->index) == FIELD_DECL);
    8207              :                               field = e->index;
    8208              :                             }
    8209              : 
    8210          167 :                           if (desig_undo.start)
    8211          104 :                             e->index = field;
    8212              :                         }
    8213           61 :                       if (desig_undo.start)
    8214           47 :                         desig_undo.end = e;
    8215           61 :                       goto found;
    8216              :                     }
    8217              :                 }
    8218              : 
    8219              :               /* Not found, e.g. FIELD is a member of a base class.  */
    8220            2 :               if (complain & tf_error)
    8221            2 :                 error ("%qD is not a direct member of %qT", field, type);
    8222            2 :               return error_mark_node;
    8223              : 
    8224          201 :             found:
    8225              :               /* Now find the TYPE member with that anon aggr type.  */
    8226          201 :               tree aafield = TYPE_FIELDS (type);
    8227         1622 :               for (; aafield; aafield = TREE_CHAIN (aafield))
    8228         1622 :                 if (TREE_TYPE (aafield) == ictx)
    8229              :                   break;
    8230            0 :               gcc_assert (aafield);
    8231              :               field = aafield;
    8232              :               direct_desig = false;
    8233              :             }
    8234              :         }
    8235              : 
    8236              :       /* If we processed all the member of the class, we are done.  */
    8237      7634244 :       if (!field)
    8238              :         break;
    8239              : 
    8240     15267920 :       last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
    8241      7633970 :                                  ? field : NULL_TREE);
    8242           20 :       if (last_was_pack_expansion)
    8243              :         /* Each non-trailing aggregate element that is a pack expansion is
    8244              :            assumed to correspond to no elements of the initializer list.  */
    8245           20 :         goto continue_;
    8246              : 
    8247      7633950 :       if (direct_desig)
    8248              :         {
    8249              :           /* The designated field F is initialized from this one element.
    8250              : 
    8251              :              Note that we don't want to do this if we found the designator
    8252              :              inside an anon aggr above; we use the normal code to implement:
    8253              : 
    8254              :              "If the element is an anonymous union member and the initializer
    8255              :              list is a brace-enclosed designated- initializer-list, the element
    8256              :              is initialized by the designated-initializer-list { D }, where D
    8257              :              is the designated- initializer-clause naming a member of the
    8258              :              anonymous union member."  */
    8259       652691 :           gcc_checking_assert (TREE_CODE (d->cur->value) != RAW_DATA_CST);
    8260       652691 :           field_init = reshape_single_init (TREE_TYPE (field),
    8261              :                                             d->cur->value, complain);
    8262       652691 :           d->cur++;
    8263              :         }
    8264              :       else
    8265      6981259 :         field_init = reshape_init_r (TREE_TYPE (field), d,
    8266              :                                      /*first_initializer_p=*/NULL_TREE,
    8267              :                                      complain);
    8268              : 
    8269      7633950 :       if (field_init == error_mark_node)
    8270              :         return error_mark_node;
    8271              : 
    8272      7633660 :       if (d->cur == old_cur && d->cur->index && d->raw_idx == old_raw_idx)
    8273              :         {
    8274              :           /* This can happen with an invalid initializer for a flexible
    8275              :              array member (c++/54441).  */
    8276            0 :           if (complain & tf_error)
    8277            0 :             error ("invalid initializer for %q#D", field);
    8278            0 :           return error_mark_node;
    8279              :         }
    8280              : 
    8281      7633660 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
    8282              : 
    8283              :       /* [dcl.init.aggr]
    8284              : 
    8285              :         When a union  is  initialized with a brace-enclosed
    8286              :         initializer, the braces shall only contain an
    8287              :         initializer for the first member of the union.  */
    8288      7633660 :       if (TREE_CODE (type) == UNION_TYPE)
    8289              :         break;
    8290              : 
    8291      7526732 :     continue_:
    8292      7526752 :       if (base_binfo)
    8293              :         {
    8294          101 :           if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
    8295              :             field = base_binfo;
    8296              :           else
    8297           38 :             field = next_aggregate_field (TYPE_FIELDS (type));
    8298              :         }
    8299              :       else
    8300      7526651 :         field = next_aggregate_field (DECL_CHAIN (field));
    8301              :     }
    8302              : 
    8303              :   /* A trailing aggregate element that is a pack expansion is assumed to
    8304              :      correspond to all remaining elements of the initializer list (if any).  */
    8305      3780185 :   if (last_was_pack_expansion)
    8306              :     {
    8307           17 :       tree init = d->cur->value;
    8308           17 :       bool inc_cur;
    8309           17 :       if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    8310            0 :         init = raw_init;
    8311           17 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    8312              :                               last_was_pack_expansion, init);
    8313           49 :       while (d->cur != d->end)
    8314           32 :         d->cur++;
    8315              :     }
    8316              : 
    8317              :   return new_init;
    8318      3780558 : }
    8319              : 
    8320              : /* Subroutine of reshape_init_r.  We're in a context where C99 initializer
    8321              :    designators are not valid; either complain or return true to indicate
    8322              :    that reshape_init_r should return error_mark_node.  */
    8323              : 
    8324              : static bool
    8325       249592 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
    8326              : {
    8327       249592 :   if (d->cur->index)
    8328              :     {
    8329           30 :       if (complain & tf_error)
    8330           45 :         error_at (cp_expr_loc_or_input_loc (d->cur->index),
    8331              :                   "C99 designator %qE outside aggregate initializer",
    8332              :                   d->cur->index);
    8333              :       else
    8334              :         return true;
    8335              :     }
    8336              :   return false;
    8337              : }
    8338              : 
    8339              : /* Subroutine of reshape_init, which processes a single initializer (part of
    8340              :    a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
    8341              :    iterator within the CONSTRUCTOR which points to the initializer to process.
    8342              :    If this is the first initializer of the outermost CONSTRUCTOR node,
    8343              :    FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE.  */
    8344              : 
    8345              : static tree
    8346     68746065 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
    8347              :                 tsubst_flags_t complain)
    8348              : {
    8349     68746065 :   tree init = d->cur->value;
    8350              : 
    8351     68746065 :   if (error_operand_p (init))
    8352          135 :     return error_mark_node;
    8353              : 
    8354      4488904 :   if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
    8355     68995343 :       && has_designator_problem (d, complain))
    8356            0 :     return error_mark_node;
    8357              : 
    8358     68745930 :   tree stripped_init = tree_strip_any_location_wrapper (init);
    8359              : 
    8360     68745930 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    8361              :     {
    8362              :       /* A complex type can be initialized from one or two initializers,
    8363              :          but braces are not elided.  */
    8364          672 :       init = consume_init (init, d);
    8365          672 :       if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
    8366              :         {
    8367            9 :           if (CONSTRUCTOR_NELTS (stripped_init) > 2)
    8368              :             {
    8369            0 :               if (complain & tf_error)
    8370            0 :                 error ("too many initializers for %qT", type);
    8371              :               else
    8372            0 :                 return error_mark_node;
    8373              :             }
    8374              :         }
    8375          663 :       else if (first_initializer_p && d->cur != d->end)
    8376              :         {
    8377           36 :           if (error_operand_p (d->cur->value)
    8378           36 :               || has_designator_problem (d, complain))
    8379            0 :             return error_mark_node;
    8380           36 :           vec<constructor_elt, va_gc> *v = 0;
    8381           36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    8382           36 :           init = consume_init (d->cur->value, d);
    8383           36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    8384           36 :           init = build_constructor (init_list_type_node, v);
    8385              :         }
    8386              :       return init;
    8387              :     }
    8388              : 
    8389              :   /* If we have a designator, d doesn't initialize TYPE directly, it
    8390              :      initializes an element, with brace elision if !first_initializer_p.  But
    8391              :      if TYPE is non-aggregate (and we didn't already return error_mark_node),
    8392              :      we should have errored about the designator in has_designator_problem, so
    8393              :      now ignore it for error recovery.  */
    8394     68745258 :   if (d->cur->index)
    8395              :     {
    8396              :       /* Deliberately not CP_AGGREGATE_TYPE_P to get a better diagnostic for
    8397              :          trying to designate a member of a non-aggregate class.  */
    8398       366515 :       if (AGGREGATE_TYPE_P (type) || gnu_vector_type_p (type))
    8399       366509 :         goto skip_single;
    8400              :       else
    8401            6 :         gcc_checking_assert (seen_error ());
    8402              :     }
    8403              : 
    8404              :   /* A non-aggregate type is always initialized with a single
    8405              :      initializer.  */
    8406    136698764 :   if (!CP_AGGREGATE_TYPE_P (type)
    8407              :       /* As is an array with dependent bound, which we can see
    8408              :          during C++20 aggregate CTAD.  */
    8409     74025497 :       || (cxx_dialect >= cxx20
    8410      5605119 :           && TREE_CODE (type) == ARRAY_TYPE
    8411       452776 :           && uses_template_parms (TYPE_DOMAIN (type))))
    8412              :     {
    8413              :       /* It is invalid to initialize a non-aggregate type with a
    8414              :          brace-enclosed initializer before C++0x.
    8415              :          We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
    8416              :          of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
    8417              :          a CONSTRUCTOR (with a record type).  */
    8418     62673278 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR
    8419              :           /* Don't complain about a capture-init.  */
    8420       302330 :           && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
    8421     62964873 :           && BRACE_ENCLOSED_INITIALIZER_P (stripped_init))  /* p7626.C */
    8422              :         {
    8423       291556 :           if (SCALAR_TYPE_P (type))
    8424              :             {
    8425          490 :               if (cxx_dialect < cxx11)
    8426              :                 {
    8427           16 :                   if (complain & tf_error)
    8428           16 :                     error ("braces around scalar initializer for type %qT",
    8429              :                            type);
    8430           16 :                   init = error_mark_node;
    8431              :                 }
    8432          474 :               else if (first_initializer_p
    8433          474 :                        || (CONSTRUCTOR_NELTS (stripped_init) > 0
    8434          296 :                            && (BRACE_ENCLOSED_INITIALIZER_P
    8435              :                                (CONSTRUCTOR_ELT (stripped_init,0)->value))))
    8436              :                 {
    8437           13 :                   if (complain & tf_error)
    8438           13 :                     error ("too many braces around scalar initializer "
    8439              :                            "for type %qT", type);
    8440           13 :                   init = error_mark_node;
    8441              :                 }
    8442              :             }
    8443              :           else
    8444       291066 :             maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    8445              :         }
    8446     62673278 :       return consume_init (init, d);
    8447              :     }
    8448              : 
    8449              :   /* "If T is a class type and the initializer list has a single element of
    8450              :      type cv U, where U is T or a class derived from T, the object is
    8451              :      initialized from that element."  Even if T is an aggregate.  */
    8452      5681776 :   if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
    8453      5203469 :       && first_initializer_p
    8454      3500760 :       && d->end - d->cur == 1
    8455       603777 :       && TREE_CODE (init) != RAW_DATA_CST
    8456      6309248 :       && reference_related_p (type, TREE_TYPE (init)))
    8457              :     {
    8458          426 :       d->cur++;
    8459          426 :       return init;
    8460              :     }
    8461              : 
    8462              :   /* [dcl.init.aggr]
    8463              : 
    8464              :      All implicit type conversions (clause _conv_) are considered when
    8465              :      initializing the aggregate member with an initializer from an
    8466              :      initializer-list.  If the initializer can initialize a member,
    8467              :      the member is initialized.  Otherwise, if the member is itself a
    8468              :      non-empty subaggregate, brace elision is assumed and the
    8469              :      initializer is considered for the initialization of the first
    8470              :      member of the subaggregate.  */
    8471      2451250 :   if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
    8472              :       /* But don't try this for the first initializer, since that would be
    8473              :          looking through the outermost braces; A a2 = { a1 }; is not a
    8474              :          valid aggregate initialization.  */
    8475      3253861 :       && !first_initializer_p
    8476      5722062 :       && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
    8477        11360 :           || can_convert_arg (type, TREE_TYPE (init),
    8478        11360 :                               TREE_CODE (init) == RAW_DATA_CST
    8479      5705045 :                               ? build_int_cst (integer_type_node,
    8480         1606 :                                                *(const unsigned char *)
    8481         1606 :                                                RAW_DATA_POINTER (init))
    8482              :                               : init,
    8483              :                               LOOKUP_NORMAL, complain)))
    8484         5693 :     return consume_init (init, d);
    8485              : 
    8486      6065861 :  skip_single:
    8487              : 
    8488              :   /* [dcl.init.string]
    8489              : 
    8490              :       A char array (whether plain char, signed char, or unsigned char)
    8491              :       can be initialized by a string-literal (optionally enclosed in
    8492              :       braces); a wchar_t array can be initialized by a wide
    8493              :       string-literal (optionally enclosed in braces).  */
    8494      6065861 :   if (TREE_CODE (type) == ARRAY_TYPE
    8495      6065861 :       && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
    8496              :     {
    8497       111541 :       tree str_init = init;
    8498       111541 :       tree stripped_str_init = stripped_init;
    8499       111541 :       reshape_iter stripd = {};
    8500              : 
    8501              :       /* Strip one level of braces if and only if they enclose a single
    8502              :          element (as allowed by [dcl.init.string]).  */
    8503       111541 :       if (!first_initializer_p
    8504         2780 :           && TREE_CODE (stripped_str_init) == CONSTRUCTOR
    8505       113167 :           && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
    8506              :         {
    8507          399 :           stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
    8508          399 :           str_init = stripd.cur->value;
    8509          399 :           stripped_str_init = tree_strip_any_location_wrapper (str_init);
    8510              :         }
    8511              : 
    8512              :       /* If it's a string literal, then it's the initializer for the array
    8513              :          as a whole. Otherwise, continue with normal initialization for
    8514              :          array types (one value per array element).  */
    8515       111541 :       if (TREE_CODE (stripped_str_init) == STRING_CST)
    8516              :         {
    8517           72 :           if ((first_initializer_p && has_designator_problem (d, complain))
    8518         1062 :               || (stripd.cur && has_designator_problem (&stripd, complain)))
    8519          990 :             return error_mark_node;
    8520          990 :           d->cur++;
    8521          990 :           return str_init;
    8522              :         }
    8523              :     }
    8524              : 
    8525              :   /* The following cases are about aggregates. If we are not within a full
    8526              :      initializer already, and there is not a CONSTRUCTOR, it means that there
    8527              :      is a missing set of braces (that is, we are processing the case for
    8528              :      which reshape_init exists).  */
    8529      6064871 :   bool braces_elided_p = false;
    8530      6064871 :   if (!first_initializer_p)
    8531              :     {
    8532      1825878 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR && !d->cur->index)
    8533              :         {
    8534      1815208 :           tree init_type = TREE_TYPE (init);
    8535      1815208 :           if (init_type && TYPE_PTRMEMFUNC_P (init_type))
    8536              :             /* There is no need to call reshape_init for pointer-to-member
    8537              :                function initializers, as they are always constructed correctly
    8538              :                by the front end.  Here we have e.g. {.__pfn=0B, .__delta=0},
    8539              :                which is missing outermost braces.  We should warn below, and
    8540              :                one of the routines below will wrap it in additional { }.  */;
    8541              :           /* For a nested compound literal, proceed to specialized routines,
    8542              :              to handle initialization of arrays and similar.  */
    8543      1815199 :           else if (COMPOUND_LITERAL_P (stripped_init))
    8544            8 :             gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    8545              :           /* A CONSTRUCTOR of the target's type is a previously
    8546              :              digested initializer.  */
    8547      1815191 :           else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
    8548              :             {
    8549            0 :               ++d->cur;
    8550            0 :               return init;
    8551              :             }
    8552              :           else
    8553              :             {
    8554              :               /* Something that hasn't been reshaped yet.  */
    8555      1815191 :               ++d->cur;
    8556      1815191 :               gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    8557      1815191 :               return reshape_init (type, init, complain);
    8558              :             }
    8559              :         }
    8560              : 
    8561        10687 :       if (complain & tf_warning)
    8562         9497 :         warning (OPT_Wmissing_braces,
    8563              :                  "missing braces around initializer for %qT",
    8564              :                  type);
    8565              :       braces_elided_p = true;
    8566              :     }
    8567              : 
    8568              :   /* Dispatch to specialized routines.  */
    8569      4249680 :   tree new_init;
    8570      4249680 :   if (CLASS_TYPE_P (type))
    8571      3780880 :     new_init = reshape_init_class (type, d, first_initializer_p, complain);
    8572       468800 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    8573       418861 :     new_init = reshape_init_array (type, d, first_initializer_p, complain);
    8574        49939 :   else if (VECTOR_TYPE_P (type))
    8575        49939 :     new_init = reshape_init_vector (type, d, complain);
    8576              :   else
    8577            0 :     gcc_unreachable ();
    8578              : 
    8579      4249680 :   if (braces_elided_p
    8580        10687 :       && TREE_CODE (new_init) == CONSTRUCTOR)
    8581        10410 :     CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
    8582              : 
    8583              :   return new_init;
    8584              : }
    8585              : 
    8586              : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
    8587              :    brace-enclosed aggregate initializer.
    8588              : 
    8589              :    INIT is the CONSTRUCTOR containing the list of initializers describing
    8590              :    a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
    8591              :    It may not presently match the shape of the TYPE; for example:
    8592              : 
    8593              :      struct S { int a; int b; };
    8594              :      struct S a[] = { 1, 2, 3, 4 };
    8595              : 
    8596              :    Here INIT will hold a vector of four elements, rather than a
    8597              :    vector of two elements, each itself a vector of two elements.  This
    8598              :    routine transforms INIT from the former form into the latter.  The
    8599              :    revised CONSTRUCTOR node is returned.  */
    8600              : 
    8601              : tree
    8602     12761614 : reshape_init (tree type, tree init, tsubst_flags_t complain)
    8603              : {
    8604     12761614 :   vec<constructor_elt, va_gc> *v;
    8605     12761614 :   reshape_iter d;
    8606     12761614 :   tree new_init;
    8607              : 
    8608     12761614 :   gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
    8609              : 
    8610     12761614 :   v = CONSTRUCTOR_ELTS (init);
    8611              : 
    8612              :   /* An empty constructor does not need reshaping, and it is always a valid
    8613              :      initializer.  */
    8614     12761614 :   if (vec_safe_is_empty (v))
    8615              :     return init;
    8616              : 
    8617      4490215 :   if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
    8618              :     /* Already reshaped.  */
    8619              :     return init;
    8620              : 
    8621              :   /* Brace elision is not performed for a CONSTRUCTOR representing
    8622              :      parenthesized aggregate initialization.  */
    8623      4490066 :   if (CONSTRUCTOR_IS_PAREN_INIT (init))
    8624              :     {
    8625          849 :       tree elt = (*v)[0].value;
    8626              :       /* If we're initializing a char array from a string-literal that is
    8627              :          enclosed in braces, unwrap it here.  */
    8628          849 :       if (TREE_CODE (type) == ARRAY_TYPE
    8629          277 :           && vec_safe_length (v) == 1
    8630          149 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    8631          888 :           && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
    8632           34 :         return elt;
    8633              :       return init;
    8634              :     }
    8635              : 
    8636              :   /* Handle [dcl.init.list] direct-list-initialization from
    8637              :      single element of enumeration with a fixed underlying type.  */
    8638      4489217 :   if (is_direct_enum_init (type, init))
    8639              :     {
    8640          181 :       tree elt = CONSTRUCTOR_ELT (init, 0)->value;
    8641          181 :       type = cv_unqualified (type);
    8642          181 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
    8643              :         {
    8644          166 :           warning_sentinel w (warn_useless_cast);
    8645          166 :           warning_sentinel w2 (warn_ignored_qualifiers);
    8646          166 :           return cp_build_c_cast (input_location, type, elt,
    8647              :                                   tf_warning_or_error);
    8648          166 :         }
    8649              :       else
    8650           15 :         return error_mark_node;
    8651              :     }
    8652              : 
    8653              :   /* Recurse on this CONSTRUCTOR.  */
    8654      4489036 :   d.cur = &(*v)[0];
    8655      4489036 :   d.end = d.cur + v->length ();
    8656      4489036 :   d.raw_idx = 0;
    8657              : 
    8658      4489036 :   new_init = reshape_init_r (type, &d, init, complain);
    8659      4489036 :   if (new_init == error_mark_node)
    8660              :     return error_mark_node;
    8661              : 
    8662              :   /* Make sure all the element of the constructor were used. Otherwise,
    8663              :      issue an error about exceeding initializers.  */
    8664      4488356 :   if (d.cur != d.end)
    8665              :     {
    8666          207 :       if (complain & tf_error)
    8667           64 :         error ("too many initializers for %qT", type);
    8668          207 :       return error_mark_node;
    8669              :     }
    8670              : 
    8671      4488149 :   if (CONSTRUCTOR_IS_DIRECT_INIT (init)
    8672      4488149 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    8673       619610 :     CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
    8674      4488149 :   if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
    8675      4488149 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    8676        74591 :     gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
    8677              :                          /* The old extension allows brace elision
    8678              :                             (128532).  */
    8679              :                          || cxx_dialect < cxx20
    8680              :                          || seen_error ());
    8681              : 
    8682              :   return new_init;
    8683              : }
    8684              : 
    8685              : /* Verify array initializer.  Returns true if errors have been reported.  */
    8686              : 
    8687              : bool
    8688      1028395 : check_array_initializer (tree decl, tree type, tree init)
    8689              : {
    8690      1028395 :   tree element_type = TREE_TYPE (type);
    8691              : 
    8692              :   /* Structured binding when initialized with an array type needs
    8693              :      to have complete type.  */
    8694      1028395 :   if (decl
    8695      1010745 :       && DECL_DECOMPOSITION_P (decl)
    8696        10451 :       && DECL_DECOMP_IS_BASE (decl)
    8697      1038846 :       && !COMPLETE_TYPE_P (type))
    8698              :     {
    8699            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    8700              :                 "structured binding has incomplete type %qT", type);
    8701            0 :       TREE_TYPE (decl) = error_mark_node;
    8702            0 :       return true;
    8703              :     }
    8704              : 
    8705              :   /* The array type itself need not be complete, because the
    8706              :      initializer may tell us how many elements are in the array.
    8707              :      But, the elements of the array must be complete.  */
    8708      1028395 :   if (!COMPLETE_TYPE_P (complete_type (element_type)))
    8709              :     {
    8710           15 :       if (decl)
    8711            9 :         error_at (DECL_SOURCE_LOCATION (decl),
    8712              :                   "elements of array %q#D have incomplete type", decl);
    8713              :       else
    8714            6 :         error ("elements of array %q#T have incomplete type", type);
    8715              :       return true;
    8716              :     }
    8717              : 
    8718      1028380 :   location_t loc = (decl ? location_of (decl) : input_location);
    8719      1028380 :   if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
    8720              :     return true;
    8721              : 
    8722              :   /* A compound literal can't have variable size.  */
    8723      1028380 :   if (init && !decl
    8724      1028380 :       && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
    8725        17641 :           || !TREE_CONSTANT (TYPE_SIZE (element_type))))
    8726              :     {
    8727            3 :       error ("variable-sized compound literal");
    8728            3 :       return true;
    8729              :     }
    8730              :   return false;
    8731              : }
    8732              : 
    8733              : /* Subroutine of check_initializer; args are passed down from that function.
    8734              :    Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init.  */
    8735              : 
    8736              : static tree
    8737      3276130 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
    8738              : {
    8739      3276130 :   gcc_assert (stmts_are_full_exprs_p ());
    8740      3276130 :   if (init)
    8741      2674414 :     maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
    8742      3276130 :   return build_aggr_init (decl, init, flags, tf_warning_or_error);
    8743              : }
    8744              : 
    8745              : /* Verify INIT (the initializer for DECL), and record the
    8746              :    initialization in DECL_INITIAL, if appropriate.  CLEANUP is as for
    8747              :    grok_reference_init.
    8748              : 
    8749              :    If the return value is non-NULL, it is an expression that must be
    8750              :    evaluated dynamically to initialize DECL.  */
    8751              : 
    8752              : static tree
    8753     58465016 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
    8754              : {
    8755     58465016 :   tree type;
    8756     58465016 :   tree init_code = NULL;
    8757     58465016 :   tree core_type;
    8758              : 
    8759              :   /* Things that are going to be initialized need to have complete
    8760              :      type.  */
    8761     58465016 :   TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
    8762              : 
    8763     58465016 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    8764              :     {
    8765              :       /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
    8766              :          it doesn't have storage to be initialized.  */
    8767          708 :       gcc_assert (init == NULL_TREE);
    8768              :       return NULL_TREE;
    8769              :     }
    8770              : 
    8771     58464308 :   if (type == error_mark_node)
    8772              :     /* We will have already complained.  */
    8773              :     return NULL_TREE;
    8774              : 
    8775     58464308 :   if (TREE_CODE (type) == ARRAY_TYPE)
    8776              :     {
    8777      1010745 :       if (check_array_initializer (decl, type, init))
    8778              :         return NULL_TREE;
    8779              :     }
    8780     57453563 :   else if (!COMPLETE_TYPE_P (type))
    8781              :     {
    8782           37 :       error_at (DECL_SOURCE_LOCATION (decl),
    8783              :                 "%q#D has incomplete type", decl);
    8784           37 :       TREE_TYPE (decl) = error_mark_node;
    8785           37 :       return NULL_TREE;
    8786              :     }
    8787              :   else
    8788              :     /* There is no way to make a variable-sized class type in GNU C++.  */
    8789     57453526 :     gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
    8790              : 
    8791     58464262 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
    8792              :     {
    8793      2928123 :       int init_len = CONSTRUCTOR_NELTS (init);
    8794      2928123 :       if (SCALAR_TYPE_P (type))
    8795              :         {
    8796        75733 :           if (init_len == 0)
    8797              :             {
    8798        42803 :               maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    8799        42803 :               init = build_zero_init (type, NULL_TREE, false);
    8800              :             }
    8801        32930 :           else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
    8802              :             {
    8803           12 :               error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    8804              :                         "scalar object %qD requires one element in "
    8805              :                         "initializer", decl);
    8806            6 :               TREE_TYPE (decl) = error_mark_node;
    8807            6 :               return NULL_TREE;
    8808              :             }
    8809              :         }
    8810              :     }
    8811              : 
    8812     58464256 :   if (TREE_CODE (decl) == CONST_DECL)
    8813              :     {
    8814            0 :       gcc_assert (!TYPE_REF_P (type));
    8815              : 
    8816            0 :       DECL_INITIAL (decl) = init;
    8817              : 
    8818            0 :       gcc_assert (init != NULL_TREE);
    8819              :       init = NULL_TREE;
    8820              :     }
    8821     58464256 :   else if (!init && DECL_REALLY_EXTERN (decl))
    8822              :     ;
    8823     58464256 :   else if (flag_openmp
    8824       198134 :            && VAR_P (decl)
    8825       198134 :            && DECL_LANG_SPECIFIC (decl)
    8826       112654 :            && DECL_OMP_DECLARE_MAPPER_P (decl)
    8827     58464256 :            && TREE_CODE (init) == OMP_DECLARE_MAPPER)
    8828              :     return NULL_TREE;
    8829      4346607 :   else if (init || type_build_ctor_call (type)
    8830     62209144 :            || TYPE_REF_P (type))
    8831              :     {
    8832     54719383 :       if (TYPE_REF_P (type))
    8833              :         {
    8834       385852 :           init = grok_reference_init (decl, type, init, flags);
    8835       385852 :           flags |= LOOKUP_ALREADY_DIGESTED;
    8836              :         }
    8837     54333531 :       else if (!init)
    8838       601719 :         check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    8839              :                                            tf_warning_or_error);
    8840              :       /* Do not reshape constructors of vectors (they don't need to be
    8841              :          reshaped.  */
    8842     53731812 :       else if (BRACE_ENCLOSED_INITIALIZER_P (init))
    8843              :         {
    8844      2884931 :           if (is_std_init_list (type))
    8845              :             {
    8846          410 :               init = perform_implicit_conversion (type, init,
    8847              :                                                   tf_warning_or_error);
    8848          410 :               flags |= LOOKUP_ALREADY_DIGESTED;
    8849              :             }
    8850      2884521 :           else if (TYPE_NON_AGGREGATE_CLASS (type))
    8851              :             {
    8852              :               /* Don't reshape if the class has constructors.  */
    8853       450931 :               if (cxx_dialect == cxx98)
    8854            6 :                 error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    8855              :                           "in C++98 %qD must be initialized by "
    8856              :                           "constructor, not by %<{...}%>",
    8857              :                           decl);
    8858              :             }
    8859      2433590 :           else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
    8860              :             {
    8861            0 :               error ("opaque vector types cannot be initialized");
    8862            0 :               init = error_mark_node;
    8863              :             }
    8864              :           else
    8865              :             {
    8866      2433590 :               init = reshape_init (type, init, tf_warning_or_error);
    8867      2433590 :               flags |= LOOKUP_NO_NARROWING;
    8868              :             }
    8869              :         }
    8870              :       /* [dcl.init] "Otherwise, if the destination type is an array, the object
    8871              :          is initialized as follows..."  So handle things like
    8872              : 
    8873              :           int a[](1, 2, 3);
    8874              : 
    8875              :          which is permitted in C++20 by P0960.  */
    8876     50846881 :       else if (TREE_CODE (init) == TREE_LIST
    8877       768856 :                && TREE_TYPE (init) == NULL_TREE
    8878       768856 :                && TREE_CODE (type) == ARRAY_TYPE
    8879          182 :                && !DECL_DECOMPOSITION_P (decl)
    8880     50847033 :                && (cxx_dialect >= cxx20))
    8881          142 :         init = do_aggregate_paren_init (init, type);
    8882     50846739 :       else if (TREE_CODE (init) == TREE_LIST
    8883       768714 :                && TREE_TYPE (init) != unknown_type_node
    8884     51615453 :                && !MAYBE_CLASS_TYPE_P (type))
    8885              :         {
    8886       131879 :           gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    8887              : 
    8888              :           /* We get here with code like `int a (2);' */
    8889       131879 :           init = build_x_compound_expr_from_list (init, ELK_INIT,
    8890              :                                                   tf_warning_or_error);
    8891              :         }
    8892              : 
    8893              :       /* If DECL has an array type without a specific bound, deduce the
    8894              :          array size from the initializer.  */
    8895     54719383 :       maybe_deduce_size_from_array_init (decl, init);
    8896     54719383 :       type = TREE_TYPE (decl);
    8897     54719383 :       if (type == error_mark_node)
    8898              :         return NULL_TREE;
    8899              : 
    8900    105927677 :       if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
    8901      5449623 :            && !(flags & LOOKUP_ALREADY_DIGESTED)
    8902      8083624 :            && !(init
    8903      4847497 :                 && BRACE_ENCLOSED_INITIALIZER_P (init)
    8904      5268822 :                 && CP_AGGREGATE_TYPE_P (type)))
    8905    106173025 :           || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
    8906              :         {
    8907      3276130 :           init_code = build_aggr_init_full_exprs (decl, init, flags);
    8908              : 
    8909              :           /* A constructor call is a non-trivial initializer even if
    8910              :              it isn't explicitly written.  */
    8911      3276130 :           if (TREE_SIDE_EFFECTS (init_code))
    8912      3252538 :             DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
    8913              : 
    8914              :           /* If this is a constexpr initializer, expand_default_init will
    8915              :              have returned an INIT_EXPR rather than a CALL_EXPR.  In that
    8916              :              case, pull the initializer back out and pass it down into
    8917              :              store_init_value.  */
    8918      8708325 :           while (true)
    8919              :             {
    8920      8708325 :               if (TREE_CODE (init_code) == EXPR_STMT
    8921      5482346 :                   || TREE_CODE (init_code) == STMT_EXPR
    8922      5429552 :                   || TREE_CODE (init_code) == CONVERT_EXPR)
    8923      5394718 :                 init_code = TREE_OPERAND (init_code, 0);
    8924      3313607 :               else if (TREE_CODE (init_code) == BIND_EXPR)
    8925        37477 :                 init_code = BIND_EXPR_BODY (init_code);
    8926              :               else
    8927              :                 break;
    8928              :             }
    8929      3276130 :           if (TREE_CODE (init_code) == INIT_EXPR)
    8930              :             {
    8931              :               /* In C++20, the call to build_aggr_init could have created
    8932              :                  an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
    8933              :                  A(1, 2).  */
    8934      2145418 :               init = TREE_OPERAND (init_code, 1);
    8935      2145418 :               init_code = NULL_TREE;
    8936              :               /* Don't call digest_init; it's unnecessary and will complain
    8937              :                  about aggregate initialization of non-aggregate classes.  */
    8938      2145418 :               flags |= LOOKUP_ALREADY_DIGESTED;
    8939              :             }
    8940      1130712 :           else if (DECL_DECLARED_CONSTEXPR_P (decl)
    8941      2227210 :                    || DECL_DECLARED_CONSTINIT_P (decl))
    8942              :             {
    8943              :               /* Declared constexpr or constinit, but no suitable initializer;
    8944              :                  massage init appropriately so we can pass it into
    8945              :                  store_init_value for the error.  */
    8946        34232 :               tree new_init = NULL_TREE;
    8947        34232 :               if (!processing_template_decl
    8948          274 :                   && TREE_CODE (init_code) == CALL_EXPR)
    8949          232 :                 new_init = build_cplus_new (type, init_code, tf_none);
    8950        34000 :               else if (CLASS_TYPE_P (type)
    8951        68000 :                        && (!init || TREE_CODE (init) == TREE_LIST))
    8952        18667 :                 new_init = build_functional_cast (input_location, type,
    8953              :                                                   init, tf_none);
    8954        18899 :               if (new_init)
    8955              :                 {
    8956        18899 :                   init = new_init;
    8957        18899 :                   if (TREE_CODE (init) == TARGET_EXPR
    8958          261 :                       && !(flags & LOOKUP_ONLYCONVERTING))
    8959          261 :                     TARGET_EXPR_DIRECT_INIT_P (init) = true;
    8960              :                 }
    8961              :               init_code = NULL_TREE;
    8962              :             }
    8963              :           else
    8964              :             init = NULL_TREE;
    8965              :         }
    8966              : 
    8967     53622899 :       if (init && TREE_CODE (init) != TREE_VEC)
    8968              :         {
    8969     53622884 :           init_code = store_init_value (decl, init, cleanups, flags);
    8970              : 
    8971     53620185 :           if (DECL_INITIAL (decl)
    8972     38849989 :               && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    8973     56757038 :               && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
    8974              :             {
    8975      1382503 :               tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
    8976      1382503 :               if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
    8977      1382503 :                   && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
    8978           36 :                 cp_complete_array_type (&TREE_TYPE (elt), elt, false);
    8979              :             }
    8980              : 
    8981      2668565 :           if (pedantic && TREE_CODE (type) == ARRAY_TYPE
    8982        66814 :               && DECL_INITIAL (decl)
    8983        66071 :               && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
    8984     53681789 :               && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
    8985            6 :             warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
    8986            3 :                                          DECL_SOURCE_LOCATION (decl)),
    8987            3 :                         0, "array %qD initialized by parenthesized "
    8988              :                         "string literal %qE",
    8989            3 :                         decl, DECL_INITIAL (decl));
    8990              :           init = NULL_TREE;
    8991              :         }
    8992              :     }
    8993      3744873 :   else if (!init && REFLECTION_TYPE_P (type))
    8994              :     {
    8995              :       /* [dcl.init.general]: To default-initialize an object of type
    8996              :          std::meta::info means that the object is zero-initialized.  */
    8997          164 :       DECL_INITIAL (decl)
    8998          164 :         = build_zero_init (type, NULL_TREE, /*static_storage_p=*/false);
    8999          164 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    9000          164 :       TREE_CONSTANT (decl) = true;
    9001          164 :       init = NULL_TREE;
    9002              :     }
    9003              :   else
    9004              :     {
    9005      7489418 :       if (CLASS_TYPE_P (core_type = strip_array_types (type))
    9006      4562280 :           && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
    9007       817556 :               || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
    9008           21 :         diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
    9009              :                                                   /*complain=*/true);
    9010              : 
    9011      3744709 :       check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    9012              :                                          tf_warning_or_error);
    9013              :     }
    9014              : 
    9015          167 :   if (init && init != error_mark_node)
    9016            0 :     init_code = cp_build_init_expr (decl, init);
    9017              : 
    9018     16021297 :   if (init_code && !TREE_SIDE_EFFECTS (init_code)
    9019     58520980 :       && init_code != error_mark_node)
    9020              :     init_code = NULL_TREE;
    9021              : 
    9022     58404413 :   if (init_code)
    9023              :     {
    9024              :       /* We might have set these in cp_finish_decl.  */
    9025     15964157 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
    9026     15964157 :       TREE_CONSTANT (decl) = false;
    9027              :     }
    9028              : 
    9029     15964157 :   if (init_code
    9030     15964157 :       && DECL_IN_AGGR_P (decl)
    9031            6 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    9032              :     {
    9033            0 :       static int explained = 0;
    9034              : 
    9035            0 :       auto_diagnostic_group d;
    9036            0 :       if (cxx_dialect < cxx11)
    9037            0 :         error ("initializer invalid for static member with constructor");
    9038            0 :       else if (cxx_dialect < cxx17)
    9039            0 :         error ("non-constant in-class initialization invalid for static "
    9040              :                "member %qD", decl);
    9041              :       else
    9042            0 :         error ("non-constant in-class initialization invalid for non-inline "
    9043              :                "static member %qD", decl);
    9044            0 :       if (!explained)
    9045              :         {
    9046            0 :           inform (input_location,
    9047              :                   "(an out of class initialization is required)");
    9048            0 :           explained = 1;
    9049              :         }
    9050            0 :       return NULL_TREE;
    9051            0 :     }
    9052              : 
    9053              :   return init_code;
    9054              : }
    9055              : 
    9056              : /* If DECL is not a local variable, give it RTL.  */
    9057              : 
    9058              : static void
    9059    124103665 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
    9060              : {
    9061    124103665 :   int toplev = toplevel_bindings_p ();
    9062    124103665 :   int defer_p;
    9063              : 
    9064              :   /* Set the DECL_ASSEMBLER_NAME for the object.  */
    9065    124103665 :   if (asmspec)
    9066              :     {
    9067              :       /* The `register' keyword, when used together with an
    9068              :          asm-specification, indicates that the variable should be
    9069              :          placed in a particular register.  */
    9070      1019249 :       if (VAR_P (decl) && DECL_REGISTER (decl))
    9071              :         {
    9072           87 :           if (TREE_ADDRESSABLE (decl))
    9073            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    9074              :                       "address of explicit register variable %qD requested",
    9075              :                       decl);
    9076              :           else
    9077              :             {
    9078           84 :               set_user_assembler_name (decl, asmspec);
    9079           84 :               DECL_HARD_REGISTER (decl) = 1;
    9080              :             }
    9081              :         }
    9082              :       else
    9083              :         {
    9084      1019162 :           if (TREE_CODE (decl) == FUNCTION_DECL
    9085      1019162 :               && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
    9086        81570 :             set_builtin_user_assembler_name (decl, asmspec);
    9087      1019162 :           set_user_assembler_name (decl, asmspec);
    9088      1019162 :           if (DECL_LOCAL_DECL_P (decl))
    9089            6 :             if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
    9090              :               /* We have to propagate the name to the ns-alias.
    9091              :                  This is horrible, as we're affecting a
    9092              :                  possibly-shared decl.  Again, a one-true-decl
    9093              :                  model breaks down.  */
    9094            6 :               if (ns_decl != error_mark_node)
    9095            6 :                 set_user_assembler_name (ns_decl, asmspec);
    9096              :         }
    9097              :     }
    9098              : 
    9099              :   /* Handle non-variables up front.  */
    9100    124103665 :   if (!VAR_P (decl))
    9101              :     {
    9102     59006664 :       rest_of_decl_compilation (decl, toplev, at_eof);
    9103     59006664 :       return;
    9104              :     }
    9105              : 
    9106              :   /* If we see a class member here, it should be a static data
    9107              :      member.  */
    9108     65097001 :   if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
    9109              :     {
    9110      5597520 :       gcc_assert (TREE_STATIC (decl));
    9111              :       /* An in-class declaration of a static data member should be
    9112              :          external; it is only a declaration, and not a definition.  */
    9113      5597520 :       if (init == NULL_TREE)
    9114      5597495 :         gcc_assert (DECL_EXTERNAL (decl)
    9115              :                     || !TREE_PUBLIC (decl));
    9116              :     }
    9117              : 
    9118              :   /* We don't create any RTL for local variables.  */
    9119     65097001 :   if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    9120              :     return;
    9121              : 
    9122              :   /* Don't output reflection variables.  */
    9123     39969977 :   if (consteval_only_p (decl))
    9124              :     {
    9125              :       /* Disable assemble_variable.  */
    9126         1570 :       DECL_EXTERNAL (decl) = true;
    9127              :       /* Undo make_decl_one_only.  */
    9128         1570 :       if (DECL_COMDAT_GROUP (decl))
    9129              :         {
    9130          276 :           symtab_node *node = symtab_node::get (decl);
    9131          276 :           node->set_comdat_group (NULL);
    9132          276 :           node->dissolve_same_comdat_group_list ();
    9133              :         }
    9134              :       return;
    9135              :     }
    9136              : 
    9137              :   /* We defer emission of local statics until the corresponding
    9138              :      DECL_EXPR is expanded.  But with constexpr its function might never
    9139              :      be expanded, so go ahead and tell cgraph about the variable now.  */
    9140     79936814 :   defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
    9141       141993 :               && !var_in_maybe_constexpr_fn (decl))
    9142     79799601 :              || DECL_VIRTUAL_P (decl));
    9143              : 
    9144              :   /* Defer template instantiations.  */
    9145     39968407 :   if (DECL_LANG_SPECIFIC (decl)
    9146     39968407 :       && DECL_IMPLICIT_INSTANTIATION (decl))
    9147              :     defer_p = 1;
    9148              : 
    9149              :   /* If we're not deferring, go ahead and assemble the variable.  */
    9150     20387935 :   if (!defer_p)
    9151     17992299 :     rest_of_decl_compilation (decl, toplev, at_eof);
    9152              : }
    9153              : 
    9154              : /* walk_tree helper for wrap_temporary_cleanups, below.  */
    9155              : 
    9156              : static tree
    9157     11417343 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
    9158              : {
    9159              :   /* Stop at types or full-expression boundaries.  */
    9160     11417343 :   if (TYPE_P (*stmt_p)
    9161     11417115 :       || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
    9162              :     {
    9163          488 :       *walk_subtrees = 0;
    9164          488 :       return NULL_TREE;
    9165              :     }
    9166              : 
    9167     11416855 :   if (TREE_CODE (*stmt_p) == TARGET_EXPR)
    9168              :     {
    9169       249989 :       tree guard = (tree)data;
    9170       249989 :       tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
    9171              : 
    9172       124844 :       if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
    9173       370797 :           && !expr_noexcept_p (tcleanup, tf_none))
    9174              :         {
    9175          149 :           tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
    9176              :           /* Tell honor_protect_cleanup_actions to handle this as a separate
    9177              :              cleanup.  */
    9178          149 :           TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
    9179          149 :           TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
    9180              :         }
    9181              :     }
    9182              : 
    9183              :   return NULL_TREE;
    9184              : }
    9185              : 
    9186              : /* We're initializing a local variable which has a cleanup GUARD.  If there
    9187              :    are any temporaries used in the initializer INIT of this variable, we
    9188              :    need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
    9189              :    variable will be cleaned up properly if one of them throws.
    9190              : 
    9191              :    Unfortunately, there's no way to express this properly in terms of
    9192              :    nesting, as the regions for the temporaries overlap the region for the
    9193              :    variable itself; if there are two temporaries, the variable needs to be
    9194              :    the first thing destroyed if either of the temporary destructors throws.
    9195              :    However, we only want to run the variable's cleanup if it actually got
    9196              :    constructed.  So we need to guard the temporary cleanups with the
    9197              :    variable's cleanup if they are run on the normal path, but not if they
    9198              :    are run on the exceptional path.  We implement this by telling
    9199              :    honor_protect_cleanup_actions to strip the variable cleanup from the
    9200              :    exceptional path.
    9201              : 
    9202              :    Another approach could be to make the variable cleanup region enclose
    9203              :    initialization, but depend on a flag to indicate that the variable is
    9204              :    initialized; that's effectively what we do for arrays.  But the current
    9205              :    approach works fine for non-arrays, and has no code overhead in the usual
    9206              :    case where the temporary destructors are noexcept.  */
    9207              : 
    9208              : static void
    9209      1026402 : wrap_temporary_cleanups (tree init, tree guard)
    9210              : {
    9211      1026402 :   if (TREE_CODE (guard) == BIND_EXPR)
    9212              :     {
    9213              :       /* An array cleanup region already encloses any temporary cleanups,
    9214              :          don't wrap it around them again.  */
    9215          422 :       gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
    9216              :       return;
    9217              :     }
    9218      1025980 :   cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
    9219              : }
    9220              : 
    9221              : /* Generate code to initialize DECL (a local variable).  */
    9222              : 
    9223              : static void
    9224     25126997 : initialize_local_var (tree decl, tree init, bool decomp)
    9225              : {
    9226     25126997 :   tree type = TREE_TYPE (decl);
    9227     25126997 :   tree cleanup;
    9228     25126997 :   int already_used;
    9229              : 
    9230     25126997 :   gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL);
    9231     25126997 :   gcc_assert (!TREE_STATIC (decl));
    9232              : 
    9233     25126997 :   if (DECL_SIZE (decl) == NULL_TREE)
    9234              :     {
    9235              :       /* If we used it already as memory, it must stay in memory.  */
    9236            0 :       DECL_INITIAL (decl) = NULL_TREE;
    9237            0 :       TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    9238            0 :       return;
    9239              :     }
    9240              : 
    9241     25126997 :   if (type == error_mark_node)
    9242              :     return;
    9243              : 
    9244              :   /* Compute and store the initial value.  */
    9245     25126997 :   already_used = TREE_USED (decl) || TREE_USED (type);
    9246     25126997 :   if (TREE_USED (type))
    9247           32 :     DECL_READ_P (decl) = 1;
    9248              : 
    9249              :   /* Generate a cleanup, if necessary.  */
    9250     25126997 :   cleanup = (decomp ? NULL_TREE
    9251     25091560 :              : cxx_maybe_build_cleanup (decl, tf_warning_or_error));
    9252              : 
    9253              :   /* Perform the initialization.  */
    9254     25126997 :   if (init)
    9255              :     {
    9256     15949841 :       tree rinit = (TREE_CODE (init) == INIT_EXPR
    9257     15949841 :                     ? TREE_OPERAND (init, 1) : NULL_TREE);
    9258     14562116 :       if (rinit && !TREE_SIDE_EFFECTS (rinit)
    9259     22552431 :           && TREE_OPERAND (init, 0) == decl)
    9260              :         {
    9261              :           /* Stick simple initializers in DECL_INITIAL so that
    9262              :              -Wno-init-self works (c++/34772).  */
    9263      7990315 :           DECL_INITIAL (decl) = rinit;
    9264              : 
    9265      7990315 :           if (warn_init_self && TYPE_REF_P (type))
    9266              :             {
    9267         2469 :               STRIP_NOPS (rinit);
    9268         2469 :               if (rinit == decl)
    9269            3 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    9270            3 :                             OPT_Winit_self,
    9271              :                             "reference %qD is initialized with itself", decl);
    9272              :             }
    9273              :         }
    9274              :       else
    9275              :         {
    9276      7959526 :           int saved_stmts_are_full_exprs_p;
    9277              : 
    9278              :           /* If we're only initializing a single object, guard the
    9279              :              destructors of any temporaries used in its initializer with
    9280              :              its destructor.  */
    9281      7959526 :           if (cleanup)
    9282      1022936 :             wrap_temporary_cleanups (init, cleanup);
    9283              : 
    9284      7959526 :           gcc_assert (building_stmt_list_p ());
    9285      7959526 :           saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    9286              :           /* Avoid CLEANUP_POINT_EXPR for the structured binding
    9287              :              bases, those will have CLEANUP_POINT_EXPR at the end of
    9288              :              code emitted by cp_finish_decomp.  */
    9289      7959526 :           if (decomp)
    9290        34917 :             current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    9291              :           else
    9292      7924609 :             current_stmt_tree ()->stmts_are_full_exprs_p = 1;
    9293      7959526 :           finish_expr_stmt (init);
    9294      7959526 :           current_stmt_tree ()->stmts_are_full_exprs_p
    9295      7959526 :             = saved_stmts_are_full_exprs_p;
    9296              :         }
    9297              :     }
    9298              : 
    9299              :   /* Set this to 0 so we can tell whether an aggregate which was
    9300              :      initialized was ever used.  Don't do this if it has a
    9301              :      destructor, so we don't complain about the 'resource
    9302              :      allocation is initialization' idiom.  Now set
    9303              :      attribute((unused)) on types so decls of that type will be
    9304              :      marked used. (see TREE_USED, above.)  */
    9305     25126997 :   if (TYPE_NEEDS_CONSTRUCTING (type)
    9306      2246034 :       && ! already_used
    9307        25289 :       && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    9308     25149377 :       && DECL_NAME (decl))
    9309        22332 :     TREE_USED (decl) = 0;
    9310     25104665 :   else if (already_used)
    9311     22072230 :     TREE_USED (decl) = 1;
    9312              : 
    9313     25126997 :   if (cleanup)
    9314      1036718 :     finish_decl_cleanup (decl, cleanup);
    9315              : }
    9316              : 
    9317              : /* DECL is a VAR_DECL for a compiler-generated variable with static
    9318              :    storage duration (like a virtual table) whose initializer is a
    9319              :    compile-time constant.  Initialize the variable and provide it to the
    9320              :    back end.  */
    9321              : 
    9322              : void
    9323      2217558 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
    9324              : {
    9325      2217558 :   tree init;
    9326      2217558 :   gcc_assert (DECL_ARTIFICIAL (decl));
    9327      2217558 :   init = build_constructor (TREE_TYPE (decl), v);
    9328      2217558 :   gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
    9329      2217558 :   DECL_INITIAL (decl) = init;
    9330      2217558 :   DECL_INITIALIZED_P (decl) = 1;
    9331              :   /* Mark the decl as constexpr so that we can access its content
    9332              :      at compile time.  */
    9333      2217558 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    9334      2217558 :   DECL_DECLARED_CONSTEXPR_P (decl) = true;
    9335      2217558 :   determine_visibility (decl);
    9336      2217558 :   layout_var_decl (decl);
    9337      2217558 :   maybe_commonize_var (decl);
    9338      2217558 :   make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
    9339      2217558 : }
    9340              : 
    9341              : /* INIT is the initializer for a variable, as represented by the
    9342              :    parser.  Returns true iff INIT is value-dependent.  */
    9343              : 
    9344              : static bool
    9345     10112560 : value_dependent_init_p (tree init)
    9346              : {
    9347     10112560 :   if (TREE_CODE (init) == TREE_LIST)
    9348              :     /* A parenthesized initializer, e.g.: int i (3, 2); ? */
    9349        21583 :     return any_value_dependent_elements_p (init);
    9350     10090977 :   else if (TREE_CODE (init) == CONSTRUCTOR)
    9351              :   /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
    9352              :     {
    9353        88623 :       if (dependent_type_p (TREE_TYPE (init)))
    9354              :         return true;
    9355              : 
    9356        88617 :       vec<constructor_elt, va_gc> *elts;
    9357        88617 :       size_t nelts;
    9358        88617 :       size_t i;
    9359              : 
    9360        88617 :       elts = CONSTRUCTOR_ELTS (init);
    9361        88617 :       nelts = vec_safe_length (elts);
    9362       665659 :       for (i = 0; i < nelts; ++i)
    9363       606307 :         if (value_dependent_init_p ((*elts)[i].value))
    9364              :           return true;
    9365              :     }
    9366              :   else
    9367              :     /* It must be a simple expression, e.g., int i = 3;  */
    9368     10002354 :     return value_dependent_expression_p (init);
    9369              : 
    9370              :   return false;
    9371              : }
    9372              : 
    9373              : /* A helper function to be called via walk_tree.  If any label exists
    9374              :    under *TP, it is (going to be) forced.  Set has_forced_label_in_static.  */
    9375              : 
    9376              : static tree
    9377          337 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
    9378              : {
    9379          337 :   if (TYPE_P (*tp))
    9380            0 :     *walk_subtrees = 0;
    9381          337 :   if (TREE_CODE (*tp) == LABEL_DECL)
    9382            6 :     cfun->has_forced_label_in_static = 1;
    9383          337 :   return NULL_TREE;
    9384              : }
    9385              : 
    9386              : /* Return true if DECL has either a trivial destructor, or for C++20
    9387              :    is constexpr and has a constexpr destructor.  */
    9388              : 
    9389              : static bool
    9390     63533792 : decl_maybe_constant_destruction (tree decl, tree type)
    9391              : {
    9392     63533792 :   return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    9393     63533792 :           || (cxx_dialect >= cxx20
    9394      4174432 :               && VAR_P (decl)
    9395      4174077 :               && DECL_DECLARED_CONSTEXPR_P (decl)
    9396          488 :               && type_has_constexpr_destructor (strip_array_types (type))));
    9397              : }
    9398              : 
    9399              : static tree declare_simd_adjust_this (tree *, int *, void *);
    9400              : 
    9401              : /* Helper function of omp_declare_variant_finalize.  Finalize one
    9402              :    "omp declare variant base" attribute.  Return true if it should be
    9403              :    removed.  */
    9404              : 
    9405              : static bool
    9406         1781 : omp_declare_variant_finalize_one (tree decl, tree attr)
    9407              : {
    9408         1781 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    9409              :     {
    9410          164 :       walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
    9411              :                  DECL_ARGUMENTS (decl), NULL);
    9412          164 :       walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
    9413              :                  DECL_ARGUMENTS (decl), NULL);
    9414              :     }
    9415              : 
    9416         1781 :   tree ctx = TREE_VALUE (TREE_VALUE (attr));
    9417         1781 :   tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
    9418              :                                         OMP_TRAIT_CONSTRUCT_SIMD);
    9419         1781 :   if (simd)
    9420              :     {
    9421           69 :       TREE_VALUE (simd)
    9422           69 :         = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
    9423           69 :                                                  OMP_TS_PROPERTIES (simd));
    9424              :       /* FIXME, adjusting simd args unimplemented.  */
    9425              :     }
    9426              : 
    9427         1781 :   tree chain = TREE_CHAIN (TREE_VALUE (attr));
    9428         1781 :   location_t varid_loc
    9429         1781 :     = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
    9430         1781 :   location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
    9431         1781 :   cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
    9432         1781 :   tree variant = TREE_PURPOSE (TREE_VALUE (attr));
    9433              : 
    9434         1781 :   location_t save_loc = input_location;
    9435         1781 :   input_location = varid_loc;
    9436              : 
    9437         1781 :   releasing_vec args;
    9438         1781 :   tree parm = DECL_ARGUMENTS (decl);
    9439         1781 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    9440          164 :     parm = DECL_CHAIN (parm);
    9441         3247 :   for (; parm; parm = DECL_CHAIN (parm))
    9442         1466 :     vec_safe_push (args, forward_parm (parm));
    9443              : 
    9444         1781 :   unsigned nappend_args = 0;
    9445         1781 :   tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    9446         1781 :   if (append_args_list)
    9447              :     {
    9448          354 :       append_args_list = TREE_VALUE (append_args_list);
    9449          354 :       append_args_list = (append_args_list && TREE_CHAIN (append_args_list)
    9450          591 :                           ? TREE_VALUE (TREE_CHAIN (append_args_list))
    9451              :                           : NULL_TREE);
    9452          741 :       for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    9453          387 :         nappend_args++;
    9454          354 :       if (nappend_args)
    9455              :         {
    9456          237 :           tree type;
    9457          237 :           if ((type = lookup_qualified_name (global_namespace,
    9458              :                                              "omp_interop_t",
    9459              :                                              LOOK_want::NORMAL,
    9460              :                                              /*complain*/false)) == NULL_TREE
    9461          237 :               || !c_omp_interop_t_p (TREE_TYPE (type)))
    9462              :             {
    9463           24 :               location_t loc = input_location;
    9464           24 :               variant = tree_strip_any_location_wrapper (variant);
    9465           24 :               if (!identifier_p (variant))
    9466              :                 {
    9467           21 :                   if (TREE_CODE (variant) == OVERLOAD && OVL_SINGLE_P (variant))
    9468           21 :                     variant = OVL_FIRST (variant);
    9469           21 :                   loc = EXPR_LOC_OR_LOC (variant,
    9470              :                                          DECL_SOURCE_LOCATION (variant));
    9471              :                 }
    9472           24 :               auto_diagnostic_group d;
    9473           24 :               error_at (loc, "argument %d of %qE must be of %<omp_interop_t%>",
    9474           24 :                         args->length () + 1, variant);
    9475           24 :               inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    9476              :                       "%<append_args%> specified here");
    9477           24 :               return true;
    9478           24 :             }
    9479          564 :           for (unsigned i = 0; i < nappend_args; i++)
    9480          351 :             vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
    9481              :         }
    9482              :     }
    9483              : 
    9484         1757 :   bool koenig_p = false;
    9485         1757 :   if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
    9486              :     {
    9487         1687 :       if (identifier_p (variant)
    9488              :           /* In C++20, we may need to perform ADL for a template
    9489              :              name.  */
    9490         1663 :           || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
    9491           18 :               && identifier_p (TREE_OPERAND (variant, 0))))
    9492              :         {
    9493           24 :           if (!args->is_empty ())
    9494              :             {
    9495           24 :               koenig_p = true;
    9496           24 :               if (!any_type_dependent_arguments_p (args))
    9497           21 :                 variant = perform_koenig_lookup (variant, args,
    9498              :                                                  tf_warning_or_error);
    9499              :             }
    9500              :           else
    9501            0 :             variant = unqualified_fn_lookup_error (variant);
    9502              :         }
    9503         1663 :       else if (!args->is_empty () && is_overloaded_fn (variant))
    9504              :         {
    9505          896 :           tree fn = get_first_fn (variant);
    9506          896 :           fn = STRIP_TEMPLATE (fn);
    9507          896 :           if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
    9508          896 :                  || DECL_FUNCTION_MEMBER_P (fn)
    9509          783 :                  || DECL_LOCAL_DECL_P (fn)))
    9510              :             {
    9511          783 :               koenig_p = true;
    9512          783 :               if (!any_type_dependent_arguments_p (args))
    9513          729 :                 variant = perform_koenig_lookup (variant, args,
    9514              :                                                  tf_warning_or_error);
    9515              :             }
    9516              :         }
    9517              :     }
    9518              : 
    9519         1757 :   if (idk == CP_ID_KIND_QUALIFIED)
    9520            6 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
    9521              :                                 koenig_p, tf_warning_or_error);
    9522         1751 :   else if (idk == CP_ID_KIND_NONE
    9523           64 :            && TREE_CODE (variant) == FUNCTION_DECL
    9524           64 :            && DECL_IOBJ_MEMBER_FUNCTION_P (variant)
    9525         1799 :            && CLASS_TYPE_P (DECL_CONTEXT (decl)))
    9526              :     {
    9527           48 :       tree saved_ccp = current_class_ptr;
    9528           48 :       tree saved_ccr = current_class_ref;
    9529           48 :       current_class_ptr = NULL_TREE;
    9530           48 :       current_class_ref = NULL_TREE;
    9531           48 :       inject_this_parameter (DECL_CONTEXT (decl), TYPE_UNQUALIFIED);
    9532           48 :       variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    9533              :                                   koenig_p, tf_warning_or_error);
    9534           48 :       current_class_ptr = saved_ccp;
    9535           48 :       current_class_ref = saved_ccr;
    9536              :     }
    9537              :   else
    9538         1703 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    9539              :                                 koenig_p, tf_warning_or_error);
    9540         1757 :   if (variant == error_mark_node && !processing_template_decl)
    9541              :     return true;
    9542              : 
    9543         1643 :   if (TREE_CODE (variant) == TARGET_EXPR)
    9544            9 :     variant = TARGET_EXPR_INITIAL (variant);
    9545              : 
    9546         3277 :   variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
    9547         1643 :   input_location = save_loc;
    9548              : 
    9549         1643 :   if (variant == decl)
    9550              :     {
    9551            0 :       error_at (varid_loc, "variant %qD is the same as base function",
    9552              :                 variant);
    9553            0 :       return true;
    9554              :     }
    9555              : 
    9556         1643 :   if (variant)
    9557              :     {
    9558         1556 :       bool fail;
    9559         1556 :       const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
    9560         1556 :       if (!nappend_args)
    9561         1397 :         fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    9562              :                            COMPARE_STRICT);
    9563              :       else
    9564              :         {
    9565          159 :           unsigned nbase_args = 0;
    9566          159 :           for (tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
    9567          756 :                t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
    9568          240 :             nbase_args++;
    9569          159 :           tree vargs, varg;
    9570          159 :           vargs = varg = TYPE_ARG_TYPES (TREE_TYPE (variant));
    9571          399 :           for (unsigned i = 0; i < nbase_args && varg;
    9572          240 :                i++, varg = TREE_CHAIN (varg))
    9573          240 :             vargs = varg;
    9574          417 :           for (unsigned i = 0; i < nappend_args && varg; i++)
    9575          258 :             varg = TREE_CHAIN (varg);
    9576          159 :           tree saved_vargs;
    9577          159 :           int saved_no_named_args_stdarg = 0;
    9578          159 :           if (nbase_args)
    9579              :             {
    9580          111 :               saved_vargs = TREE_CHAIN (vargs);
    9581          111 :               TREE_CHAIN (vargs) = varg;
    9582              :             }
    9583              :           else
    9584              :             {
    9585           48 :               saved_vargs = vargs;
    9586           48 :               TYPE_ARG_TYPES (TREE_TYPE (variant)) = varg;
    9587           48 :               saved_no_named_args_stdarg
    9588           48 :                 = TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant));
    9589           48 :               if (TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl))
    9590           48 :                   && varg == NULL_TREE)
    9591            2 :                 TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant)) = 1;
    9592              :             }
    9593              :           /* Skip assert check that TYPE_CANONICAL is the same.  */
    9594          159 :           fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    9595              :                              COMPARE_STRUCTURAL);
    9596          159 :           if (nbase_args)
    9597          111 :             TREE_CHAIN (vargs) = saved_vargs;
    9598              :           else
    9599              :             {
    9600           48 :               TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_vargs;
    9601           48 :               TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant))
    9602           96 :                 = saved_no_named_args_stdarg;
    9603              :             }
    9604          159 :           varg = saved_vargs;
    9605          159 :           if (!fail && !processing_template_decl)
    9606          402 :             for (unsigned i = 0; i < nappend_args;
    9607          246 :                  i++, varg = TREE_CHAIN (varg))
    9608          507 :               if (!varg || !c_omp_interop_t_p (TREE_VALUE (varg)))
    9609              :                 {
    9610            9 :                   auto_diagnostic_group d;
    9611            9 :                   error_at (DECL_SOURCE_LOCATION (variant),
    9612              :                             "argument %d of %qD must be of %<omp_interop_t%>",
    9613            9 :                             nbase_args + i + 1, variant);
    9614            9 :                   inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    9615              :                           "%<append_args%> specified here");
    9616            9 :                   break;
    9617            9 :                 }
    9618              :         }
    9619         1556 :       if (fail)
    9620              :         {
    9621           69 :           error_at (varid_loc, "variant %qD and base %qD have incompatible "
    9622              :                                "types", variant, decl);
    9623           69 :           return true;
    9624              :         }
    9625         1487 :       if (fndecl_built_in_p (variant)
    9626         1487 :           && (startswith (varname, "__builtin_")
    9627            0 :               || startswith (varname, "__sync_")
    9628            0 :               || startswith (varname, "__atomic_")))
    9629              :         {
    9630            6 :           error_at (varid_loc, "variant %qD is a built-in", variant);
    9631            6 :           return true;
    9632              :         }
    9633              :       else
    9634              :         {
    9635         1481 :           tree construct
    9636         1481 :             = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
    9637         1481 :           omp_mark_declare_variant (match_loc, variant, construct);
    9638         1481 :           if (!omp_context_selector_matches (ctx, NULL_TREE, false))
    9639              :             return true;
    9640         1057 :           TREE_PURPOSE (TREE_VALUE (attr)) = variant;
    9641              : 
    9642              :           // Prepend adjust_args list to variant attributes
    9643         1057 :           tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    9644         1057 :           if (adjust_args_list != NULL_TREE)
    9645              :             {
    9646          507 :               if (DECL_NONSTATIC_MEMBER_P (variant)
    9647          285 :                   && TREE_VALUE (adjust_args_list))
    9648              :                 {
    9649              :                   /* Shift arg position for the added 'this' pointer.  */
    9650              :                   /* Handle need_device_ptr  */
    9651           21 :                   for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
    9652           51 :                        t; t = TREE_CHAIN (t))
    9653           30 :                     TREE_VALUE (t)
    9654           30 :                       = build_int_cst (TREE_TYPE (t),
    9655           30 :                                        tree_to_uhwi (TREE_VALUE (t)) + 1);
    9656              :                 }
    9657          264 :               if (DECL_NONSTATIC_MEMBER_P (variant) && append_args_list)
    9658              :                 {
    9659              :                   /* Shift likewise the number of args after which the
    9660              :                      interop object should be added.  */
    9661            6 :                   tree nargs = TREE_CHAIN (TREE_VALUE (adjust_args_list));
    9662            6 :                   TREE_PURPOSE (nargs)
    9663            6 :                     = build_int_cst (TREE_TYPE (nargs),
    9664            6 :                                      tree_to_uhwi (TREE_PURPOSE (nargs)) + 1);
    9665              :                 }
    9666          528 :               for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    9667          264 :                 TREE_VALUE (t)
    9668          264 :                   = cp_finish_omp_init_prefer_type (TREE_VALUE (t));
    9669          528 :               DECL_ATTRIBUTES (variant) = tree_cons (
    9670              :                 get_identifier ("omp declare variant variant args"),
    9671          528 :                 TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
    9672              :             }
    9673              :         }
    9674              :     }
    9675           87 :   else if (!processing_template_decl)
    9676              :     {
    9677            0 :       error_at (varid_loc, "could not find variant declaration");
    9678            0 :       return true;
    9679              :     }
    9680              : 
    9681              :   return false;
    9682         1781 : }
    9683              : 
    9684              : /* Helper function, finish up "omp declare variant base" attribute
    9685              :    now that there is a DECL.  ATTR is the first "omp declare variant base"
    9686              :    attribute.  */
    9687              : 
    9688              : void
    9689         1564 : omp_declare_variant_finalize (tree decl, tree attr)
    9690              : {
    9691         1564 :   size_t attr_len = strlen ("omp declare variant base");
    9692         1564 :   tree *list = &DECL_ATTRIBUTES (decl);
    9693         1564 :   bool remove_all = false;
    9694         1564 :   location_t match_loc = DECL_SOURCE_LOCATION (decl);
    9695         1564 :   if (TREE_CHAIN (TREE_VALUE (attr))
    9696         1564 :       && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
    9697         3128 :       && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
    9698         1564 :     match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
    9699         3128 :   if (DECL_CONSTRUCTOR_P (decl))
    9700              :     {
    9701           27 :       error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
    9702           27 :       remove_all = true;
    9703              :     }
    9704         1537 :   else if (DECL_DESTRUCTOR_P (decl))
    9705              :     {
    9706            9 :       error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
    9707            9 :       remove_all = true;
    9708              :     }
    9709         1528 :   else if (DECL_DEFAULTED_FN (decl))
    9710              :     {
    9711            2 :       error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
    9712            2 :       remove_all = true;
    9713              :     }
    9714         1526 :   else if (DECL_DELETED_FN (decl))
    9715              :     {
    9716            2 :       error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
    9717            2 :       remove_all = true;
    9718              :     }
    9719         1524 :   else if (DECL_VIRTUAL_P (decl))
    9720              :     {
    9721            0 :       error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
    9722            0 :       remove_all = true;
    9723              :     }
    9724              :   /* This loop is like private_lookup_attribute, except that it works
    9725              :      with tree * rather than tree, as we might want to remove the
    9726              :      attributes that are diagnosed as erroneous.  */
    9727         3397 :   while (*list)
    9728              :     {
    9729         1833 :       tree attr = get_attribute_name (*list);
    9730         1833 :       size_t ident_len = IDENTIFIER_LENGTH (attr);
    9731         4810 :       if (cmp_attribs ("omp declare variant base", attr_len,
    9732         1833 :                        IDENTIFIER_POINTER (attr), ident_len))
    9733              :         {
    9734         1821 :           if (remove_all || omp_declare_variant_finalize_one (decl, *list))
    9735              :             {
    9736          677 :               *list = TREE_CHAIN (*list);
    9737          677 :               continue;
    9738              :             }
    9739              :         }
    9740         1156 :       list = &TREE_CHAIN (*list);
    9741              :     }
    9742         1564 : }
    9743              : 
    9744              : /* [basic.stc.dynamic.deallocation]/3 - A deallocation function shall not
    9745              :    have a potentially throwing exception specification.  */
    9746              : 
    9747              : void
    9748    208641923 : maybe_diagnose_deallocation_noexcept_false (tree decl)
    9749              : {
    9750    208641923 :   if (cxx_dialect >= cxx29
    9751     17060208 :       && DECL_NAME (decl)
    9752     17060208 :       && IDENTIFIER_NEWDEL_OP_P (DECL_NAME (decl))
    9753    208682890 :       && !IDENTIFIER_NEW_OP_P (DECL_NAME (decl)))
    9754              :     {
    9755        22490 :       tree spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl));
    9756        22490 :       if (spec && spec == noexcept_false_spec)
    9757           15 :         error_at (DECL_SOURCE_LOCATION (decl),
    9758              :                   "deallocation function %qD declared possibly throwing",
    9759              :                   decl);
    9760              :     }
    9761    208641923 : }
    9762              : 
    9763              : static void cp_maybe_mangle_decomp (tree, cp_decomp *);
    9764              : 
    9765              : /* Finish processing of a declaration;
    9766              :    install its line number and initial value.
    9767              :    If the length of an array type is not known before,
    9768              :    it must be determined now, from the initial value, or it is an error.
    9769              : 
    9770              :    INIT is the initializer (if any) for DECL.  If INIT_CONST_EXPR_P is
    9771              :    true, then INIT is an integral constant expression.
    9772              : 
    9773              :    FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
    9774              :    if the (init) syntax was used.
    9775              : 
    9776              :    DECOMP is first identifier's DECL and identifier count in a structured
    9777              :    bindings, nullptr if not a structured binding.  */
    9778              : 
    9779              : void
    9780    336082701 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
    9781              :                 tree asmspec_tree, int flags, cp_decomp *decomp)
    9782              : {
    9783    336082701 :   vec<tree, va_gc> *cleanups = NULL;
    9784    336082701 :   const char *asmspec = NULL;
    9785    336082701 :   int was_readonly = 0;
    9786    336082701 :   bool var_definition_p = false;
    9787    336082701 :   tree auto_node;
    9788    336082701 :   auto_vec<tree> extra_cleanups;
    9789    336082701 :   tree aggregates1 = NULL_TREE;
    9790    336082701 :   struct decomp_cleanup {
    9791              :     tree decl;
    9792              :     cp_decomp *&decomp;
    9793    336080000 :     ~decomp_cleanup ()
    9794              :     {
    9795    336080000 :       if (decomp && DECL_DECOMPOSITION_P (decl))
    9796       237107 :         cp_finish_decomp (decl, decomp);
    9797    336080000 :     }
    9798    336082701 :   } decomp_cl = { decl, decomp };
    9799              : 
    9800    336082701 :   if (decl == error_mark_node)
    9801              :     return;
    9802    336082661 :   else if (! decl)
    9803              :     {
    9804            0 :       if (init)
    9805            0 :         error ("assignment (not initialization) in declaration");
    9806              :       return;
    9807              :     }
    9808              : 
    9809    336082661 :   gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    9810              :   /* Parameters are handled by store_parm_decls, not cp_finish_decl.  */
    9811    336082661 :   gcc_assert (TREE_CODE (decl) != PARM_DECL);
    9812              : 
    9813    336082661 :   tree type = TREE_TYPE (decl);
    9814    336082661 :   if (type == error_mark_node)
    9815              :     return;
    9816              : 
    9817    336082015 :   if (VAR_P (decl) && is_copy_initialization (init))
    9818    100417696 :     flags |= LOOKUP_ONLYCONVERTING;
    9819              : 
    9820              :   /* Warn about register storage specifiers except when in GNU global
    9821              :      or local register variable extension.  */
    9822    336082015 :   if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
    9823              :     {
    9824         1931 :       if (cxx_dialect >= cxx17)
    9825         1282 :         pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    9826              :                  "ISO C++17 does not allow %<register%> storage "
    9827              :                  "class specifier");
    9828              :       else
    9829          649 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    9830              :                     "%<register%> storage class specifier used");
    9831              :     }
    9832              : 
    9833              :   /* If a name was specified, get the string.  */
    9834    336082015 :   if (at_namespace_scope_p ())
    9835     72742262 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    9836    336082015 :   if (asmspec_tree && asmspec_tree != error_mark_node)
    9837      1019258 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    9838              : 
    9839    336082015 :   bool in_class_decl
    9840    336082015 :     = (current_class_type
    9841    211943864 :        && CP_DECL_CONTEXT (decl) == current_class_type
    9842    140370618 :        && TYPE_BEING_DEFINED (current_class_type)
    9843    474396489 :        && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
    9844              : 
    9845    133110821 :   if (in_class_decl
    9846    133110821 :       && (DECL_INITIAL (decl) || init))
    9847     97741256 :     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
    9848              : 
    9849    336082015 :   if (VAR_P (decl)
    9850    336082015 :       && (auto_node = type_uses_auto (type)))
    9851              :     {
    9852     14274085 :       tree d_init;
    9853     14274085 :       if (init == NULL_TREE)
    9854              :         {
    9855         4610 :           if (DECL_LANG_SPECIFIC (decl)
    9856         4525 :               && DECL_TEMPLATE_INSTANTIATION (decl)
    9857         9132 :               && !DECL_TEMPLATE_INSTANTIATED (decl))
    9858              :             {
    9859              :               /* init is null because we're deferring instantiating the
    9860              :                  initializer until we need it.  Well, we need it now.  */
    9861         4516 :               instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
    9862         4516 :               return;
    9863              :             }
    9864              : 
    9865           94 :           if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    9866              :             /* Class deduction with no initializer is OK.  */;
    9867              :           else
    9868              :             {
    9869              :               /* Ordinary auto deduction without an initializer, a situation
    9870              :                  which grokdeclarator already detects and rejects for the most
    9871              :                  part.  But we can still get here if we're instantiating a
    9872              :                  variable template before we've fully parsed (and attached) its
    9873              :                  initializer, e.g. template<class> auto x = x<int>;  */
    9874            3 :               error_at (DECL_SOURCE_LOCATION (decl),
    9875              :                         "declaration of %q#D has no initializer", decl);
    9876            3 :               TREE_TYPE (decl) = error_mark_node;
    9877            3 :               return;
    9878              :             }
    9879              :         }
    9880     14269566 :       d_init = init;
    9881     14269566 :       if (d_init)
    9882              :         {
    9883     14269475 :           if (TREE_CODE (d_init) == TREE_LIST
    9884     14343733 :               && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    9885        47577 :             d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
    9886              :                                                       tf_warning_or_error);
    9887     14269475 :           d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
    9888              :           /* Force auto deduction now.  Use tf_none to avoid redundant warnings
    9889              :              on deprecated-14.C.  */
    9890     14269475 :           mark_single_function (d_init, tf_none);
    9891              :         }
    9892     14269566 :       enum auto_deduction_context adc = adc_variable_type;
    9893     14269566 :       if (DECL_DECOMPOSITION_P (decl))
    9894              :         adc = adc_decomp_type;
    9895     14269566 :       tree outer_targs = NULL_TREE;
    9896     14269566 :       if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
    9897          325 :           && DECL_LANG_SPECIFIC (decl)
    9898          126 :           && DECL_TEMPLATE_INFO (decl)
    9899     14269623 :           && !DECL_FUNCTION_SCOPE_P (decl))
    9900              :         /* The outer template arguments might be needed for satisfaction.
    9901              :            (For function scope variables, do_auto_deduction will obtain the
    9902              :            outer template arguments from current_function_decl.)  */
    9903           57 :         outer_targs = DECL_TI_ARGS (decl);
    9904     14269566 :       type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
    9905              :                                                    tf_warning_or_error, adc,
    9906              :                                                    outer_targs, flags);
    9907     14269566 :       if (type == error_mark_node)
    9908              :         return;
    9909     14268357 :       if (TREE_CODE (type) == FUNCTION_TYPE)
    9910              :         {
    9911            3 :           error ("initializer for %<decltype(auto) %D%> has function type; "
    9912              :                  "did you forget the %<()%>?", decl);
    9913            3 :           TREE_TYPE (decl) = error_mark_node;
    9914            3 :           return;
    9915              :         }
    9916              :       /* As in start_decl_1, complete so TREE_READONLY is set properly.  */
    9917     14268354 :       if (!processing_template_decl
    9918      3162126 :           && !type_uses_auto (type)
    9919     17430473 :           && !COMPLETE_TYPE_P (complete_type (type)))
    9920              :         {
    9921           18 :           auto_diagnostic_group d;
    9922           18 :           error_at (location_of (decl),
    9923              :                     "deduced type %qT for %qD is incomplete", type, decl);
    9924           18 :           cxx_incomplete_type_inform (type);
    9925           18 :           TREE_TYPE (decl) = error_mark_node;
    9926           18 :           return;
    9927           18 :         }
    9928              : 
    9929              :       /* Now that we have a type, try these again.  */
    9930     14268336 :       layout_decl (decl, 0);
    9931     14268336 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    9932              : 
    9933              :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    9934     14268336 :       if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    9935              :         {
    9936       289388 :           tree tmpl = template_for_substitution (decl);
    9937       289388 :           if (DECL_TEMPLATE_RESULT (tmpl) == decl)
    9938       277159 :             TREE_TYPE (tmpl) = type;
    9939              :         }
    9940              :     }
    9941              : 
    9942    336076266 :   if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
    9943              :     {
    9944           65 :       DECL_DECLARED_CONSTEXPR_P (decl) = 0;
    9945           65 :       if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
    9946              :         {
    9947            6 :           init = NULL_TREE;
    9948            6 :           DECL_EXTERNAL (decl) = 1;
    9949              :         }
    9950              :     }
    9951              : 
    9952    336076266 :   if (VAR_P (decl)
    9953    126950232 :       && DECL_CLASS_SCOPE_P (decl)
    9954     20382628 :       && verify_type_context (DECL_SOURCE_LOCATION (decl),
    9955              :                               TCTX_STATIC_STORAGE, type)
    9956    356458894 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    9957     19021560 :     check_static_variable_definition (decl, type);
    9958              : 
    9959    336076266 :   if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
    9960              :     {
    9961     37754988 :       type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    9962     37754988 :                                    ? TCTX_THREAD_STORAGE
    9963              :                                    : TCTX_STATIC_STORAGE);
    9964     37754988 :       verify_type_context (input_location, context, TREE_TYPE (decl));
    9965              :     }
    9966              : 
    9967    336076266 :   if (init && TREE_CODE (decl) == FUNCTION_DECL)
    9968              :     {
    9969       586113 :       tree clone;
    9970       586113 :       if (init == ridpointers[(int)RID_DELETE]
    9971       586113 :           || (TREE_CODE (init) == STRING_CST
    9972           36 :               && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
    9973              :         {
    9974              :           /* FIXME check this is 1st decl.  */
    9975       563529 :           if (UNLIKELY (DECL_MAIN_P (decl)))
    9976              :             {
    9977              :               /* [basic.start.main]/3: A program that defines main as deleted
    9978              :                  is ill-formed.  */
    9979            6 :               error ("%<::main%> cannot be deleted");
    9980            6 :               DECL_INITIAL (decl) = error_mark_node;
    9981              :             }
    9982              :           else
    9983              :             {
    9984       563523 :               DECL_DELETED_FN (decl) = 1;
    9985       563523 :               DECL_DECLARED_INLINE_P (decl) = 1;
    9986       563523 :               DECL_INITIAL (decl)
    9987       563523 :                 = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
    9988       563541 :               FOR_EACH_CLONE (clone, decl)
    9989              :                 {
    9990           18 :                   DECL_DELETED_FN (clone) = 1;
    9991           18 :                   DECL_DECLARED_INLINE_P (clone) = 1;
    9992           18 :                   DECL_INITIAL (clone) = DECL_INITIAL (decl);
    9993              :                 }
    9994              :             }
    9995       563529 :           init = NULL_TREE;
    9996              :         }
    9997        22584 :       else if (init == ridpointers[(int)RID_DEFAULT])
    9998              :         {
    9999        22572 :           if (defaultable_fn_check (decl))
   10000        22548 :             DECL_DEFAULTED_FN (decl) = 1;
   10001              :           else
   10002           24 :             DECL_INITIAL (decl) = NULL_TREE;
   10003              :         }
   10004              :     }
   10005              : 
   10006    336076266 :   if (init && VAR_P (decl))
   10007              :     {
   10008    110454486 :       DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
   10009              :       /* If DECL is a reference, then we want to know whether init is a
   10010              :          reference constant; init_const_expr_p as passed tells us whether
   10011              :          it's an rvalue constant.  */
   10012    110454486 :       if (TYPE_REF_P (type))
   10013      2380115 :         init_const_expr_p = potential_constant_expression (init);
   10014    110454486 :       if (init_const_expr_p)
   10015              :         {
   10016              :           /* Set these flags now for templates.  We'll update the flags in
   10017              :              store_init_value for instantiations.  */
   10018     97286075 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
   10019     97286075 :           if (decl_maybe_constant_var_p (decl)
   10020              :               /* FIXME setting TREE_CONSTANT on refs breaks the back end.  */
   10021     97286075 :               && !TYPE_REF_P (type))
   10022     42851894 :             TREE_CONSTANT (decl) = true;
   10023              :         }
   10024              :       /* This is handled mostly by gimplify.cc, but we have to deal with
   10025              :          not warning about int x = x; as it is a GCC extension to turn off
   10026              :          this warning but only if warn_init_self is zero.  */
   10027    110454486 :       if (!DECL_EXTERNAL (decl)
   10028    108810014 :           && !TREE_STATIC (decl)
   10029     73520528 :           && decl == tree_strip_any_location_wrapper (init)
   10030    219264500 :           && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
   10031         3760 :         suppress_warning (decl, OPT_Winit_self);
   10032              :     }
   10033    225621780 :   else if (VAR_P (decl)
   10034     16495746 :            && COMPLETE_TYPE_P (type)
   10035     12969389 :            && !TYPE_REF_P (type)
   10036     12968681 :            && !dependent_type_p (type)
   10037    238259711 :            && is_really_empty_class (type, /*ignore_vptr*/false))
   10038              :     /* We have no initializer but there's nothing to initialize anyway.
   10039              :        Treat DECL as constant due to c++/109876.  */
   10040       598281 :     TREE_CONSTANT (decl) = true;
   10041              : 
   10042    336076266 :   if (flag_openmp
   10043       888631 :       && TREE_CODE (decl) == FUNCTION_DECL
   10044              :       /* #pragma omp declare variant on methods handled in finish_struct
   10045              :          instead.  */
   10046    336459429 :       && (!DECL_OBJECT_MEMBER_FUNCTION_P (decl)
   10047       144411 :           || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
   10048       239215 :     if (tree attr = lookup_attribute ("omp declare variant base",
   10049       239215 :                                       DECL_ATTRIBUTES (decl)))
   10050          970 :       omp_declare_variant_finalize (decl, attr);
   10051              : 
   10052    336076266 :   if (processing_template_decl)
   10053              :     {
   10054    193632638 :       bool type_dependent_p;
   10055              : 
   10056              :       /* Add this declaration to the statement-tree.  */
   10057    193632638 :       if (at_function_scope_p ())
   10058     69632165 :         add_decl_expr (decl);
   10059              : 
   10060    193632638 :       type_dependent_p = dependent_type_p (type);
   10061              : 
   10062    193632638 :       if (check_for_bare_parameter_packs (init))
   10063              :         {
   10064            3 :           init = NULL_TREE;
   10065            3 :           DECL_INITIAL (decl) = NULL_TREE;
   10066              :         }
   10067              : 
   10068              :       /* Generally, initializers in templates are expanded when the
   10069              :          template is instantiated.  But, if DECL is a variable constant
   10070              :          then it can be used in future constant expressions, so its value
   10071              :          must be available. */
   10072              : 
   10073    193632638 :       bool dep_init = false;
   10074              : 
   10075    193632638 :       if (!VAR_P (decl) || type_dependent_p)
   10076              :         /* We can't do anything if the decl has dependent type.  */;
   10077     24162189 :       else if (init
   10078     22461446 :                && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
   10079     18313660 :                && !TYPE_REF_P (type)
   10080     18279916 :                && decl_maybe_constant_var_p (decl)
   10081     33668442 :                && !(dep_init = value_dependent_init_p (init)))
   10082              :         {
   10083              :           /* This variable seems to be a non-dependent constant, so process
   10084              :              its initializer.  If check_initializer returns non-null the
   10085              :              initialization wasn't constant after all.  */
   10086      2497322 :           tree init_code;
   10087      2497322 :           cleanups = make_tree_vector ();
   10088      2497322 :           init_code = check_initializer (decl, init, flags, &cleanups);
   10089      2497320 :           if (init_code == NULL_TREE)
   10090      2497320 :             init = NULL_TREE;
   10091      2497320 :           release_tree_vector (cleanups);
   10092              :         }
   10093              :       else
   10094              :         {
   10095     21664867 :           gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
   10096              :           /* Try to deduce array size.  */
   10097     21664867 :           maybe_deduce_size_from_array_init (decl, init);
   10098              :           /* And complain about multiple initializers.  */
   10099     19964124 :           if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
   10100     21771087 :               && !MAYBE_CLASS_TYPE_P (type))
   10101            7 :             init = build_x_compound_expr_from_list (init, ELK_INIT,
   10102              :                                                     tf_warning_or_error);
   10103              :         }
   10104              : 
   10105    193632636 :       if (init)
   10106     58145167 :         DECL_INITIAL (decl) = init;
   10107              : 
   10108    193632636 :       if (dep_init)
   10109              :         {
   10110      7008931 :           retrofit_lang_decl (decl);
   10111      7008931 :           SET_DECL_DEPENDENT_INIT_P (decl, true);
   10112              :         }
   10113              : 
   10114    193632636 :       if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
   10115              :         {
   10116            9 :           if (TREE_ADDRESSABLE (decl))
   10117            3 :             error_at (DECL_SOURCE_LOCATION (decl),
   10118              :                       "address of explicit register variable %qD requested",
   10119              :                       decl);
   10120              :           else
   10121              :             {
   10122            6 :               set_user_assembler_name (decl, asmspec);
   10123            6 :               DECL_HARD_REGISTER (decl) = 1;
   10124              :             }
   10125              :         }
   10126              :       return;
   10127              :     }
   10128              : 
   10129              :   /* Just store non-static data member initializers for later.  */
   10130    142443628 :   if (init && TREE_CODE (decl) == FIELD_DECL)
   10131       612606 :     DECL_INITIAL (decl) = init;
   10132              : 
   10133              :   /* Take care of TYPE_DECLs up front.  */
   10134    142443628 :   if (TREE_CODE (decl) == TYPE_DECL)
   10135              :     {
   10136     11084792 :       if (type != error_mark_node
   10137     11084792 :           && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
   10138              :         {
   10139      5305181 :           if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
   10140            0 :             warning (0, "shadowing previous type declaration of %q#D", decl);
   10141      5305181 :           set_identifier_type_value (DECL_NAME (decl), decl);
   10142              :         }
   10143              : 
   10144              :       /* If we have installed this as the canonical typedef for this
   10145              :          type, and that type has not been defined yet, delay emitting
   10146              :          the debug information for it, as we will emit it later.  */
   10147     11084792 :       if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
   10148     11084792 :           && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
   10149       609665 :         TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
   10150              : 
   10151     11084792 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
   10152              :                                 at_eof);
   10153     11084792 :       return;
   10154              :     }
   10155              : 
   10156              :   /* A reference will be modified here, as it is initialized.  */
   10157    131358836 :   if (! DECL_EXTERNAL (decl)
   10158     64415805 :       && TREE_READONLY (decl)
   10159    169801106 :       && TYPE_REF_P (type))
   10160              :     {
   10161       253571 :       was_readonly = 1;
   10162       253571 :       TREE_READONLY (decl) = 0;
   10163              :     }
   10164              : 
   10165              :   /* This needs to happen before extend_ref_init_temps.  */
   10166    131358836 :   if (VAR_OR_FUNCTION_DECL_P (decl))
   10167              :     {
   10168    121888828 :       if (VAR_P (decl))
   10169     62882164 :         maybe_commonize_var (decl);
   10170    121888828 :       determine_visibility (decl);
   10171              :     }
   10172              : 
   10173    131358836 :   if (VAR_P (decl))
   10174              :     {
   10175     62882164 :       duration_kind dk = decl_storage_duration (decl);
   10176              :       /* [dcl.constinit]/1 "The constinit specifier shall be applied
   10177              :          only to a declaration of a variable with static or thread storage
   10178              :          duration."  */
   10179     62882164 :       if (DECL_DECLARED_CONSTINIT_P (decl)
   10180     62882164 :           && !(dk == dk_thread || dk == dk_static))
   10181              :         {
   10182           24 :           error_at (DECL_SOURCE_LOCATION (decl),
   10183              :                     "%<constinit%> can only be applied to a variable with "
   10184              :                     "static or thread storage duration");
   10185           24 :           return;
   10186              :         }
   10187              : 
   10188     62882140 :       if (decomp)
   10189              :         {
   10190        69164 :           if (DECL_DECLARED_CONSTINIT_P (decl) && cxx_dialect < cxx26)
   10191           40 :             pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
   10192              :                      "%<constinit%> can be applied to structured binding "
   10193              :                      "only with %<-std=c++2c%> or %<-std=gnu++2c%>");
   10194        69164 :           cp_maybe_mangle_decomp (decl, decomp);
   10195        69164 :           if (TREE_STATIC (decl) && !DECL_FUNCTION_SCOPE_P (decl))
   10196              :             {
   10197          628 :               if (CP_DECL_THREAD_LOCAL_P (decl))
   10198           37 :                 aggregates1 = tls_aggregates;
   10199              :               else
   10200          591 :                 aggregates1 = static_aggregates;
   10201              :             }
   10202              :         }
   10203              : 
   10204              :       /* If this is a local variable that will need a mangled name,
   10205              :          register it now.  We must do this before processing the
   10206              :          initializer for the variable, since the initialization might
   10207              :          require a guard variable, and since the mangled name of the
   10208              :          guard variable will depend on the mangled name of this
   10209              :          variable.  */
   10210     62882140 :       if (DECL_FUNCTION_SCOPE_P (decl) && TREE_STATIC (decl))
   10211              :         {
   10212              :           /* The variable holding an anonymous union will have had its
   10213              :              discriminator set in finish_anon_union, after which it's
   10214              :              NAME will have been cleared.  */
   10215       142251 :           if (DECL_NAME (decl))
   10216       141932 :             determine_local_discriminator (decl);
   10217              :           /* Normally has_forced_label_in_static is set during GIMPLE
   10218              :              lowering, but [cd]tors are never actually compiled directly.
   10219              :              We need to set this early so we can deal with the label
   10220              :              address extension.  */
   10221       142251 :           if ((DECL_CONSTRUCTOR_P (current_function_decl)
   10222       142210 :                || DECL_DESTRUCTOR_P (current_function_decl))
   10223       142267 :               && init)
   10224              :             {
   10225           29 :               walk_tree (&init, notice_forced_label_r, NULL, NULL);
   10226           29 :               add_local_decl (cfun, decl);
   10227              :             }
   10228              :           /* And make sure it's in the symbol table for
   10229              :              c_parse_final_cleanups to find.  */
   10230       142251 :           gcc_checking_assert (!consteval_only_p (decl));
   10231       142251 :           varpool_node::get_create (decl);
   10232              :         }
   10233              : 
   10234     62882140 :       if (flag_openmp
   10235       202249 :           && VAR_P (decl)
   10236       202249 :           && DECL_LANG_SPECIFIC (decl)
   10237       117061 :           && DECL_OMP_DECLARE_MAPPER_P (decl)
   10238     62882153 :           && init)
   10239              :         {
   10240           12 :           gcc_assert (TREE_CODE (init) == OMP_DECLARE_MAPPER);
   10241           12 :           DECL_INITIAL (decl) = init;
   10242              :         }
   10243              :       /* Convert the initializer to the type of DECL, if we have not
   10244              :          already initialized DECL.  */
   10245     62882128 :       else if (!DECL_INITIALIZED_P (decl)
   10246              :                /* If !DECL_EXTERNAL then DECL is being defined.  In the
   10247              :                   case of a static data member initialized inside the
   10248              :                   class-specifier, there can be an initializer even if DECL
   10249              :                   is *not* defined.  */
   10250     62882128 :                && (!DECL_EXTERNAL (decl) || init))
   10251              :         {
   10252     55967694 :           cleanups = make_tree_vector ();
   10253     55967694 :           init = check_initializer (decl, init, flags, &cleanups);
   10254              : 
   10255              :           /* Handle:
   10256              : 
   10257              :              [dcl.init]
   10258              : 
   10259              :              The memory occupied by any object of static storage
   10260              :              duration is zero-initialized at program startup before
   10261              :              any other initialization takes place.
   10262              : 
   10263              :              We cannot create an appropriate initializer until after
   10264              :              the type of DECL is finalized.  If DECL_INITIAL is set,
   10265              :              then the DECL is statically initialized, and any
   10266              :              necessary zero-initialization has already been performed.  */
   10267     55964997 :           if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
   10268       523871 :             DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
   10269              :                                                    /*nelts=*/NULL_TREE,
   10270              :                                                    /*static_storage_p=*/true);
   10271              :           /* Remember that the initialization for this variable has
   10272              :              taken place.  */
   10273     55964997 :           DECL_INITIALIZED_P (decl) = 1;
   10274              :           /* This declaration is the definition of this variable,
   10275              :              unless we are initializing a static data member within
   10276              :              the class specifier.  */
   10277     55964997 :           if (!DECL_EXTERNAL (decl))
   10278     62879443 :             var_definition_p = true;
   10279              :         }
   10280              :       /* If the variable has an array type, lay out the type, even if
   10281              :          there is no initializer.  It is valid to index through the
   10282              :          array, and we must get TYPE_ALIGN set correctly on the array
   10283              :          type.  */
   10284      6914434 :       else if (TREE_CODE (type) == ARRAY_TYPE)
   10285       215856 :         layout_type (type);
   10286              : 
   10287     62879443 :       if (TREE_STATIC (decl)
   10288     37194045 :           && !at_function_scope_p ()
   10289     99931237 :           && current_function_decl == NULL)
   10290              :         /* So decl is a global variable or a static member of a
   10291              :            non local class. Record the types it uses
   10292              :            so that we can decide later to emit debug info for them.  */
   10293     37051782 :         record_types_used_by_current_var_decl (decl);
   10294              :     }
   10295              : 
   10296              :   /* Add this declaration to the statement-tree.  This needs to happen
   10297              :      after the call to check_initializer so that the DECL_EXPR for a
   10298              :      reference temp is added before the DECL_EXPR for the reference itself.  */
   10299    131356115 :   if (DECL_FUNCTION_SCOPE_P (decl))
   10300              :     {
   10301              :       /* If we're building a variable sized type, and we might be
   10302              :          reachable other than via the top of the current binding
   10303              :          level, then create a new BIND_EXPR so that we deallocate
   10304              :          the object at the right time.  */
   10305     25269275 :       if (VAR_P (decl)
   10306     25269275 :           && DECL_SIZE (decl)
   10307     25207403 :           && !TREE_CONSTANT (DECL_SIZE (decl))
   10308     25270322 :           && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
   10309              :         {
   10310            3 :           tree bind;
   10311            3 :           bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
   10312            3 :           TREE_SIDE_EFFECTS (bind) = 1;
   10313            3 :           add_stmt (bind);
   10314            3 :           BIND_EXPR_BODY (bind) = push_stmt_list ();
   10315              :         }
   10316     25269275 :       add_decl_expr (decl);
   10317              :     }
   10318              : 
   10319    131356115 :   tree decomp_init = NULL_TREE;
   10320              :   /* Let the middle end know about variables and functions -- but not
   10321              :      static data members in uninstantiated class templates.  */
   10322    131356115 :   if (VAR_OR_FUNCTION_DECL_P (decl))
   10323              :     {
   10324    121886107 :       if (VAR_P (decl))
   10325              :         {
   10326     62879443 :           layout_var_decl (decl);
   10327     62879443 :           if (!flag_weak)
   10328              :             /* Check again now that we have an initializer.  */
   10329           57 :             maybe_commonize_var (decl);
   10330              :           /* A class-scope constexpr variable with an out-of-class declaration.
   10331              :              C++17 makes them implicitly inline, but still force it out.  */
   10332     84730488 :           if (DECL_INLINE_VAR_P (decl)
   10333     29469201 :               && !DECL_VAR_DECLARED_INLINE_P (decl)
   10334     13214650 :               && !DECL_TEMPLATE_INSTANTIATION (decl)
   10335     47299556 :               && !in_class_decl)
   10336          118 :             mark_needed (decl);
   10337              :         }
   10338              : 
   10339    121886107 :       if (var_definition_p
   10340              :           /* With -fmerge-all-constants, gimplify_init_constructor
   10341              :              might add TREE_STATIC to aggregate variables.  */
   10342     54780721 :           && (TREE_STATIC (decl)
   10343     25127152 :               || (flag_merge_constants >= 2
   10344           38 :                   && AGGREGATE_TYPE_P (type))))
   10345              :         {
   10346              :           /* If a TREE_READONLY variable needs initialization
   10347              :              at runtime, it is no longer readonly and we need to
   10348              :              avoid MEM_READONLY_P being set on RTL created for it.  */
   10349     29653572 :           if (init)
   10350              :             {
   10351        14305 :               if (TREE_READONLY (decl))
   10352          346 :                 TREE_READONLY (decl) = 0;
   10353              :               was_readonly = 0;
   10354              :             }
   10355     29639267 :           else if (was_readonly)
   10356         2622 :             TREE_READONLY (decl) = 1;
   10357              : 
   10358              :           /* Likewise if it needs destruction.  */
   10359     29653572 :           if (!decl_maybe_constant_destruction (decl, type))
   10360         3567 :             TREE_READONLY (decl) = 0;
   10361              :         }
   10362     92232535 :       else if (VAR_P (decl)
   10363     33225871 :                && CP_DECL_THREAD_LOCAL_P (decl)
   10364        19281 :                && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
   10365        19281 :                && (was_readonly || TREE_READONLY (decl))
   10366     92232550 :                && var_needs_tls_wrapper (decl))
   10367              :         {
   10368              :           /* TLS variables need dynamic initialization by the TLS wrapper
   10369              :              function, we don't want to hoist accesses to it before the
   10370              :              wrapper.  */
   10371            6 :           was_readonly = 0;
   10372            6 :           TREE_READONLY (decl) = 0;
   10373              :         }
   10374              : 
   10375    121886107 :       make_rtl_for_nonlocal_decl (decl, init, asmspec);
   10376              : 
   10377              :       /* Check for abstractness of the type.  */
   10378    121886105 :       if (var_definition_p)
   10379     54780719 :         abstract_virtuals_error (decl, type);
   10380              : 
   10381    121886105 :       if (decomp && !cp_finish_decomp (decl, decomp, true))
   10382        33473 :         decomp = NULL;
   10383              : 
   10384    121886105 :       if (TREE_TYPE (decl) == error_mark_node)
   10385              :         /* No initialization required.  */
   10386              :         ;
   10387    121886012 :       else if (TREE_CODE (decl) == FUNCTION_DECL)
   10388              :         {
   10389     59006664 :           if (init)
   10390              :             {
   10391          602 :               if (init == ridpointers[(int)RID_DEFAULT])
   10392              :                 {
   10393              :                   /* An out-of-class default definition is defined at
   10394              :                      the point where it is explicitly defaulted.  */
   10395          590 :                   if (DECL_DELETED_FN (decl))
   10396           17 :                     maybe_explain_implicit_delete (decl);
   10397          573 :                   else if (DECL_INITIAL (decl) == error_mark_node)
   10398          549 :                     synthesize_method (decl);
   10399              :                 }
   10400              :               else
   10401           24 :                 error_at (cp_expr_loc_or_loc (init,
   10402           12 :                                               DECL_SOURCE_LOCATION (decl)),
   10403              :                           "function %q#D is initialized like a variable",
   10404              :                           decl);
   10405              :             }
   10406              :           /* else no initialization required.  */
   10407              :         }
   10408     62879348 :       else if (DECL_EXTERNAL (decl)
   10409     62879348 :                && ! (DECL_LANG_SPECIFIC (decl)
   10410      7795240 :                      && DECL_NOT_REALLY_EXTERN (decl)))
   10411              :         {
   10412              :           /* check_initializer will have done any constant initialization.  */
   10413              :         }
   10414              :       /* A variable definition.  */
   10415     56704243 :       else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
   10416              :         {
   10417              :           /* Initialize the local variable.  */
   10418     25126997 :           if (!decomp)
   10419     25091560 :             initialize_local_var (decl, init, false);
   10420              :           else
   10421              :             {
   10422        35437 :               tree cleanup = NULL_TREE;
   10423        35437 :               if (DECL_SIZE (decl))
   10424        35437 :                 cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   10425              :               /* If cp_finish_decomp needs to emit any code, we need to emit that
   10426              :                  code after code emitted by initialize_local_var in a single
   10427              :                  CLEANUP_POINT_EXPR, so that temporaries are destructed only
   10428              :                  after the cp_finish_decomp emitted code.
   10429              :                  If there are any cleanups, either extend_ref_init_temps
   10430              :                  created ones or e.g. array destruction, push those first
   10431              :                  with the cleanups guarded on a bool temporary, initially
   10432              :                  set to false and set to true after initialize_local_var
   10433              :                  emitted code.  */
   10434        35437 :               tree guard = NULL_TREE;
   10435        35437 :               if (cleanups || cleanup)
   10436              :                 {
   10437              :                   /* Since the CLEANUP_STMT will refer to the guard, we need it
   10438              :                       to be a variable with the same lifetime.  ??? It might be
   10439              :                       better to use wrap_temporary_cleanups.  */
   10440        35437 :                   guard = get_temp_regvar (boolean_type_node, boolean_false_node);
   10441              :                   /* And make sure register_local_var_uses sees it.  */
   10442        35437 :                   pushdecl (guard);
   10443              :                 }
   10444              : 
   10445        35437 :               tree sl = push_stmt_list ();
   10446        35437 :               initialize_local_var (decl, init, true);
   10447        35437 :               if (guard)
   10448              :                 {
   10449        35437 :                   add_stmt (build2 (MODIFY_EXPR, boolean_type_node,
   10450              :                                     guard, boolean_true_node));
   10451        35455 :                   for (tree &t : *cleanups)
   10452           18 :                     t = build3 (COND_EXPR, void_type_node,
   10453              :                                 guard, t, void_node);
   10454        35437 :                   if (cleanup)
   10455           32 :                     cleanup = build3 (COND_EXPR, void_type_node,
   10456              :                                       guard, cleanup, void_node);
   10457              :                 }
   10458        35437 :               unsigned before = stmt_list_stack->length ();
   10459        35437 :               cp_finish_decomp (decl, decomp);
   10460        35437 :               decomp = NULL;
   10461        35437 :               unsigned n_extra_cleanups = stmt_list_stack->length () - before;
   10462        35437 :               sl = pop_stmt_list (sl);
   10463        35437 :               if (n_extra_cleanups)
   10464              :                 {
   10465              :                   /* If cp_finish_decomp needs any cleanups, such as for
   10466              :                      extend_ref_init_temps created vars, pop_stmt_list
   10467              :                      popped that all, so push those extra cleanups around
   10468              :                      the whole sequence with a guard variable.  */
   10469           15 :                   gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
   10470           15 :                   guard = get_temp_regvar (integer_type_node, integer_zero_node);
   10471           15 :                   pushdecl (guard);
   10472           78 :                   for (unsigned i = 0; i < n_extra_cleanups; ++i)
   10473              :                     {
   10474           48 :                       tree_stmt_iterator tsi = tsi_last (sl);
   10475           48 :                       gcc_assert (!tsi_end_p (tsi));
   10476           48 :                       tree last = tsi_stmt (tsi);
   10477           48 :                       gcc_assert (TREE_CODE (last) == CLEANUP_STMT
   10478              :                                   && !CLEANUP_EH_ONLY (last));
   10479           48 :                       tree cst = build_int_cst (integer_type_node, i + 1);
   10480           96 :                       tree cl = build3 (COND_EXPR, void_type_node,
   10481              :                                         build2 (GE_EXPR, boolean_type_node,
   10482              :                                                 guard, cst),
   10483           48 :                                         CLEANUP_EXPR (last), void_node);
   10484           48 :                       extra_cleanups.safe_push (cl);
   10485           48 :                       tsi_link_before (&tsi, build2 (MODIFY_EXPR,
   10486              :                                                      integer_type_node,
   10487              :                                                      guard, cst),
   10488              :                                        TSI_SAME_STMT);
   10489           48 :                       tree sl2 = CLEANUP_BODY (last);
   10490           48 :                       gcc_assert (TREE_CODE (sl2) == STATEMENT_LIST);
   10491           48 :                       tsi_link_before (&tsi, sl2, TSI_SAME_STMT);
   10492           48 :                       tsi_delink (&tsi);
   10493              :                     }
   10494              :                 }
   10495        35437 :               decomp_init = maybe_cleanup_point_expr_void (sl);
   10496        35437 :               if (cleanup)
   10497           32 :                 finish_decl_cleanup (decl, cleanup);
   10498              :             }
   10499              :         }
   10500              : 
   10501              :       /* If a variable is defined, and then a subsequent
   10502              :          definition with external linkage is encountered, we will
   10503              :          get here twice for the same variable.  We want to avoid
   10504              :          calling expand_static_init more than once.  For variables
   10505              :          that are not static data members, we can call
   10506              :          expand_static_init only when we actually process the
   10507              :          initializer.  It is not legal to redeclare a static data
   10508              :          member, so this issue does not arise in that case.  */
   10509     31577246 :       else if (var_definition_p && TREE_STATIC (decl))
   10510              :         {
   10511     29652007 :           if (decomp && DECL_FUNCTION_SCOPE_P (decl))
   10512              :             {
   10513          106 :               tree sl = push_stmt_list ();
   10514          106 :               auto saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
   10515          106 :               current_stmt_tree ()->stmts_are_full_exprs_p = 0;
   10516          106 :               expand_static_init (decl, init);
   10517          106 :               current_stmt_tree ()->stmts_are_full_exprs_p
   10518          106 :                 = saved_stmts_are_full_exprs_p;
   10519          106 :               cp_finish_decomp (decl, decomp);
   10520          106 :               decomp = NULL;
   10521          106 :               sl = pop_stmt_list (sl);
   10522          106 :               sl = maybe_cleanup_point_expr_void (sl);
   10523          106 :               add_stmt (sl);
   10524              :             }
   10525              :           else
   10526     29651901 :             expand_static_init (decl, init);
   10527              :         }
   10528              :     }
   10529              : 
   10530              :   /* If a CLEANUP_STMT was created to destroy a temporary bound to a
   10531              :      reference, insert it in the statement-tree now.  */
   10532    131356113 :   if (cleanups)
   10533              :     {
   10534     55968461 :       for (tree t : *cleanups)
   10535              :         {
   10536         3466 :           push_cleanup (NULL_TREE, t, false);
   10537              :           /* As in initialize_local_var.  */
   10538         3466 :           wrap_temporary_cleanups (init, t);
   10539              :         }
   10540     55964995 :       release_tree_vector (cleanups);
   10541              :     }
   10542              : 
   10543    131356191 :   for (tree t : &extra_cleanups)
   10544           48 :     push_cleanup (NULL_TREE, t, false);
   10545              : 
   10546    131356113 :   if (decomp_init)
   10547        35437 :     add_stmt (decomp_init);
   10548              : 
   10549    131356113 :   if (decomp
   10550          148 :       && var_definition_p
   10551          148 :       && TREE_STATIC (decl)
   10552    131356261 :       && !DECL_FUNCTION_SCOPE_P (decl))
   10553              :     {
   10554          146 :       tree &aggregates3 = (CP_DECL_THREAD_LOCAL_P (decl)
   10555          146 :                            ? tls_aggregates : static_aggregates);
   10556          146 :       tree aggregates2 = aggregates3;
   10557          146 :       if (aggregates2 != aggregates1)
   10558              :         {
   10559           66 :           cp_finish_decomp (decl, decomp);
   10560           66 :           decomp = NULL;
   10561           66 :           if (aggregates3 != aggregates2)
   10562              :             {
   10563              :               /* If there are dynamic initializers for the structured
   10564              :                  binding base or associated extended ref temps and also
   10565              :                  dynamic initializers for the structured binding non-base
   10566              :                  vars, mark them.  */
   10567          267 :               for (tree t = aggregates3; t != aggregates2; t = TREE_CHAIN (t))
   10568          204 :                 STATIC_INIT_DECOMP_NONBASE_P (t) = 1;
   10569          150 :               for (tree t = aggregates2; t != aggregates1; t = TREE_CHAIN (t))
   10570           87 :                 STATIC_INIT_DECOMP_BASE_P (t) = 1;
   10571              :             }
   10572              :         }
   10573              :     }
   10574              : 
   10575    131356113 :   if (was_readonly)
   10576       253001 :     TREE_READONLY (decl) = 1;
   10577              : 
   10578    131356113 :   if (flag_openmp
   10579       462897 :       && VAR_P (decl)
   10580    131558360 :       && lookup_attribute ("omp declare target implicit",
   10581       202247 :                            DECL_ATTRIBUTES (decl)))
   10582              :     {
   10583           52 :       DECL_ATTRIBUTES (decl)
   10584           52 :         = remove_attribute ("omp declare target implicit",
   10585           52 :                             DECL_ATTRIBUTES (decl));
   10586           52 :       complete_type (TREE_TYPE (decl));
   10587           52 :       if (!omp_mappable_type (TREE_TYPE (decl)))
   10588              :         {
   10589           30 :           auto_diagnostic_group d;
   10590           30 :           error ("%q+D in declare target directive does not have mappable"
   10591              :                  " type", decl);
   10592           30 :           if (TREE_TYPE (decl) != error_mark_node
   10593           30 :               && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
   10594           30 :             cxx_incomplete_type_inform (TREE_TYPE (decl));
   10595           30 :         }
   10596           22 :       else if (!lookup_attribute ("omp declare target",
   10597           22 :                                   DECL_ATTRIBUTES (decl))
   10598           44 :                && !lookup_attribute ("omp declare target link",
   10599           22 :                                      DECL_ATTRIBUTES (decl)))
   10600              :         {
   10601           22 :           DECL_ATTRIBUTES (decl)
   10602           22 :             = tree_cons (get_identifier ("omp declare target"),
   10603           22 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
   10604           22 :           symtab_node *node = symtab_node::get (decl);
   10605           22 :           if (node != NULL)
   10606              :             {
   10607           19 :               node->offloadable = 1;
   10608           19 :               if (ENABLE_OFFLOADING)
   10609              :                 {
   10610              :                   g->have_offload = true;
   10611              :                   if (is_a <varpool_node *> (node))
   10612              :                     vec_safe_push (offload_vars, decl);
   10613              :                 }
   10614              :             }
   10615              :         }
   10616              :     }
   10617              : 
   10618              :   /* This is the last point we can lower alignment so give the target the
   10619              :      chance to do so.  */
   10620    131356113 :   if (VAR_P (decl)
   10621     62879441 :       && !is_global_var (decl)
   10622    156483265 :       && !DECL_HARD_REGISTER (decl))
   10623     25127099 :     targetm.lower_local_decl_alignment (decl);
   10624              : 
   10625    131356113 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
   10626    336080000 : }
   10627              : 
   10628              : /* For class TYPE return itself or some its bases that contain
   10629              :    any direct non-static data members.  Return error_mark_node if an
   10630              :    error has been diagnosed.  */
   10631              : 
   10632              : static tree
   10633        31899 : find_decomp_class_base (location_t loc, tree type, tree ret,
   10634              :                         tsubst_flags_t complain)
   10635              : {
   10636        63798 :   if (LAMBDA_TYPE_P (type))
   10637              :     {
   10638           12 :       if (complain & tf_error)
   10639              :         {
   10640           12 :           auto_diagnostic_group d;
   10641           12 :           error_at (loc, "cannot decompose lambda closure type %qT", type);
   10642           12 :           inform (location_of (type), "lambda declared here");
   10643           12 :         }
   10644           12 :       return error_mark_node;
   10645              :     }
   10646              : 
   10647        31887 :   bool member_seen = false;
   10648       406604 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   10649       685039 :     if (TREE_CODE (field) != FIELD_DECL
   10650        64609 :         || DECL_ARTIFICIAL (field)
   10651       439265 :         || DECL_UNNAMED_BIT_FIELD (field))
   10652       310283 :       continue;
   10653        64473 :     else if (ret)
   10654              :       return type;
   10655        64447 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   10656              :       {
   10657            8 :         if ((complain & tf_error) == 0)
   10658            0 :           return error_mark_node;
   10659            8 :         auto_diagnostic_group d;
   10660            8 :         if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
   10661            4 :           error_at (loc, "cannot decompose class type %qT because it has an "
   10662              :                          "anonymous struct member", type);
   10663              :         else
   10664            4 :           error_at (loc, "cannot decompose class type %qT because it has an "
   10665              :                          "anonymous union member", type);
   10666            8 :         inform (DECL_SOURCE_LOCATION (field), "declared here");
   10667            8 :         return error_mark_node;
   10668            8 :       }
   10669        64439 :     else if (!accessible_p (type, field, true))
   10670              :       {
   10671            5 :         if ((complain & tf_error) == 0)
   10672            0 :           return error_mark_node;
   10673            5 :         auto_diagnostic_group d;
   10674            5 :         error_at (loc, "cannot decompose inaccessible member %qD of %qT",
   10675              :                   field, type);
   10676            5 :         inform (DECL_SOURCE_LOCATION (field),
   10677            5 :                 TREE_PRIVATE (field)
   10678              :                 ? G_("declared private here")
   10679              :                 : G_("declared protected here"));
   10680            5 :         return error_mark_node;
   10681            5 :       }
   10682              :     else
   10683              :       member_seen = true;
   10684              : 
   10685        31848 :   tree base_binfo, binfo;
   10686        31848 :   tree orig_ret = ret;
   10687        31848 :   int i;
   10688        31848 :   if (member_seen)
   10689        31743 :     ret = type;
   10690        31912 :   for (binfo = TYPE_BINFO (type), i = 0;
   10691        31912 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   10692              :     {
   10693           84 :       auto_diagnostic_group d;
   10694           84 :       tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret,
   10695              :                                        complain);
   10696           84 :       if (t == error_mark_node)
   10697              :         {
   10698            3 :           if (complain & tf_error)
   10699            3 :             inform (location_of (type), "in base class of %qT", type);
   10700            3 :           return error_mark_node;
   10701              :         }
   10702           81 :       if (t != NULL_TREE && t != ret)
   10703              :         {
   10704           54 :           if (ret == type)
   10705              :             {
   10706           10 :               if (complain & tf_error)
   10707           10 :                 error_at (loc, "cannot decompose class type %qT: both it and "
   10708              :                                "its base class %qT have non-static data "
   10709              :                                "members", type, t);
   10710           10 :               return error_mark_node;
   10711              :             }
   10712           44 :           else if (orig_ret != NULL_TREE)
   10713              :             return t;
   10714           44 :           else if (ret != NULL_TREE)
   10715              :             {
   10716            7 :               if (complain & tf_error)
   10717            7 :                 error_at (loc, "cannot decompose class type %qT: its base "
   10718              :                                "classes %qT and %qT have non-static data "
   10719              :                                "members", type, ret, t);
   10720            7 :               return error_mark_node;
   10721              :             }
   10722              :           else
   10723              :             ret = t;
   10724              :         }
   10725           84 :     }
   10726              :   return ret;
   10727              : }
   10728              : 
   10729              : /* Return std::tuple_size<TYPE>::value.  */
   10730              : 
   10731              : static tree
   10732       113140 : get_tuple_size (tree type)
   10733              : {
   10734       113140 :   tree args = make_tree_vec (1);
   10735       113140 :   TREE_VEC_ELT (args, 0) = type;
   10736       113140 :   tree inst = lookup_template_class (tuple_size_identifier, args,
   10737              :                                      /*in_decl*/NULL_TREE,
   10738              :                                      /*context*/std_node,
   10739              :                                      tf_none);
   10740       113140 :   inst = complete_type (inst);
   10741       113140 :   if (inst == error_mark_node
   10742       111624 :       || !COMPLETE_TYPE_P (inst)
   10743       194423 :       || !CLASS_TYPE_P (inst))
   10744              :     return NULL_TREE;
   10745        81283 :   tree val = lookup_qualified_name (inst, value_identifier,
   10746              :                                     LOOK_want::NORMAL, /*complain*/false);
   10747        81283 :   if (val == error_mark_node)
   10748              :     return NULL_TREE;
   10749        81277 :   if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
   10750        81277 :     val = maybe_constant_value (val, NULL_TREE, mce_true);
   10751        81277 :   if (TREE_CODE (val) == INTEGER_CST)
   10752              :     return val;
   10753              :   else
   10754            6 :     return error_mark_node;
   10755              : }
   10756              : 
   10757              : /* Return std::tuple_element<I,TYPE>::type.  */
   10758              : 
   10759              : static tree
   10760        91739 : get_tuple_element_type (tree type, unsigned HOST_WIDE_INT i)
   10761              : {
   10762        91739 :   tree args = make_tree_vec (2);
   10763        91739 :   TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
   10764        91739 :   TREE_VEC_ELT (args, 1) = type;
   10765        91739 :   tree inst = lookup_template_class (tuple_element_identifier, args,
   10766              :                                      /*in_decl*/NULL_TREE,
   10767              :                                      /*context*/std_node,
   10768              :                                      tf_warning_or_error);
   10769        91739 :   return make_typename_type (inst, type_identifier,
   10770        91739 :                              none_type, tf_warning_or_error);
   10771              : }
   10772              : 
   10773              : /* Return e.get<i>() or get<i>(e).  */
   10774              : 
   10775              : static tree
   10776        91748 : get_tuple_decomp_init (tree decl, unsigned HOST_WIDE_INT i)
   10777              : {
   10778        91748 :   tree targs = make_tree_vec (1);
   10779        91748 :   TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
   10780              : 
   10781        91748 :   tree etype = TREE_TYPE (decl);
   10782        91748 :   tree e = convert_from_reference (decl);
   10783              : 
   10784              :   /* [The id-expression] e is an lvalue if the type of the entity e is an
   10785              :      lvalue reference and an xvalue otherwise.  */
   10786        91748 :   if (!TYPE_REF_P (etype)
   10787        91748 :       || TYPE_REF_IS_RVALUE (etype))
   10788        90336 :     e = move (e);
   10789              : 
   10790        91748 :   tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
   10791              :                                     LOOK_want::NORMAL, /*complain*/false);
   10792        91748 :   bool use_member_get = false;
   10793              : 
   10794              :   /* To use a member get, member lookup must find at least one
   10795              :      declaration that is a function template
   10796              :      whose first template parameter is a non-type parameter.  */
   10797       272758 :   for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
   10798              :     {
   10799        91748 :       tree fn = *iter;
   10800        91748 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
   10801              :         {
   10802         2489 :           tree tparms = DECL_TEMPLATE_PARMS (fn);
   10803         2489 :           tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
   10804         2489 :           if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
   10805              :             {
   10806              :               use_member_get = true;
   10807              :               break;
   10808              :             }
   10809              :         }
   10810              :     }
   10811              : 
   10812        91748 :   if (use_member_get)
   10813              :     {
   10814         2486 :       fns = lookup_template_function (fns, targs);
   10815         2486 :       return build_new_method_call (e, fns, /*args*/NULL,
   10816              :                                     /*path*/NULL_TREE, LOOKUP_NORMAL,
   10817         2486 :                                     /*fn_p*/NULL, tf_warning_or_error);
   10818              :     }
   10819              :   else
   10820              :     {
   10821        89262 :       releasing_vec args (make_tree_vector_single (e));
   10822        89262 :       fns = lookup_template_function (get__identifier, targs);
   10823        89262 :       fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
   10824        89262 :       return finish_call_expr (fns, &args, /*novirt*/false,
   10825              :                                /*koenig*/true, tf_warning_or_error);
   10826        89262 :     }
   10827              : }
   10828              : 
   10829              : /* It's impossible to recover the decltype of a tuple decomposition variable
   10830              :    based on the actual type of the variable, so store it in a hash table.  */
   10831              : 
   10832              : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
   10833              : 
   10834              : tree
   10835          662 : lookup_decomp_type (tree v)
   10836              : {
   10837          662 :   if (decomp_type_table)
   10838          535 :     if (tree *slot = decomp_type_table->get (v))
   10839          471 :       return *slot;
   10840              :   return NULL_TREE;
   10841              : }
   10842              : 
   10843              : /* Mangle a decomposition declaration if needed.  Arguments like
   10844              :    in cp_finish_decomp.  */
   10845              : 
   10846              : static void
   10847        69164 : cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp)
   10848              : {
   10849        69164 :   if (!processing_template_decl
   10850        69164 :       && !error_operand_p (decl)
   10851       138328 :       && TREE_STATIC (decl))
   10852              :     {
   10853          897 :       auto_vec<tree, 16> v;
   10854          897 :       v.safe_grow (decomp->count, true);
   10855          897 :       tree d = decomp->decl;
   10856         2966 :       for (unsigned int i = 0; i < decomp->count; i++, d = DECL_CHAIN (d))
   10857         2069 :         v[decomp->count - i - 1] = d;
   10858          897 :       if (DECL_FUNCTION_SCOPE_P (decl))
   10859              :         {
   10860              :           size_t sz = 3;
   10861          933 :           for (unsigned int i = 0; i < decomp->count; ++i)
   10862          664 :             sz += IDENTIFIER_LENGTH (DECL_NAME (v[i])) + 1;
   10863          269 :           char *name = XALLOCAVEC (char, sz);
   10864          269 :           name[0] = 'D';
   10865          269 :           name[1] = 'C';
   10866          269 :           char *p = name + 2;
   10867          933 :           for (unsigned int i = 0; i < decomp->count; ++i)
   10868              :             {
   10869          664 :               size_t len = IDENTIFIER_LENGTH (DECL_NAME (v[i]));
   10870          664 :               *p++ = ' ';
   10871          664 :               memcpy (p, IDENTIFIER_POINTER (DECL_NAME (v[i])), len);
   10872          664 :               p += len;
   10873              :             }
   10874          269 :           *p = '\0';
   10875          269 :           determine_local_discriminator (decl, get_identifier (name));
   10876              :         }
   10877          897 :       SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
   10878          897 :       maybe_apply_pragma_weak (decl);
   10879          897 :     }
   10880        69164 : }
   10881              : 
   10882              : /* Append #i to DECL_NAME (decl) or for name independent decls
   10883              :    clear DECL_NAME (decl).  */
   10884              : 
   10885              : static void
   10886        33811 : set_sb_pack_name (tree decl, unsigned HOST_WIDE_INT i)
   10887              : {
   10888        33811 :   if (name_independent_decl_p (decl))
   10889              :     /* Only "_" names are treated as name independent, "_#0" etc. is not and
   10890              :        because we pushdecl the individual decl elements of structured binding
   10891              :        pack, we could get redeclaration errors if there are 2 or more name
   10892              :        independent structured binding packs in the same scope.  */
   10893          312 :     DECL_NAME (decl) = NULL_TREE;
   10894              :   else
   10895              :     {
   10896        33499 :       tree name = DECL_NAME (decl);
   10897        33499 :       size_t len = IDENTIFIER_LENGTH (name) + 22;
   10898        33499 :       char *n = XALLOCAVEC (char, len);
   10899        33499 :       snprintf (n, len, "%s#" HOST_WIDE_INT_PRINT_UNSIGNED,
   10900        33499 :                 IDENTIFIER_POINTER (name), i);
   10901        33499 :       DECL_NAME (decl) = get_identifier (n);
   10902              :     }
   10903        33811 : }
   10904              : 
   10905              : /* Return structured binding size of TYPE or -1 if erroneous.  */
   10906              : 
   10907              : HOST_WIDE_INT
   10908         1029 : cp_decomp_size (location_t loc, tree type, tsubst_flags_t complain)
   10909              : {
   10910         1029 :   if (TYPE_REF_P (type))
   10911              :     {
   10912            0 :       type = complete_type (TREE_TYPE (type));
   10913            0 :       if (type == error_mark_node)
   10914              :         return -1;
   10915            0 :       if (!COMPLETE_TYPE_P (type))
   10916              :         {
   10917            0 :           if (complain & tf_error)
   10918            0 :             error_at (loc, "structured binding refers to incomplete type %qT",
   10919              :                       type);
   10920              :           return -1;
   10921              :         }
   10922              :     }
   10923              : 
   10924         1029 :   unsigned HOST_WIDE_INT eltscnt = 0;
   10925         1029 :   if (TREE_CODE (type) == ARRAY_TYPE)
   10926              :     {
   10927          796 :       if (TYPE_DOMAIN (type) == NULL_TREE)
   10928              :         {
   10929            9 :           if (complain & tf_error)
   10930            6 :             error_at (loc, "cannot decompose array of unknown bound %qT",
   10931              :                       type);
   10932              :           return -1;
   10933              :         }
   10934          787 :       tree nelts = array_type_nelts_top (type);
   10935          787 :       if (nelts == error_mark_node)
   10936              :         return -1;
   10937          787 :       if (!tree_fits_shwi_p (nelts))
   10938              :         {
   10939            3 :           if (complain & tf_error)
   10940            3 :             error_at (loc, "cannot decompose variable length array %qT", type);
   10941              :           return -1;
   10942              :         }
   10943          784 :       return tree_to_shwi (nelts);
   10944              :     }
   10945              :   /* 2 GNU extensions.  */
   10946          233 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
   10947              :     return 2;
   10948          227 :   else if (TREE_CODE (type) == VECTOR_TYPE)
   10949              :     {
   10950           12 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
   10951              :         {
   10952              :           if (complain & tf_error)
   10953              :             error_at (loc, "cannot decompose variable length vector %qT", type);
   10954              :           return -1;
   10955              :         }
   10956           12 :       return eltscnt;
   10957              :     }
   10958          215 :   else if (tree tsize = get_tuple_size (type))
   10959              :     {
   10960           38 :       if (tsize == error_mark_node
   10961           32 :           || !tree_fits_shwi_p (tsize)
   10962           70 :           || tree_int_cst_sgn (tsize) < 0)
   10963              :         {
   10964            9 :           if (complain & tf_error)
   10965            9 :             error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
   10966              :                            "constant expression", type);
   10967              :           return -1;
   10968              :         }
   10969           29 :       return tree_to_shwi (tsize);
   10970              :     }
   10971          177 :   else if (TREE_CODE (type) == UNION_TYPE)
   10972              :     {
   10973            3 :       if (complain & tf_error)
   10974            3 :         error_at (loc, "cannot decompose union type %qT", type);
   10975              :       return -1;
   10976              :     }
   10977          174 :   else if (!CLASS_TYPE_P (type))
   10978              :     {
   10979           21 :       if (complain & tf_error)
   10980           18 :         error_at (loc, "cannot decompose non-array non-class type %qT", type);
   10981              :       return -1;
   10982              :     }
   10983          153 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
   10984              :     return -1;
   10985          153 :   else if (!COMPLETE_TYPE_P (type))
   10986              :     {
   10987            0 :       if (complain & tf_error)
   10988            0 :         error_at (loc, "structured binding refers to incomplete class type "
   10989              :                   "%qT", type);
   10990              :       return -1;
   10991              :     }
   10992              :   else
   10993              :     {
   10994          153 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE, complain);
   10995          153 :       if (btype == error_mark_node)
   10996              :         return -1;
   10997          132 :       else if (btype == NULL_TREE)
   10998              :         return 0;
   10999          111 :       if (btype != type)
   11000              :         {
   11001            6 :           tree binfo = lookup_base (type, btype, ba_check, NULL, complain);
   11002            6 :           if (binfo == NULL_TREE || binfo == error_mark_node)
   11003              :             return -1;
   11004              :         }
   11005         1150 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   11006         1730 :         if (TREE_CODE (field) != FIELD_DECL
   11007          372 :             || DECL_ARTIFICIAL (field)
   11008         1417 :             || DECL_UNNAMED_BIT_FIELD (field))
   11009          685 :           continue;
   11010              :         else
   11011          360 :           eltscnt++;
   11012          105 :       return eltscnt;
   11013              :     }
   11014              : }
   11015              : 
   11016              : /* Finish a decomposition declaration.  DECL is the underlying declaration
   11017              :    "e", FIRST is the head of a chain of decls for the individual identifiers
   11018              :    chained through DECL_CHAIN in reverse order and COUNT is the number of
   11019              :    those decls.  If TEST_P is true, return true if any code would need to be
   11020              :    actually emitted but don't emit it.  Return false otherwise.  */
   11021              : 
   11022              : bool
   11023       342726 : cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p)
   11024              : {
   11025       342726 :   tree first = decomp->decl;
   11026       342726 :   unsigned count = decomp->count;
   11027       342726 :   if (error_operand_p (decl))
   11028              :     {
   11029          200 :      error_out:
   11030          625 :       while (count--)
   11031              :         {
   11032          425 :           TREE_TYPE (first) = error_mark_node;
   11033          425 :           if (DECL_HAS_VALUE_EXPR_P (first))
   11034              :             {
   11035            9 :               SET_DECL_VALUE_EXPR (first, NULL_TREE);
   11036            9 :               DECL_HAS_VALUE_EXPR_P (first) = 0;
   11037              :             }
   11038          425 :           first = DECL_CHAIN (first);
   11039              :         }
   11040          200 :       if (DECL_P (decl) && TREE_STATIC (decl))
   11041           54 :         SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
   11042              :       return false;
   11043              :     }
   11044              : 
   11045       342663 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   11046       342663 :   if (type_dependent_expression_p (decl)
   11047              :       /* This happens for range for when not in templates.
   11048              :          Still add the DECL_VALUE_EXPRs for later processing.  */
   11049       342663 :       || (!processing_template_decl
   11050       105136 :           && type_uses_auto (TREE_TYPE (decl))))
   11051              :     {
   11052       654159 :       for (unsigned int i = 0; i < count; i++)
   11053              :         {
   11054       435868 :           if (!DECL_HAS_VALUE_EXPR_P (first))
   11055              :             {
   11056       435868 :               tree v = build_nt (ARRAY_REF, decl,
   11057       435868 :                                  size_int (count - i - 1),
   11058              :                                  NULL_TREE, NULL_TREE);
   11059       435868 :               SET_DECL_VALUE_EXPR (first, v);
   11060       435868 :               DECL_HAS_VALUE_EXPR_P (first) = 1;
   11061              :             }
   11062       435868 :           if (processing_template_decl)
   11063       435232 :             fit_decomposition_lang_decl (first, decl);
   11064       435868 :           first = DECL_CHAIN (first);
   11065              :         }
   11066              :       return false;
   11067              :     }
   11068              : 
   11069       124372 :   auto_vec<tree, 16> v;
   11070       124372 :   v.safe_grow (count, true);
   11071       124372 :   tree d = first;
   11072       124372 :   int pack = -1;
   11073       488653 :   for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
   11074              :     {
   11075       239909 :       v[count - i - 1] = d;
   11076       239909 :       fit_decomposition_lang_decl (d, decl);
   11077       239909 :       if (DECL_PACK_P (d))
   11078        11119 :         pack = count - i - 1;
   11079              :     }
   11080              : 
   11081       124372 :   tree type = TREE_TYPE (decl);
   11082       124372 :   tree dexp = decl;
   11083              : 
   11084       124372 :   if (TYPE_REF_P (type))
   11085              :     {
   11086         2318 :       dexp = convert_from_reference (dexp);
   11087         2318 :       type = complete_type (TREE_TYPE (type));
   11088         2318 :       if (type == error_mark_node)
   11089          137 :         goto error_out;
   11090         2318 :       if (!COMPLETE_TYPE_P (type))
   11091              :         {
   11092            3 :           error_at (loc, "structured binding refers to incomplete type %qT",
   11093              :                     type);
   11094            3 :           goto error_out;
   11095              :         }
   11096              :     }
   11097              : 
   11098       124369 :   tree eltype = NULL_TREE;
   11099       124369 :   unsigned HOST_WIDE_INT eltscnt = 0;
   11100              :   /* Structured binding packs when initializer is non-dependent should
   11101              :      have their DECL_VALUE_EXPR set to a TREE_VEC.  First two elements
   11102              :      of that TREE_VEC are the base and index, what is normally represented
   11103              :      as DECL_VALUE_EXPR ARRAY_REF <base, index> where index is the index
   11104              :      of the pack first element.  The remaining elements of the TREE_VEC
   11105              :      are VAR_DECLs for the pack elements.  */
   11106       124369 :   tree packv = NULL_TREE;
   11107              : 
   11108       124369 :   if (TREE_CODE (type) == ARRAY_TYPE)
   11109              :     {
   11110        11306 :       tree nelts;
   11111        11306 :       nelts = array_type_nelts_top (type);
   11112        11306 :       if (nelts == error_mark_node)
   11113            0 :         goto error_out;
   11114        11306 :       if (DECL_DECOMP_BASE (decl))
   11115              :         {
   11116            9 :           error_at (loc, "array initializer for structured binding "
   11117              :                     "declaration in condition");
   11118            9 :           goto error_out;
   11119              :         }
   11120        11297 :       if (!tree_fits_uhwi_p (nelts))
   11121              :         {
   11122            3 :           error_at (loc, "cannot decompose variable length array %qT", type);
   11123            3 :           goto error_out;
   11124              :         }
   11125        11294 :       eltscnt = tree_to_uhwi (nelts);
   11126        11294 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11127              :         {
   11128           11 :        cnt_mismatch:
   11129           38 :           auto_diagnostic_group d;
   11130           38 :           if (count > eltscnt)
   11131           27 :             error_n (loc, count,
   11132              :                      "%u name provided for structured binding",
   11133              :                      "%u names provided for structured binding", count);
   11134              :           else
   11135           11 :             error_n (loc, count,
   11136              :                      "only %u name provided for structured binding",
   11137              :                      "only %u names provided for structured binding", count);
   11138           38 :           inform_n (loc, eltscnt,
   11139              :                     "while %qT decomposes into %wu element",
   11140              :                     "while %qT decomposes into %wu elements",
   11141              :                     type, eltscnt);
   11142           38 :           goto error_out;
   11143              :         }
   11144        11283 :       eltype = TREE_TYPE (type);
   11145        24568 :       for (unsigned int i = 0; i < count; i++)
   11146              :         {
   11147        13285 :           if ((unsigned) pack == i)
   11148              :             {
   11149        10060 :               packv = make_tree_vec (eltscnt - count + 3);
   11150        51506 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   11151              :                 {
   11152        31386 :                   tree t;
   11153        31386 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   11154        31386 :                   set_sb_pack_name (t, j);
   11155        31386 :                   maybe_push_decl (t);
   11156        31386 :                   TREE_TYPE (t) = eltype;
   11157        31386 :                   layout_decl (t, 0);
   11158        31386 :                   if (!processing_template_decl)
   11159              :                     {
   11160        31288 :                       tree a = unshare_expr (dexp);
   11161        31288 :                       a = build4 (ARRAY_REF, eltype, a, size_int (j + pack),
   11162              :                                   NULL_TREE, NULL_TREE);
   11163        31288 :                       SET_DECL_VALUE_EXPR (t, a);
   11164        31288 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   11165              :                     }
   11166              :                 }
   11167        13285 :               continue;
   11168        10060 :             }
   11169         3225 :           TREE_TYPE (v[i]) = eltype;
   11170         3225 :           layout_decl (v[i], 0);
   11171         3225 :           if (processing_template_decl)
   11172          140 :             continue;
   11173         3085 :           tree t = unshare_expr (dexp);
   11174         3085 :           unsigned HOST_WIDE_INT j = i;
   11175         3085 :           if (pack != -1 && (unsigned) pack < i)
   11176           64 :             j = i + eltscnt - count;
   11177         3085 :           t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
   11178         3085 :           SET_DECL_VALUE_EXPR (v[i], t);
   11179         3085 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11180              :         }
   11181              :     }
   11182              :   /* 2 GNU extensions.  */
   11183       113063 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
   11184              :     {
   11185           78 :       eltscnt = 2;
   11186           78 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11187            3 :         goto cnt_mismatch;
   11188           75 :       eltype = cp_build_qualified_type (TREE_TYPE (type), cp_type_quals (type));
   11189          288 :       for (unsigned int i = 0; i < count; i++)
   11190              :         {
   11191          138 :           if ((unsigned) pack == i)
   11192              :             {
   11193           60 :               packv = make_tree_vec (eltscnt - count + 3);
   11194          192 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   11195              :                 {
   11196           72 :                   tree t;
   11197           72 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   11198           72 :                   set_sb_pack_name (t, j);
   11199           72 :                   maybe_push_decl (t);
   11200           72 :                   TREE_TYPE (t) = eltype;
   11201           72 :                   layout_decl (t, 0);
   11202           72 :                   if (!processing_template_decl)
   11203              :                     {
   11204           72 :                       tree a = build1 (pack + j ? IMAGPART_EXPR : REALPART_EXPR, eltype,
   11205              :                                        unshare_expr (dexp));
   11206           48 :                       SET_DECL_VALUE_EXPR (t, a);
   11207           48 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   11208              :                     }
   11209              :                 }
   11210           60 :               continue;
   11211           60 :             }
   11212           78 :           TREE_TYPE (v[i]) = eltype;
   11213           78 :           layout_decl (v[i], 0);
   11214           78 :           if (processing_template_decl)
   11215           16 :             continue;
   11216           62 :           tree t = unshare_expr (dexp);
   11217           62 :           unsigned HOST_WIDE_INT j = i;
   11218           62 :           if (pack != -1 && (unsigned) pack < i)
   11219           16 :             j = i + eltscnt - count;
   11220           93 :           t = build1 (j ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
   11221           62 :           SET_DECL_VALUE_EXPR (v[i], t);
   11222           62 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11223              :         }
   11224              :     }
   11225       112985 :   else if (TREE_CODE (type) == VECTOR_TYPE)
   11226              :     {
   11227           60 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
   11228              :         {
   11229              :           error_at (loc, "cannot decompose variable length vector %qT", type);
   11230              :           goto error_out;
   11231              :         }
   11232           60 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11233            3 :         goto cnt_mismatch;
   11234           57 :       eltype = cp_build_qualified_type (TREE_TYPE (type), cp_type_quals (type));
   11235          306 :       for (unsigned int i = 0; i < count; i++)
   11236              :         {
   11237          192 :           if ((unsigned) pack == i)
   11238              :             {
   11239           48 :               packv = make_tree_vec (eltscnt - count + 3);
   11240          756 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   11241              :                 {
   11242          660 :                   tree t;
   11243          660 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   11244          660 :                   set_sb_pack_name (t, j);
   11245          660 :                   maybe_push_decl (t);
   11246          660 :                   TREE_TYPE (t) = eltype;
   11247          660 :                   layout_decl (t, 0);
   11248          660 :                   if (!processing_template_decl)
   11249              :                     {
   11250          440 :                       tree a = unshare_expr (dexp);
   11251          440 :                       location_t loc = DECL_SOURCE_LOCATION (t);
   11252          440 :                       tree s = size_int (j + pack);
   11253          440 :                       convert_vector_to_array_for_subscript (loc, &a, s);
   11254          440 :                       a = build4 (ARRAY_REF, eltype, a, s,
   11255              :                                   NULL_TREE, NULL_TREE);
   11256          440 :                       SET_DECL_VALUE_EXPR (t, a);
   11257          440 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   11258              :                     }
   11259              :                 }
   11260           84 :               continue;
   11261           48 :             }
   11262          144 :           TREE_TYPE (v[i]) = eltype;
   11263          144 :           layout_decl (v[i], 0);
   11264          144 :           if (processing_template_decl)
   11265           36 :             continue;
   11266          108 :           tree t = unshare_expr (dexp);
   11267          108 :           unsigned HOST_WIDE_INT j = i;
   11268          108 :           if (pack != -1 && (unsigned) pack < i)
   11269           24 :             j = i + eltscnt - count;
   11270          108 :           convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
   11271          108 :                                                  &t, size_int (j));
   11272          108 :           t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
   11273          108 :           SET_DECL_VALUE_EXPR (v[i], t);
   11274          108 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11275              :         }
   11276              :     }
   11277       112925 :   else if (tree tsize = get_tuple_size (type))
   11278              :     {
   11279        81239 :       if (tsize == error_mark_node)
   11280              :         {
   11281            0 :           error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
   11282              :                          "constant expression", type);
   11283            0 :           goto error_out;
   11284              :         }
   11285        81239 :       if (!tree_fits_uhwi_p (tsize))
   11286              :         {
   11287           12 :           auto_diagnostic_group d;
   11288           12 :           error_n (loc, count,
   11289              :                    "%u name provided for structured binding",
   11290              :                    "%u names provided for structured binding", count);
   11291           12 :           inform (loc, "while %qT decomposes into %E elements",
   11292              :                   type, tsize);
   11293           12 :           goto error_out;
   11294           12 :         }
   11295        81227 :       eltscnt = tree_to_uhwi (tsize);
   11296        81227 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11297            6 :         goto cnt_mismatch;
   11298        81221 :       if (test_p && eltscnt)
   11299       124235 :         return true;
   11300        45530 :       if (!processing_template_decl && DECL_DECOMP_BASE (decl) && eltscnt)
   11301              :         {
   11302              :           /* For structured bindings used in conditions we need to evaluate
   11303              :              the conversion of decl (aka e in the standard) to bool or
   11304              :              integral/enumeral type (the latter for switch conditions)
   11305              :              before the get methods, as [dcl.struct.bind]/7 requires that:
   11306              :              "The initialization of e and any conversion of e considered as
   11307              :              a decision variable is sequenced before the initialization of
   11308              :              any r_i."  */
   11309           89 :           tree cond = convert_from_reference (decl);
   11310           89 :           if (integer_onep (DECL_DECOMP_BASE (decl)))
   11311              :             /* switch condition.  */
   11312           18 :             cond = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   11313              :                                                cond, true);
   11314              :           else
   11315              :             /* if/while/for condition.  */
   11316           71 :             cond = contextual_conv_bool (cond, tf_warning_or_error);
   11317           89 :           if (cond && !error_operand_p (cond))
   11318              :             {
   11319           89 :               cond = get_temp_regvar (TREE_TYPE (cond), cond);
   11320           89 :               pushdecl (cond);
   11321              :               /* Set DECL_DECOMP_BASE to cond VAR_DECL wrapped in
   11322              :                  NON_LVALUE_EXPR, such that it is considered to be
   11323              :                  the condition of a structured binding rather than
   11324              :                  structured binding's base variable.  */
   11325           89 :               DECL_DECOMP_BASE (decl)
   11326          178 :                 = build1 (NON_LVALUE_EXPR, TREE_TYPE (cond), cond);
   11327              :             }
   11328              :         }
   11329        45530 :       int save_read = DECL_READ_P (decl);
   11330       136473 :       for (unsigned i = 0; i < count; ++i)
   11331              :         {
   11332        90964 :           location_t sloc = input_location;
   11333        90964 :           location_t dloc = DECL_SOURCE_LOCATION (v[i]);
   11334              : 
   11335        90964 :           if ((unsigned) pack == i)
   11336              :             {
   11337          405 :               packv = make_tree_vec (eltscnt - count + 3);
   11338         1999 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   11339              :                 {
   11340         1189 :                   tree t;
   11341         1189 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   11342         1189 :                   set_sb_pack_name (t, j);
   11343         1189 :                   input_location = dloc;
   11344         1189 :                   tree init = get_tuple_decomp_init (decl, j + pack);
   11345         1189 :                   tree eltype = (init == error_mark_node ? error_mark_node
   11346         1189 :                                  : get_tuple_element_type (type, j + pack));
   11347         1189 :                   input_location = sloc;
   11348              : 
   11349         1189 :                   if (VOID_TYPE_P (eltype))
   11350              :                     {
   11351            0 :                       error ("%<std::tuple_element<%wu, %T>::type%> is "
   11352              :                              "%<void%>", j + pack, type);
   11353            0 :                       eltype = error_mark_node;
   11354              :                     }
   11355         1189 :                   if (init == error_mark_node || eltype == error_mark_node)
   11356              :                     {
   11357            0 :                       inform (dloc, "in initialization of structured binding "
   11358            0 :                               "pack %qD", v[pack]);
   11359            0 :                       goto error_out;
   11360              :                     }
   11361         1189 :                   maybe_push_decl (t);
   11362              :                   /* Save the decltype away before reference collapse.  */
   11363         1189 :                   hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype);
   11364         1189 :                   if (glvalue_p (init))
   11365         1087 :                     eltype = cp_build_reference_type (eltype, !lvalue_p (init));
   11366         1189 :                   TREE_TYPE (t) = eltype;
   11367         1189 :                   layout_decl (t, 0);
   11368         1189 :                   DECL_HAS_VALUE_EXPR_P (t) = 0;
   11369         1189 :                   if (!processing_template_decl)
   11370              :                     {
   11371          797 :                       copy_linkage (t, decl);
   11372          797 :                       tree name = DECL_NAME (t);
   11373          797 :                       if (TREE_STATIC (decl))
   11374           54 :                         DECL_NAME (t) = DECL_NAME (v[pack]);
   11375          797 :                       cp_finish_decl (t, init, /*constexpr*/false,
   11376              :                                       /*asm*/NULL_TREE, LOOKUP_NORMAL);
   11377          797 :                       if (TREE_STATIC (decl))
   11378              :                         {
   11379           54 :                           DECL_ASSEMBLER_NAME (t);
   11380           54 :                           DECL_NAME (t) = name;
   11381              :                         }
   11382              :                     }
   11383              :                 }
   11384          405 :               continue;
   11385          405 :             }
   11386              : 
   11387        90559 :           unsigned HOST_WIDE_INT j = i;
   11388        90559 :           if (pack != -1 && (unsigned) pack < i)
   11389          235 :             j = i + eltscnt - count;
   11390        90559 :           input_location = dloc;
   11391        90559 :           tree init = get_tuple_decomp_init (decl, j);
   11392        90559 :           tree eltype = (init == error_mark_node ? error_mark_node
   11393        90550 :                          : get_tuple_element_type (type, j));
   11394        90559 :           input_location = sloc;
   11395              : 
   11396        90559 :           if (VOID_TYPE_P (eltype))
   11397              :             {
   11398            3 :               error ("%<std::tuple_element<%wu, %T>::type%> is %<void%>",
   11399              :                      j, type);
   11400            3 :               eltype = error_mark_node;
   11401              :             }
   11402        90559 :           if (init == error_mark_node || eltype == error_mark_node)
   11403              :             {
   11404           21 :               inform (dloc, "in initialization of structured binding "
   11405           21 :                       "variable %qD", v[i]);
   11406           21 :               goto error_out;
   11407              :             }
   11408              :           /* Save the decltype away before reference collapse.  */
   11409        90538 :           hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
   11410        90538 :           if (glvalue_p (init))
   11411        90119 :             eltype = cp_build_reference_type (eltype, !lvalue_p (init));
   11412        90538 :           TREE_TYPE (v[i]) = eltype;
   11413        90538 :           layout_decl (v[i], 0);
   11414        90538 :           if (DECL_HAS_VALUE_EXPR_P (v[i]))
   11415              :             {
   11416              :               /* In this case the names are variables, not just proxies.  */
   11417          220 :               SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
   11418          220 :               DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
   11419              :             }
   11420        90538 :           if (!processing_template_decl)
   11421              :             {
   11422        70958 :               copy_linkage (v[i], decl);
   11423        70958 :               cp_finish_decl (v[i], init, /*constexpr*/false,
   11424              :                               /*asm*/NULL_TREE, LOOKUP_NORMAL);
   11425              :             }
   11426              :         }
   11427              :       /* Ignore reads from the underlying decl performed during initialization
   11428              :          of the individual variables.  If those will be read, we'll mark
   11429              :          the underlying decl as read at that point.  */
   11430        45509 :       DECL_READ_P (decl) = save_read;
   11431              :     }
   11432        31686 :   else if (TREE_CODE (type) == UNION_TYPE)
   11433              :     {
   11434            3 :       error_at (loc, "cannot decompose union type %qT", type);
   11435            3 :       goto error_out;
   11436              :     }
   11437        31683 :   else if (!CLASS_TYPE_P (type))
   11438              :     {
   11439           19 :       error_at (loc, "cannot decompose non-array non-class type %qT", type);
   11440           19 :       goto error_out;
   11441              :     }
   11442        31664 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
   11443            0 :     goto error_out;
   11444        31664 :   else if (processing_template_decl && !COMPLETE_TYPE_P (type))
   11445            2 :     pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
   11446              :              type);
   11447              :   else
   11448              :     {
   11449        31662 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE,
   11450              :                                            tf_warning_or_error);
   11451        31662 :       if (btype == error_mark_node)
   11452           21 :         goto error_out;
   11453        31641 :       else if (btype == NULL_TREE)
   11454              :         {
   11455           26 :           if (pack == 0 && count == 1)
   11456              :             {
   11457           18 :               eltscnt = 0;
   11458           18 :               packv = make_tree_vec (2);
   11459           18 :               goto done;
   11460              :             }
   11461            8 :           error_at (loc, "cannot decompose class type %qT without non-static "
   11462              :                          "data members", type);
   11463            8 :           goto error_out;
   11464              :         }
   11465       403743 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   11466       680220 :         if (TREE_CODE (field) != FIELD_DECL
   11467        64052 :             || DECL_ARTIFICIAL (field)
   11468       436176 :             || DECL_UNNAMED_BIT_FIELD (field))
   11469       308092 :           continue;
   11470              :         else
   11471        64036 :           eltscnt++;
   11472        31615 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11473           15 :         goto cnt_mismatch;
   11474        31600 :       tree t = dexp;
   11475        31600 :       if (type != btype)
   11476              :         {
   11477           18 :           t = convert_to_base (t, btype, /*check_access*/true,
   11478              :                                /*nonnull*/false, tf_warning_or_error);
   11479           18 :           type = btype;
   11480              :         }
   11481        31600 :       unsigned HOST_WIDE_INT j = 0;
   11482        31600 :       unsigned int i = 0;
   11483       403532 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   11484       679865 :         if (TREE_CODE (field) != FIELD_DECL
   11485        64015 :             || DECL_ARTIFICIAL (field)
   11486       435943 :             || DECL_UNNAMED_BIT_FIELD (field))
   11487       307933 :           continue;
   11488              :         else
   11489              :           {
   11490        63999 :             tree tt = finish_non_static_data_member (field, unshare_expr (t),
   11491              :                                                      NULL_TREE);
   11492        63999 :             if (REFERENCE_REF_P (tt))
   11493           30 :               tt = TREE_OPERAND (tt, 0);
   11494        63999 :             if (pack != -1 && j >= (unsigned) pack)
   11495              :               {
   11496          685 :                 if (j == (unsigned) pack)
   11497              :                   {
   11498          227 :                     packv = make_tree_vec (eltscnt - count + 3);
   11499          227 :                     i++;
   11500              :                   }
   11501          685 :                 if (j < (unsigned) pack + eltscnt - (count - 1))
   11502              :                   {
   11503          504 :                     tree t;
   11504          504 :                     TREE_VEC_ELT (packv, j + 3 - i) = t = copy_node (v[pack]);
   11505          504 :                     set_sb_pack_name (t, j + 1 - i);
   11506          504 :                     maybe_push_decl (t);
   11507          504 :                     TREE_TYPE (t) = TREE_TYPE (tt);
   11508          504 :                     layout_decl (t, 0);
   11509          504 :                     if (!processing_template_decl)
   11510              :                       {
   11511          383 :                         SET_DECL_VALUE_EXPR (t, tt);
   11512          383 :                         DECL_HAS_VALUE_EXPR_P (t) = 1;
   11513              :                       }
   11514              :                     else
   11515          121 :                       DECL_HAS_VALUE_EXPR_P (t) = 0;
   11516          504 :                     j++;
   11517          504 :                     continue;
   11518          504 :                   }
   11519              :               }
   11520        63495 :             TREE_TYPE (v[i]) = TREE_TYPE (tt);
   11521        63495 :             layout_decl (v[i], 0);
   11522        63495 :             if (!processing_template_decl)
   11523              :               {
   11524        44469 :                 SET_DECL_VALUE_EXPR (v[i], tt);
   11525        44469 :                 DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11526              :               }
   11527        63495 :             i++;
   11528        63495 :             j++;
   11529              :           }
   11530        31600 :       if (pack != -1 && j == (unsigned) pack)
   11531              :         {
   11532           20 :           gcc_checking_assert (eltscnt == count - 1);
   11533           20 :           packv = make_tree_vec (2);
   11534              :         }
   11535              :     }
   11536        88544 :  done:
   11537        88544 :   if (packv)
   11538              :     {
   11539        10838 :       gcc_checking_assert (pack != -1);
   11540        10838 :       TREE_VEC_ELT (packv, 0) = decl;
   11541        10838 :       TREE_VEC_ELT (packv, 1) = size_int (pack);
   11542        10838 :       SET_DECL_VALUE_EXPR (v[pack], packv);
   11543        10838 :       DECL_HAS_VALUE_EXPR_P (v[pack]) = 1;
   11544        10838 :       DECL_IGNORED_P (v[pack]) = 1;
   11545        10838 :       if (!processing_template_decl)
   11546        43487 :         for (unsigned int i = 0; i < TREE_VEC_LENGTH (packv) - 2U; ++i)
   11547        32956 :           pushdecl (TREE_VEC_ELT (packv, 2 + i));
   11548              :     }
   11549        88544 :   if (processing_template_decl)
   11550              :     {
   11551        58587 :       for (unsigned int i = 0; i < count; i++)
   11552        39107 :         if (!DECL_HAS_VALUE_EXPR_P (v[i]))
   11553              :           {
   11554        38653 :             tree a = build_nt (ARRAY_REF, decl, size_int (i),
   11555              :                                NULL_TREE, NULL_TREE);
   11556        38653 :             SET_DECL_VALUE_EXPR (v[i], a);
   11557        38653 :             DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11558              :           }
   11559              :     }
   11560        69064 :   else if (DECL_NAMESPACE_SCOPE_P (decl) && !seen_error ())
   11561              :     {
   11562          480 :       tree attr = NULL_TREE, *pa = &attr;
   11563         1550 :       for (unsigned int i = 0; i < count; i++)
   11564         1070 :         if ((unsigned) pack != i
   11565         1070 :             && DECL_HAS_VALUE_EXPR_P (v[i])
   11566         1796 :             && !DECL_IGNORED_P (v[i]))
   11567              :           {
   11568          726 :             (*debug_hooks->early_global_decl) (v[i]);
   11569          726 :             *pa = build_tree_list (NULL_TREE, v[i]);
   11570          726 :             pa = &TREE_CHAIN (*pa);
   11571              :           }
   11572          480 :       if (attr)
   11573          364 :         DECL_ATTRIBUTES (decl)
   11574          728 :           = tree_cons (get_identifier ("structured bindings"),
   11575          364 :                        attr, DECL_ATTRIBUTES (decl));
   11576              :     }
   11577              :   return false;
   11578              : }
   11579              : 
   11580              : /* Returns a declaration for a VAR_DECL as if:
   11581              : 
   11582              :      extern "C" TYPE NAME;
   11583              : 
   11584              :    had been seen.  Used to create compiler-generated global
   11585              :    variables.  */
   11586              : 
   11587              : static tree
   11588         2210 : declare_global_var (tree name, tree type)
   11589              : {
   11590         2210 :   auto cookie = push_abi_namespace (global_namespace);
   11591         2210 :   tree decl = build_decl (input_location, VAR_DECL, name, type);
   11592         2210 :   TREE_PUBLIC (decl) = 1;
   11593         2210 :   DECL_EXTERNAL (decl) = 1;
   11594         2210 :   DECL_ARTIFICIAL (decl) = 1;
   11595         2210 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   11596              :   /* If the user has explicitly declared this variable (perhaps
   11597              :      because the code we are compiling is part of a low-level runtime
   11598              :      library), then it is possible that our declaration will be merged
   11599              :      with theirs by pushdecl.  */
   11600         2210 :   decl = pushdecl (decl);
   11601         2210 :   cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
   11602         2210 :   pop_abi_namespace (cookie, global_namespace);
   11603              : 
   11604         2210 :   return decl;
   11605              : }
   11606              : 
   11607              : /* Returns the type for the argument to "atexit" corresponding to the function
   11608              :    to be called when the program exits.  */
   11609              : 
   11610              : static tree
   11611           24 : get_atexit_fn_ptr_type ()
   11612              : {
   11613           24 :   if (!atexit_fn_ptr_type_node)
   11614              :     {
   11615           12 :       tree fn_type = build_function_type_list (void_type_node, NULL_TREE);
   11616           12 :       atexit_fn_ptr_type_node = build_pointer_type (fn_type);
   11617              :     }
   11618              : 
   11619           24 :   return atexit_fn_ptr_type_node;
   11620              : }
   11621              : 
   11622              : /* Returns the type for the argument to "__cxa_atexit", "__cxa_thread_atexit"
   11623              :    or "__cxa_throw" corresponding to the destructor to be called when the
   11624              :    program exits.  */
   11625              : 
   11626              : tree
   11627        19432 : get_cxa_atexit_fn_ptr_type ()
   11628              : {
   11629        19432 :   if (!cleanup_type)
   11630              :     {
   11631        14651 :       tree fntype = build_function_type_list (void_type_node,
   11632              :                                               ptr_type_node, NULL_TREE);
   11633        14651 :       fntype = targetm.cxx.adjust_cdtor_callabi_fntype (fntype);
   11634        14651 :       cleanup_type = build_pointer_type (fntype);
   11635              :     }
   11636              : 
   11637        19432 :   return cleanup_type;
   11638              : }
   11639              : 
   11640              : /* Returns a pointer to the `atexit' function.  Note that if
   11641              :    FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
   11642              :    `__cxa_atexit' function specified in the IA64 C++ ABI.  */
   11643              : 
   11644              : static tree
   11645         3501 : get_atexit_node (void)
   11646              : {
   11647         3501 :   tree atexit_fndecl;
   11648         3501 :   tree fn_type;
   11649         3501 :   tree fn_ptr_type;
   11650         3501 :   const char *name;
   11651         3501 :   bool use_aeabi_atexit;
   11652         3501 :   tree ctx = global_namespace;
   11653              : 
   11654         3501 :   if (atexit_node)
   11655              :     return atexit_node;
   11656              : 
   11657         2173 :   if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
   11658              :     {
   11659              :       /* The declaration for `__cxa_atexit' is:
   11660              : 
   11661              :            int __cxa_atexit (void (*)(void *), void *, void *)
   11662              : 
   11663              :          We build up the argument types and then the function type
   11664              :          itself.  */
   11665         2161 :       tree argtype0, argtype1, argtype2;
   11666              : 
   11667         2161 :       use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
   11668              :       /* First, build the pointer-to-function type for the first
   11669              :          argument.  */
   11670         2161 :       fn_ptr_type = get_cxa_atexit_fn_ptr_type ();
   11671              :       /* Then, build the rest of the argument types.  */
   11672         2161 :       argtype2 = ptr_type_node;
   11673         2161 :       if (use_aeabi_atexit)
   11674              :         {
   11675              :           argtype1 = fn_ptr_type;
   11676              :           argtype0 = ptr_type_node;
   11677              :         }
   11678              :       else
   11679              :         {
   11680         2161 :           argtype1 = ptr_type_node;
   11681         2161 :           argtype0 = fn_ptr_type;
   11682              :         }
   11683              :       /* And the final __cxa_atexit type.  */
   11684         2161 :       fn_type = build_function_type_list (integer_type_node,
   11685              :                                           argtype0, argtype1, argtype2,
   11686              :                                           NULL_TREE);
   11687              :       /* ... which needs noexcept.  */
   11688         2161 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   11689         2161 :       if (use_aeabi_atexit)
   11690              :         {
   11691            0 :           name = "__aeabi_atexit";
   11692            0 :           push_to_top_level ();
   11693            0 :           int n = push_namespace (get_identifier ("__aeabiv1"), false);
   11694            0 :           ctx = current_namespace;
   11695            0 :           while (n--)
   11696            0 :             pop_namespace ();
   11697            0 :           pop_from_top_level ();
   11698              :         }
   11699              :       else
   11700              :         {
   11701         2161 :           name = "__cxa_atexit";
   11702         2161 :           ctx = abi_node;
   11703              :         }
   11704              :     }
   11705              :   else
   11706              :     {
   11707              :       /* The declaration for `atexit' is:
   11708              : 
   11709              :            int atexit (void (*)());
   11710              : 
   11711              :          We build up the argument types and then the function type
   11712              :          itself.  */
   11713           12 :       fn_ptr_type = get_atexit_fn_ptr_type ();
   11714              :       /* Build the final atexit type.  */
   11715           12 :       fn_type = build_function_type_list (integer_type_node,
   11716              :                                           fn_ptr_type, NULL_TREE);
   11717              :       /* ... which needs noexcept.  */
   11718           12 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   11719           12 :       name = "atexit";
   11720              :     }
   11721              : 
   11722              :   /* Now, build the function declaration.  */
   11723         2173 :   push_lang_context (lang_name_c);
   11724         2173 :   auto cookie = push_abi_namespace (ctx);
   11725         2173 :   atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
   11726         2173 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   11727              :   /* Install as hidden builtin so we're (a) more relaxed about
   11728              :     exception spec matching and (b) will not give a confusing location
   11729              :     in diagnostic and (c) won't magically appear in user-visible name
   11730              :     lookups.  */
   11731         2173 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   11732         2173 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   11733         2173 :   pop_abi_namespace (cookie, ctx);
   11734         2173 :   mark_used (atexit_fndecl);
   11735         2173 :   pop_lang_context ();
   11736         2173 :   atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   11737              : 
   11738         2173 :   return atexit_node;
   11739              : }
   11740              : 
   11741              : /* Like get_atexit_node, but for thread-local cleanups.  */
   11742              : 
   11743              : static tree
   11744           98 : get_thread_atexit_node (void)
   11745              : {
   11746           98 :   if (thread_atexit_node)
   11747              :     return thread_atexit_node;
   11748              : 
   11749              :   /* The declaration for `__cxa_thread_atexit' is:
   11750              : 
   11751              :      int __cxa_thread_atexit (void (*)(void *), void *, void *) */
   11752           59 :   tree fn_type = build_function_type_list (integer_type_node,
   11753              :                                            get_cxa_atexit_fn_ptr_type (),
   11754              :                                            ptr_type_node, ptr_type_node,
   11755              :                                            NULL_TREE);
   11756              : 
   11757              :   /* Now, build the function declaration, as with __cxa_atexit.  */
   11758           59 :   unsigned flags = push_abi_namespace ();
   11759           59 :   tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
   11760              :                                              ECF_LEAF | ECF_NOTHROW);
   11761           59 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   11762           59 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   11763           59 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   11764           59 :   pop_abi_namespace (flags);
   11765           59 :   mark_used (atexit_fndecl);
   11766           59 :   thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   11767              : 
   11768           59 :   return thread_atexit_node;
   11769              : }
   11770              : 
   11771              : /* Returns the __dso_handle VAR_DECL.  */
   11772              : 
   11773              : static tree
   11774         3587 : get_dso_handle_node (void)
   11775              : {
   11776         3587 :   if (dso_handle_node)
   11777              :     return dso_handle_node;
   11778              : 
   11779              :   /* Declare the variable.  */
   11780         2210 :   dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
   11781              :                                         ptr_type_node);
   11782              : 
   11783              : #ifdef HAVE_GAS_HIDDEN
   11784         2210 :   if (dso_handle_node != error_mark_node)
   11785              :     {
   11786         2207 :       DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
   11787         2207 :       DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
   11788              :     }
   11789              : #endif
   11790              : 
   11791         2210 :   return dso_handle_node;
   11792              : }
   11793              : 
   11794              : /* Begin a new function with internal linkage whose job will be simply
   11795              :    to destroy some particular DECL.  OB_PARM is true if object pointer
   11796              :    is passed to the cleanup function, otherwise no argument is passed.  */
   11797              : 
   11798              : static tree
   11799          383 : start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
   11800              : {
   11801          383 :   push_to_top_level ();
   11802              : 
   11803              :   /* No need to mangle this.  */
   11804          383 :   push_lang_context (lang_name_c);
   11805              : 
   11806              :   /* Build the name of the function.  */
   11807          383 :   gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
   11808          383 :   const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   11809          383 :   dname = targetm.strip_name_encoding (dname);
   11810          763 :   char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
   11811              : 
   11812          383 :   tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
   11813              :                                    : get_atexit_fn_ptr_type ());
   11814              :   /* Build the function declaration.  */
   11815          383 :   tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
   11816          383 :   DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
   11817              :   /* It's a function with internal linkage, generated by the
   11818              :      compiler.  */
   11819          383 :   TREE_PUBLIC (fndecl) = 0;
   11820          383 :   DECL_ARTIFICIAL (fndecl) = 1;
   11821              :   /* Make the function `inline' so that it is only emitted if it is
   11822              :      actually needed.  It is unlikely that it will be inlined, since
   11823              :      it is only called via a function pointer, but we avoid unnecessary
   11824              :      emissions this way.  */
   11825          383 :   DECL_DECLARED_INLINE_P (fndecl) = 1;
   11826          383 :   DECL_INTERFACE_KNOWN (fndecl) = 1;
   11827          383 :   if (ob_parm)
   11828              :     {
   11829              :       /* Build the parameter.  */
   11830          371 :       tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
   11831          371 :       TREE_USED (parmdecl) = 1;
   11832          371 :       DECL_READ_P (parmdecl) = 1;
   11833          371 :       DECL_ARGUMENTS (fndecl) = parmdecl;
   11834              :     }
   11835              : 
   11836          383 :   fndecl = pushdecl (fndecl, /*hidden=*/true);
   11837          383 :   if (omp_target)
   11838              :     {
   11839            3 :       DECL_ATTRIBUTES (fndecl)
   11840            3 :         = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
   11841            3 :                      DECL_ATTRIBUTES (fndecl));
   11842            3 :       DECL_ATTRIBUTES (fndecl)
   11843            6 :         = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
   11844            3 :                      DECL_ATTRIBUTES (fndecl));
   11845              :     }
   11846          383 :   start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
   11847              : 
   11848          383 :   pop_lang_context ();
   11849              : 
   11850          383 :   return current_function_decl;
   11851              : }
   11852              : 
   11853              : /* Finish the cleanup function begun by start_cleanup_fn.  */
   11854              : 
   11855              : static void
   11856          383 : end_cleanup_fn (void)
   11857              : {
   11858          383 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
   11859              : 
   11860          383 :   pop_from_top_level ();
   11861          383 : }
   11862              : 
   11863              : /* Generate code to handle the destruction of DECL, an object with
   11864              :    static storage duration.  */
   11865              : 
   11866              : tree
   11867        15294 : register_dtor_fn (tree decl, bool omp_target)
   11868              : {
   11869        15294 :   tree cleanup;
   11870        15294 :   tree addr;
   11871        15294 :   tree compound_stmt;
   11872        15294 :   tree fcall;
   11873        15294 :   tree type;
   11874        15294 :   bool ob_parm, dso_parm, use_dtor;
   11875        15294 :   tree arg0, arg1, arg2;
   11876        15294 :   tree atex_node;
   11877              : 
   11878        15294 :   type = TREE_TYPE (decl);
   11879        15294 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   11880        11695 :     return void_node;
   11881              : 
   11882         3599 :   if (decl_maybe_constant_destruction (decl, type)
   11883         3599 :       && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   11884              :     {
   11885            0 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   11886            0 :       return void_node;
   11887              :     }
   11888              : 
   11889              :   /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
   11890              :      "__aeabi_atexit"), and DECL is a class object, we can just pass the
   11891              :      destructor to "__cxa_atexit"; we don't have to build a temporary
   11892              :      function to do the cleanup.  */
   11893         7198 :   dso_parm = (flag_use_cxa_atexit
   11894         3599 :               && !targetm.cxx.use_atexit_for_cxa_atexit ());
   11895         3599 :   ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
   11896         3587 :   use_dtor = ob_parm && CLASS_TYPE_P (type);
   11897         3599 :   if (use_dtor)
   11898              :     {
   11899         3216 :       cleanup = get_class_binding (type, complete_dtor_identifier);
   11900              : 
   11901              :       /* Make sure it is accessible.  */
   11902         3216 :       perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
   11903              :                                      tf_warning_or_error);
   11904              :     }
   11905              :   else
   11906              :     {
   11907              :       /* Call build_cleanup before we enter the anonymous function so
   11908              :          that any access checks will be done relative to the current
   11909              :          scope, rather than the scope of the anonymous function.  */
   11910          383 :       build_cleanup (decl);
   11911              : 
   11912              :       /* Now start the function.  */
   11913          383 :       cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
   11914              : 
   11915              :       /* Now, recompute the cleanup.  It may contain SAVE_EXPRs that refer
   11916              :          to the original function, rather than the anonymous one.  That
   11917              :          will make the back end think that nested functions are in use,
   11918              :          which causes confusion.  */
   11919          383 :       push_deferring_access_checks (dk_no_check);
   11920          383 :       fcall = build_cleanup (decl);
   11921          383 :       pop_deferring_access_checks ();
   11922              : 
   11923              :       /* Create the body of the anonymous function.  */
   11924          383 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
   11925          383 :       finish_expr_stmt (fcall);
   11926          383 :       finish_compound_stmt (compound_stmt);
   11927          383 :       end_cleanup_fn ();
   11928              :     }
   11929              : 
   11930              :   /* Call atexit with the cleanup function.  */
   11931         3599 :   mark_used (cleanup);
   11932         3599 :   cleanup = build_address (cleanup);
   11933              : 
   11934         3599 :   if (CP_DECL_THREAD_LOCAL_P (decl))
   11935           98 :     atex_node = get_thread_atexit_node ();
   11936              :   else
   11937         3501 :     atex_node = get_atexit_node ();
   11938              : 
   11939         3599 :   if (use_dtor)
   11940              :     {
   11941              :       /* We must convert CLEANUP to the type that "__cxa_atexit"
   11942              :          expects.  */
   11943         3216 :       cleanup = build_nop (get_cxa_atexit_fn_ptr_type (), cleanup);
   11944              :       /* "__cxa_atexit" will pass the address of DECL to the
   11945              :          cleanup function.  */
   11946         3216 :       mark_used (decl);
   11947         3216 :       addr = build_address (decl);
   11948              :       /* The declared type of the parameter to "__cxa_atexit" is
   11949              :          "void *".  For plain "T*", we could just let the
   11950              :          machinery in cp_build_function_call convert it -- but if the
   11951              :          type is "cv-qualified T *", then we need to convert it
   11952              :          before passing it in, to avoid spurious errors.  */
   11953         3216 :       addr = build_nop (ptr_type_node, addr);
   11954              :     }
   11955              :   else
   11956              :     /* Since the cleanup functions we build ignore the address
   11957              :        they're given, there's no reason to pass the actual address
   11958              :        in, and, in general, it's cheaper to pass NULL than any
   11959              :        other value.  */
   11960          383 :     addr = null_pointer_node;
   11961              : 
   11962         3599 :   if (dso_parm)
   11963         3587 :     arg2 = cp_build_addr_expr (get_dso_handle_node (),
   11964              :                                tf_warning_or_error);
   11965           12 :   else if (ob_parm)
   11966              :     /* Just pass NULL to the dso handle parm if we don't actually
   11967              :        have a DSO handle on this target.  */
   11968            0 :     arg2 = null_pointer_node;
   11969              :   else
   11970              :     arg2 = NULL_TREE;
   11971              : 
   11972         3587 :   if (ob_parm)
   11973              :     {
   11974         3587 :       if (!CP_DECL_THREAD_LOCAL_P (decl)
   11975         3587 :           && targetm.cxx.use_aeabi_atexit ())
   11976              :         {
   11977              :           arg1 = cleanup;
   11978              :           arg0 = addr;
   11979              :         }
   11980              :       else
   11981              :         {
   11982              :           arg1 = addr;
   11983              :           arg0 = cleanup;
   11984              :         }
   11985              :     }
   11986              :   else
   11987              :     {
   11988              :       arg0 = cleanup;
   11989              :       arg1 = NULL_TREE;
   11990              :     }
   11991         3599 :   return cp_build_function_call_nary (atex_node, tf_warning_or_error,
   11992         3599 :                                       arg0, arg1, arg2, NULL_TREE);
   11993              : }
   11994              : 
   11995              : /* DECL is a VAR_DECL with static storage duration.  INIT, if present,
   11996              :    is its initializer.  Generate code to handle the construction
   11997              :    and destruction of DECL.  */
   11998              : 
   11999              : static void
   12000     29652007 : expand_static_init (tree decl, tree init)
   12001              : {
   12002     29652007 :   gcc_assert (VAR_P (decl));
   12003     29652007 :   gcc_assert (TREE_STATIC (decl));
   12004              : 
   12005              :   /* Some variables require no dynamic initialization.  */
   12006     29652007 :   if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
   12007              :     {
   12008              :       /* Make sure the destructor is callable.  */
   12009     29648443 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   12010     29648443 :       if (!init)
   12011              :         return;
   12012              :     }
   12013              : 
   12014        16158 :   if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
   12015        15232 :       && !DECL_FUNCTION_SCOPE_P (decl))
   12016              :     {
   12017           15 :       auto_diagnostic_group d;
   12018           15 :       location_t dloc = DECL_SOURCE_LOCATION (decl);
   12019           15 :       if (init)
   12020           12 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   12021              :                   "needs dynamic initialization", decl);
   12022              :       else
   12023            3 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   12024              :                   "has a non-trivial destructor", decl);
   12025           15 :       static bool informed;
   12026           15 :       if (!informed)
   12027              :         {
   12028            6 :           inform (dloc, "C++11 %<thread_local%> allows dynamic "
   12029              :                   "initialization and destruction");
   12030            6 :           informed = true;
   12031              :         }
   12032           15 :       return;
   12033           15 :     }
   12034              : 
   12035        15188 :   if (DECL_FUNCTION_SCOPE_P (decl))
   12036              :     {
   12037              :       /* Emit code to perform this initialization but once.  */
   12038         3856 :       tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
   12039         3856 :       tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
   12040         3856 :       tree guard, guard_addr;
   12041         3856 :       tree flag, begin;
   12042              :       /* We don't need thread-safety code for thread-local vars.  */
   12043         3856 :       bool thread_guard = (flag_threadsafe_statics
   12044         3856 :                            && !CP_DECL_THREAD_LOCAL_P (decl));
   12045              : 
   12046              :       /* Emit code to perform this initialization but once.  This code
   12047              :          looks like:
   12048              : 
   12049              :            static <type> guard;
   12050              :            if (!__atomic_load (guard.first_byte)) {
   12051              :              if (__cxa_guard_acquire (&guard)) {
   12052              :                bool flag = false;
   12053              :                try {
   12054              :                  // Do initialization.
   12055              :                  flag = true; __cxa_guard_release (&guard);
   12056              :                  // Register variable for destruction at end of program.
   12057              :                } catch {
   12058              :                  if (!flag) __cxa_guard_abort (&guard);
   12059              :                }
   12060              :              }
   12061              :            }
   12062              : 
   12063              :          Note that the `flag' variable is only set to 1 *after* the
   12064              :          initialization is complete.  This ensures that an exception,
   12065              :          thrown during the construction, will cause the variable to
   12066              :          reinitialized when we pass through this code again, as per:
   12067              : 
   12068              :            [stmt.dcl]
   12069              : 
   12070              :            If the initialization exits by throwing an exception, the
   12071              :            initialization is not complete, so it will be tried again
   12072              :            the next time control enters the declaration.
   12073              : 
   12074              :          This process should be thread-safe, too; multiple threads
   12075              :          should not be able to initialize the variable more than
   12076              :          once.  */
   12077              : 
   12078              :       /* Create the guard variable.  */
   12079         3856 :       guard = get_guard (decl);
   12080              : 
   12081              :       /* Begin the conditional initialization.  */
   12082         3856 :       if_stmt = begin_if_stmt ();
   12083              : 
   12084         3856 :       finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
   12085         3856 :       then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   12086              : 
   12087         3856 :       if (thread_guard)
   12088              :         {
   12089         3708 :           tree vfntype = NULL_TREE;
   12090         3708 :           tree acquire_name, release_name, abort_name;
   12091         3708 :           tree acquire_fn, release_fn, abort_fn;
   12092         3708 :           guard_addr = build_address (guard);
   12093              : 
   12094         3708 :           acquire_name = get_identifier ("__cxa_guard_acquire");
   12095         3708 :           release_name = get_identifier ("__cxa_guard_release");
   12096         3708 :           abort_name = get_identifier ("__cxa_guard_abort");
   12097         3708 :           acquire_fn = get_global_binding (acquire_name);
   12098         3708 :           release_fn = get_global_binding (release_name);
   12099         3708 :           abort_fn = get_global_binding (abort_name);
   12100         3708 :           if (!acquire_fn)
   12101         2070 :             acquire_fn = push_library_fn
   12102         2070 :               (acquire_name, build_function_type_list (integer_type_node,
   12103         2070 :                                                        TREE_TYPE (guard_addr),
   12104              :                                                        NULL_TREE),
   12105              :                NULL_TREE, ECF_NOTHROW);
   12106         3708 :           if (!release_fn || !abort_fn)
   12107         2073 :             vfntype = build_function_type_list (void_type_node,
   12108         2073 :                                                 TREE_TYPE (guard_addr),
   12109              :                                                 NULL_TREE);
   12110         2073 :           if (!release_fn)
   12111         2073 :             release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
   12112              :                                           ECF_NOTHROW);
   12113         3708 :           if (!abort_fn)
   12114         2073 :             abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
   12115              :                                         ECF_NOTHROW | ECF_LEAF);
   12116              : 
   12117         3708 :           inner_if_stmt = begin_if_stmt ();
   12118         3708 :           finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
   12119              :                                inner_if_stmt);
   12120              : 
   12121         3708 :           inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   12122         3708 :           begin = get_internal_target_expr (boolean_false_node);
   12123         3708 :           flag = TARGET_EXPR_SLOT (begin);
   12124              : 
   12125         3708 :           TARGET_EXPR_CLEANUP (begin)
   12126         3708 :             = build3 (COND_EXPR, void_type_node, flag,
   12127              :                       void_node,
   12128              :                       build_call_n (abort_fn, 1, guard_addr));
   12129         3708 :           CLEANUP_EH_ONLY (begin) = 1;
   12130              : 
   12131              :           /* Do the initialization itself.  */
   12132         3708 :           init = add_stmt_to_compound (begin, init);
   12133         3708 :           init = add_stmt_to_compound (init,
   12134              :                                        build2 (MODIFY_EXPR, void_type_node,
   12135              :                                                flag, boolean_true_node));
   12136              : 
   12137              :           /* Use atexit to register a function for destroying this static
   12138              :              variable.  Do this before calling __cxa_guard_release.  */
   12139         3708 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   12140              : 
   12141         3708 :           init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
   12142              :                                                            guard_addr));
   12143              :         }
   12144              :       else
   12145              :         {
   12146          148 :           init = add_stmt_to_compound (init, set_guard (guard));
   12147              : 
   12148              :           /* Use atexit to register a function for destroying this static
   12149              :              variable.  */
   12150          148 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   12151              :         }
   12152              : 
   12153         3856 :       finish_expr_stmt (init);
   12154              : 
   12155         3856 :       if (thread_guard)
   12156              :         {
   12157         3708 :           finish_compound_stmt (inner_then_clause);
   12158         3708 :           finish_then_clause (inner_if_stmt);
   12159         3708 :           finish_if_stmt (inner_if_stmt);
   12160              :         }
   12161              : 
   12162         3856 :       finish_compound_stmt (then_clause);
   12163         3856 :       finish_then_clause (if_stmt);
   12164         3856 :       finish_if_stmt (if_stmt);
   12165              :     }
   12166        11332 :   else if (CP_DECL_THREAD_LOCAL_P (decl))
   12167          795 :     tls_aggregates = tree_cons (init, decl, tls_aggregates);
   12168              :   else
   12169        10537 :     static_aggregates = tree_cons (init, decl, static_aggregates);
   12170              : }
   12171              : 
   12172              : 
   12173              : /* Make TYPE a complete type based on INITIAL_VALUE.
   12174              :    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
   12175              :    2 if there was no information (in which case assume 0 if DO_DEFAULT),
   12176              :    3 if the initializer list is empty (in pedantic mode). */
   12177              : 
   12178              : int
   12179       624768 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
   12180              : {
   12181       624768 :   int failure;
   12182       624768 :   tree type, elt_type;
   12183              : 
   12184              :   /* Don't get confused by a CONSTRUCTOR for some other type.  */
   12185       624738 :   if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
   12186       149817 :       && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
   12187       625100 :       && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
   12188              :     return 1;
   12189              : 
   12190       624765 :   if (initial_value)
   12191              :     {
   12192              :       /* An array of character type can be initialized from a
   12193              :          brace-enclosed string constant so call reshape_init to
   12194              :          remove the optional braces from a braced string literal.  */
   12195       624735 :       if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
   12196       624735 :           && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
   12197        51495 :         initial_value = reshape_init (*ptype, initial_value,
   12198              :                                       tf_warning_or_error);
   12199              : 
   12200              :       /* If any of the elements are parameter packs, we can't actually
   12201              :          complete this type now because the array size is dependent.  */
   12202       624735 :       if (TREE_CODE (initial_value) == CONSTRUCTOR)
   12203     49316033 :         for (auto &e: CONSTRUCTOR_ELTS (initial_value))
   12204     48866978 :           if (PACK_EXPANSION_P (e.value))
   12205              :             return 0;
   12206              :     }
   12207              : 
   12208       624765 :   failure = complete_array_type (ptype, initial_value, do_default);
   12209              : 
   12210              :   /* We can create the array before the element type is complete, which
   12211              :      means that we didn't have these two bits set in the original type
   12212              :      either.  In completing the type, we are expected to propagate these
   12213              :      bits.  See also complete_type which does the same thing for arrays
   12214              :      of fixed size.  */
   12215       624765 :   type = *ptype;
   12216      1249527 :   if (type != error_mark_node && TYPE_DOMAIN (type))
   12217              :     {
   12218       624738 :       elt_type = TREE_TYPE (type);
   12219       624738 :       TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
   12220      1249476 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   12221       624738 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
   12222              :     }
   12223              : 
   12224              :   return failure;
   12225              : }
   12226              : 
   12227              : /* As above, but either give an error or reject zero-size arrays, depending
   12228              :    on COMPLAIN.  */
   12229              : 
   12230              : int
   12231         1253 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
   12232              :                                  bool do_default, tsubst_flags_t complain)
   12233              : {
   12234         1253 :   int failure;
   12235         1253 :   bool sfinae = !(complain & tf_error);
   12236              :   /* In SFINAE context we can't be lenient about zero-size arrays.  */
   12237         1253 :   if (sfinae)
   12238            3 :     ++pedantic;
   12239         1253 :   failure = cp_complete_array_type (ptype, initial_value, do_default);
   12240         1253 :   if (sfinae)
   12241            3 :     --pedantic;
   12242         1253 :   if (failure)
   12243              :     {
   12244            3 :       if (sfinae)
   12245              :         /* Not an error.  */;
   12246            0 :       else if (failure == 1)
   12247            0 :         error ("initializer fails to determine size of %qT", *ptype);
   12248            0 :       else if (failure == 2)
   12249              :         {
   12250            0 :           if (do_default)
   12251            0 :             error ("array size missing in %qT", *ptype);
   12252              :         }
   12253            0 :       else if (failure == 3)
   12254            0 :         error ("zero-size array %qT", *ptype);
   12255            3 :       *ptype = error_mark_node;
   12256              :     }
   12257         1253 :   return failure;
   12258              : }
   12259              : 
   12260              : /* Return zero if something is declared to be a member of type
   12261              :    CTYPE when in the context of CUR_TYPE.  STRING is the error
   12262              :    message to print in that case.  Otherwise, quietly return 1.  */
   12263              : 
   12264              : static int
   12265     27267450 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
   12266              : {
   12267     27267450 :   if (ctype && ctype != cur_type)
   12268              :     {
   12269            0 :       if (flags == DTOR_FLAG)
   12270            0 :         error ("destructor for alien class %qT cannot be a member", ctype);
   12271              :       else
   12272            0 :         error ("constructor for alien class %qT cannot be a member", ctype);
   12273              :       return 0;
   12274              :     }
   12275              :   return 1;
   12276              : }
   12277              : 
   12278              : /* Subroutine of `grokdeclarator'.  */
   12279              : 
   12280              : /* Generate errors possibly applicable for a given set of specifiers.
   12281              :    This is for ARM $7.1.2.  */
   12282              : 
   12283              : static void
   12284    457493301 : bad_specifiers (tree object,
   12285              :                 enum bad_spec_place type,
   12286              :                 int virtualp,
   12287              :                 int quals,
   12288              :                 int inlinep,
   12289              :                 int friendp,
   12290              :                 int raises,
   12291              :                 const location_t* locations)
   12292              : {
   12293    457493301 :   switch (type)
   12294              :     {
   12295     71098564 :       case BSP_VAR:
   12296     71098564 :         if (virtualp)
   12297            0 :           error_at (locations[ds_virtual],
   12298              :                     "%qD declared as a %<virtual%> variable", object);
   12299     71098564 :         if (quals)
   12300            3 :           error ("%<const%> and %<volatile%> function specifiers on "
   12301              :                  "%qD invalid in variable declaration", object);
   12302              :         break;
   12303    303736744 :       case BSP_PARM:
   12304    303736744 :         if (virtualp)
   12305            0 :           error_at (locations[ds_virtual],
   12306              :                     "%qD declared as a %<virtual%> parameter", object);
   12307    303736744 :         if (inlinep)
   12308            6 :           error_at (locations[ds_inline],
   12309              :                     "%qD declared as an %<inline%> parameter", object);
   12310    303736744 :         if (quals)
   12311            3 :           error ("%<const%> and %<volatile%> function specifiers on "
   12312              :                  "%qD invalid in parameter declaration", object);
   12313              :         break;
   12314     48716782 :       case BSP_TYPE:
   12315     48716782 :         if (virtualp)
   12316            0 :           error_at (locations[ds_virtual],
   12317              :                     "%qD declared as a %<virtual%> type", object);
   12318     48716782 :         if (inlinep)
   12319            6 :           error_at (locations[ds_inline],
   12320              :                     "%qD declared as an %<inline%> type", object);
   12321     48716782 :         if (quals)
   12322            0 :           error ("%<const%> and %<volatile%> function specifiers on "
   12323              :                  "%qD invalid in type declaration", object);
   12324              :         break;
   12325     33941211 :       case BSP_FIELD:
   12326     33941211 :         if (virtualp)
   12327            6 :           error_at (locations[ds_virtual],
   12328              :                     "%qD declared as a %<virtual%> field", object);
   12329     33941211 :         if (inlinep)
   12330            6 :           error_at (locations[ds_inline],
   12331              :                     "%qD declared as an %<inline%> field", object);
   12332     33941211 :         if (quals)
   12333            0 :           error ("%<const%> and %<volatile%> function specifiers on "
   12334              :                  "%qD invalid in field declaration", object);
   12335              :         break;
   12336            0 :       default:
   12337            0 :         gcc_unreachable();
   12338              :     }
   12339    457493301 :   if (friendp)
   12340            0 :     error ("%q+D declared as a friend", object);
   12341    457493301 :   if (raises
   12342          131 :       && !flag_noexcept_type
   12343    457493326 :       && (TREE_CODE (object) == TYPE_DECL
   12344           19 :           || (!TYPE_PTRFN_P (TREE_TYPE (object))
   12345            5 :               && !TYPE_REFFN_P (TREE_TYPE (object))
   12346            4 :               && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
   12347            6 :     error ("%q+D declared with an exception specification", object);
   12348    457493301 : }
   12349              : 
   12350              : /* DECL is a member function or static data member and is presently
   12351              :    being defined.  Check that the definition is taking place in a
   12352              :    valid namespace.  */
   12353              : 
   12354              : static void
   12355    100768488 : check_class_member_definition_namespace (tree decl)
   12356              : {
   12357              :   /* These checks only apply to member functions and static data
   12358              :      members.  */
   12359    100768488 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
   12360              :   /* We check for problems with specializations in pt.cc in
   12361              :      check_specialization_namespace, where we can issue better
   12362              :      diagnostics.  */
   12363    100768488 :   if (processing_specialization)
   12364              :     return;
   12365              :   /* We check this in check_explicit_instantiation_namespace.  */
   12366    100625322 :   if (processing_explicit_instantiation)
   12367              :     return;
   12368              :   /* [class.mfct]
   12369              : 
   12370              :      A member function definition that appears outside of the
   12371              :      class definition shall appear in a namespace scope enclosing
   12372              :      the class definition.
   12373              : 
   12374              :      [class.static.data]
   12375              : 
   12376              :      The definition for a static data member shall appear in a
   12377              :      namespace scope enclosing the member's class definition.  */
   12378    100625238 :   if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
   12379           18 :     permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
   12380           18 :                decl, DECL_CONTEXT (decl));
   12381              : }
   12382              : 
   12383              : /* Build a PARM_DECL for the "this" parameter of FN.  TYPE is the
   12384              :    METHOD_TYPE for a non-static member function; QUALS are the
   12385              :    cv-qualifiers that apply to the function.  */
   12386              : 
   12387              : tree
   12388    244093818 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
   12389              : {
   12390    244093818 :   tree this_type;
   12391    244093818 :   tree qual_type;
   12392    244093818 :   tree parm;
   12393    244093818 :   cp_cv_quals this_quals;
   12394              : 
   12395    244093818 :   if (CLASS_TYPE_P (type))
   12396              :     {
   12397    106522016 :       this_type
   12398    106522016 :         = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
   12399    106522016 :       this_type = build_pointer_type (this_type);
   12400              :     }
   12401              :   else
   12402    137571802 :     this_type = type_of_this_parm (type);
   12403              :   /* The `this' parameter is implicitly `const'; it cannot be
   12404              :      assigned to.  */
   12405    244093818 :   this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
   12406    244093818 :   qual_type = cp_build_qualified_type (this_type, this_quals);
   12407    244093818 :   parm = build_artificial_parm (fn, this_identifier, qual_type);
   12408    244093818 :   cp_apply_type_quals_to_decl (this_quals, parm);
   12409    244093818 :   return parm;
   12410              : }
   12411              : 
   12412              : /* DECL is a static member function.  Complain if it was declared
   12413              :    with function-cv-quals.  */
   12414              : 
   12415              : static void
   12416     10901486 : check_static_quals (tree decl, cp_cv_quals quals)
   12417              : {
   12418            0 :   if (quals != TYPE_UNQUALIFIED)
   12419            6 :     error ("static member function %q#D declared with type qualifiers",
   12420              :            decl);
   12421            0 : }
   12422              : 
   12423              : /* Helper function.  Replace the temporary this parameter injected
   12424              :    during cp_finish_omp_declare_simd with the real this parameter.  */
   12425              : 
   12426              : static tree
   12427         2692 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
   12428              : {
   12429         2692 :   tree this_parm = (tree) data;
   12430         2692 :   if (TREE_CODE (*tp) == PARM_DECL
   12431          450 :       && DECL_NAME (*tp) == this_identifier
   12432         2965 :       && *tp != this_parm)
   12433          273 :     *tp = this_parm;
   12434         2419 :   else if (TYPE_P (*tp))
   12435           33 :     *walk_subtrees = 0;
   12436         2692 :   return NULL_TREE;
   12437              : }
   12438              : 
   12439              : /* CTYPE is class type, or null if non-class.
   12440              :    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
   12441              :    or METHOD_TYPE.
   12442              :    DECLARATOR is the function's name.
   12443              :    PARMS is a chain of PARM_DECLs for the function.
   12444              :    VIRTUALP is truthvalue of whether the function is virtual or not.
   12445              :    FLAGS are to be passed through to `grokclassfn'.
   12446              :    QUALS are qualifiers indicating whether the function is `const'
   12447              :    or `volatile'.
   12448              :    RAISES is a list of exceptions that this function can raise.
   12449              :    CHECK is 1 if we must find this method in CTYPE, 0 if we should
   12450              :    not look, and -1 if we should not call `grokclassfn' at all.
   12451              : 
   12452              :    SFK is the kind of special function (if any) for the new function.
   12453              : 
   12454              :    Returns `NULL_TREE' if something goes wrong, after issuing
   12455              :    applicable error messages.  */
   12456              : 
   12457              : static tree
   12458    194389337 : grokfndecl (tree ctype,
   12459              :             tree type,
   12460              :             tree declarator,
   12461              :             tree parms,
   12462              :             tree orig_declarator,
   12463              :             const cp_decl_specifier_seq *declspecs,
   12464              :             tree decl_reqs,
   12465              :             int virtualp,
   12466              :             enum overload_flags flags,
   12467              :             cp_cv_quals quals,
   12468              :             cp_ref_qualifier rqual,
   12469              :             tree raises,
   12470              :             int check,
   12471              :             int friendp,
   12472              :             int publicp,
   12473              :             int inlinep,
   12474              :             int initialized,
   12475              :             bool xobj_func_p,
   12476              :             special_function_kind sfk,
   12477              :             bool funcdef_flag,
   12478              :             bool late_return_type_p,
   12479              :             int template_count,
   12480              :             tree in_namespace,
   12481              :             tree* attrlist,
   12482              :             tree contract_specifiers,
   12483              :             location_t location)
   12484              : {
   12485    194389337 :   tree decl;
   12486    194389337 :   tree t;
   12487              : 
   12488    194389337 :   if (location == UNKNOWN_LOCATION)
   12489            0 :     location = input_location;
   12490              : 
   12491              :   /* Was the concept specifier present?  */
   12492    194389337 :   bool concept_p = inlinep & 4;
   12493              : 
   12494    194389337 :   if (concept_p)
   12495              :     {
   12496           15 :       error_at (location, "function concepts are no longer supported");
   12497           15 :       return NULL_TREE;
   12498              :     }
   12499              : 
   12500              :   /* [except.spec]/9 - A deallocation function with no explicit noexcept-specifier
   12501              :      has a non-throwing exception specification.  */
   12502    194389322 :   if (raises == NULL_TREE
   12503    116378418 :       && cxx_dialect >= cxx11
   12504    140654786 :       && IDENTIFIER_NEWDEL_OP_P (declarator)
   12505    194453595 :       && !IDENTIFIER_NEW_OP_P (declarator))
   12506          919 :     raises = noexcept_true_spec;
   12507              : 
   12508    194389322 :   type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
   12509              : 
   12510    194389322 :   decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
   12511              : 
   12512              :   /* Set the constraints on the declaration. */
   12513    194389322 :   if (flag_concepts)
   12514              :     {
   12515    190155206 :       tree tmpl_reqs = NULL_TREE;
   12516    190155206 :       tree ctx = friendp ? current_class_type : ctype;
   12517    190155206 :       bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
   12518    190155206 :       bool memtmpl = (!block_local
   12519    190155206 :                       && (current_template_depth
   12520    190097110 :                           > template_class_depth (ctx)));
   12521     52588169 :       if (memtmpl)
   12522              :         {
   12523     52588169 :           if (!current_template_parms)
   12524              :             /* If there are no template parameters, something must have
   12525              :                gone wrong.  */
   12526            0 :             gcc_assert (seen_error ());
   12527              :           else
   12528     52588169 :             tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
   12529              :         }
   12530    190155206 :       tree ci = build_constraints (tmpl_reqs, decl_reqs);
   12531              :       /* C++20 CA378: Remove non-templated constrained functions.  */
   12532              :       /* [temp.friend]/9 A non-template friend declaration with a
   12533              :          requires-clause shall be a definition. A friend function template with
   12534              :          a constraint that depends on a template parameter from an enclosing
   12535              :          template shall be a definition. */
   12536    190155206 :       if (ci
   12537     10255286 :           && (block_local
   12538     10255283 :               || !processing_template_decl
   12539     10255222 :               || (friendp && !memtmpl && !funcdef_flag)))
   12540              :         {
   12541           73 :           if (!friendp || !processing_template_decl)
   12542           64 :             error_at (location, "constraints on a non-templated function");
   12543              :           else
   12544            9 :             error_at (location, "constrained non-template friend declaration"
   12545              :                       " must be a definition");
   12546              :           ci = NULL_TREE;
   12547              :         }
   12548    190155206 :       set_constraints (decl, ci);
   12549      1280824 :       if (ci && friendp && memtmpl && !funcdef_flag
   12550    190192680 :           && uses_outer_template_parms_in_constraints (decl, ctx))
   12551            6 :         error_at (location, "friend function template with constraints that "
   12552              :                   "depend on outer template parameters must be a definition");
   12553              :     }
   12554              : 
   12555    194389322 :   if (TREE_CODE (type) == METHOD_TYPE)
   12556              :     {
   12557    105007001 :       tree parm = build_this_parm (decl, type, quals);
   12558    105007001 :       DECL_CHAIN (parm) = parms;
   12559    105007001 :       parms = parm;
   12560              : 
   12561              :       /* Allocate space to hold the vptr bit if needed.  */
   12562    105007001 :       SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
   12563              :     }
   12564              : 
   12565    194389322 :   DECL_ARGUMENTS (decl) = parms;
   12566    586833825 :   for (t = parms; t; t = DECL_CHAIN (t))
   12567              :     {
   12568    392444503 :       DECL_CONTEXT (t) = decl;
   12569    392444503 :       if (flag_reflection
   12570      8169540 :           && initialized == SD_INITIALIZED
   12571    394091011 :           && DECL_ATTRIBUTES (t))
   12572         3718 :         for (tree a = DECL_ATTRIBUTES (t);
   12573         3722 :              (a = lookup_annotation (a));
   12574            4 :              a = TREE_CHAIN (a))
   12575              :           {
   12576            4 :             gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);
   12577              :             /* Mark TREE_PURPOSE of the value that it is an annotation
   12578              :                on an argument of a function definition (rather than
   12579              :                annotation from function declaration).  For function parameter
   12580              :                reflection all annotations are listed, while for variable_of
   12581              :                only those marked here.  Annotation is marked as coming from
   12582              :                function definition's argument if it has TREE_PURPOSE
   12583              :                void_node or INTEGER_CST with signed type.  */
   12584            4 :             tree val = TREE_VALUE (a);
   12585            4 :             gcc_assert (TREE_PURPOSE (val) == NULL_TREE);
   12586            4 :             TREE_PURPOSE (val) = void_node;
   12587              :           }
   12588              :     }
   12589              : 
   12590              :   /* Propagate volatile out from type to decl.  */
   12591    194389322 :   if (TYPE_VOLATILE (type))
   12592            0 :     TREE_THIS_VOLATILE (decl) = 1;
   12593              : 
   12594              :   /* Setup decl according to sfk.  */
   12595    194389322 :   switch (sfk)
   12596              :     {
   12597     24921138 :     case sfk_constructor:
   12598     24921138 :     case sfk_copy_constructor:
   12599     24921138 :     case sfk_move_constructor:
   12600     24921138 :       DECL_CXX_CONSTRUCTOR_P (decl) = 1;
   12601     24921138 :       DECL_NAME (decl) = ctor_identifier;
   12602     24921138 :       break;
   12603      3323881 :     case sfk_destructor:
   12604      3323881 :       DECL_CXX_DESTRUCTOR_P (decl) = 1;
   12605      3323881 :       DECL_NAME (decl) = dtor_identifier;
   12606      3323881 :       break;
   12607      1258638 :     case sfk_deduction_guide:
   12608              :       /* Give deduction guides a definition even though they don't really
   12609              :          have one: the restriction that you can't repeat a deduction guide
   12610              :          makes them more like a definition anyway.  */
   12611      1258638 :       DECL_INITIAL (decl) = void_node;
   12612              :       /* But to ensure that external-linkage deduction guides in header units
   12613              :          don't fall afoul of [module.import] p6, mark them as inline.  */
   12614      1258638 :       DECL_DECLARED_INLINE_P (decl) = true;
   12615      1258638 :       break;
   12616              :     default:
   12617              :       break;
   12618              :     }
   12619              : 
   12620    194389322 :   if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
   12621              :     {
   12622       109722 :       if (funcdef_flag)
   12623            3 :         error_at (location,
   12624              :                   "defining explicit specialization %qD in friend declaration",
   12625              :                   orig_declarator);
   12626              :       else
   12627              :         {
   12628       109719 :           tree fns = TREE_OPERAND (orig_declarator, 0);
   12629       109719 :           tree args = TREE_OPERAND (orig_declarator, 1);
   12630              : 
   12631       109719 :           if (PROCESSING_REAL_TEMPLATE_DECL_P ())
   12632              :             {
   12633              :               /* Something like `template <class T> friend void f<T>()'.  */
   12634            6 :               error_at (location,
   12635              :                         "invalid use of template-id %qD in declaration "
   12636              :                         "of primary template",
   12637              :                         orig_declarator);
   12638            6 :               return NULL_TREE;
   12639              :             }
   12640              : 
   12641              :           /* A friend declaration of the form friend void f<>().  Record
   12642              :              the information in the TEMPLATE_ID_EXPR.  */
   12643       109713 :           SET_DECL_IMPLICIT_INSTANTIATION (decl);
   12644              : 
   12645       109713 :           gcc_assert (identifier_p (fns) || OVL_P (fns));
   12646       109713 :           DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
   12647              : 
   12648              :           /* Remember the befriending class like push_template_decl does for
   12649              :              template friends.  */
   12650       109713 :           gcc_checking_assert (!DECL_CHAIN (decl));
   12651       109713 :           DECL_CHAIN (decl) = current_scope ();
   12652              : 
   12653       363624 :           for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
   12654       253916 :             if (TREE_PURPOSE (t)
   12655       253916 :                 && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
   12656              :             {
   12657            5 :               error_at (defparse_location (TREE_PURPOSE (t)),
   12658              :                         "default arguments are not allowed in declaration "
   12659              :                         "of friend template specialization %qD",
   12660              :                         decl);
   12661            5 :               return NULL_TREE;
   12662              :             }
   12663              : 
   12664       109708 :           if (inlinep & 1)
   12665              :             {
   12666            5 :               error_at (declspecs->locations[ds_inline],
   12667              :                         "%<inline%> is not allowed in declaration of friend "
   12668              :                         "template specialization %qD",
   12669              :                         decl);
   12670            5 :               return NULL_TREE;
   12671              :             }
   12672              :         }
   12673              :     }
   12674              : 
   12675              :   /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
   12676              :      expression, that declaration shall be a definition..."  */
   12677    194389306 :   if (friendp && !funcdef_flag)
   12678              :     {
   12679      1894577 :       bool has_errored = false;
   12680      1894577 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
   12681      5311226 :            t && t != void_list_node; t = TREE_CHAIN (t))
   12682      3416649 :         if (TREE_PURPOSE (t))
   12683              :           {
   12684           51 :             enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
   12685              :             /* For templates, mark the default argument as erroneous and give a
   12686              :                hard error.  */
   12687           51 :             if (processing_template_decl)
   12688              :               {
   12689           33 :                 diag_kind = diagnostics::kind::error;
   12690           33 :                 TREE_PURPOSE (t) = error_mark_node;
   12691              :               }
   12692           51 :             if (!has_errored)
   12693              :               {
   12694           48 :                 has_errored = true;
   12695           48 :                 emit_diagnostic (diag_kind,
   12696           48 :                                  DECL_SOURCE_LOCATION (decl),
   12697           48 :                                  /*diagnostics::option_id=*/0,
   12698              :                                  "friend declaration of %qD specifies default "
   12699              :                                  "arguments and isn%'t a definition", decl);
   12700              :               }
   12701              :           }
   12702              :     }
   12703              : 
   12704              :   /* If this decl has namespace scope, set that up.  */
   12705    194389306 :   if (in_namespace)
   12706       415442 :     set_decl_namespace (decl, in_namespace, friendp);
   12707    193973864 :   else if (ctype)
   12708    115824071 :     DECL_CONTEXT (decl) = ctype;
   12709              :   else
   12710     78149793 :     DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
   12711              : 
   12712              :   /* `main' and builtins have implicit 'C' linkage.  */
   12713    194389306 :   if (ctype == NULL_TREE
   12714     78565235 :       && DECL_FILE_SCOPE_P (decl)
   12715     32351451 :       && current_lang_name == lang_name_cplusplus
   12716    197421325 :       && (MAIN_NAME_P (declarator)
   12717      2997015 :           || (IDENTIFIER_LENGTH (declarator) > 10
   12718      2150304 :               && IDENTIFIER_POINTER (declarator)[0] == '_'
   12719      1666883 :               && IDENTIFIER_POINTER (declarator)[1] == '_'
   12720       349533 :               && startswith (IDENTIFIER_POINTER (declarator) + 2,
   12721              :                              "builtin_"))
   12722      2996997 :           || (targetcm.cxx_implicit_extern_c
   12723            0 :               && (targetcm.cxx_implicit_extern_c
   12724            0 :                   (IDENTIFIER_POINTER (declarator))))))
   12725        35022 :     SET_DECL_LANGUAGE (decl, lang_c);
   12726              : 
   12727    194389306 :   DECL_STATIC_FUNCTION_P (decl)
   12728    194389306 :     = !xobj_func_p && ctype && TREE_CODE (type) == FUNCTION_TYPE;
   12729    194389306 :   DECL_FUNCTION_XOBJ_FLAG (decl) = xobj_func_p;
   12730              : 
   12731    194389306 :   if (initialized == SD_DELETED)
   12732      4304715 :     DECL_DELETED_FN (decl) = 1;
   12733              : 
   12734    194389306 :   if (ctype && funcdef_flag)
   12735    100261542 :     check_class_member_definition_namespace (decl);
   12736              : 
   12737    194389306 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   12738              :     {
   12739        35010 :       if (PROCESSING_REAL_TEMPLATE_DECL_P())
   12740            9 :         error_at (location, "cannot declare %<::main%> to be a template");
   12741        35010 :       if (inlinep & 1)
   12742            3 :         error_at (declspecs->locations[ds_inline],
   12743              :                   "cannot declare %<::main%> to be inline");
   12744        35010 :       if (inlinep & 2)
   12745            6 :         error_at (declspecs->locations[ds_constexpr],
   12746              :                   "cannot declare %<::main%> to be %qs", "constexpr");
   12747        35010 :       if (inlinep & 8)
   12748            3 :         error_at (declspecs->locations[ds_consteval],
   12749              :                   "cannot declare %<::main%> to be %qs", "consteval");
   12750        35010 :       if (!publicp)
   12751            0 :         error_at (location, "cannot declare %<::main%> to be static");
   12752        35010 :       if (current_lang_name != lang_name_cplusplus)
   12753           12 :         pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
   12754              :                  " linkage specification other than %<extern \"C++\"%>");
   12755        35010 :       if (module_attach_p ())
   12756              :         {
   12757            3 :           auto_diagnostic_group adg;
   12758            3 :           error_at (location, "cannot attach %<::main%> to a named module");
   12759            3 :           inform (location, "use %<extern \"C++\"%> to attach it to the "
   12760              :                   "global module instead");
   12761            3 :         }
   12762              :       inlinep = 0;
   12763              :       publicp = 1;
   12764              :     }
   12765              : 
   12766              :   /* Members of anonymous types and local classes have no linkage; make
   12767              :      them internal.  If a typedef is made later, this will be changed.  */
   12768    194389306 :   if (ctype && !TREE_PUBLIC (TYPE_MAIN_DECL (ctype)))
   12769              :     publicp = 0;
   12770    194374045 :   else if (ctype && decl_function_context (TYPE_MAIN_DECL (ctype)))
   12771              :     /* But members of local classes in a module CMI should have their
   12772              :        definitions exported, in case they are (directly or indirectly)
   12773              :        used by an importer.  We don't just use module_has_cmi_p here
   12774              :        because for entities in the GMF we don't yet know whether this
   12775              :        module will have a CMI, so we'll conservatively assume it might.  */
   12776      2427063 :     publicp = module_maybe_has_cmi_p ();
   12777              : 
   12778    194374045 :   if (publicp && cxx_dialect == cxx98)
   12779              :     {
   12780              :       /* [basic.link]: A name with no linkage (notably, the name of a class
   12781              :          or enumeration declared in a local scope) shall not be used to
   12782              :          declare an entity with linkage.
   12783              : 
   12784              :          DR 757 relaxes this restriction for C++0x.  */
   12785      1013024 :       no_linkage_error (decl);
   12786              :     }
   12787              : 
   12788    194389306 :   TREE_PUBLIC (decl) = publicp;
   12789    194389306 :   if (! publicp)
   12790              :     {
   12791      2546402 :       DECL_INTERFACE_KNOWN (decl) = 1;
   12792      2546402 :       DECL_NOT_REALLY_EXTERN (decl) = 1;
   12793              :     }
   12794              : 
   12795              :   /* If the declaration was declared inline, mark it as such.  */
   12796    194389306 :   if (inlinep)
   12797              :     {
   12798     75871211 :       DECL_DECLARED_INLINE_P (decl) = 1;
   12799     75871211 :       if (publicp)
   12800     75621963 :         DECL_COMDAT (decl) = 1;
   12801              :     }
   12802     75871211 :   if (inlinep & 2)
   12803     55454921 :     DECL_DECLARED_CONSTEXPR_P (decl) = true;
   12804    138934385 :   else if (inlinep & 8)
   12805              :     {
   12806      1165014 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
   12807      1165014 :       SET_DECL_IMMEDIATE_FUNCTION_P (decl);
   12808              :     }
   12809              : 
   12810    194389306 :   DECL_EXTERNAL (decl) = 1;
   12811    194389306 :   if (TREE_CODE (type) == FUNCTION_TYPE)
   12812              :     {
   12813     89382305 :       if (quals || rqual)
   12814          393 :         TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
   12815              :                                               TYPE_UNQUALIFIED,
   12816              :                                               REF_QUAL_NONE);
   12817     89382305 :       auto_diagnostic_group d;
   12818     89382305 :       if (quals)
   12819          621 :         error (!ctype
   12820              :                ? G_("non-member function %qD cannot have cv-qualifier")
   12821              :                : !xobj_func_p
   12822          297 :                  ? G_("static member function %qD cannot have cv-qualifier")
   12823              :                  : G_("explicit object member function "
   12824              :                       "%qD cannot have cv-qualifier"),
   12825              :                decl);
   12826     89382305 :       if (rqual)
   12827          531 :         error (!ctype
   12828              :                ? G_("non-member function %qD cannot have ref-qualifier")
   12829              :                : !xobj_func_p
   12830          264 :                  ? G_("static member function %qD cannot have ref-qualifier")
   12831              :                  : G_("explicit object member function "
   12832              :                       "%qD cannot have ref-qualifier"),
   12833              :                  decl);
   12834              : 
   12835     89382305 :       if (xobj_func_p && (quals || rqual))
   12836          363 :         inform (DECL_SOURCE_LOCATION (DECL_ARGUMENTS (decl)),
   12837              :                 "explicit object parameter declared here");
   12838     89382305 :       quals = TYPE_UNQUALIFIED;
   12839     89382305 :       rqual = REF_QUAL_NONE;
   12840              : 
   12841     89382305 :     }
   12842              : 
   12843    194389306 :   if (deduction_guide_p (decl))
   12844              :     {
   12845      1258638 :       tree type = TREE_TYPE (DECL_NAME (decl));
   12846      1258638 :       if (in_namespace == NULL_TREE
   12847      1258638 :           && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
   12848              :         {
   12849            3 :           auto_diagnostic_group d;
   12850            3 :           error_at (location, "deduction guide %qD must be declared in the "
   12851              :                               "same scope as %qT", decl, type);
   12852            3 :           inform (location_of (type), "  declared here");
   12853            3 :           return NULL_TREE;
   12854            3 :         }
   12855      2517270 :       if (DECL_CLASS_SCOPE_P (decl)
   12856      1258676 :           && current_access_specifier != declared_access (TYPE_NAME (type)))
   12857              :         {
   12858            3 :           auto_diagnostic_group d;
   12859            3 :           error_at (location, "deduction guide %qD must have the same access "
   12860              :                               "as %qT", decl, type);
   12861            3 :           inform (location_of (type), "  declared here");
   12862            3 :         }
   12863      1258635 :       if (funcdef_flag)
   12864            3 :         error_at (location,
   12865              :                   "deduction guide %qD must not have a function body", decl);
   12866              :     }
   12867    360079705 :   else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
   12868    205315807 :            && !grok_op_properties (decl, /*complain=*/true))
   12869              :     return NULL_TREE;
   12870    193130521 :   else if (UDLIT_OPER_P (DECL_NAME (decl)))
   12871              :     {
   12872       313518 :       bool long_long_unsigned_p;
   12873       313518 :       bool long_double_p;
   12874       313518 :       const char *suffix = NULL;
   12875              :       /* [over.literal]/6: Literal operators shall not have C linkage. */
   12876       313518 :       if (DECL_LANGUAGE (decl) == lang_c)
   12877              :         {
   12878            6 :           auto_diagnostic_group d;
   12879            6 :           error_at (location, "literal operator with C linkage");
   12880            6 :           maybe_show_extern_c_location ();
   12881            6 :           return NULL_TREE;
   12882            6 :         }
   12883              : 
   12884       313512 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   12885              :         {
   12886       313506 :           if (!check_literal_operator_args (decl, &long_long_unsigned_p,
   12887              :                                             &long_double_p))
   12888              :             {
   12889           42 :               error_at (location, "%qD has invalid argument list", decl);
   12890           42 :               return NULL_TREE;
   12891              :             }
   12892              : 
   12893       313464 :           suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
   12894       313464 :           if (long_long_unsigned_p)
   12895              :             {
   12896        46890 :               if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
   12897           68 :                 warning_at (location, 0, "integer suffix %qs"
   12898              :                             " shadowed by implementation", suffix);
   12899              :             }
   12900       266574 :           else if (long_double_p)
   12901              :             {
   12902        85799 :               if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
   12903           80 :                 warning_at (location, 0, "floating-point suffix %qs"
   12904              :                             " shadowed by implementation", suffix);
   12905              :             }
   12906              :           /* 17.6.3.3.5  */
   12907       313464 :           if (suffix[0] != '_'
   12908       312857 :               && !current_function_decl && !(friendp && !funcdef_flag))
   12909       312851 :             warning_at (location, OPT_Wliteral_suffix,
   12910              :                         "literal operator suffixes not preceded by %<_%>"
   12911              :                         " are reserved for future standardization");
   12912              :         }
   12913              :       else
   12914              :         {
   12915            6 :           error_at (location, "%qD must be a non-member function", decl);
   12916            6 :           return NULL_TREE;
   12917              :         }
   12918              :     }
   12919              : 
   12920    193130470 :   if (funcdef_flag)
   12921              :     /* Make the init_value nonzero so pushdecl knows this is not
   12922              :        tentative.  error_mark_node is replaced later with the BLOCK.  */
   12923    137244556 :     DECL_INITIAL (decl) = error_mark_node;
   12924              : 
   12925    194389102 :   if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
   12926     73566039 :     TREE_NOTHROW (decl) = 1;
   12927              : 
   12928    194389102 :   if (flag_openmp || flag_openmp_simd)
   12929              :     {
   12930              :       /* Adjust "omp declare simd" attributes.  */
   12931       497999 :       tree ods = lookup_attribute ("omp declare simd", *attrlist);
   12932       497999 :       if (ods)
   12933              :         {
   12934              :           tree attr;
   12935         2081 :           for (attr = ods; attr;
   12936         1102 :                attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
   12937              :             {
   12938         1102 :               if (TREE_CODE (type) == METHOD_TYPE)
   12939          204 :                 walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
   12940              :                            DECL_ARGUMENTS (decl), NULL);
   12941         1102 :               if (TREE_VALUE (attr) != NULL_TREE)
   12942              :                 {
   12943          896 :                   tree cl = TREE_VALUE (TREE_VALUE (attr));
   12944          896 :                   cl = c_omp_declare_simd_clauses_to_numbers
   12945          896 :                                                 (DECL_ARGUMENTS (decl), cl);
   12946          896 :                   if (cl)
   12947          896 :                     TREE_VALUE (TREE_VALUE (attr)) = cl;
   12948              :                   else
   12949            0 :                     TREE_VALUE (attr) = NULL_TREE;
   12950              :                 }
   12951              :             }
   12952              :         }
   12953              :     }
   12954              : 
   12955              :   /* [basic.stc.dynamic.deallocation]/3 - A deallocation function shall not
   12956              :      have a potentially throwing exception specification.  */
   12957    194389102 :   maybe_diagnose_deallocation_noexcept_false (decl);
   12958              : 
   12959              :   /* Caller will do the rest of this.  */
   12960    194389102 :   if (check < 0)
   12961              :     {
   12962      6768974 :       if (decl && decl != error_mark_node && contract_specifiers)
   12963           24 :         set_fn_contract_specifiers (decl, contract_specifiers);
   12964      6768974 :       return decl;
   12965              :     }
   12966              : 
   12967    187620128 :   if (ctype != NULL_TREE)
   12968    115823752 :     grokclassfn (ctype, decl, flags);
   12969              : 
   12970              :   /* 12.4/3  */
   12971    187620128 :   if (cxx_dialect >= cxx11
   12972    373229100 :       && DECL_DESTRUCTOR_P (decl)
   12973      3305789 :       && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
   12974    187787547 :       && !processing_template_decl)
   12975        85395 :     deduce_noexcept_on_destructor (decl);
   12976              : 
   12977    187620128 :   set_originating_module (decl);
   12978              : 
   12979    187620128 :   decl = check_explicit_specialization (orig_declarator, decl,
   12980              :                                         template_count,
   12981    187620128 :                                         2 * funcdef_flag +
   12982    187620128 :                                         4 * (friendp != 0),
   12983              :                                         *attrlist);
   12984    187620128 :   if (decl == error_mark_node)
   12985              :     return NULL_TREE;
   12986              : 
   12987    187619854 :   if (DECL_STATIC_FUNCTION_P (decl))
   12988     10723205 :     check_static_quals (decl, quals);
   12989              : 
   12990    187619854 :   if (attrlist)
   12991              :     {
   12992    187619854 :       cplus_decl_attributes (&decl, *attrlist, 0);
   12993    187619854 :       *attrlist = NULL_TREE;
   12994              :     }
   12995              : 
   12996              :   /* Update now we have a decl and maybe know the return type.  */
   12997    187619854 :   if (contract_specifiers)
   12998              :     {
   12999          918 :       tree t = decl;
   13000          918 :       if (TREE_CODE (decl) == TEMPLATE_DECL)
   13001            7 :         t = DECL_TEMPLATE_RESULT (decl);
   13002          918 :       set_fn_contract_specifiers (t, contract_specifiers);
   13003          918 :       rebuild_postconditions (t);
   13004              :     }
   13005              : 
   13006              :   /* Check main's type after attributes have been applied.  */
   13007    187619854 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   13008              :     {
   13009        34998 :       if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
   13010              :                         integer_type_node))
   13011              :         {
   13012           20 :           tree dtype = TREE_TYPE (decl);
   13013           20 :           tree oldtypeargs = TYPE_ARG_TYPES (dtype);
   13014           20 :           tree newtype;
   13015           20 :           error_at (declspecs->locations[ds_type_spec],
   13016              :                     "%<::main%> must return %<int%>");
   13017           60 :           newtype = build_function_type (integer_type_node, oldtypeargs,
   13018           20 :                                          TYPE_NO_NAMED_ARGS_STDARG_P (dtype));
   13019           20 :           TREE_TYPE (decl) = newtype;
   13020              :         }
   13021        34998 :       if (warn_main)
   13022        34976 :         check_main_parameter_types (decl);
   13023              :     }
   13024              : 
   13025    187619854 :   if (ctype != NULL_TREE && check)
   13026              :     {
   13027      9214835 :       tree old_decl = check_classfn (ctype, decl,
   13028      9214835 :                                      (current_template_depth
   13029      9214835 :                                       > template_class_depth (ctype))
   13030      2309237 :                                      ? current_template_parms
   13031              :                                      : NULL_TREE);
   13032              : 
   13033      9214835 :       if (old_decl == error_mark_node)
   13034              :         return NULL_TREE;
   13035              : 
   13036      9214724 :       if (old_decl)
   13037              :         {
   13038      8818612 :           tree ok;
   13039      8818612 :           tree pushed_scope;
   13040              : 
   13041      8818612 :           if (TREE_CODE (old_decl) == TEMPLATE_DECL)
   13042              :             /* Because grokfndecl is always supposed to return a
   13043              :                FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
   13044              :                here.  We depend on our callers to figure out that its
   13045              :                really a template that's being returned.  */
   13046      2309225 :             old_decl = DECL_TEMPLATE_RESULT (old_decl);
   13047              : 
   13048      8818612 :           if (DECL_STATIC_FUNCTION_P (old_decl)
   13049      8818612 :               && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
   13050              :             {
   13051              :               /* Remove the `this' parm added by grokclassfn.  */
   13052       178281 :               revert_static_member_fn (decl);
   13053       178281 :               check_static_quals (decl, quals);
   13054              :             }
   13055      8818612 :           if (DECL_ARTIFICIAL (old_decl))
   13056              :             {
   13057            9 :               error ("definition of implicitly-declared %qD", old_decl);
   13058            9 :               return NULL_TREE;
   13059              :             }
   13060      8818603 :           else if (DECL_DEFAULTED_FN (old_decl)
   13061      8818605 :                    && !(initialized == SD_DEFAULTED
   13062            2 :                         && redefinable_import_p (old_decl)))
   13063              :             {
   13064            3 :               auto_diagnostic_group d;
   13065            3 :               error ("definition of explicitly-defaulted %q+D", decl);
   13066            3 :               inform (DECL_SOURCE_LOCATION (old_decl),
   13067              :                       "%q#D explicitly defaulted here", old_decl);
   13068            3 :               return NULL_TREE;
   13069            3 :             }
   13070              : 
   13071      8818600 :           if (modules_p () && !module_may_redeclare (old_decl))
   13072              :             return NULL_TREE;
   13073              : 
   13074              :           /* Since we've smashed OLD_DECL to its
   13075              :              DECL_TEMPLATE_RESULT, we must do the same to DECL.  */
   13076      8818540 :           if (TREE_CODE (decl) == TEMPLATE_DECL)
   13077          969 :             decl = DECL_TEMPLATE_RESULT (decl);
   13078              : 
   13079              :           /* Attempt to merge the declarations.  This can fail, in
   13080              :              the case of some invalid specialization declarations.  */
   13081      8818540 :           pushed_scope = push_scope (ctype);
   13082      8818540 :           ok = duplicate_decls (decl, old_decl);
   13083      8818540 :           if (pushed_scope)
   13084      8818540 :             pop_scope (pushed_scope);
   13085      8818540 :           if (!ok)
   13086              :             {
   13087            0 :               error ("no %q#D member function declared in class %qT",
   13088              :                      decl, ctype);
   13089            0 :               return NULL_TREE;
   13090              :             }
   13091      8818540 :           if (ok == error_mark_node)
   13092              :             return NULL_TREE;
   13093      8818516 :           return old_decl;
   13094              :         }
   13095              :     }
   13096              : 
   13097    357602262 :   if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
   13098              :     return NULL_TREE;
   13099              : 
   13100    178801128 :   if (ctype == NULL_TREE || check)
   13101     72192283 :     return decl;
   13102              : 
   13103    106608845 :   if (virtualp)
   13104      4187848 :     DECL_VIRTUAL_P (decl) = 1;
   13105              : 
   13106    106608845 :   return decl;
   13107              : }
   13108              : 
   13109              : /* decl is a FUNCTION_DECL.
   13110              :    specifiers are the parsed virt-specifiers.
   13111              : 
   13112              :    Set flags to reflect the virt-specifiers.
   13113              : 
   13114              :    Returns decl.  */
   13115              : 
   13116              : static tree
   13117    113377916 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
   13118              : {
   13119    113377916 :   if (decl == NULL_TREE)
   13120              :     return decl;
   13121    113377819 :   if (specifiers & VIRT_SPEC_OVERRIDE)
   13122       391779 :     DECL_OVERRIDE_P (decl) = 1;
   13123    113377819 :   if (specifiers & VIRT_SPEC_FINAL)
   13124         9937 :     DECL_FINAL_P (decl) = 1;
   13125              :   return decl;
   13126              : }
   13127              : 
   13128              : /* DECL is a VAR_DECL for a static data member.  Set flags to reflect
   13129              :    the linkage that DECL will receive in the object file.  */
   13130              : 
   13131              : static void
   13132     13952425 : set_linkage_for_static_data_member (tree decl)
   13133              : {
   13134              :   /* A static data member always has static storage duration and
   13135              :      external linkage.  Note that static data members are forbidden in
   13136              :      local classes -- the only situation in which a class has
   13137              :      non-external linkage.  */
   13138     13952425 :   TREE_PUBLIC (decl) = 1;
   13139     13952425 :   TREE_STATIC (decl) = 1;
   13140              :   /* For non-template classes, static data members are always put
   13141              :      out in exactly those files where they are defined, just as
   13142              :      with ordinary namespace-scope variables.  */
   13143     13952425 :   if (!processing_template_decl)
   13144     10626689 :     DECL_INTERFACE_KNOWN (decl) = 1;
   13145     13952425 : }
   13146              : 
   13147              : /* Create a VAR_DECL named NAME with the indicated TYPE.
   13148              : 
   13149              :    If SCOPE is non-NULL, it is the class type or namespace containing
   13150              :    the variable.  If SCOPE is NULL, the variable should is created in
   13151              :    the innermost enclosing scope.  */
   13152              : 
   13153              : static tree
   13154     71098656 : grokvardecl (tree type,
   13155              :              tree name,
   13156              :              tree orig_declarator,
   13157              :              const cp_decl_specifier_seq *declspecs,
   13158              :              int initialized,
   13159              :              int type_quals,
   13160              :              int inlinep,
   13161              :              bool conceptp,
   13162              :              int template_count,
   13163              :              tree scope,
   13164              :              location_t location)
   13165              : {
   13166     71098656 :   tree decl;
   13167     71098656 :   tree explicit_scope;
   13168              : 
   13169     71098656 :   gcc_assert (!name || identifier_p (name));
   13170              : 
   13171     71098656 :   bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
   13172     71098656 :   bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
   13173              : 
   13174              :   /* Compute the scope in which to place the variable, but remember
   13175              :      whether or not that scope was explicitly specified by the user.   */
   13176     71098656 :   explicit_scope = scope;
   13177     71098656 :   if (!scope)
   13178              :     {
   13179              :       /* An explicit "extern" specifier indicates a namespace-scope
   13180              :          variable.  */
   13181     70575370 :       if (declspecs->storage_class == sc_extern)
   13182       556513 :         scope = current_decl_namespace ();
   13183     70018857 :       else if (!at_function_scope_p ())
   13184      7639066 :         scope = current_scope ();
   13185              :     }
   13186              : 
   13187     70575370 :   if (scope
   13188      8718865 :       && (/* If the variable is a namespace-scope variable declared in a
   13189              :              template, we need DECL_LANG_SPECIFIC.  */
   13190      8718865 :           (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
   13191              :           /* Similarly for namespace-scope variables with language linkage
   13192              :              other than C++.  */
   13193      8211919 :           || (TREE_CODE (scope) == NAMESPACE_DECL
   13194      4579223 :               && current_lang_name != lang_name_cplusplus)
   13195              :           /* Similarly for static data members.  */
   13196      4850002 :           || TYPE_P (scope)
   13197              :           /* Similarly for explicit specializations.  */
   13198      4343056 :           || (orig_declarator
   13199      4342206 :               && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
   13200      5312889 :     decl = build_lang_decl_loc (location, VAR_DECL, name, type);
   13201              :   else
   13202     65785767 :     decl = build_decl (location, VAR_DECL, name, type);
   13203              : 
   13204     71098656 :   if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
   13205        16340 :     set_decl_namespace (decl, explicit_scope, 0);
   13206              :   else
   13207     71082316 :     DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
   13208              : 
   13209     71098656 :   if (declspecs->storage_class == sc_extern)
   13210              :     {
   13211       556513 :       DECL_THIS_EXTERN (decl) = 1;
   13212       556513 :       DECL_EXTERNAL (decl) = !initialized;
   13213              :     }
   13214              : 
   13215     71098656 :   if (DECL_CLASS_SCOPE_P (decl))
   13216              :     {
   13217       506946 :       set_linkage_for_static_data_member (decl);
   13218              :       /* This function is only called with out-of-class definitions.  */
   13219       506946 :       DECL_EXTERNAL (decl) = 0;
   13220       506946 :       check_class_member_definition_namespace (decl);
   13221              :     }
   13222              :   /* At top level, either `static' or no s.c. makes a definition
   13223              :      (perhaps tentative), and absence of `static' makes it public.  */
   13224     70591710 :   else if (toplevel_bindings_p ())
   13225              :     {
   13226     16421510 :       TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
   13227      8210755 :                             && (DECL_THIS_EXTERN (decl)
   13228      7615930 :                                 || ! constp
   13229      7615930 :                                 || volatilep
   13230      7535573 :                                 || inlinep
   13231       902310 :                                 || in_template_context
   13232        31795 :                                 || processing_specialization
   13233        31712 :                                 || module_attach_p ()));
   13234      8210755 :       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
   13235              :     }
   13236              :   /* Not at top level, only `static' makes a static definition.  */
   13237              :   else
   13238              :     {
   13239     62380955 :       TREE_STATIC (decl) = declspecs->storage_class == sc_static;
   13240     62380955 :       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
   13241              :     }
   13242              : 
   13243     71098656 :   set_originating_module (decl);
   13244              : 
   13245     71098656 :   if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
   13246              :     {
   13247        20118 :       if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
   13248              :         {
   13249        20110 :           CP_DECL_THREAD_LOCAL_P (decl) = true;
   13250              :           // NB: Set a tentative TLS model to avoid tls_model attribute
   13251              :           // warnings due to lack of thread storage duration.  It will
   13252              :           // be updated by cplus_decl_attributes later.
   13253        20110 :           if (!processing_template_decl)
   13254        19985 :             set_decl_tls_model (decl, TLS_MODEL_REAL);
   13255              :         }
   13256        20118 :       if (declspecs->gnu_thread_keyword_p)
   13257        19099 :         SET_DECL_GNU_TLS_P (decl);
   13258              :     }
   13259              : 
   13260              :   /* If the type of the decl has no linkage, make sure that we'll
   13261              :      notice that in mark_used.  */
   13262     71098656 :   if (cxx_dialect > cxx98
   13263     70834462 :       && decl_linkage (decl) != lk_none
   13264     70113364 :       && DECL_LANG_SPECIFIC (decl) == NULL
   13265     64719633 :       && !DECL_EXTERN_C_P (decl)
   13266    135818289 :       && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
   13267         4757 :     retrofit_lang_decl (decl);
   13268              : 
   13269     71098656 :   if (TREE_PUBLIC (decl))
   13270              :     {
   13271              :       /* [basic.link]: A name with no linkage (notably, the name of a class
   13272              :          or enumeration declared in a local scope) shall not be used to
   13273              :          declare an entity with linkage.
   13274              : 
   13275              :          DR 757 relaxes this restriction for C++0x.  */
   13276      8647685 :       if (cxx_dialect < cxx11)
   13277        21895 :         no_linkage_error (decl);
   13278              :     }
   13279              :   else
   13280     62450971 :     DECL_INTERFACE_KNOWN (decl) = 1;
   13281              : 
   13282     71098656 :   if (DECL_NAME (decl)
   13283     71098656 :       && MAIN_NAME_P (DECL_NAME (decl)))
   13284              :     {
   13285           12 :       if (scope == global_namespace)
   13286            6 :         error_at (DECL_SOURCE_LOCATION (decl),
   13287              :                   "cannot declare %<::main%> to be a global variable");
   13288            6 :       else if (DECL_EXTERN_C_P (decl))
   13289            3 :         error_at (DECL_SOURCE_LOCATION (decl),
   13290              :                   "an entity named %<main%> cannot be declared with "
   13291              :                   "C language linkage");
   13292              :     }
   13293              : 
   13294              :   /* Check if a variable is being declared as a concept.  */
   13295     71098656 :   if (conceptp)
   13296              :     {
   13297           30 :       if (!processing_template_decl)
   13298           13 :         error_at (declspecs->locations[ds_concept],
   13299              :                   "a non-template variable cannot be %<concept%>");
   13300           17 :       else if (!at_namespace_scope_p ())
   13301            2 :         error_at (declspecs->locations[ds_concept],
   13302              :                   "concept must be defined at namespace scope");
   13303              :       else
   13304           15 :         error_at (declspecs->locations[ds_concept],
   13305              :                   "variable concepts are no longer supported");
   13306              :       return NULL_TREE;
   13307              :     }
   13308     71098626 :   else if (flag_concepts
   13309     71098626 :            && current_template_depth > template_class_depth (scope))
   13310              :     {
   13311     61271666 :       tree ci = current_template_constraints ();
   13312     61271666 :       set_constraints (decl, ci);
   13313              :     }
   13314              : 
   13315              :   // Handle explicit specializations and instantiations of variable templates.
   13316     71098626 :   if (orig_declarator)
   13317     70370262 :     decl = check_explicit_specialization (orig_declarator, decl,
   13318              :                                           template_count, 0);
   13319              : 
   13320     71098626 :   return decl != error_mark_node ? decl : NULL_TREE;
   13321              : }
   13322              : 
   13323              : /* Create and return a canonical pointer to member function type, for
   13324              :    TYPE, which is a POINTER_TYPE to a METHOD_TYPE.  */
   13325              : 
   13326              : tree
   13327      3120250 : build_ptrmemfunc_type (tree type)
   13328              : {
   13329      3120250 :   tree field, fields;
   13330      3120250 :   tree t;
   13331              : 
   13332      3120250 :   if (type == error_mark_node)
   13333              :     return type;
   13334              : 
   13335              :   /* Make sure that we always have the unqualified pointer-to-member
   13336              :      type first.  */
   13337      3120250 :   if (cp_cv_quals quals = cp_type_quals (type))
   13338              :     {
   13339            0 :       tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
   13340            0 :       return cp_build_qualified_type (unqual, quals);
   13341              :     }
   13342              : 
   13343              :   /* If a canonical type already exists for this type, use it.  We use
   13344              :      this method instead of type_hash_canon, because it only does a
   13345              :      simple equality check on the list of field members.  */
   13346              : 
   13347      3120250 :   t = TYPE_PTRMEMFUNC_TYPE (type);
   13348      3120250 :   if (t)
   13349              :     return t;
   13350              : 
   13351      1041397 :   t = make_node (RECORD_TYPE);
   13352              : 
   13353              :   /* Let the front end know this is a pointer to member function.  */
   13354      1041397 :   TYPE_PTRMEMFUNC_FLAG (t) = 1;
   13355              : 
   13356      1041397 :   field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
   13357      1041397 :   DECL_NONADDRESSABLE_P (field) = 1;
   13358      1041397 :   fields = field;
   13359              : 
   13360      1041397 :   field = build_decl (input_location, FIELD_DECL, delta_identifier,
   13361              :                       delta_type_node);
   13362      1041397 :   DECL_NONADDRESSABLE_P (field) = 1;
   13363      1041397 :   DECL_CHAIN (field) = fields;
   13364      1041397 :   fields = field;
   13365              : 
   13366      1041397 :   finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
   13367              : 
   13368              :   /* Zap out the name so that the back end will give us the debugging
   13369              :      information for this anonymous RECORD_TYPE.  */
   13370      1041397 :   TYPE_NAME (t) = NULL_TREE;
   13371              : 
   13372              :   /* Cache this pointer-to-member type so that we can find it again
   13373              :      later.  */
   13374      1041397 :   TYPE_PTRMEMFUNC_TYPE (type) = t;
   13375              : 
   13376      1041397 :   if (TYPE_STRUCTURAL_EQUALITY_P (type))
   13377       519576 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
   13378       521821 :   else if (TYPE_CANONICAL (type) != type)
   13379       330446 :     TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
   13380              : 
   13381              :   return t;
   13382              : }
   13383              : 
   13384              : /* Create and return a pointer to data member type.  */
   13385              : 
   13386              : tree
   13387       332492 : build_ptrmem_type (tree class_type, tree member_type)
   13388              : {
   13389       332492 :   if (TREE_CODE (member_type) == METHOD_TYPE)
   13390              :     {
   13391        60547 :       cp_cv_quals quals = type_memfn_quals (member_type);
   13392        60547 :       cp_ref_qualifier rqual = type_memfn_rqual (member_type);
   13393        60547 :       member_type = build_memfn_type (member_type, class_type, quals, rqual);
   13394        60547 :       return build_ptrmemfunc_type (build_pointer_type (member_type));
   13395              :     }
   13396              :   else
   13397              :     {
   13398       271945 :       gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
   13399       271945 :       return build_offset_type (class_type, member_type);
   13400              :     }
   13401              : }
   13402              : 
   13403              : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
   13404              :    Check to see that the definition is valid.  Issue appropriate error
   13405              :    messages.  */
   13406              : 
   13407              : static void
   13408     19021560 : check_static_variable_definition (tree decl, tree type)
   13409              : {
   13410              :   /* Avoid redundant diagnostics on out-of-class definitions.  */
   13411     19021560 :   if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
   13412              :     ;
   13413              :   /* Can't check yet if we don't know the type.  */
   13414     17663206 :   else if (dependent_type_p (type))
   13415              :     ;
   13416              :   /* If DECL is declared constexpr, we'll do the appropriate checks
   13417              :      in check_initializer.  Similarly for inline static data members.  */
   13418     17117225 :   else if (DECL_P (decl)
   13419     17117225 :       && (DECL_DECLARED_CONSTEXPR_P (decl)
   13420      2731453 :           || DECL_VAR_DECLARED_INLINE_P (decl)))
   13421              :     ;
   13422      2730870 :   else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   13423              :     {
   13424           60 :       if (!COMPLETE_TYPE_P (type))
   13425           11 :         error_at (DECL_SOURCE_LOCATION (decl),
   13426              :                   "in-class initialization of static data member %q#D of "
   13427              :                   "incomplete type", decl);
   13428           49 :       else if (literal_type_p (type))
   13429           43 :         permerror (DECL_SOURCE_LOCATION (decl),
   13430              :                    "%<constexpr%> needed for in-class initialization of "
   13431              :                    "static data member %q#D of non-integral type", decl);
   13432              :       else
   13433            6 :         error_at (DECL_SOURCE_LOCATION (decl),
   13434              :                   "in-class initialization of static data member %q#D of "
   13435              :                   "non-literal type", decl);
   13436              :     }
   13437              :   /* Motion 10 at San Diego: If a static const integral data member is
   13438              :      initialized with an integral constant expression, the initializer
   13439              :      may appear either in the declaration (within the class), or in
   13440              :      the definition, but not both.  If it appears in the class, the
   13441              :      member is a member constant.  The file-scope definition is always
   13442              :      required.  */
   13443      2730810 :   else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
   13444           11 :     error_at (DECL_SOURCE_LOCATION (decl),
   13445              :               "invalid in-class initialization of static data member "
   13446              :               "of non-integral type %qT",
   13447              :               type);
   13448      2730799 :   else if (!CP_TYPE_CONST_P (type))
   13449            5 :     error_at (DECL_SOURCE_LOCATION (decl),
   13450              :               "ISO C++ forbids in-class initialization of non-const "
   13451              :               "static member %qD",
   13452              :               decl);
   13453      2730794 :   else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   13454            5 :     pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   13455              :              "ISO C++ forbids initialization of member constant "
   13456              :              "%qD of non-integral type %qT", decl, type);
   13457     19021560 : }
   13458              : 
   13459              : /* *expr_p is part of the TYPE_SIZE of a variably-sized array.  If any
   13460              :    SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
   13461              :    expressions out into temporary variables so that walk_tree doesn't
   13462              :    step into them (c++/15764).  */
   13463              : 
   13464              : static tree
   13465         3412 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
   13466              : {
   13467         3412 :   hash_set<tree> *pset = (hash_set<tree> *)data;
   13468         3412 :   tree expr = *expr_p;
   13469         3412 :   if (TREE_CODE (expr) == SAVE_EXPR)
   13470              :     {
   13471         1487 :       tree op = TREE_OPERAND (expr, 0);
   13472         1487 :       cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
   13473         1487 :       if (TREE_SIDE_EFFECTS (op))
   13474           56 :         TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
   13475         1487 :       *walk_subtrees = 0;
   13476              :     }
   13477         1925 :   else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
   13478         1750 :     *walk_subtrees = 0;
   13479         3412 :   return NULL;
   13480              : }
   13481              : 
   13482              : /* Entry point for the above.  */
   13483              : 
   13484              : static void
   13485         1546 : stabilize_vla_size (tree size)
   13486              : {
   13487         1546 :   hash_set<tree> pset;
   13488              :   /* Break out any function calls into temporary variables.  */
   13489         1546 :   cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
   13490         1546 : }
   13491              : 
   13492              : /* Reduce a SIZEOF_EXPR to its value.  */
   13493              : 
   13494              : tree
   13495     13293691 : fold_sizeof_expr (tree t)
   13496              : {
   13497     13293691 :   tree r;
   13498     13293691 :   if (SIZEOF_EXPR_TYPE_P (t))
   13499     12675416 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   13500     12675416 :                                     TREE_TYPE (TREE_OPERAND (t, 0)),
   13501              :                                     SIZEOF_EXPR, false, false);
   13502       618275 :   else if (TYPE_P (TREE_OPERAND (t, 0)))
   13503            0 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   13504            0 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   13505              :                                     false, false);
   13506              :   else
   13507       618275 :     r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
   13508       618275 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   13509              :                                     false, false);
   13510     13293691 :   if (r == error_mark_node)
   13511           94 :     r = size_one_node;
   13512     13293691 :   r = cp_fold_convert (size_type_node, r);
   13513     13293691 :   return r;
   13514              : }
   13515              : 
   13516              : /* Given the SIZE (i.e., number of elements) in an array, compute
   13517              :    an appropriate index type for the array.  If non-NULL, NAME is
   13518              :    the name of the entity being declared.  */
   13519              : 
   13520              : static tree
   13521      3505639 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
   13522              :                               tsubst_flags_t complain)
   13523              : {
   13524      3505639 :   if (error_operand_p (size))
   13525           32 :     return error_mark_node;
   13526              : 
   13527              :   /* The type of the index being computed.  */
   13528      3505607 :   tree itype;
   13529              : 
   13530              :   /* The original numeric size as seen in the source code before
   13531              :      conversion to size_t.  */
   13532      3505607 :   tree origsize = size;
   13533              : 
   13534      3505607 :   location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
   13535              : 
   13536      3505607 :   if (!type_dependent_expression_p (size))
   13537              :     {
   13538      3457688 :       origsize = size = mark_rvalue_use (size);
   13539              : 
   13540        34936 :       if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
   13541      3457849 :           && TREE_SIDE_EFFECTS (size))
   13542              :         /* In C++98, we mark a non-constant array bound with a magic
   13543              :            NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case.  */;
   13544              :       else
   13545              :         {
   13546      3457687 :           size = build_converted_constant_expr (size_type_node, size, complain);
   13547              :           /* Pedantically a constant expression is required here and so
   13548              :              __builtin_is_constant_evaluated () should fold to true if it
   13549              :              is successfully folded into a constant.  */
   13550      3457687 :           size = fold_non_dependent_expr (size, complain,
   13551              :                                           /*manifestly_const_eval=*/true);
   13552              : 
   13553      3457687 :           if (!TREE_CONSTANT (size))
   13554       147673 :             size = origsize;
   13555              :         }
   13556              : 
   13557      3457688 :       if (error_operand_p (size))
   13558            3 :         return error_mark_node;
   13559              : 
   13560              :       /* The array bound must be an integer type.  */
   13561      3457685 :       tree type = TREE_TYPE (size);
   13562      3457685 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
   13563              :         {
   13564           21 :           if (!(complain & tf_error))
   13565            0 :             return error_mark_node;
   13566           21 :           if (name)
   13567           18 :             error_at (loc, "size of array %qD has non-integral type %qT",
   13568              :                       name, type);
   13569              :           else
   13570            3 :             error_at (loc, "size of array has non-integral type %qT", type);
   13571           21 :           size = integer_one_node;
   13572              :         }
   13573              :     }
   13574              : 
   13575              :   /* A type is dependent if it is...an array type constructed from any
   13576              :      dependent type or whose size is specified by a constant expression
   13577              :      that is value-dependent.  */
   13578              :   /* We can only call value_dependent_expression_p on integral constant
   13579              :      expressions.  */
   13580      3505604 :   if (processing_template_decl
   13581      1607641 :       && potential_constant_expression (size)
   13582      5113220 :       && value_dependent_expression_p (size))
   13583              :     {
   13584              :       /* Just build the index type and mark that it requires
   13585              :          structural equality checks.  */
   13586       899683 :     in_template:
   13587       899683 :       itype = build_index_type (build_min (MINUS_EXPR, sizetype,
   13588              :                                            size, size_one_node));
   13589       899683 :       TYPE_DEPENDENT_P (itype) = 1;
   13590       899683 :       TYPE_DEPENDENT_P_VALID (itype) = 1;
   13591       899683 :       SET_TYPE_STRUCTURAL_EQUALITY (itype);
   13592       899683 :       return itype;
   13593              :     }
   13594              : 
   13595      2623056 :   if (TREE_CODE (size) != INTEGER_CST)
   13596              :     {
   13597        19291 :       tree folded = cp_fully_fold (size);
   13598        19291 :       if (TREE_CODE (folded) == INTEGER_CST)
   13599              :         {
   13600          246 :           if (name)
   13601          172 :             pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
   13602              :                      "integral constant-expression", name);
   13603              :           else
   13604           74 :             pedwarn (loc, OPT_Wpedantic,
   13605              :                      "size of array is not an integral constant-expression");
   13606              :         }
   13607        19291 :       if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
   13608              :         /* We might have lost the TREE_CONSTANT flag e.g. when we are
   13609              :            folding a conversion from a pointer to integral type.  In that
   13610              :            case issue an error below and don't treat this as a VLA.  */;
   13611              :       else
   13612              :         /* Use the folded result for VLAs, too; it will have resolved
   13613              :            SIZEOF_EXPR.  */
   13614              :         size = folded;
   13615              :     }
   13616              : 
   13617              :   /* Normally, the array-bound will be a constant.  */
   13618      2623056 :   if (TREE_CODE (size) == INTEGER_CST)
   13619              :     {
   13620              :       /* The size to use in diagnostics that reflects the constant
   13621              :          size used in the source, rather than SIZE massaged above.  */
   13622      2604011 :       tree diagsize = size;
   13623              : 
   13624              :       /* If the original size before conversion to size_t was signed
   13625              :          and negative, convert it to ssizetype to restore the sign.  */
   13626      2604011 :       if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
   13627              :           && TREE_CODE (size) == INTEGER_CST
   13628      2604011 :           && tree_int_cst_sign_bit (size))
   13629              :         {
   13630          265 :           diagsize = fold_convert (ssizetype, size);
   13631              : 
   13632              :           /* Clear the overflow bit that may have been set as a result
   13633              :              of the conversion from the sizetype of the new size to
   13634              :              ssizetype.  */
   13635          265 :           TREE_OVERFLOW (diagsize) = false;
   13636              :         }
   13637              : 
   13638              :       /* Verify that the array has a positive number of elements
   13639              :          and issue the appropriate diagnostic if it doesn't.  */
   13640      2604011 :       if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
   13641              :         {
   13642          496 :           if (!(complain & tf_error))
   13643           15 :             return error_mark_node;
   13644          481 :           size = integer_one_node;
   13645              :         }
   13646              :       /* As an extension we allow zero-sized arrays.  */
   13647      2603515 :       else if (integer_zerop (size))
   13648              :         {
   13649         3190 :           if (!(complain & tf_error))
   13650              :             /* We must fail if performing argument deduction (as
   13651              :                indicated by the state of complain), so that
   13652              :                another substitution can be found.  */
   13653            8 :             return error_mark_node;
   13654         3182 :           else if (name)
   13655         2884 :             pedwarn (loc, OPT_Wpedantic,
   13656              :                      "ISO C++ forbids zero-size array %qD", name);
   13657              :           else
   13658          298 :             pedwarn (loc, OPT_Wpedantic,
   13659              :                      "ISO C++ forbids zero-size array");
   13660              :         }
   13661              :     }
   13662        19045 :   else if (TREE_CONSTANT (size)
   13663              :            /* We don't allow VLAs at non-function scopes, or during
   13664              :               tentative template substitution.  */
   13665        19030 :            || !at_function_scope_p ()
   13666        37732 :            || !(complain & tf_error))
   13667              :     {
   13668          364 :       if (!(complain & tf_error))
   13669          313 :         return error_mark_node;
   13670              :       /* `(int) &fn' is not a valid array bound.  */
   13671           51 :       if (name)
   13672           37 :         error_at (loc,
   13673              :                   "size of array %qD is not an integral constant-expression",
   13674              :                   name);
   13675              :       else
   13676           14 :         error_at (loc, "size of array is not an integral constant-expression");
   13677           51 :       size = integer_one_node;
   13678              :     }
   13679        18681 :   else if (pedantic && warn_vla != 0)
   13680              :     {
   13681           30 :       if (name)
   13682           15 :         pedwarn (name_loc, OPT_Wvla,
   13683              :                  "ISO C++ forbids variable length array %qD", name);
   13684              :       else
   13685           15 :         pedwarn (input_location, OPT_Wvla,
   13686              :                  "ISO C++ forbids variable length array");
   13687              :     }
   13688        18651 :   else if (warn_vla > 0)
   13689              :     {
   13690            3 :       if (name)
   13691            3 :         warning_at (name_loc, OPT_Wvla,
   13692              :                     "variable length array %qD is used", name);
   13693              :       else
   13694            0 :         warning (OPT_Wvla,
   13695              :                  "variable length array is used");
   13696              :     }
   13697              : 
   13698      2622720 :   if (processing_template_decl && !TREE_CONSTANT (size))
   13699        17135 :     goto in_template;
   13700              :   else
   13701              :     {
   13702      2605585 :       if (!TREE_CONSTANT (size))
   13703              :         {
   13704              :           /* A variable sized array.  Arrange for the SAVE_EXPR on the inside
   13705              :              of the MINUS_EXPR, which allows the -1 to get folded with the +1
   13706              :              that happens when building TYPE_SIZE.  */
   13707         1546 :           size = variable_size (size);
   13708         1546 :           stabilize_vla_size (size);
   13709              :         }
   13710              : 
   13711              :       /* Compute the index of the largest element in the array.  It is
   13712              :          one less than the number of elements in the array.  We save
   13713              :          and restore PROCESSING_TEMPLATE_DECL so that computations in
   13714              :          cp_build_binary_op will be appropriately folded.  */
   13715      2605585 :       {
   13716      2605585 :         processing_template_decl_sentinel s;
   13717      2605585 :         itype = cp_build_binary_op (input_location,
   13718              :                                     MINUS_EXPR,
   13719              :                                     cp_convert (ssizetype, size, complain),
   13720              :                                     cp_convert (ssizetype, integer_one_node,
   13721              :                                                 complain),
   13722              :                                     complain);
   13723      2605585 :         itype = maybe_constant_value (itype, NULL_TREE, mce_true);
   13724      2605585 :       }
   13725              : 
   13726      2605585 :       if (!TREE_CONSTANT (itype))
   13727              :         {
   13728         1546 :           if (sanitize_flags_p (SANITIZE_VLA)
   13729         1546 :               && current_function_decl != NULL_TREE)
   13730              :             {
   13731              :               /* We have to add 1 -- in the ubsan routine we generate
   13732              :                  LE_EXPR rather than LT_EXPR.  */
   13733           78 :               tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
   13734              :                                     build_one_cst (TREE_TYPE (itype)));
   13735           78 :               t = ubsan_instrument_vla (input_location, t);
   13736           78 :               finish_expr_stmt (t);
   13737              :             }
   13738              :         }
   13739              :       /* Make sure that there was no overflow when creating to a signed
   13740              :          index type.  (For example, on a 32-bit machine, an array with
   13741              :          size 2^32 - 1 is too big.)  */
   13742      2604039 :       else if (TREE_CODE (itype) == INTEGER_CST
   13743      2604039 :                && TREE_OVERFLOW (itype))
   13744              :         {
   13745            0 :           if (!(complain & tf_error))
   13746            0 :             return error_mark_node;
   13747            0 :           error ("overflow in array dimension");
   13748            0 :           TREE_OVERFLOW (itype) = 0;
   13749              :         }
   13750              :     }
   13751              : 
   13752              :   /* Create and return the appropriate index type.  */
   13753      2605585 :   itype = build_index_type (itype);
   13754              : 
   13755              :   /* If the index type were dependent, we would have returned early, so
   13756              :      remember that it isn't.  */
   13757      2605585 :   TYPE_DEPENDENT_P (itype) = 0;
   13758      2605585 :   TYPE_DEPENDENT_P_VALID (itype) = 1;
   13759      2605585 :   return itype;
   13760              : }
   13761              : 
   13762              : tree
   13763       618484 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
   13764              : {
   13765       618484 :   return compute_array_index_type_loc (input_location, name, size, complain);
   13766              : }
   13767              : 
   13768              : /* Returns the scope (if any) in which the entity declared by
   13769              :    DECLARATOR will be located.  If the entity was declared with an
   13770              :    unqualified name, NULL_TREE is returned.  */
   13771              : 
   13772              : tree
   13773    776131736 : get_scope_of_declarator (const cp_declarator *declarator)
   13774              : {
   13775    899274672 :   while (declarator && declarator->kind != cdk_id)
   13776    123142936 :     declarator = declarator->declarator;
   13777              : 
   13778              :   /* If the declarator-id is a SCOPE_REF, the scope in which the
   13779              :      declaration occurs is the first operand.  */
   13780    776131736 :   if (declarator
   13781    774866834 :       && declarator->u.id.qualifying_scope)
   13782              :     return declarator->u.id.qualifying_scope;
   13783              : 
   13784              :   /* Otherwise, the declarator is not a qualified name; the entity will
   13785              :      be declared in the current scope.  */
   13786              :   return NULL_TREE;
   13787              : }
   13788              : 
   13789              : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
   13790              :    indicated TYPE.  If non-NULL, NAME is the NAME of the declaration
   13791              :    with this type.  */
   13792              : 
   13793              : static tree
   13794      3712264 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
   13795              : {
   13796      3712264 :   tree itype = NULL_TREE;
   13797              : 
   13798              :   /* If things have already gone awry, bail now.  */
   13799      3712264 :   if (type == error_mark_node || size == error_mark_node)
   13800              :     return error_mark_node;
   13801              : 
   13802              :   /* [dcl.type.class.deduct] prohibits forming an array of placeholder
   13803              :      for a deduced class type.  */
   13804      3712201 :   if (template_placeholder_p (type))
   13805              :     {
   13806            6 :       if (name)
   13807            0 :         error_at (loc, "%qD declared as array of template placeholder "
   13808              :                   "type %qT", name, type);
   13809              :       else
   13810            6 :         error ("creating array of template placeholder type %qT", type);
   13811            6 :       return error_mark_node;
   13812              :     }
   13813              : 
   13814              :   /* If there are some types which cannot be array elements,
   13815              :      issue an error-message and return.  */
   13816      3712195 :   switch (TREE_CODE (type))
   13817              :     {
   13818            3 :     case VOID_TYPE:
   13819            3 :       if (name)
   13820            0 :         error_at (loc, "declaration of %qD as array of void", name);
   13821              :       else
   13822            3 :         error ("creating array of void");
   13823            3 :       return error_mark_node;
   13824              : 
   13825            6 :     case FUNCTION_TYPE:
   13826            6 :       if (name)
   13827            6 :         error_at (loc, "declaration of %qD as array of functions", name);
   13828              :       else
   13829            0 :         error ("creating array of functions");
   13830            6 :       return error_mark_node;
   13831              : 
   13832           21 :     case REFERENCE_TYPE:
   13833           21 :       if (name)
   13834           15 :         error_at (loc, "declaration of %qD as array of references", name);
   13835              :       else
   13836            6 :         error ("creating array of references");
   13837           21 :       return error_mark_node;
   13838              : 
   13839            0 :     case METHOD_TYPE:
   13840            0 :       if (name)
   13841            0 :         error_at (loc, "declaration of %qD as array of function members",
   13842              :                   name);
   13843              :       else
   13844            0 :         error ("creating array of function members");
   13845            0 :       return error_mark_node;
   13846              : 
   13847      3712165 :     default:
   13848      3712165 :       break;
   13849              :     }
   13850              : 
   13851      3712165 :   if (!verify_type_context (name ? loc : input_location,
   13852              :                             TCTX_ARRAY_ELEMENT, type))
   13853            0 :     return error_mark_node;
   13854              : 
   13855              :   /* [dcl.array]
   13856              : 
   13857              :      The constant expressions that specify the bounds of the arrays
   13858              :      can be omitted only for the first member of the sequence.  */
   13859      3712165 :   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   13860              :     {
   13861           30 :       if (name)
   13862           24 :         error_at (loc, "declaration of %qD as multidimensional array must "
   13863              :                   "have bounds for all dimensions except the first",
   13864              :                   name);
   13865              :       else
   13866            6 :         error ("multidimensional array must have bounds for all "
   13867              :                "dimensions except the first");
   13868              : 
   13869           30 :       return error_mark_node;
   13870              :     }
   13871              : 
   13872              :   /* Figure out the index type for the array.  */
   13873      3712135 :   if (size)
   13874              :     {
   13875      2887155 :       itype = compute_array_index_type_loc (loc, name, size,
   13876              :                                             tf_warning_or_error);
   13877      2887155 :       if (type_uses_auto (type)
   13878      2887155 :           && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
   13879              :         {
   13880            9 :           sorry_at (loc, "variable-length array of %<auto%>");
   13881            9 :           return error_mark_node;
   13882              :         }
   13883              :     }
   13884              : 
   13885      3712126 :   return build_cplus_array_type (type, itype);
   13886              : }
   13887              : 
   13888              : /* Returns the smallest location that is not UNKNOWN_LOCATION.  */
   13889              : 
   13890              : static location_t
   13891   1077806515 : min_location (location_t loca, location_t locb)
   13892              : {
   13893   1077806515 :   if (loca == UNKNOWN_LOCATION
   13894   1077806515 :       || (locb != UNKNOWN_LOCATION
   13895    112620265 :           && linemap_location_before_p (line_table, locb, loca)))
   13896    966426119 :     return locb;
   13897              :   return loca;
   13898              : }
   13899              : 
   13900              : /* Returns the smallest location != UNKNOWN_LOCATION among the
   13901              :    three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
   13902              :    and LOCATIONS[ds_restrict].  */
   13903              : 
   13904              : static location_t
   13905   1076019289 : smallest_type_quals_location (int type_quals, const location_t* locations)
   13906              : {
   13907   1076019289 :   location_t loc = UNKNOWN_LOCATION;
   13908              : 
   13909   1076019289 :   if (type_quals & TYPE_QUAL_CONST)
   13910    111088759 :     loc = locations[ds_const];
   13911              : 
   13912   1076019289 :   if (type_quals & TYPE_QUAL_VOLATILE)
   13913      1787135 :     loc = min_location (loc, locations[ds_volatile]);
   13914              : 
   13915   1076019289 :   if (type_quals & TYPE_QUAL_RESTRICT)
   13916           43 :     loc = min_location (loc, locations[ds_restrict]);
   13917              : 
   13918   1076019289 :   return loc;
   13919              : }
   13920              : 
   13921              : /* Returns the smallest among the latter and locations[ds_type_spec].  */
   13922              : 
   13923              : static location_t
   13924   1076019268 : smallest_type_location (int type_quals, const location_t* locations)
   13925              : {
   13926   1076019268 :   location_t loc = smallest_type_quals_location (type_quals, locations);
   13927   1076019268 :   return min_location (loc, locations[ds_type_spec]);
   13928              : }
   13929              : 
   13930              : static location_t
   13931           26 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
   13932              : {
   13933           26 :   int type_quals = get_type_quals (declspecs);
   13934           26 :   return smallest_type_location (type_quals, declspecs->locations);
   13935              : }
   13936              : 
   13937              : /* Returns whether DECLARATOR represented a pointer or a reference and if so,
   13938              :    strip out the pointer/reference declarator(s).  */
   13939              : 
   13940              : static bool
   13941     30554604 : maybe_strip_indirect_ref (const cp_declarator** declarator)
   13942              : {
   13943     30554604 :   bool indirect_ref_p = false;
   13944     61109355 :   while (declarator && *declarator
   13945     30554751 :          && ((*declarator)->kind == cdk_pointer
   13946     30554751 :              || (*declarator)->kind == cdk_reference))
   13947              :     {
   13948          147 :       indirect_ref_p = true;
   13949          147 :       *declarator = (*declarator)->declarator;
   13950              :     }
   13951     30554604 :   return indirect_ref_p;
   13952              : }
   13953              : 
   13954              : /* Check that it's OK to declare a function with the indicated TYPE, TYPE_QUALS
   13955              :    and DECLARATOR.  SFK indicates the kind of special function (if any) that
   13956              :    this function is.  OPTYPE is the type given in a conversion operator
   13957              :    declaration, or the class type for a constructor/destructor.
   13958              :    Returns the actual return type of the function; that may be different
   13959              :    than TYPE if an error occurs, or for certain special functions.  */
   13960              : 
   13961              : static tree
   13962     30554604 : check_special_function_return_type (special_function_kind sfk,
   13963              :                                     tree type,
   13964              :                                     tree optype,
   13965              :                                     int type_quals,
   13966              :                                     const cp_declarator** declarator,
   13967              :                                     const location_t* locations)
   13968              : {
   13969     30554604 :   gcc_assert (declarator);
   13970     30554604 :   location_t rettype_loc = (type
   13971     30554604 :                             ? smallest_type_location (type_quals, locations)
   13972     30554523 :                             : (*declarator)->id_loc);
   13973     30554604 :   switch (sfk)
   13974              :     {
   13975     24921180 :     case sfk_constructor:
   13976     24921180 :       if (maybe_strip_indirect_ref (declarator) || type)
   13977           81 :         error_at (rettype_loc,
   13978              :                   "return type specification for constructor invalid");
   13979     24921099 :       else if (type_quals != TYPE_UNQUALIFIED)
   13980           15 :         error_at (smallest_type_quals_location (type_quals, locations),
   13981              :                   "qualifiers are not allowed on constructor declaration");
   13982              : 
   13983     24921180 :       if (targetm.cxx.cdtor_returns_this ())
   13984            0 :         type = build_pointer_type (optype);
   13985              :       else
   13986     24921180 :         type = void_type_node;
   13987              :       break;
   13988              : 
   13989      3323932 :     case sfk_destructor:
   13990      3323932 :       if (maybe_strip_indirect_ref (declarator) || type)
   13991           45 :         error_at (rettype_loc,
   13992              :                   "return type specification for destructor invalid");
   13993      3323887 :       else if (type_quals != TYPE_UNQUALIFIED)
   13994            3 :         error_at (smallest_type_quals_location (type_quals, locations),
   13995              :                   "qualifiers are not allowed on destructor declaration");
   13996              : 
   13997              :       /* We can't use the proper return type here because we run into
   13998              :          problems with ambiguous bases and covariant returns.  */
   13999      3323932 :       if (targetm.cxx.cdtor_returns_this ())
   14000            0 :         type = build_pointer_type (void_type_node);
   14001              :       else
   14002      3323932 :         type = void_type_node;
   14003              :       break;
   14004              : 
   14005      1050848 :     case sfk_conversion:
   14006      1050848 :       if (maybe_strip_indirect_ref (declarator) || type)
   14007           42 :         error_at (rettype_loc,
   14008              :                   "return type specified for %<operator %T%>", optype);
   14009      1050806 :       else if (type_quals != TYPE_UNQUALIFIED)
   14010            3 :         error_at (smallest_type_quals_location (type_quals, locations),
   14011              :                   "qualifiers are not allowed on declaration of "
   14012              :                   "%<operator %T%>", optype);
   14013              : 
   14014              :       type = optype;
   14015              :       break;
   14016              : 
   14017      1258644 :     case sfk_deduction_guide:
   14018      1258644 :       if (maybe_strip_indirect_ref (declarator) || type)
   14019            0 :         error_at (rettype_loc,
   14020              :                   "return type specified for deduction guide");
   14021      1258644 :       else if (type_quals != TYPE_UNQUALIFIED)
   14022            0 :         error_at (smallest_type_quals_location (type_quals, locations),
   14023              :                   "qualifiers are not allowed on declaration of "
   14024              :                   "deduction guide");
   14025      1258644 :       if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
   14026              :         {
   14027            3 :           error ("template template parameter %qT in declaration of "
   14028              :                  "deduction guide", optype);
   14029            3 :           type = error_mark_node;
   14030              :         }
   14031              :       else
   14032      1258641 :         type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
   14033     33983388 :       for (int i = 0; i < ds_last; ++i)
   14034     32724744 :         if (i != ds_explicit && locations[i])
   14035            3 :           error_at (locations[i],
   14036              :                     "%<decl-specifier%> in declaration of deduction guide");
   14037              :       break;
   14038              : 
   14039            0 :     default:
   14040            0 :       gcc_unreachable ();
   14041              :     }
   14042              : 
   14043     30554604 :   return type;
   14044              : }
   14045              : 
   14046              : /* A variable or data member (whose unqualified name is IDENTIFIER)
   14047              :    has been declared with the indicated TYPE.  If the TYPE is not
   14048              :    acceptable, issue an error message and return a type to use for
   14049              :    error-recovery purposes.  */
   14050              : 
   14051              : tree
   14052    337895231 : check_var_type (tree identifier, tree type, location_t loc)
   14053              : {
   14054    337895231 :   if (VOID_TYPE_P (type))
   14055              :     {
   14056           92 :       if (!identifier)
   14057            0 :         error_at (loc, "unnamed variable or field declared void");
   14058           92 :       else if (identifier_p (identifier))
   14059              :         {
   14060           92 :           gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
   14061           92 :           error_at (loc, "variable or field %qE declared void",
   14062              :                     identifier);
   14063              :         }
   14064              :       else
   14065            0 :         error_at (loc, "variable or field declared void");
   14066           92 :       type = error_mark_node;
   14067              :     }
   14068              : 
   14069    337895231 :   return type;
   14070              : }
   14071              : 
   14072              : /* Handle declaring DECL as an inline variable.  */
   14073              : 
   14074              : static void
   14075      6819972 : mark_inline_variable (tree decl, location_t loc)
   14076              : {
   14077      6819972 :   bool inlinep = true;
   14078      6819972 :   if (! toplevel_bindings_p ())
   14079              :     {
   14080           24 :       error_at (loc, "%<inline%> specifier invalid for variable "
   14081              :                 "%qD declared at block scope", decl);
   14082           24 :       inlinep = false;
   14083              :     }
   14084      6819948 :   else if (cxx_dialect < cxx17)
   14085          662 :     pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
   14086              :              "with %<-std=c++17%> or %<-std=gnu++17%>");
   14087          686 :   if (inlinep)
   14088              :     {
   14089      6819948 :       retrofit_lang_decl (decl);
   14090      6819948 :       SET_DECL_VAR_DECLARED_INLINE_P (decl);
   14091              :     }
   14092      6819972 : }
   14093              : 
   14094              : 
   14095              : /* Diagnose -Wnon-c-typedef-for-linkage pedwarn.  TYPE is the unnamed class
   14096              :    with a typedef name for linkage purposes with freshly updated TYPE_NAME,
   14097              :    ORIG is the anonymous TYPE_NAME before that change.  */
   14098              : 
   14099              : static bool
   14100           42 : diagnose_non_c_class_typedef_for_linkage (tree type, tree orig)
   14101              : {
   14102           42 :   gcc_rich_location richloc (DECL_SOURCE_LOCATION (orig));
   14103           42 :   tree name = DECL_NAME (TYPE_NAME (type));
   14104           42 :   richloc.add_fixit_insert_before (IDENTIFIER_POINTER (name));
   14105           42 :   return pedwarn (&richloc, OPT_Wnon_c_typedef_for_linkage,
   14106              :                   "anonymous non-C-compatible type given name for linkage "
   14107           42 :                   "purposes by %<typedef%> declaration");
   14108           42 : }
   14109              : 
   14110              : /* Diagnose -Wnon-c-typedef-for-linkage violations on T.  TYPE and ORIG
   14111              :    like for diagnose_non_c_class_typedef_for_linkage, T is initially equal
   14112              :    to TYPE but during recursion can be set to nested classes.  */
   14113              : 
   14114              : static bool
   14115       527407 : maybe_diagnose_non_c_class_typedef_for_linkage (tree type, tree orig, tree t)
   14116              : {
   14117       527407 :   if (!COMPLETE_TYPE_P (t))
   14118              :     return false;
   14119       527404 :   if (!BINFO_BASE_BINFOS (TYPE_BINFO (t))->is_empty ())
   14120              :     {
   14121            6 :       auto_diagnostic_group d;
   14122            6 :       if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   14123            9 :         inform (type == t ? DECL_SOURCE_LOCATION (orig)
   14124            3 :                 : DECL_SOURCE_LOCATION (TYPE_NAME (t)),
   14125              :                 "type is not C-compatible because it has a base class");
   14126            6 :       return true;
   14127            6 :     }
   14128      2478919 :   for (tree field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
   14129      1951582 :     switch (TREE_CODE (field))
   14130              :       {
   14131            9 :       case VAR_DECL:
   14132              :         /* static data members have been diagnosed already.  */
   14133            9 :         continue;
   14134      1298198 :       case FIELD_DECL:
   14135      1298198 :         if (DECL_INITIAL (field))
   14136              :           {
   14137            4 :             auto_diagnostic_group d;
   14138            4 :             if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   14139            4 :               inform (DECL_SOURCE_LOCATION (field),
   14140              :                       "type is not C-compatible because %qD has default "
   14141              :                       "member initializer", field);
   14142            4 :             return true;
   14143            4 :           }
   14144      1298194 :         continue;
   14145            9 :       case CONST_DECL:
   14146            9 :         continue;
   14147       653285 :       case TYPE_DECL:
   14148       653285 :         if (DECL_SELF_REFERENCE_P (field))
   14149       527372 :           continue;
   14150       125913 :         if (DECL_IMPLICIT_TYPEDEF_P (field))
   14151              :           {
   14152       125903 :             if (TREE_CODE (TREE_TYPE (field)) == ENUMERAL_TYPE)
   14153            3 :               continue;
   14154       125900 :             if (CLASS_TYPE_P (TREE_TYPE (field)))
   14155              :               {
   14156       125900 :                 tree tf = TREE_TYPE (field);
   14157       125900 :                 if (maybe_diagnose_non_c_class_typedef_for_linkage (type, orig,
   14158              :                                                                     tf))
   14159              :                   return true;
   14160       125875 :                 continue;
   14161       125875 :               }
   14162              :           }
   14163              :         /* FALLTHRU */
   14164           32 :       case FUNCTION_DECL:
   14165           32 :       case TEMPLATE_DECL:
   14166           32 :         {
   14167           32 :           auto_diagnostic_group d;
   14168           32 :           if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   14169           32 :             inform (DECL_SOURCE_LOCATION (field),
   14170              :                     "type is not C-compatible because it contains %qD "
   14171              :                     "declaration", field);
   14172           32 :           return true;
   14173           32 :         }
   14174              :       default:
   14175              :         break;
   14176      1298212 :       }
   14177              :   return false;
   14178              : }
   14179              : 
   14180              : /* Assign a typedef-given name to a class or enumeration type declared
   14181              :    as anonymous at first.  This was split out of grokdeclarator
   14182              :    because it is also used in libcc1.  */
   14183              : 
   14184              : void
   14185       403304 : name_unnamed_type (tree type, tree decl)
   14186              : {
   14187      1209912 :   gcc_assert (TYPE_UNNAMED_P (type)
   14188              :               || enum_with_enumerator_for_linkage_p (type));
   14189              : 
   14190       403304 :   tree orig = TYPE_NAME (type);
   14191       403304 :   if (flag_reflection)
   14192              :     {
   14193              :       /* For -freflection for typedef struct { ... } S; ^^S needs to be
   14194              :          a reflection of a type alias.  So, TREE_TYPE (DECL) can't be
   14195              :          TYPE.  Instead of what we do below, override DECL_NAME (orig).  */
   14196        16292 :       DECL_NAME (orig) = DECL_NAME (decl);
   14197        16292 :       TYPE_DECL_FOR_LINKAGE_PURPOSES_P (orig) = 1;
   14198              :     }
   14199              :   else
   14200              :     /* Replace the anonymous decl with the real decl.  Be careful not to
   14201              :        rename other typedefs (such as the self-reference) of type.  */
   14202      1159320 :     for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   14203       772308 :       if (TYPE_NAME (t) == orig)
   14204       387012 :         TYPE_NAME (t) = decl;
   14205       403304 :   TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl) = 1;
   14206              : 
   14207              :   /* If this is a typedef within a template class, the nested
   14208              :      type is a (non-primary) template.  The name for the
   14209              :      template needs updating as well.  */
   14210       403304 :   if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
   14211           68 :     DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
   14212              : 
   14213              :   /* Adjust linkage now that we aren't unnamed anymore.  */
   14214       403304 :   reset_type_linkage (type);
   14215              : 
   14216       403304 :   if (CLASS_TYPE_P (type) && warn_non_c_typedef_for_linkage)
   14217       401507 :     maybe_diagnose_non_c_class_typedef_for_linkage (type, orig, type);
   14218              : 
   14219              :   /* FIXME remangle member functions; member functions of a
   14220              :      type with external linkage have external linkage.  */
   14221              : 
   14222              :   /* Check that our job is done, and that it would fail if we
   14223              :      attempted to do it again.  */
   14224       806608 :   gcc_assert (!TYPE_UNNAMED_P (type)
   14225              :               && !enum_with_enumerator_for_linkage_p (type));
   14226       403304 : }
   14227              : 
   14228              : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
   14229              :    is allowed.  TYPE might contain a decltype(auto).  Returns true if
   14230              :    there was a problem, false otherwise.  */
   14231              : 
   14232              : static bool
   14233    654162093 : check_decltype_auto (location_t loc, tree type)
   14234              : {
   14235    654162093 :   if (tree a = type_uses_auto (type))
   14236              :     {
   14237     18718027 :       if (AUTO_IS_DECLTYPE (a))
   14238              :         {
   14239       653686 :           if (a != type)
   14240              :             {
   14241           33 :               error_at (loc, "%qT as type rather than plain "
   14242              :                         "%<decltype(auto)%>", type);
   14243           33 :               return true;
   14244              :             }
   14245       653653 :           else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
   14246              :             {
   14247           37 :               error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
   14248           37 :               return true;
   14249              :             }
   14250              :         }
   14251              :     }
   14252              :   return false;
   14253              : }
   14254              : 
   14255              : /* Issue an error about two mutually incompatible declspecs
   14256              :    with the given names and locations
   14257              :    e.g. "error: `signed' and `unsigned' specified together" */
   14258              : 
   14259              : static void
   14260           66 : complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
   14261              :                                        const char *name_b, location_t loc_b)
   14262              : {
   14263           66 :   gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
   14264           66 :   richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
   14265              :                      nullptr, highlight_colors::rhs);
   14266           66 :   pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
   14267           66 :   pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
   14268           66 :   error_at (&richloc, "%e and %e specified together",
   14269              :             &e_name_a, &e_name_b);
   14270           66 : }
   14271              : 
   14272              : /* Given declspecs and a declarator (abstract or otherwise), determine
   14273              :    the name and type of the object declared and construct a DECL node
   14274              :    for it.
   14275              : 
   14276              :    DECLSPECS points to the representation of declaration-specifier
   14277              :    sequence that precedes declarator.
   14278              : 
   14279              :    DECL_CONTEXT says which syntactic context this declaration is in:
   14280              :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
   14281              :      FUNCDEF for a function definition.  Like NORMAL but a few different
   14282              :       error messages in each case.  Return value may be zero meaning
   14283              :       this definition is too screwy to try to parse.
   14284              :      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
   14285              :       handle member functions (which have FIELD context).
   14286              :       Return value may be zero meaning this definition is too screwy to
   14287              :       try to parse.
   14288              :      PARM for a parameter declaration (either within a function prototype
   14289              :       or before a function body).  Make a PARM_DECL, or return void_type_node.
   14290              :      TPARM for a template parameter declaration.
   14291              :      CATCHPARM for a parameter declaration before a catch clause.
   14292              :      TYPENAME if for a typename (in a cast or sizeof).
   14293              :       Don't make a DECL node; just return the ..._TYPE node.
   14294              :      FIELD for a struct or union field; make a FIELD_DECL.
   14295              :      BITFIELD for a field with specified width.
   14296              : 
   14297              :    INITIALIZED is as for start_decl.
   14298              : 
   14299              :    ATTRLIST is a pointer to the list of attributes, which may be NULL
   14300              :    if there are none; *ATTRLIST may be modified if attributes from inside
   14301              :    the declarator should be applied to the declaration.
   14302              : 
   14303              :    When this function is called, scoping variables (such as
   14304              :    CURRENT_CLASS_TYPE) should reflect the scope in which the
   14305              :    declaration occurs, not the scope in which the new declaration will
   14306              :    be placed.  For example, on:
   14307              : 
   14308              :      void S::f() { ... }
   14309              : 
   14310              :    when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
   14311              :    should not be `S'.
   14312              : 
   14313              :    Returns a DECL (if a declarator is present), a TYPE (if there is no
   14314              :    declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
   14315              :    error occurs. */
   14316              : 
   14317              : tree
   14318   1076019161 : grokdeclarator (const cp_declarator *declarator,
   14319              :                 cp_decl_specifier_seq *declspecs,
   14320              :                 enum decl_context decl_context,
   14321              :                 int initialized,
   14322              :                 tree* attrlist)
   14323              : {
   14324   1076019161 :   tree type = NULL_TREE;
   14325   1076019161 :   int longlong = 0;
   14326   1076019161 :   int explicit_intN = 0;
   14327   1076019161 :   int int_n_alt = 0;
   14328   1076019161 :   int virtualp, explicitp, friendp, inlinep, staticp;
   14329   1076019161 :   int explicit_int = 0;
   14330   1076019161 :   int explicit_char = 0;
   14331   1076019161 :   int defaulted_int = 0;
   14332              : 
   14333   1076019161 :   tree typedef_decl = NULL_TREE;
   14334   1076019161 :   const char *name = NULL;
   14335   1076019161 :   tree typedef_type = NULL_TREE;
   14336              :   /* True if this declarator is a function definition.  */
   14337   1076019161 :   bool funcdef_flag = false;
   14338   1076019161 :   cp_declarator_kind innermost_code = cdk_error;
   14339   1076019161 :   int bitfield = 0;
   14340              : #if 0
   14341              :   /* See the code below that used this.  */
   14342              :   tree decl_attr = NULL_TREE;
   14343              : #endif
   14344              : 
   14345              :   /* Keep track of what sort of function is being processed
   14346              :      so that we can warn about default return values, or explicit
   14347              :      return values which do not match prescribed defaults.  */
   14348   1076019161 :   special_function_kind sfk = sfk_none;
   14349              : 
   14350   1076019161 :   tree dname = NULL_TREE;
   14351   1076019161 :   tree ctor_return_type = NULL_TREE;
   14352   1076019161 :   enum overload_flags flags = NO_SPECIAL;
   14353              :   /* cv-qualifiers that apply to the declarator, for a declaration of
   14354              :      a member function.  */
   14355   1076019161 :   cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
   14356              :   /* virt-specifiers that apply to the declarator, for a declaration of
   14357              :      a member function.  */
   14358   1076019161 :   cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
   14359              :   /* ref-qualifier that applies to the declarator, for a declaration of
   14360              :      a member function.  */
   14361   1076019161 :   cp_ref_qualifier rqual = REF_QUAL_NONE;
   14362              :   /* cv-qualifiers that apply to the type specified by the DECLSPECS.  */
   14363   1076019161 :   auto type_quals = get_type_quals (declspecs);
   14364   1076019161 :   tree raises = NULL_TREE;
   14365   1076019161 :   int template_count = 0;
   14366   1076019161 :   tree returned_attrs = NULL_TREE;
   14367   1076019161 :   tree contract_specifiers = NULL_TREE;
   14368   1076019161 :   tree parms = NULL_TREE;
   14369   1076019161 :   const cp_declarator *id_declarator;
   14370              :   /* The unqualified name of the declarator; either an
   14371              :      IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR.  */
   14372   1076019161 :   tree unqualified_id;
   14373              :   /* The class type, if any, in which this entity is located,
   14374              :      or NULL_TREE if none.  Note that this value may be different from
   14375              :      the current class type; for example if an attempt is made to declare
   14376              :      "A::f" inside "B", this value will be "A".  */
   14377   1076019161 :   tree ctype = current_class_type;
   14378              :   /* The NAMESPACE_DECL for the namespace in which this entity is
   14379              :      located.  If an unqualified name is used to declare the entity,
   14380              :      this value will be NULL_TREE, even if the entity is located at
   14381              :      namespace scope.  */
   14382   1076019161 :   tree in_namespace = NULL_TREE;
   14383   1076019161 :   cp_storage_class storage_class;
   14384   1076019161 :   bool unsigned_p, signed_p, short_p, long_p, thread_p;
   14385   1076019161 :   bool type_was_error_mark_node = false;
   14386   1076019161 :   bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
   14387   1076019161 :   bool template_type_arg = false;
   14388   1076019161 :   bool template_parm_flag = false;
   14389   1076019161 :   bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
   14390   1076019161 :   bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
   14391   1076019161 :   bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
   14392   1076019161 :   bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
   14393   1076019161 :   bool late_return_type_p = false;
   14394   1076019161 :   bool array_parameter_p = false;
   14395   1076019161 :   tree reqs = NULL_TREE;
   14396              : 
   14397   1076019161 :   signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
   14398   1076019161 :   unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
   14399   1076019161 :   short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
   14400   1076019161 :   long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
   14401   1076019161 :   longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
   14402   1076019161 :   explicit_intN = declspecs->explicit_intN_p;
   14403   1076019161 :   int_n_alt = declspecs->int_n_alt;
   14404   1076019161 :   thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
   14405              : 
   14406              :   // Was concept_p specified? Note that ds_concept
   14407              :   // implies ds_constexpr!
   14408   1076019161 :   bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
   14409   1076019161 :   if (concept_p)
   14410          117 :     constexpr_p = true;
   14411              : 
   14412   1076019161 :   if (decl_context == FUNCDEF)
   14413              :     funcdef_flag = true, decl_context = NORMAL;
   14414              :   else if (decl_context == MEMFUNCDEF)
   14415              :     funcdef_flag = true, decl_context = FIELD;
   14416              :   else if (decl_context == BITFIELD)
   14417              :     bitfield = 1, decl_context = FIELD;
   14418              :   else if (decl_context == TEMPLATE_TYPE_ARG)
   14419              :     template_type_arg = true, decl_context = TYPENAME;
   14420              :   else if (decl_context == TPARM)
   14421     11565090 :     template_parm_flag = true, decl_context = PARM;
   14422              : 
   14423   1076019161 :   if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
   14424     11324234 :     funcdef_flag = true;
   14425              : 
   14426   1076019161 :   location_t typespec_loc = loc_or_input_loc (smallest_type_location
   14427              :                                               (type_quals,
   14428   1076019161 :                                                declspecs->locations));
   14429   1076019161 :   location_t id_loc;
   14430   1076019161 :   location_t init_loc;
   14431   1076019161 :   if (declarator)
   14432              :     {
   14433    648427418 :       id_loc = loc_or_input_loc (declarator->id_loc);
   14434    648427418 :       init_loc = loc_or_input_loc (declarator->init_loc);
   14435              :     }
   14436              :   else
   14437    427591743 :     init_loc = id_loc = input_location;
   14438              : 
   14439              :   /* Look inside a declarator for the name being declared
   14440              :      and get it as a string, for an error message.  */
   14441   1076019161 :   for (id_declarator = declarator;
   14442   1476713425 :        id_declarator;
   14443    400694264 :        id_declarator = id_declarator->declarator)
   14444              :     {
   14445   1005751174 :       if (id_declarator->kind != cdk_id)
   14446    400694289 :         innermost_code = id_declarator->kind;
   14447              : 
   14448   1005751174 :       switch (id_declarator->kind)
   14449              :         {
   14450    196812538 :         case cdk_function:
   14451    196812538 :           if (id_declarator->declarator
   14452    196422695 :               && id_declarator->declarator->kind == cdk_id)
   14453              :             {
   14454    194533156 :               sfk = id_declarator->declarator->u.id.sfk;
   14455    194533156 :               if (sfk == sfk_destructor)
   14456      3323935 :                 flags = DTOR_FLAG;
   14457              :             }
   14458              :           break;
   14459              : 
   14460    605056885 :         case cdk_id:
   14461    605056885 :           {
   14462    605056885 :             tree qualifying_scope = id_declarator->u.id.qualifying_scope;
   14463    605056885 :             tree decl = id_declarator->u.id.unqualified_name;
   14464    605056885 :             if (!decl)
   14465              :               break;
   14466    605056885 :             if (qualifying_scope)
   14467              :               {
   14468     10154132 :                 if (check_for_bare_parameter_packs (qualifying_scope,
   14469     10154132 :                                                     id_declarator->id_loc))
   14470            6 :                   return error_mark_node;
   14471     10154126 :                 if (at_function_scope_p ())
   14472              :                   {
   14473              :                     /* [dcl.meaning]
   14474              : 
   14475              :                        A declarator-id shall not be qualified except
   14476              :                        for ...
   14477              : 
   14478              :                        None of the cases are permitted in block
   14479              :                        scope.  */
   14480            0 :                     if (qualifying_scope == global_namespace)
   14481            0 :                       error ("invalid use of qualified-name %<::%D%>",
   14482              :                              decl);
   14483            0 :                     else if (TYPE_P (qualifying_scope))
   14484            0 :                       error ("invalid use of qualified-name %<%T::%D%>",
   14485              :                              qualifying_scope, decl);
   14486              :                     else
   14487            0 :                       error ("invalid use of qualified-name %<%D::%D%>",
   14488              :                              qualifying_scope, decl);
   14489            0 :                     return error_mark_node;
   14490              :                   }
   14491     10154126 :                 else if (TYPE_P (qualifying_scope))
   14492              :                   {
   14493      9722302 :                     ctype = qualifying_scope;
   14494      9722302 :                     if (!MAYBE_CLASS_TYPE_P (ctype))
   14495              :                       {
   14496            6 :                         error_at (id_declarator->id_loc,
   14497              :                                   "%q#T is not a class or namespace", ctype);
   14498            6 :                         ctype = NULL_TREE;
   14499              :                       }
   14500      9722296 :                     else if (innermost_code != cdk_function
   14501       506997 :                              && current_class_type
   14502      9722311 :                              && !uniquely_derived_from_p (ctype,
   14503              :                                                           current_class_type))
   14504              :                       {
   14505            9 :                         error_at (id_declarator->id_loc,
   14506              :                                   "invalid use of qualified-name %<%T::%D%>",
   14507              :                                   qualifying_scope, decl);
   14508            9 :                         return error_mark_node;
   14509              :                       }
   14510              :                   }
   14511       431824 :                 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
   14512    605056870 :                   in_namespace = qualifying_scope;
   14513              :               }
   14514    605056870 :             switch (TREE_CODE (decl))
   14515              :               {
   14516      3323950 :               case BIT_NOT_EXPR:
   14517      3323950 :                 {
   14518      3323950 :                   if (innermost_code != cdk_function)
   14519              :                     {
   14520            6 :                       error_at (EXPR_LOCATION (decl),
   14521              :                                 "declaration of %qE as non-function", decl);
   14522            6 :                       return error_mark_node;
   14523              :                     }
   14524      3323944 :                   else if (!qualifying_scope
   14525      3323944 :                            && !(current_class_type && at_class_scope_p ()))
   14526              :                     {
   14527            9 :                       error_at (EXPR_LOCATION (decl),
   14528              :                                 "declaration of %qE as non-member", decl);
   14529            9 :                       return error_mark_node;
   14530              :                     }
   14531              : 
   14532      3323935 :                   tree type = TREE_OPERAND (decl, 0);
   14533      3323935 :                   if (TYPE_P (type))
   14534      3323932 :                     type = constructor_name (type);
   14535      3323935 :                   name = identifier_to_locale (IDENTIFIER_POINTER (type));
   14536      3323935 :                   dname = decl;
   14537              :                 }
   14538      3323935 :                 break;
   14539              : 
   14540      3158924 :               case TEMPLATE_ID_EXPR:
   14541      3158924 :                 {
   14542      3158924 :                   tree fns = TREE_OPERAND (decl, 0);
   14543              : 
   14544      3158924 :                   dname = fns;
   14545      4131614 :                   if (!identifier_p (dname))
   14546      3158897 :                     dname = OVL_NAME (dname);
   14547              :                 }
   14548              :                 /* Fall through.  */
   14549              : 
   14550    601732920 :               case IDENTIFIER_NODE:
   14551    601732920 :                 if (identifier_p (decl))
   14552    598573996 :                   dname = decl;
   14553              : 
   14554    601732920 :                 if (IDENTIFIER_KEYWORD_P (dname))
   14555              :                   {
   14556            0 :                     error ("declarator-id missing; using reserved word %qD",
   14557              :                            dname);
   14558            0 :                     name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14559              :                   }
   14560    601732920 :                 else if (!IDENTIFIER_CONV_OP_P (dname))
   14561    600682069 :                   name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14562              :                 else
   14563              :                   {
   14564      1050851 :                     gcc_assert (flags == NO_SPECIAL);
   14565      1050851 :                     flags = TYPENAME_FLAG;
   14566      1050851 :                     sfk = sfk_conversion;
   14567      1050851 :                     tree glob = get_global_binding (dname);
   14568      1050851 :                     if (glob && TREE_CODE (glob) == TYPE_DECL)
   14569            0 :                       name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14570              :                     else
   14571              :                       name = "<invalid operator>";
   14572              :                   }
   14573              :                 break;
   14574              : 
   14575            0 :               default:
   14576            0 :                 gcc_unreachable ();
   14577              :               }
   14578              :             break;
   14579              :           }
   14580              : 
   14581              :         case cdk_array:
   14582              :         case cdk_pointer:
   14583              :         case cdk_reference:
   14584              :         case cdk_ptrmem:
   14585              :           break;
   14586              : 
   14587              :         case cdk_decomp:
   14588   1005751119 :           name = "structured binding";
   14589              :           break;
   14590              : 
   14591           25 :         case cdk_error:
   14592           25 :           return error_mark_node;
   14593              : 
   14594            0 :         default:
   14595            0 :           gcc_unreachable ();
   14596              :         }
   14597   1005751119 :       if (id_declarator->kind == cdk_id)
   14598              :         break;
   14599              :     }
   14600              : 
   14601              :   /* [dcl.fct.edf]
   14602              : 
   14603              :      The declarator in a function-definition shall have the form
   14604              :      D1 ( parameter-declaration-clause) ...  */
   14605   1076019106 :   if (funcdef_flag && innermost_code != cdk_function)
   14606              :     {
   14607            3 :       error_at (id_loc, "function definition does not declare parameters");
   14608            3 :       return error_mark_node;
   14609              :     }
   14610              : 
   14611   1076019103 :   if (flags == TYPENAME_FLAG
   14612   1076019103 :       && innermost_code != cdk_function
   14613            3 :       && ! (ctype && !declspecs->any_specifiers_p))
   14614              :     {
   14615            3 :       error_at (id_loc, "declaration of %qD as non-function", dname);
   14616            3 :       return error_mark_node;
   14617              :     }
   14618              : 
   14619   1076019100 :   if (dname && identifier_p (dname))
   14620              :     {
   14621    601732914 :       if (UDLIT_OPER_P (dname)
   14622    601732914 :           && innermost_code != cdk_function)
   14623              :         {
   14624            6 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   14625            6 :           return error_mark_node;
   14626              :         }
   14627              : 
   14628    601732908 :       if (IDENTIFIER_ANY_OP_P (dname))
   14629              :         {
   14630     38366830 :           if (typedef_p)
   14631              :             {
   14632            3 :               error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
   14633            3 :               return error_mark_node;
   14634              :             }
   14635     38366827 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   14636              :             {
   14637           15 :               error_at (id_loc, "declaration of %qD as parameter", dname);
   14638           15 :               return error_mark_node;
   14639              :             }
   14640              :         }
   14641              :     }
   14642              : 
   14643              :   /* Anything declared one level down from the top level
   14644              :      must be one of the parameters of a function
   14645              :      (because the body is at least two levels down).  */
   14646              : 
   14647              :   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
   14648              :      by not allowing C++ class definitions to specify their parameters
   14649              :      with xdecls (must be spec.d in the parmlist).
   14650              : 
   14651              :      Since we now wait to push a class scope until we are sure that
   14652              :      we are in a legitimate method context, we must set oldcname
   14653              :      explicitly (since current_class_name is not yet alive).
   14654              : 
   14655              :      We also want to avoid calling this a PARM if it is in a namespace.  */
   14656              : 
   14657   1076019076 :   if (decl_context == NORMAL && !toplevel_bindings_p ())
   14658              :     {
   14659     74616251 :       cp_binding_level *b = current_binding_level;
   14660     74616251 :       current_binding_level = b->level_chain;
   14661     74616251 :       if (current_binding_level != 0 && toplevel_bindings_p ())
   14662              :         decl_context = PARM;
   14663     74616251 :       current_binding_level = b;
   14664              :     }
   14665              : 
   14666   1076019076 :   if (name == NULL)
   14667    470716678 :     name = decl_context == PARM ? "parameter" : "type name";
   14668              : 
   14669   1076019076 :   if (consteval_p && constexpr_p)
   14670              :     {
   14671            6 :       error_at (declspecs->locations[ds_consteval],
   14672              :                 "both %qs and %qs specified", "constexpr", "consteval");
   14673            6 :       return error_mark_node;
   14674              :     }
   14675              : 
   14676   1076019070 :   if (concept_p && typedef_p)
   14677              :     {
   14678            9 :       error_at (declspecs->locations[ds_concept],
   14679              :                 "%qs cannot appear in a typedef declaration", "concept");
   14680            9 :       return error_mark_node;
   14681              :     }
   14682              : 
   14683   1076019061 :   if (constexpr_p && typedef_p)
   14684              :     {
   14685            3 :       error_at (declspecs->locations[ds_constexpr],
   14686              :                 "%qs cannot appear in a typedef declaration", "constexpr");
   14687            3 :       return error_mark_node;
   14688              :     }
   14689              : 
   14690   1076019058 :   if (consteval_p && typedef_p)
   14691              :     {
   14692            3 :       error_at (declspecs->locations[ds_consteval],
   14693              :                 "%qs cannot appear in a typedef declaration", "consteval");
   14694            3 :       return error_mark_node;
   14695              :     }
   14696              : 
   14697   1076019055 :   if (constinit_p && typedef_p)
   14698              :     {
   14699            3 :       error_at (declspecs->locations[ds_constinit],
   14700              :                 "%qs cannot appear in a typedef declaration", "constinit");
   14701            3 :       return error_mark_node;
   14702              :     }
   14703              : 
   14704              :   /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
   14705              :      keywords shall appear in a decl-specifier-seq."  */
   14706   1076019052 :   if (constinit_p && constexpr_p)
   14707              :     {
   14708            6 :       gcc_rich_location richloc (declspecs->locations[ds_constinit]);
   14709            6 :       richloc.add_range (declspecs->locations[ds_constexpr]);
   14710            6 :       error_at (&richloc,
   14711              :                 "can use at most one of the %<constinit%> and %<constexpr%> "
   14712              :                 "specifiers");
   14713            6 :       return error_mark_node;
   14714            6 :     }
   14715              : 
   14716              :   /* If there were multiple types specified in the decl-specifier-seq,
   14717              :      issue an error message.  */
   14718   1076019046 :   if (declspecs->multiple_types_p)
   14719              :     {
   14720         1501 :       error_at (typespec_loc,
   14721              :                 "two or more data types in declaration of %qs", name);
   14722         1501 :       return error_mark_node;
   14723              :     }
   14724              : 
   14725   1076017545 :   if (declspecs->conflicting_specifiers_p)
   14726           31 :     return error_mark_node;
   14727              : 
   14728              :   /* Extract the basic type from the decl-specifier-seq.  */
   14729   1076017514 :   type = declspecs->type;
   14730   1076017514 :   if (type == error_mark_node)
   14731              :     {
   14732         1246 :       type = NULL_TREE;
   14733         1246 :       type_was_error_mark_node = true;
   14734              :     }
   14735              : 
   14736              :   /* Ignore erroneous attributes.  */
   14737   1076017514 :   if (attrlist && *attrlist == error_mark_node)
   14738           12 :     *attrlist = NULL_TREE;
   14739              : 
   14740              :   /* An object declared as __attribute__((unavailable)) suppresses
   14741              :      any reports of being declared with unavailable or deprecated
   14742              :      items.  An object declared as __attribute__((deprecated))
   14743              :      suppresses warnings of uses of other deprecated items.  */
   14744   1076017514 :   auto ds = make_temp_override (deprecated_state);
   14745   1076017514 :   if (attrlist && lookup_attribute ("unavailable", *attrlist))
   14746          171 :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
   14747   1076017343 :   else if (attrlist && lookup_attribute ("deprecated", *attrlist))
   14748       963680 :     deprecated_state = DEPRECATED_SUPPRESS;
   14749              : 
   14750   1076017514 :   cp_handle_deprecated_or_unavailable (type);
   14751   1076017514 :   if (type && TREE_CODE (type) == TYPE_DECL)
   14752              :     {
   14753    749618338 :       cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
   14754    749618338 :       typedef_decl = type;
   14755    749618338 :       type = TREE_TYPE (typedef_decl);
   14756    749618338 :       if (DECL_ARTIFICIAL (typedef_decl))
   14757    544819940 :         cp_handle_deprecated_or_unavailable (type);
   14758              :     }
   14759              :   /* No type at all: default to `int', and set DEFAULTED_INT
   14760              :      because it was not a user-defined typedef.  */
   14761   1076017514 :   if (type == NULL_TREE)
   14762              :     {
   14763     39983643 :       if (signed_p || unsigned_p || long_p || short_p)
   14764              :         {
   14765              :           /* These imply 'int'.  */
   14766      9427393 :           type = integer_type_node;
   14767      9427393 :           defaulted_int = 1;
   14768              :         }
   14769              :       /* If we just have "complex", it is equivalent to "complex double".  */
   14770     30556250 :       else if (!longlong && !explicit_intN
   14771     30556250 :                && decl_spec_seq_has_spec_p (declspecs, ds_complex))
   14772              :         {
   14773           81 :           type = double_type_node;
   14774           81 :           pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
   14775              :                    "ISO C++ does not support plain %<complex%> meaning "
   14776              :                    "%<double complex%>");
   14777              :         }
   14778              :     }
   14779              :   /* Gather flags.  */
   14780   1076017514 :   explicit_int = declspecs->explicit_int_p;
   14781   1076017514 :   explicit_char = declspecs->explicit_char_p;
   14782              : 
   14783              : #if 0
   14784              :   /* See the code below that used this.  */
   14785              :   if (typedef_decl)
   14786              :     decl_attr = DECL_ATTRIBUTES (typedef_decl);
   14787              : #endif
   14788   1076017514 :   typedef_type = type;
   14789              : 
   14790   1076017514 :   if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
   14791      2309492 :     ctor_return_type = TREE_TYPE (dname);
   14792              :   else
   14793              :     ctor_return_type = ctype;
   14794              : 
   14795   1076017514 :   if (sfk != sfk_none)
   14796              :     {
   14797     30554604 :       type = check_special_function_return_type (sfk, type,
   14798              :                                                  ctor_return_type,
   14799              :                                                  type_quals,
   14800              :                                                  &declarator,
   14801              :                                                  declspecs->locations);
   14802     30554604 :       type_quals = TYPE_UNQUALIFIED;
   14803              :     }
   14804   1045462910 :   else if (type == NULL_TREE)
   14805              :     {
   14806         1646 :       int is_main;
   14807              : 
   14808         1646 :       explicit_int = -1;
   14809              : 
   14810              :       /* We handle `main' specially here, because 'main () { }' is so
   14811              :          common.  With no options, it is allowed.  With -Wreturn-type,
   14812              :          it is a warning.  It is only an error with -pedantic-errors.  */
   14813         3292 :       is_main = (funcdef_flag
   14814         3526 :                  && dname && identifier_p (dname)
   14815          234 :                  && MAIN_NAME_P (dname)
   14816           68 :                  && ctype == NULL_TREE
   14817           68 :                  && in_namespace == NULL_TREE
   14818         1714 :                  && current_namespace == global_namespace);
   14819              : 
   14820         1646 :       if (type_was_error_mark_node)
   14821              :         /* We've already issued an error, don't complain more.  */;
   14822          400 :       else if (in_system_header_at (id_loc) || flag_ms_extensions)
   14823              :         /* Allow it, sigh.  */;
   14824          338 :       else if (! is_main)
   14825          276 :         permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
   14826              :                    name);
   14827           62 :       else if (pedantic)
   14828            4 :         pedwarn (id_loc, OPT_Wpedantic,
   14829              :                  "ISO C++ forbids declaration of %qs with no type", name);
   14830              :       else
   14831           58 :         warning_at (id_loc, OPT_Wreturn_type,
   14832              :                     "ISO C++ forbids declaration of %qs with no type", name);
   14833              : 
   14834         1646 :       if (type_was_error_mark_node && template_parm_flag)
   14835              :         /* FIXME we should be able to propagate the error_mark_node as is
   14836              :            for other contexts too.  */
   14837          162 :         type = error_mark_node;
   14838              :       else
   14839         1484 :         type = integer_type_node;
   14840              :     }
   14841              : 
   14842   1076017514 :   ctype = NULL_TREE;
   14843              : 
   14844   1076017514 :   if (explicit_intN)
   14845              :     {
   14846      1137141 :       if (! int_n_enabled_p[declspecs->int_n_idx])
   14847              :         {
   14848            0 :           error_at (declspecs->locations[ds_type_spec],
   14849              :                     "%<__int%d%> is not supported by this target",
   14850            0 :                     int_n_data[declspecs->int_n_idx].bitsize);
   14851            0 :           explicit_intN = false;
   14852              :         }
   14853              :       /* Don't pedwarn if the alternate "__intN__" form has been used instead
   14854              :          of "__intN".  */
   14855      1137141 :       else if (!int_n_alt && pedantic)
   14856        11206 :         pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
   14857              :                  "ISO C++ does not support %<__int%d%> for %qs",
   14858        11206 :                  int_n_data[declspecs->int_n_idx].bitsize, name);
   14859              :     }
   14860              : 
   14861              :   /* Now process the modifiers that were specified
   14862              :      and check for invalid combinations.  */
   14863              : 
   14864              :   /* Long double is a special combination.  */
   14865   1076017514 :   if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
   14866              :     {
   14867      9145071 :       long_p = false;
   14868      9145071 :       type = cp_build_qualified_type (long_double_type_node,
   14869              :                                       cp_type_quals (type));
   14870              :     }
   14871              : 
   14872              :   /* Check all other uses of type modifiers.  */
   14873              : 
   14874   1076017514 :   if (unsigned_p || signed_p || long_p || short_p)
   14875              :     {
   14876     21736502 :       location_t loc;
   14877     21736502 :       const char *key;
   14878     21736502 :       if (unsigned_p)
   14879              :         {
   14880     14814046 :           key = "unsigned";
   14881     14814046 :           loc = declspecs->locations[ds_unsigned];
   14882              :         }
   14883      6922456 :       else if (signed_p)
   14884              :         {
   14885      1053022 :           key = "signed";
   14886      1053022 :           loc = declspecs->locations[ds_signed];
   14887              :         }
   14888      5869434 :       else if (longlong)
   14889              :         {
   14890      2292826 :           key = "long long";
   14891      2292826 :           loc = declspecs->locations[ds_long_long];
   14892              :         }
   14893      3576608 :       else if (long_p)
   14894              :         {
   14895      3007782 :           key = "long";
   14896      3007782 :           loc = declspecs->locations[ds_long];
   14897              :         }
   14898              :       else /* if (short_p) */
   14899              :         {
   14900       568826 :           key = "short";
   14901       568826 :           loc = declspecs->locations[ds_short];
   14902              :         }
   14903              : 
   14904     21736502 :       int ok = 0;
   14905              : 
   14906     21736502 :       if (signed_p && unsigned_p)
   14907           54 :         complain_about_incompatible_declspecs
   14908           54 :           ("signed", declspecs->locations[ds_signed],
   14909              :            "unsigned", declspecs->locations[ds_unsigned]);
   14910     21736448 :       else if (long_p && short_p)
   14911           12 :         complain_about_incompatible_declspecs
   14912           12 :           ("long", declspecs->locations[ds_long],
   14913              :            "short", declspecs->locations[ds_short]);
   14914     21736436 :       else if (TREE_CODE (type) != INTEGER_TYPE
   14915     21736423 :                || type == char8_type_node
   14916     21736399 :                || type == char16_type_node
   14917     21736375 :                || type == char32_type_node
   14918     21736351 :                || ((long_p || short_p)
   14919     11404259 :                    && (explicit_char || explicit_intN)))
   14920          418 :         error_at (loc, "%qs specified with %qT", key, type);
   14921     21736018 :       else if (!explicit_int && !defaulted_int
   14922     21736018 :                && !explicit_char && !explicit_intN)
   14923              :         {
   14924           30 :           if (typedef_decl)
   14925              :             {
   14926           27 :               pedwarn (loc, OPT_Wpedantic,
   14927              :                        "%qs specified with typedef-name %qD",
   14928              :                        key, typedef_decl);
   14929           27 :               ok = !flag_pedantic_errors;
   14930              :               /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
   14931              :                  and is not built as a typedef.  */
   14932           27 :               if (is_typedef_decl (typedef_decl))
   14933           18 :                 type = DECL_ORIGINAL_TYPE (typedef_decl);
   14934              :             }
   14935            3 :           else if (declspecs->decltype_p)
   14936            0 :             error_at (loc, "%qs specified with %<decltype%>", key);
   14937              :           else
   14938            3 :             error_at (loc, "%qs specified with %<typeof%>", key);
   14939              :         }
   14940              :       else
   14941              :         ok = 1;
   14942              : 
   14943              :       /* Discard the type modifiers if they are invalid.  */
   14944          514 :       if (! ok)
   14945              :         {
   14946              :           unsigned_p = false;
   14947              :           signed_p = false;
   14948              :           long_p = false;
   14949              :           short_p = false;
   14950              :           longlong = 0;
   14951              :         }
   14952              :     }
   14953              : 
   14954              :   /* Decide whether an integer type is signed or not.
   14955              :      Optionally treat bitfields as signed by default.  */
   14956   1076017024 :   if (unsigned_p
   14957              :       /* [class.bit]
   14958              : 
   14959              :          It is implementation-defined whether a plain (neither
   14960              :          explicitly signed or unsigned) char, short, int, or long
   14961              :          bit-field is signed or unsigned.
   14962              : 
   14963              :          Naturally, we extend this to long long as well.  Note that
   14964              :          this does not include wchar_t.  */
   14965   1076017514 :       || (bitfield && !flag_signed_bitfields
   14966           18 :           && !signed_p
   14967              :           /* A typedef for plain `int' without `signed' can be
   14968              :              controlled just like plain `int', but a typedef for
   14969              :              `signed int' cannot be so controlled.  */
   14970           18 :           && !(typedef_decl
   14971           18 :                && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
   14972           13 :           && TREE_CODE (type) == INTEGER_TYPE
   14973           10 :           && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
   14974              :     {
   14975     14813831 :       if (explicit_intN)
   14976       538426 :         type = int_n_trees[declspecs->int_n_idx].unsigned_type;
   14977     14275405 :       else if (longlong)
   14978      1468248 :         type = long_long_unsigned_type_node;
   14979     12807157 :       else if (long_p)
   14980      2404306 :         type = long_unsigned_type_node;
   14981     10402851 :       else if (short_p)
   14982      1448751 :         type = short_unsigned_type_node;
   14983      8954100 :       else if (type == char_type_node)
   14984      1940486 :         type = unsigned_char_type_node;
   14985      7013614 :       else if (typedef_decl)
   14986           25 :         type = c_common_unsigned_type (type);
   14987              :       else
   14988      7013589 :         type = unsigned_type_node;
   14989              :     }
   14990   1061203683 :   else if (signed_p && type == char_type_node)
   14991       691854 :     type = signed_char_type_node;
   14992   1060511829 :   else if (explicit_intN)
   14993       598715 :     type = int_n_trees[declspecs->int_n_idx].signed_type;
   14994   1059913114 :   else if (longlong)
   14995      2357402 :     type = long_long_integer_type_node;
   14996   1057555712 :   else if (long_p)
   14997      3076736 :     type = long_integer_type_node;
   14998   1054478976 :   else if (short_p)
   14999       648483 :     type = short_integer_type_node;
   15000   1053830493 :   else if (signed_p && typedef_decl)
   15001            9 :     type = c_common_signed_type (type);
   15002              : 
   15003   1076017514 :   if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
   15004              :     {
   15005      1276047 :       if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
   15006            3 :         error_at (declspecs->locations[ds_complex],
   15007              :                   "complex invalid for %qs", name);
   15008              :       /* If a modifier is specified, the resulting complex is the complex
   15009              :          form of TYPE.  E.g, "complex short" is "complex short int".  */
   15010      1276044 :       else if (type == integer_type_node)
   15011          171 :         type = complex_integer_type_node;
   15012      1275873 :       else if (type == float_type_node)
   15013       346936 :         type = complex_float_type_node;
   15014       928937 :       else if (type == double_type_node)
   15015       347495 :         type = complex_double_type_node;
   15016       581442 :       else if (type == long_double_type_node)
   15017       346977 :         type = complex_long_double_type_node;
   15018              :       else
   15019       234465 :         type = build_complex_type (type);
   15020              :     }
   15021              : 
   15022              :   /* If we're using the injected-class-name to form a compound type or a
   15023              :      declaration, replace it with the underlying class so we don't get
   15024              :      redundant typedefs in the debug output.  But if we are returning the
   15025              :      type unchanged, leave it alone so that it's available to
   15026              :      maybe_get_template_decl_from_type_decl.  */
   15027    210597038 :   if (CLASS_TYPE_P (type)
   15028    210533178 :       && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
   15029     36204901 :       && type == TREE_TYPE (TYPE_NAME (type))
   15030   1112222415 :       && (declarator || type_quals))
   15031     34573511 :     type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
   15032              : 
   15033   1076017514 :   type_quals |= cp_type_quals (type);
   15034   2152035028 :   type = cp_build_qualified_type
   15035   2152035028 :     (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
   15036    871219116 :                           || declspecs->decltype_p)
   15037              :                          ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
   15038              :   /* We might have ignored or rejected some of the qualifiers.  */
   15039   1076017514 :   type_quals = cp_type_quals (type);
   15040              : 
   15041   1060779795 :   if (cxx_dialect >= cxx17 && type && is_auto (type)
   15042     23910639 :       && innermost_code != cdk_function
   15043              :       /* Placeholder in parm gets a better error below.  */
   15044     14915894 :       && !(decl_context == PARM || decl_context == CATCHPARM)
   15045   1090894205 :       && id_declarator && declarator != id_declarator)
   15046      1210103 :     if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
   15047              :       {
   15048           16 :         auto_diagnostic_group g;
   15049           16 :         gcc_rich_location richloc (typespec_loc);
   15050           16 :         richloc.add_fixit_insert_after ("<>");
   15051           16 :         error_at (&richloc, "missing template argument list after %qE; "
   15052              :                   "for deduction, template placeholder must be followed "
   15053              :                   "by a simple declarator-id", tmpl);
   15054           16 :         inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
   15055           16 :         type = error_mark_node;
   15056           16 :       }
   15057              : 
   15058   1076017514 :   staticp = 0;
   15059   1076017514 :   inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
   15060   1076017514 :   virtualp =  decl_spec_seq_has_spec_p (declspecs, ds_virtual);
   15061   1076017514 :   explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
   15062              : 
   15063   1076017514 :   storage_class = declspecs->storage_class;
   15064   1076017514 :   if (storage_class == sc_static)
   15065     24509244 :     staticp = 1 + (decl_context == FIELD);
   15066   1051508270 :   else if (decl_context == FIELD && sfk == sfk_deduction_guide)
   15067              :     /* Treat class-scope deduction guides as static member functions
   15068              :        so that they get a FUNCTION_TYPE instead of a METHOD_TYPE.  */
   15069     24158973 :     staticp = 2;
   15070              : 
   15071   1076017514 :   if (virtualp)
   15072              :     {
   15073      4187979 :       if (staticp == 2)
   15074              :         {
   15075           21 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   15076           21 :           richloc.add_range (declspecs->locations[ds_storage_class]);
   15077           21 :           error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
   15078              :                     "and %<static%>", dname);
   15079           21 :           storage_class = sc_none;
   15080           21 :           staticp = 0;
   15081           21 :         }
   15082      4187979 :       if (constexpr_p && pedantic && cxx_dialect < cxx20)
   15083              :         {
   15084            6 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   15085            6 :           richloc.add_range (declspecs->locations[ds_constexpr]);
   15086            6 :           pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
   15087              :                    "declared both %<virtual%> and %<constexpr%> only in "
   15088              :                    "%<-std=c++20%> or %<-std=gnu++20%>", dname);
   15089            6 :         }
   15090              :     }
   15091   1076017514 :   friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   15092              : 
   15093              :   /* Issue errors about use of storage classes for parameters.  */
   15094   1076017514 :   if (decl_context == PARM)
   15095              :     {
   15096    303736896 :       if (typedef_p)
   15097              :         {
   15098           24 :           error_at (declspecs->locations[ds_typedef],
   15099              :                     "typedef declaration invalid in parameter declaration");
   15100           24 :           return error_mark_node;
   15101              :         }
   15102    303736872 :       else if (template_parm_flag && storage_class != sc_none)
   15103              :         {
   15104           16 :           error_at (min_location (declspecs->locations[ds_thread],
   15105              :                                   declspecs->locations[ds_storage_class]),
   15106              :                     "storage class specified for template parameter %qs",
   15107              :                     name);
   15108           16 :           return error_mark_node;
   15109              :         }
   15110    303736856 :       else if (storage_class == sc_static
   15111    303736856 :                || storage_class == sc_extern
   15112    303736853 :                || thread_p)
   15113              :         {
   15114            9 :           error_at (min_location (declspecs->locations[ds_thread],
   15115              :                                   declspecs->locations[ds_storage_class]),
   15116              :                     "storage class specified for parameter %qs", name);
   15117            9 :           return error_mark_node;
   15118              :         }
   15119              : 
   15120              :       /* Function parameters cannot be concept. */
   15121    303736847 :       if (concept_p)
   15122              :         {
   15123            9 :           error_at (declspecs->locations[ds_concept],
   15124              :                     "a parameter cannot be declared %qs", "concept");
   15125            9 :           concept_p = 0;
   15126            9 :           constexpr_p = 0;
   15127              :         }
   15128              :       /* Function parameters cannot be constexpr.  If we saw one, moan
   15129              :          and pretend it wasn't there.  */
   15130    303736838 :       else if (constexpr_p)
   15131              :         {
   15132            9 :           error_at (declspecs->locations[ds_constexpr],
   15133              :                     "a parameter cannot be declared %qs", "constexpr");
   15134            9 :           constexpr_p = 0;
   15135              :         }
   15136    303736847 :       if (constinit_p)
   15137              :         {
   15138            6 :           error_at (declspecs->locations[ds_constinit],
   15139              :                     "a parameter cannot be declared %qs", "constinit");
   15140            6 :           constinit_p = 0;
   15141              :         }
   15142    303736847 :       if (consteval_p)
   15143              :         {
   15144            3 :           error_at (declspecs->locations[ds_consteval],
   15145              :                     "a parameter cannot be declared %qs", "consteval");
   15146            3 :           consteval_p = 0;
   15147              :         }
   15148              :     }
   15149              : 
   15150              :   /* Give error if `virtual' is used outside of class declaration.  */
   15151   1076017465 :   if (virtualp
   15152      4187979 :       && (current_class_name == NULL_TREE || decl_context != FIELD))
   15153              :     {
   15154           68 :       error_at (declspecs->locations[ds_virtual],
   15155              :                 "%<virtual%> outside class declaration");
   15156           68 :       virtualp = 0;
   15157              :     }
   15158              : 
   15159   1076017465 :   if (innermost_code == cdk_decomp)
   15160              :     {
   15161       235332 :       location_t loc = (declarator->kind == cdk_reference
   15162       245573 :                         ? declarator->declarator->id_loc : declarator->id_loc);
   15163       245573 :       if (inlinep)
   15164           29 :         error_at (declspecs->locations[ds_inline],
   15165              :                   "structured binding declaration cannot be %qs", "inline");
   15166       245573 :       if (typedef_p)
   15167           29 :         error_at (declspecs->locations[ds_typedef],
   15168              :                   "structured binding declaration cannot be %qs", "typedef");
   15169       245573 :       if (constexpr_p && !concept_p && cxx_dialect < cxx26)
   15170          101 :         pedwarn (declspecs->locations[ds_constexpr], OPT_Wc__26_extensions,
   15171              :                  "structured binding declaration can be %qs only with "
   15172              :                  "%<-std=c++2c%> or %<-std=gnu++2c%>", "constexpr");
   15173       245573 :       if (consteval_p)
   15174           13 :         error_at (declspecs->locations[ds_consteval], "structured "
   15175              :                   "binding declaration cannot be %qs", "consteval");
   15176       245573 :       if (thread_p && cxx_dialect < cxx20)
   15177           75 :         pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
   15178              :                  "structured binding declaration can be %qs only in "
   15179              :                  "%<-std=c++20%> or %<-std=gnu++20%>",
   15180           75 :                  declspecs->gnu_thread_keyword_p
   15181              :                  ? "__thread" : "thread_local");
   15182       245573 :       if (concept_p)
   15183              :         {
   15184            0 :           error_at (declspecs->locations[ds_concept],
   15185              :                     "structured binding declaration cannot be %qs", "concept");
   15186            0 :           constexpr_p = 0;
   15187              :         }
   15188              :       /* [dcl.struct.bind] "A cv that includes volatile is deprecated."  */
   15189       245573 :       if (type_quals & TYPE_QUAL_VOLATILE)
   15190           26 :         warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
   15191              :                     "%<volatile%>-qualified structured binding is deprecated");
   15192       245573 :       switch (storage_class)
   15193              :         {
   15194              :         case sc_none:
   15195              :           break;
   15196           28 :         case sc_register:
   15197           28 :           error_at (loc, "structured binding declaration cannot be %qs",
   15198              :                     "register");
   15199           28 :           break;
   15200          254 :         case sc_static:
   15201          254 :           if (cxx_dialect < cxx20)
   15202          185 :             pedwarn (loc, OPT_Wc__20_extensions,
   15203              :                      "structured binding declaration can be %qs only in "
   15204              :                      "%<-std=c++20%> or %<-std=gnu++20%>", "static");
   15205              :           break;
   15206           29 :         case sc_extern:
   15207           29 :           error_at (loc, "structured binding declaration cannot be %qs",
   15208              :                     "extern");
   15209           29 :           break;
   15210           28 :         case sc_mutable:
   15211           28 :           error_at (loc, "structured binding declaration cannot be %qs",
   15212              :                     "mutable");
   15213           28 :           break;
   15214            0 :         case sc_auto:
   15215            0 :           error_at (loc, "structured binding declaration cannot be "
   15216              :                     "C++98 %<auto%>");
   15217            0 :           break;
   15218            0 :         default:
   15219            0 :           gcc_unreachable ();
   15220              :         }
   15221       245573 :       if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
   15222       245573 :           || TYPE_IDENTIFIER (type) != auto_identifier)
   15223              :         {
   15224            3 :           if (type != error_mark_node)
   15225              :             {
   15226            3 :               auto_diagnostic_group d;
   15227            3 :               error_at (loc, "structured binding declaration cannot have "
   15228              :                         "type %qT", type);
   15229            3 :               inform (loc,
   15230              :                       "type must be cv-qualified %<auto%> or reference to "
   15231              :                       "cv-qualified %<auto%>");
   15232            3 :             }
   15233            3 :           type = build_qualified_type (make_auto (), type_quals);
   15234            3 :           declspecs->type = type;
   15235              :         }
   15236       245570 :       else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
   15237           51 :         pedwarn (loc, OPT_Wpedantic,
   15238              :                  "structured binding declaration cannot have constrained "
   15239              :                  "%<auto%> type %qT", type);
   15240       245573 :       inlinep = 0;
   15241       245573 :       typedef_p = 0;
   15242       245573 :       consteval_p = 0;
   15243       245573 :       concept_p = 0;
   15244       245573 :       if (storage_class != sc_static)
   15245              :         {
   15246       245319 :           storage_class = sc_none;
   15247       245319 :           declspecs->storage_class = sc_none;
   15248              :         }
   15249              :     }
   15250              : 
   15251              :   /* Static anonymous unions are dealt with here.  */
   15252   1076017465 :   if (staticp && decl_context == TYPENAME
   15253            0 :       && declspecs->type
   15254   1076017465 :       && ANON_AGGR_TYPE_P (declspecs->type))
   15255              :     decl_context = FIELD;
   15256              : 
   15257              :   /* Warn about storage classes that are invalid for certain
   15258              :      kinds of declarations (parameters, typenames, etc.).  */
   15259   1076017465 :   if (thread_p
   15260        20564 :       && ((storage_class
   15261        20564 :            && storage_class != sc_extern
   15262          528 :            && storage_class != sc_static)
   15263        20553 :           || typedef_p))
   15264              :     {
   15265           17 :       location_t loc
   15266           17 :         = min_location (declspecs->locations[ds_thread],
   15267              :                         declspecs->locations[ds_storage_class]);
   15268           17 :       error_at (loc, "multiple storage classes in declaration of %qs", name);
   15269           17 :       thread_p = false;
   15270              :     }
   15271   1076017465 :   if (decl_context != NORMAL
   15272    901820945 :       && ((storage_class != sc_none
   15273    901820945 :            && storage_class != sc_mutable)
   15274    877661986 :           || thread_p))
   15275              :     {
   15276     24158962 :       if ((decl_context == PARM || decl_context == CATCHPARM)
   15277           36 :           && (storage_class == sc_register
   15278           36 :               || storage_class == sc_auto))
   15279              :         ;
   15280     24158926 :       else if (typedef_p)
   15281              :         ;
   15282     24158926 :       else if (decl_context == FIELD
   15283              :                /* C++ allows static class elements.  */
   15284     24158926 :                && storage_class == sc_static)
   15285              :         /* C++ also allows inlines and signed and unsigned elements,
   15286              :            but in those cases we don't come in here.  */
   15287              :         ;
   15288              :       else
   15289              :         {
   15290           15 :           location_t loc
   15291           15 :             = min_location (declspecs->locations[ds_thread],
   15292              :                             declspecs->locations[ds_storage_class]);
   15293           15 :           if (decl_context == FIELD)
   15294           15 :             error_at (loc, "storage class specified for %qs", name);
   15295            0 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   15296            0 :             error_at (loc, "storage class specified for parameter %qs", name);
   15297              :           else
   15298            0 :             error_at (loc, "storage class specified for typename");
   15299           15 :           if (storage_class == sc_register
   15300           15 :               || storage_class == sc_auto
   15301           15 :               || storage_class == sc_extern
   15302            3 :               || thread_p)
   15303           15 :             storage_class = sc_none;
   15304              :         }
   15305              :     }
   15306   1051858503 :   else if (storage_class == sc_extern && funcdef_flag
   15307   1051858503 :            && ! toplevel_bindings_p ())
   15308            0 :     error ("nested function %qs declared %<extern%>", name);
   15309   1051858503 :   else if (toplevel_bindings_p ())
   15310              :     {
   15311    490886819 :       if (storage_class == sc_auto)
   15312            2 :         error_at (declspecs->locations[ds_storage_class],
   15313              :                   "top-level declaration of %qs specifies %<auto%>", name);
   15314              :     }
   15315    560971684 :   else if (thread_p
   15316    560971684 :            && storage_class != sc_extern
   15317          243 :            && storage_class != sc_static)
   15318              :     {
   15319          210 :       if (declspecs->gnu_thread_keyword_p)
   15320           49 :         pedwarn (declspecs->locations[ds_thread],
   15321           49 :                  0, "function-scope %qs implicitly auto and "
   15322              :                  "declared %<__thread%>", name);
   15323              : 
   15324              :       /* When thread_local is applied to a variable of block scope the
   15325              :          storage-class-specifier static is implied if it does not appear
   15326              :          explicitly.  */
   15327          210 :       storage_class = declspecs->storage_class = sc_static;
   15328          210 :       staticp = 1;
   15329              :     }
   15330              : 
   15331   1076017465 :   if (storage_class && friendp)
   15332              :     {
   15333           12 :       error_at (min_location (declspecs->locations[ds_thread],
   15334              :                               declspecs->locations[ds_storage_class]),
   15335              :                 "storage class specifiers invalid in friend function "
   15336              :                 "declarations");
   15337           12 :       storage_class = sc_none;
   15338           12 :       staticp = 0;
   15339              :     }
   15340              : 
   15341   1076017465 :   if (!id_declarator)
   15342              :     unqualified_id = NULL_TREE;
   15343              :   else
   15344              :     {
   15345    605055294 :       unqualified_id = id_declarator->u.id.unqualified_name;
   15346    605055294 :       switch (TREE_CODE (unqualified_id))
   15347              :         {
   15348      3323935 :         case BIT_NOT_EXPR:
   15349      3323935 :           unqualified_id = TREE_OPERAND (unqualified_id, 0);
   15350      3323935 :           if (TYPE_P (unqualified_id))
   15351      3323932 :             unqualified_id = constructor_name (unqualified_id);
   15352              :           break;
   15353              : 
   15354              :         case IDENTIFIER_NODE:
   15355              :         case TEMPLATE_ID_EXPR:
   15356              :           break;
   15357              : 
   15358            0 :         default:
   15359            0 :           gcc_unreachable ();
   15360              :         }
   15361              :     }
   15362              : 
   15363   1076017465 :   if (declspecs->std_attributes)
   15364              :     {
   15365          795 :       location_t attr_loc = declspecs->locations[ds_std_attribute];
   15366          795 :       auto_diagnostic_group d;
   15367          795 :       if (any_nonignored_attribute_p (declspecs->std_attributes)
   15368          795 :           && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
   15369          792 :         inform (attr_loc, "an attribute that appertains to a type-specifier "
   15370              :                 "is ignored");
   15371          795 :     }
   15372              : 
   15373              :   /* Skip over build_memfn_type when a FUNCTION_DECL is an xobj memfn.  */
   15374   1076017465 :   bool is_xobj_member_function = false;
   15375              :   /* Determine the type of the entity declared by recurring on the
   15376              :      declarator.  */
   15377   1476464142 :   for (; declarator; declarator = declarator->declarator)
   15378              :     {
   15379   1005747570 :       const cp_declarator *inner_declarator;
   15380   1005747570 :       tree attrs;
   15381              : 
   15382   1005747570 :       if (type == error_mark_node)
   15383          607 :         return error_mark_node;
   15384              : 
   15385   1005747242 :       attrs = declarator->attributes;
   15386   1005747242 :       if (attrs)
   15387              :         {
   15388        13337 :           int attr_flags;
   15389              : 
   15390        13337 :           attr_flags = 0;
   15391        13337 :           if (declarator->kind == cdk_id)
   15392        12629 :             attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
   15393        13337 :           if (declarator->kind == cdk_function)
   15394          691 :             attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
   15395        13337 :           if (declarator->kind == cdk_array)
   15396            2 :             attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
   15397        13337 :           tree late_attrs = NULL_TREE;
   15398        13337 :           if (decl_context != PARM && decl_context != TYPENAME)
   15399              :             /* Assume that any attributes that get applied late to
   15400              :                templates will DTRT when applied to the declaration
   15401              :                as a whole.  */
   15402        13325 :             late_attrs = splice_template_attributes (&attrs, type);
   15403        13337 :           returned_attrs = decl_attributes (&type,
   15404              :                                             attr_chainon (returned_attrs,
   15405              :                                                           attrs),
   15406              :                                             attr_flags);
   15407        13337 :           returned_attrs = attr_chainon (late_attrs, returned_attrs);
   15408              :         }
   15409              : 
   15410   1005747242 :       inner_declarator = declarator->declarator;
   15411              : 
   15412              :       /* We don't want to warn in parameter context because we don't
   15413              :          yet know if the parse will succeed, and this might turn out
   15414              :          to be a constructor call.  */
   15415   1005747242 :       if (decl_context != PARM
   15416   1005747242 :           && decl_context != TYPENAME
   15417    584349564 :           && !typedef_p
   15418    534503866 :           && declarator->parenthesized != UNKNOWN_LOCATION
   15419              :           /* If the type is class-like and the inner name used a
   15420              :              global namespace qualifier, we need the parens.
   15421              :              Unfortunately all we can tell is whether a qualified name
   15422              :              was used or not.  */
   15423   1005747426 :           && !(inner_declarator
   15424          126 :                && inner_declarator->kind == cdk_id
   15425          108 :                && inner_declarator->u.id.qualifying_scope
   15426           18 :                && (MAYBE_CLASS_TYPE_P (type)
   15427           12 :                    || TREE_CODE (type) == ENUMERAL_TYPE)))
   15428              :         {
   15429          172 :           auto_diagnostic_group d;
   15430          172 :           if (warning_at (declarator->parenthesized, OPT_Wparentheses,
   15431              :                           "unnecessary parentheses in declaration of %qs",
   15432              :                           name))
   15433              :             {
   15434           42 :               gcc_rich_location iloc (declarator->parenthesized);
   15435           42 :               iloc.add_fixit_remove (get_start (declarator->parenthesized));
   15436           42 :               iloc.add_fixit_remove (get_finish (declarator->parenthesized));
   15437           42 :               inform (&iloc, "remove parentheses");
   15438           42 :             }
   15439          172 :         }
   15440   1005747242 :       if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
   15441              :         break;
   15442              : 
   15443    400446956 :       switch (declarator->kind)
   15444              :         {
   15445      3712264 :         case cdk_array:
   15446      7424528 :           type = create_array_type_for_decl (dname, type,
   15447      3712264 :                                              declarator->u.array.bounds,
   15448      3712264 :                                              declarator->id_loc);
   15449      3712264 :           if (!valid_array_size_p (dname
   15450              :                                    ? declarator->id_loc : input_location,
   15451              :                                    type, dname))
   15452          267 :             type = error_mark_node;
   15453              : 
   15454      3712264 :           if (declarator->std_attributes)
   15455              :             /* [dcl.array]/1:
   15456              : 
   15457              :                The optional attribute-specifier-seq appertains to the
   15458              :                array type.  */
   15459          209 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   15460              :           break;
   15461              : 
   15462    196812502 :         case cdk_function:
   15463    196812502 :           {
   15464    196812502 :             tree arg_types;
   15465    196812502 :             int funcdecl_p;
   15466              : 
   15467              :             /* Declaring a function type.  */
   15468              : 
   15469              :             /* Pick up type qualifiers which should be applied to `this'.  */
   15470    196812502 :             memfn_quals = declarator->u.function.qualifiers;
   15471              :             /* Pick up virt-specifiers.  */
   15472    196812502 :             virt_specifiers = declarator->u.function.virt_specifiers;
   15473              :             /* And ref-qualifier, too */
   15474    196812502 :             rqual = declarator->u.function.ref_qualifier;
   15475              :             /* And tx-qualifier.  */
   15476    196812502 :             tree tx_qual = declarator->u.function.tx_qualifier;
   15477              :             /* Pick up the exception specifications.  */
   15478    196812502 :             raises = declarator->u.function.exception_specification;
   15479              :             /* If the exception-specification is ill-formed, let's pretend
   15480              :                there wasn't one.  */
   15481    196812502 :             if (raises == error_mark_node)
   15482            9 :               raises = NULL_TREE;
   15483              : 
   15484    393625004 :             auto find_xobj_parm = [](tree parm_list)
   15485              :               {
   15486              :                 /* There is no need to iterate over the list,
   15487              :                    only the first parm can be a valid xobj parm.  */
   15488    393392587 :                 if (!parm_list || TREE_PURPOSE (parm_list) != this_identifier)
   15489              :                   return NULL_TREE;
   15490              :                 /* If we make it here, we are looking at an xobj parm.
   15491              : 
   15492              :                    Non-null 'purpose' usually means the parm has a default
   15493              :                    argument, we don't want to violate this assumption.  */
   15494        94984 :                 TREE_PURPOSE (parm_list) = NULL_TREE;
   15495        94984 :                 return TREE_VALUE (parm_list);
   15496              :               };
   15497              : 
   15498    196812502 :             tree xobj_parm
   15499    196812502 :               = find_xobj_parm (declarator->u.function.parameters);
   15500    196812502 :             is_xobj_member_function = xobj_parm;
   15501              : 
   15502    196812502 :             if (xobj_parm && cxx_dialect < cxx23)
   15503        42024 :               pedwarn (DECL_SOURCE_LOCATION (xobj_parm), OPT_Wc__23_extensions,
   15504              :                        "explicit object member function only available "
   15505              :                        "with %<-std=c++23%> or %<-std=gnu++23%>");
   15506              : 
   15507    196812502 :             if (xobj_parm && decl_context == TYPENAME)
   15508              :               {
   15509              :                 /* We inform in every case, just differently depending on what
   15510              :                    case it is.  */
   15511            9 :                 auto_diagnostic_group d;
   15512            9 :                 bool ptr_type = true;
   15513              :                 /* If declarator->kind is cdk_function and we are at the end of
   15514              :                    the declarator chain, we are looking at a function type.  */
   15515            9 :                 if (!declarator->declarator)
   15516              :                   {
   15517            3 :                     error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15518              :                               "a function type cannot "
   15519              :                               "have an explicit object parameter");
   15520            3 :                     ptr_type = false;
   15521              :                   }
   15522            6 :                 else if (declarator->declarator->kind == cdk_pointer)
   15523            3 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15524              :                             "a pointer to function type cannot "
   15525              :                             "have an explicit object parameter");
   15526            3 :                 else if (declarator->declarator->kind == cdk_ptrmem)
   15527            3 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15528              :                             "a pointer to member function type "
   15529              :                             "cannot have an explicit object parameter");
   15530              :                 else
   15531            0 :                   gcc_unreachable ();
   15532              : 
   15533              :                 /* The locations being used here are probably not correct.  */
   15534            6 :                 if (ptr_type)
   15535            6 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   15536              :                           "the type of a pointer to explicit object member "
   15537              :                           "function is a regular pointer to function type");
   15538              :                 else
   15539            3 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   15540              :                           "the type of an explicit object "
   15541              :                           "member function is a regular function type");
   15542              :                 /* Ideally we should synthesize the correct syntax
   15543              :                    for the user, perhaps this could be added later.  */
   15544            9 :               }
   15545              :             /* Since a valid xobj parm has its purpose cleared in find_xobj_parm
   15546              :                the first parm node will never erroneously be detected here.  */
   15547    196812502 :             {
   15548    196812502 :               auto_diagnostic_group d;
   15549    196812502 :               bool bad_xobj_parm_encountered = false;
   15550    196812502 :               for (tree parm = declarator->u.function.parameters;
   15551    488013261 :                    parm && parm != void_list_node;
   15552    291200759 :                    parm = TREE_CHAIN (parm))
   15553              :                 {
   15554    291200759 :                   if (TREE_PURPOSE (parm) != this_identifier)
   15555    291200750 :                     continue;
   15556            9 :                   bad_xobj_parm_encountered = true;
   15557            9 :                   TREE_PURPOSE (parm) = NULL_TREE;
   15558            9 :                   gcc_rich_location bad_xobj_parm
   15559            9 :                     (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
   15560            9 :                   error_at (&bad_xobj_parm,
   15561              :                             "only the first parameter of a member function "
   15562              :                             "can be declared as an explicit object parameter");
   15563            9 :                 }
   15564    196812502 :               if (bad_xobj_parm_encountered && xobj_parm)
   15565            0 :                 inform (DECL_SOURCE_LOCATION (xobj_parm),
   15566              :                         "valid explicit object parameter declared here");
   15567    196812502 :             }
   15568              : 
   15569    196812502 :             if (reqs)
   15570            3 :               error_at (location_of (reqs), "requires-clause on return type");
   15571    196812502 :             reqs = declarator->u.function.requires_clause;
   15572              : 
   15573              :             /* Say it's a definition only for the CALL_EXPR
   15574              :                closest to the identifier.  */
   15575    196812502 :             funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
   15576              : 
   15577              :             /* Handle a late-specified return type.  */
   15578    196812502 :             tree late_return_type = declarator->u.function.late_return_type;
   15579    196812502 :             if (tree auto_node = type_uses_auto (type))
   15580              :               {
   15581      9007064 :                 if (!late_return_type)
   15582              :                   {
   15583      5278002 :                     if (!funcdecl_p)
   15584              :                       /* auto (*fp)() = f; is OK.  */;
   15585      5277968 :                     else if (current_class_type
   15586      9707108 :                              && LAMBDA_TYPE_P (current_class_type))
   15587              :                       /* OK for C++11 lambdas.  */;
   15588      3404977 :                     else if (cxx_dialect < cxx14)
   15589              :                       {
   15590            7 :                         auto_diagnostic_group d;
   15591            7 :                         error_at (typespec_loc, "%qs function uses "
   15592              :                                   "%<auto%> type specifier without "
   15593              :                                   "trailing return type", name);
   15594            7 :                         inform (typespec_loc,
   15595              :                                 "deduced return type only available "
   15596              :                                 "with %<-std=c++14%> or %<-std=gnu++14%>");
   15597            7 :                       }
   15598      3404970 :                     else if (virtualp)
   15599              :                       {
   15600            6 :                         error_at (typespec_loc, "virtual function "
   15601              :                                   "cannot have deduced return type");
   15602            6 :                         virtualp = false;
   15603              :                       }
   15604              :                   }
   15605      3729062 :                 else if (!is_auto (type) && sfk != sfk_conversion)
   15606              :                   {
   15607           15 :                     error_at (typespec_loc, "%qs function with trailing "
   15608              :                               "return type has %qT as its type rather "
   15609              :                               "than plain %<auto%>", name, type);
   15610          276 :                     return error_mark_node;
   15611              :                   }
   15612      3729047 :                 else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
   15613              :                   {
   15614            9 :                     if (funcdecl_p)
   15615            3 :                       error_at (typespec_loc,
   15616              :                                 "%qs function with trailing return type "
   15617              :                                 "has %<decltype(auto)%> as its type "
   15618              :                                 "rather than plain %<auto%>", name);
   15619              :                     else
   15620            6 :                       error_at (typespec_loc,
   15621              :                                 "invalid use of %<decltype(auto)%>");
   15622            9 :                     return error_mark_node;
   15623              :                   }
   15624      3729038 :                 else if (is_constrained_auto (type))
   15625              :                   {
   15626            6 :                     if (funcdecl_p)
   15627            3 :                       error_at (typespec_loc,
   15628              :                                 "%qs function with trailing return type "
   15629              :                                 "has constrained %<auto%> type specifier "
   15630              :                                 "rather than plain %<auto%>",
   15631              :                                 name);
   15632              :                     else
   15633            3 :                       error_at (typespec_loc,
   15634              :                                 "invalid use of constrained %<auto%> type");
   15635            6 :                     return error_mark_node;
   15636              :                   }
   15637      9007034 :                 tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
   15638      9007034 :                 if (!tmpl)
   15639      7748386 :                   if (tree late_auto = type_uses_auto (late_return_type))
   15640        50727 :                     tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
   15641      7748386 :                 if (tmpl)
   15642              :                   {
   15643      1258654 :                     if (!funcdecl_p || !dguide_name_p (unqualified_id))
   15644              :                       {
   15645           13 :                         auto_diagnostic_group g;
   15646           13 :                         error_at (typespec_loc, "deduced class "
   15647              :                                   "type %qD in function return type",
   15648           13 :                                   DECL_NAME (tmpl));
   15649           13 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   15650              :                                 "%qD declared here", tmpl);
   15651           13 :                         return error_mark_node;
   15652           13 :                       }
   15653      1258641 :                     else if (!late_return_type)
   15654              :                       {
   15655            3 :                         auto_diagnostic_group d;
   15656            3 :                         error_at (declarator->id_loc, "deduction guide "
   15657              :                                   "for %qT must have trailing return "
   15658            3 :                                   "type", TREE_TYPE (tmpl));
   15659            3 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   15660              :                                 "%qD declared here", tmpl);
   15661            3 :                         return error_mark_node;
   15662            3 :                       }
   15663      1258638 :                     else if (CLASS_TYPE_P (late_return_type)
   15664      1258638 :                               && CLASSTYPE_TEMPLATE_INFO (late_return_type)
   15665      2517276 :                               && (CLASSTYPE_TI_TEMPLATE (late_return_type)
   15666              :                                   == tmpl))
   15667              :                       /* OK */;
   15668              :                     else
   15669            0 :                       error ("trailing return type %qT of deduction guide "
   15670              :                               "is not a specialization of %qT",
   15671            0 :                               late_return_type, TREE_TYPE (tmpl));
   15672              :                   }
   15673              :               }
   15674    187805438 :             else if (late_return_type
   15675    187805438 :                      && sfk != sfk_conversion)
   15676              :               {
   15677           37 :                 if (late_return_type == error_mark_node)
   15678              :                   return error_mark_node;
   15679           37 :                 if (cxx_dialect < cxx11)
   15680              :                   /* Not using maybe_warn_cpp0x because this should
   15681              :                      always be an error.  */
   15682            1 :                   error_at (typespec_loc,
   15683              :                             "trailing return type only available "
   15684              :                             "with %<-std=c++11%> or %<-std=gnu++11%>");
   15685              :                 else
   15686           36 :                   error_at (typespec_loc, "%qs function with trailing "
   15687              :                             "return type not declared with %<auto%> "
   15688              :                             "type specifier", name);
   15689           37 :                 return error_mark_node;
   15690              :               }
   15691    196812419 :             if (late_return_type && sfk == sfk_conversion)
   15692              :               {
   15693           14 :                 error ("a conversion function cannot have a trailing return type");
   15694           14 :                 return error_mark_node;
   15695              :               }
   15696    196812405 :             type = splice_late_return_type (type, late_return_type);
   15697    196812405 :             if (type == error_mark_node)
   15698              :               return error_mark_node;
   15699              : 
   15700    196812327 :             if (late_return_type)
   15701              :               {
   15702      3728940 :                 late_return_type_p = true;
   15703      3728940 :                 type_quals = cp_type_quals (type);
   15704              :               }
   15705              : 
   15706    196812327 :             if (type_quals != TYPE_UNQUALIFIED)
   15707              :               {
   15708              :                 /* It's wrong, for instance, to issue a -Wignored-qualifiers
   15709              :                    warning for
   15710              :                     static_assert(!is_same_v<void(*)(), const void(*)()>);
   15711              :                     because there the qualifier matters.  */
   15712        12292 :                 if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
   15713          232 :                   warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
   15714              :                               "qualifiers ignored on function return type");
   15715              :                 /* [dcl.fct] "A volatile-qualified return type is
   15716              :                    deprecated."  */
   15717        12292 :                 if (type_quals & TYPE_QUAL_VOLATILE)
   15718          643 :                   warning_at (typespec_loc, OPT_Wvolatile,
   15719              :                               "%<volatile%>-qualified return type is "
   15720              :                               "deprecated");
   15721              : 
   15722              :                 /* We now know that the TYPE_QUALS don't apply to the
   15723              :                    decl, but to its return type.  */
   15724              :                 type_quals = TYPE_UNQUALIFIED;
   15725              :               }
   15726              : 
   15727              :             /* Error about some types functions can't return.  */
   15728              : 
   15729    196812327 :             if (TREE_CODE (type) == FUNCTION_TYPE)
   15730              :               {
   15731           30 :                 error_at (typespec_loc, "%qs declared as function returning "
   15732              :                           "a function", name);
   15733           30 :                 return error_mark_node;
   15734              :               }
   15735    196812297 :             if (TREE_CODE (type) == ARRAY_TYPE)
   15736              :               {
   15737            6 :                 error_at (typespec_loc, "%qs declared as function returning "
   15738              :                           "an array", name);
   15739            6 :                 return error_mark_node;
   15740              :               }
   15741    196812291 :             if (constinit_p && funcdecl_p)
   15742              :               {
   15743           15 :                 error_at (declspecs->locations[ds_constinit],
   15744              :                           "%<constinit%> on function return type is not "
   15745              :                           "allowed");
   15746           15 :                 return error_mark_node;
   15747              :               }
   15748              : 
   15749    196812276 :             if (check_decltype_auto (typespec_loc, type))
   15750           50 :               return error_mark_node;
   15751              : 
   15752    196812226 :             if (ctype == NULL_TREE
   15753    196812226 :                 && decl_context == FIELD
   15754              :                 && funcdecl_p
   15755    113700417 :                 && friendp == 0)
   15756    106609139 :               ctype = current_class_type;
   15757              : 
   15758    196812226 :             if (ctype && (sfk == sfk_constructor
   15759    106609139 :                           || sfk == sfk_destructor))
   15760              :               {
   15761              :                 /* We are within a class's scope. If our declarator name
   15762              :                    is the same as the class name, and we are defining
   15763              :                    a function, then it is a constructor/destructor, and
   15764              :                    therefore returns a void type.  */
   15765              : 
   15766              :                 /* ISO C++ 12.4/2.  A destructor may not be declared
   15767              :                    const or volatile.  A destructor may not be static.
   15768              :                    A destructor may not be declared with ref-qualifier.
   15769              : 
   15770              :                    ISO C++ 12.1.  A constructor may not be declared
   15771              :                    const or volatile.  A constructor may not be
   15772              :                    virtual.  A constructor may not be static.
   15773              :                    A constructor may not be declared with ref-qualifier. */
   15774     27267450 :                 if (staticp == 2)
   15775            9 :                   error_at (declspecs->locations[ds_storage_class],
   15776              :                             (flags == DTOR_FLAG)
   15777              :                             ? G_("destructor cannot be static member "
   15778              :                                  "function")
   15779              :                             : G_("constructor cannot be static member "
   15780              :                                  "function"));
   15781     27267450 :                 if (memfn_quals)
   15782              :                   {
   15783            9 :                     error ((flags == DTOR_FLAG)
   15784              :                            ? G_("destructors may not be cv-qualified")
   15785              :                            : G_("constructors may not be cv-qualified"));
   15786            9 :                     memfn_quals = TYPE_UNQUALIFIED;
   15787              :                   }
   15788              : 
   15789     27267450 :                 if (rqual)
   15790              :                   {
   15791            6 :                     maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
   15792            6 :                     error ((flags == DTOR_FLAG)
   15793              :                            ? G_("destructors may not be ref-qualified")
   15794              :                            : G_("constructors may not be ref-qualified"));
   15795            6 :                     rqual = REF_QUAL_NONE;
   15796              :                   }
   15797              : 
   15798     27267450 :                 if (decl_context == FIELD
   15799     27267450 :                     && !member_function_or_else (ctype,
   15800              :                                                  current_class_type,
   15801              :                                                  flags))
   15802            0 :                   return error_mark_node;
   15803              : 
   15804     27267450 :                 if (flags != DTOR_FLAG)
   15805              :                   {
   15806              :                     /* It's a constructor.  */
   15807     24112283 :                     if (explicitp == 1)
   15808      5635449 :                       explicitp = 2;
   15809     24112283 :                     if (virtualp)
   15810              :                       {
   15811            3 :                         permerror (declspecs->locations[ds_virtual],
   15812              :                                    "constructors cannot be declared %<virtual%>");
   15813            3 :                         virtualp = 0;
   15814              :                       }
   15815     24112283 :                     if (decl_context == FIELD
   15816     24112283 :                         && sfk != sfk_constructor)
   15817            0 :                       return error_mark_node;
   15818              :                   }
   15819     27267450 :                 if (decl_context == FIELD)
   15820     27267450 :                   staticp = 0;
   15821              :               }
   15822    169544776 :             else if (friendp)
   15823              :               {
   15824      6769065 :                 if (virtualp)
   15825              :                   {
   15826              :                     /* Cannot be both friend and virtual.  */
   15827           12 :                     gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   15828           12 :                     richloc.add_range (declspecs->locations[ds_friend]);
   15829           12 :                     error_at (&richloc, "virtual functions cannot be friends");
   15830           12 :                     friendp = 0;
   15831           12 :                   }
   15832      6769065 :                 if (decl_context == NORMAL)
   15833            0 :                   error_at (declarator->id_loc,
   15834              :                             "friend declaration not in class definition");
   15835      6769065 :                 if (current_function_decl && funcdef_flag)
   15836              :                   {
   15837            9 :                     error_at (declarator->id_loc,
   15838              :                               "cannot define friend function %qs in a local "
   15839              :                               "class definition", name);
   15840            9 :                     friendp = 0;
   15841              :                   }
   15842              :                 /* [class.friend]/6: A function can be defined in a friend
   15843              :                    declaration if the function name is unqualified.  */
   15844      6769065 :                 if (funcdef_flag && in_namespace)
   15845              :                   {
   15846            6 :                     if (in_namespace == global_namespace)
   15847            3 :                       error_at (declarator->id_loc,
   15848              :                                 "friend function definition %qs cannot have "
   15849              :                                 "a name qualified with %<::%>", name);
   15850              :                     else
   15851            3 :                       error_at (declarator->id_loc,
   15852              :                                 "friend function definition %qs cannot have "
   15853              :                                 "a name qualified with %<%D::%>", name,
   15854              :                                 in_namespace);
   15855              :                   }
   15856              :               }
   15857    162775711 :             else if (ctype && sfk == sfk_conversion)
   15858              :               {
   15859      1050437 :                 if (explicitp == 1)
   15860              :                   {
   15861       491514 :                     maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
   15862       491514 :                     explicitp = 2;
   15863              :                   }
   15864              :               }
   15865    161725274 :             else if (sfk == sfk_deduction_guide)
   15866              :               {
   15867      1258638 :                 if (explicitp == 1)
   15868    196812226 :                   explicitp = 2;
   15869              :               }
   15870              : 
   15871    196812226 :             if (xobj_parm)
   15872              :               {
   15873        94984 :                 if (!ctype
   15874          110 :                     && (decl_context == NORMAL || friendp)
   15875          101 :                     && (in_namespace
   15876          101 :                         || !declarator->declarator->u.id.qualifying_scope))
   15877              :                   {
   15878           24 :                     error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15879              :                               "a non-member function cannot have "
   15880              :                               "an explicit object parameter");
   15881           24 :                     is_xobj_member_function = false;
   15882              :                   }
   15883              :                 else
   15884              :                   {
   15885        94960 :                     if (virtualp)
   15886              :                       {
   15887           24 :                         auto_diagnostic_group d;
   15888           24 :                         error_at (declspecs->locations[ds_virtual],
   15889              :                                   "an explicit object member function cannot "
   15890              :                                   "be %<virtual%>");
   15891           24 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   15892              :                                 "explicit object parameter declared here");
   15893           24 :                         virtualp = false;
   15894           24 :                       }
   15895        94960 :                     if (staticp >= 2)
   15896              :                       {
   15897            3 :                         auto_diagnostic_group d;
   15898            3 :                         error_at (declspecs->locations[ds_storage_class],
   15899              :                                   "an explicit object member function cannot "
   15900              :                                   "be %<static%>");
   15901            3 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   15902              :                                 "explicit object parameter declared here");
   15903            3 :                       }
   15904        94960 :                     if (unqualified_id
   15905    196907177 :                         && identifier_p (unqualified_id)
   15906       189911 :                         && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   15907           12 :                       error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15908              :                                 "%qD cannot be an explicit object member "
   15909              :                                 "function", unqualified_id);
   15910              :                   }
   15911              :               }
   15912    196812226 :             tree pushed_scope = NULL_TREE;
   15913    196812226 :             if (funcdecl_p
   15914    196812226 :                 && decl_context != FIELD
   15915     81154687 :                 && inner_declarator->u.id.qualifying_scope
   15916    206183006 :                 && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
   15917      9214940 :               pushed_scope
   15918      9214940 :                 = push_scope (inner_declarator->u.id.qualifying_scope);
   15919              : 
   15920    196812226 :             arg_types = grokparms (declarator->u.function.parameters, &parms);
   15921              : 
   15922    196812226 :             if (pushed_scope)
   15923      9214940 :               pop_scope (pushed_scope);
   15924              : 
   15925    196812226 :             if (inner_declarator
   15926    196422400 :                 && inner_declarator->kind == cdk_id
   15927    194532891 :                 && inner_declarator->u.id.sfk == sfk_destructor
   15928      3323926 :                 && arg_types != void_list_node)
   15929              :               {
   15930           21 :                 error_at (declarator->id_loc,
   15931              :                           "destructors may not have parameters");
   15932           21 :                 arg_types = void_list_node;
   15933           21 :                 parms = NULL_TREE;
   15934           21 :                 is_xobj_member_function = false;
   15935              :               }
   15936              : 
   15937    196812226 :             type = cp_build_function_type (type, arg_types);
   15938              : 
   15939    196812226 :             tree attrs = declarator->std_attributes;
   15940    196812226 :             if (tx_qual)
   15941              :               {
   15942          242 :                 tree att = build_tree_list (tx_qual, NULL_TREE);
   15943              :                 /* transaction_safe applies to the type, but
   15944              :                    transaction_safe_dynamic applies to the function.  */
   15945          242 :                 if (is_attribute_p ("transaction_safe", tx_qual))
   15946          213 :                   attrs = attr_chainon (attrs, att);
   15947              :                 else
   15948           29 :                   returned_attrs = attr_chainon (returned_attrs, att);
   15949              :               }
   15950              : 
   15951              :             /* Actually apply the contract specifiers to the declaration.  */
   15952    196812226 :             if (flag_contracts)
   15953     23392225 :               contract_specifiers
   15954              :                 = contract_specifiers_concat
   15955     23392225 :                     (contract_specifiers,
   15956     23392225 :                      declarator->u.function.contract_specifiers);
   15957              : 
   15958    196812226 :             if (attrs)
   15959              :               /* [dcl.fct]/2:
   15960              : 
   15961              :                  The optional attribute-specifier-seq appertains to
   15962              :                  the function type.  */
   15963          513 :               cplus_decl_attributes (&type, attrs, 0);
   15964              : 
   15965    196812226 :             if (raises)
   15966     78349399 :               type = build_exception_variant (type, raises);
   15967              :           }
   15968    196812226 :           break;
   15969              : 
   15970    199922190 :         case cdk_pointer:
   15971    199922190 :         case cdk_reference:
   15972    199922190 :         case cdk_ptrmem:
   15973              :           /* Filter out pointers-to-references and references-to-references.
   15974              :              We can get these if a TYPE_DECL is used.  */
   15975              : 
   15976    199922190 :           if (TYPE_REF_P (type))
   15977              :             {
   15978          240 :               if (declarator->kind != cdk_reference)
   15979              :                 {
   15980            3 :                   error ("cannot declare pointer to %q#T", type);
   15981            3 :                   type = TREE_TYPE (type);
   15982              :                 }
   15983              : 
   15984              :               /* In C++0x, we allow reference to reference declarations
   15985              :                  that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
   15986              :                  and template type arguments [14.3.1/4 temp.arg.type]. The
   15987              :                  check for direct reference to reference declarations, which
   15988              :                  are still forbidden, occurs below. Reasoning behind the change
   15989              :                  can be found in DR106, DR540, and the rvalue reference
   15990              :                  proposals. */
   15991          237 :               else if (cxx_dialect == cxx98)
   15992              :                 {
   15993            0 :                   error ("cannot declare reference to %q#T", type);
   15994            0 :                   type = TREE_TYPE (type);
   15995              :                 }
   15996              :             }
   15997    199921950 :           else if (VOID_TYPE_P (type))
   15998              :             {
   15999      5314537 :               if (declarator->kind == cdk_reference)
   16000            4 :                 error ("cannot declare reference to %q#T", type);
   16001      5314533 :               else if (declarator->kind == cdk_ptrmem)
   16002            3 :                 error ("cannot declare pointer to %q#T member", type);
   16003              :             }
   16004              : 
   16005              :           /* We now know that the TYPE_QUALS don't apply to the decl,
   16006              :              but to the target of the pointer.  */
   16007    199922190 :           type_quals = TYPE_UNQUALIFIED;
   16008              : 
   16009              :           /* This code used to handle METHOD_TYPE, but I don't think it's
   16010              :              possible to get it here anymore.  */
   16011    199922190 :           gcc_assert (TREE_CODE (type) != METHOD_TYPE);
   16012    199922190 :           if (declarator->kind == cdk_ptrmem
   16013      1141580 :               && TREE_CODE (type) == FUNCTION_TYPE)
   16014              :             {
   16015       923741 :               memfn_quals |= type_memfn_quals (type);
   16016       923741 :               if (rqual == REF_QUAL_NONE)
   16017       585821 :                 rqual = type_memfn_rqual (type);
   16018      1847482 :               type = build_memfn_type (type,
   16019       923741 :                                        declarator->u.pointer.class_type,
   16020              :                                        memfn_quals,
   16021              :                                        rqual);
   16022       923741 :               if (type == error_mark_node)
   16023              :                 return error_mark_node;
   16024              : 
   16025              :               rqual = REF_QUAL_NONE;
   16026              :               memfn_quals = TYPE_UNQUALIFIED;
   16027              :             }
   16028              : 
   16029    199922187 :           if (TREE_CODE (type) == FUNCTION_TYPE
   16030    199922187 :               && (type_memfn_quals (type) != TYPE_UNQUALIFIED
   16031      1040758 :                   || type_memfn_rqual (type) != REF_QUAL_NONE))
   16032           15 :             error (declarator->kind == cdk_reference
   16033              :                    ? G_("cannot declare reference to qualified function type %qT")
   16034              :                    : G_("cannot declare pointer to qualified function type %qT"),
   16035              :                    type);
   16036              : 
   16037              :           /* When the pointed-to type involves components of variable size,
   16038              :              care must be taken to ensure that the size evaluation code is
   16039              :              emitted early enough to dominate all the possible later uses
   16040              :              and late enough for the variables on which it depends to have
   16041              :              been assigned.
   16042              : 
   16043              :              This is expected to happen automatically when the pointed-to
   16044              :              type has a name/declaration of it's own, but special attention
   16045              :              is required if the type is anonymous.
   16046              : 
   16047              :              We handle the NORMAL and FIELD contexts here by inserting a
   16048              :              dummy statement that just evaluates the size at a safe point
   16049              :              and ensures it is not deferred until e.g. within a deeper
   16050              :              conditional context (c++/43555).
   16051              : 
   16052              :              We expect nothing to be needed here for PARM or TYPENAME.
   16053              :              Evaluating the size at this point for TYPENAME would
   16054              :              actually be incorrect, as we might be in the middle of an
   16055              :              expression with side effects on the pointed-to type size
   16056              :              "arguments" prior to the pointer declaration point and the
   16057              :              size evaluation could end up prior to the side effects.  */
   16058              : 
   16059    199922187 :           if (!TYPE_NAME (type)
   16060      5617743 :               && (decl_context == NORMAL || decl_context == FIELD)
   16061       627328 :               && at_function_scope_p ()
   16062    199962827 :               && variably_modified_type_p (type, NULL_TREE))
   16063              :             {
   16064          119 :               TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
   16065              :                                              NULL_TREE, type);
   16066          119 :               add_decl_expr (TYPE_NAME (type));
   16067              :             }
   16068              : 
   16069    199922187 :           if (declarator->kind == cdk_reference)
   16070              :             {
   16071              :               /* In C++0x, the type we are creating a reference to might be
   16072              :                  a typedef which is itself a reference type. In that case,
   16073              :                  we follow the reference collapsing rules in
   16074              :                  [7.1.3/8 dcl.typedef] to create the final reference type:
   16075              : 
   16076              :                  "If a typedef TD names a type that is a reference to a type
   16077              :                  T, an attempt to create the type 'lvalue reference to cv TD'
   16078              :                  creates the type 'lvalue reference to T,' while an attempt
   16079              :                  to create the type "rvalue reference to cv TD' creates the
   16080              :                  type TD."
   16081              :               */
   16082    134114172 :               if (VOID_TYPE_P (type))
   16083              :                 /* We already gave an error.  */;
   16084    134114168 :               else if (TYPE_REF_P (type))
   16085              :                 {
   16086          237 :                   if (declarator->u.reference.rvalue_ref)
   16087              :                     /* Leave type alone.  */;
   16088              :                   else
   16089          116 :                     type = cp_build_reference_type (TREE_TYPE (type), false);
   16090              :                 }
   16091              :               else
   16092    134113931 :                 type = cp_build_reference_type
   16093    134113931 :                   (type, declarator->u.reference.rvalue_ref);
   16094              : 
   16095              :               /* In C++0x, we need this check for direct reference to
   16096              :                  reference declarations, which are forbidden by
   16097              :                  [8.3.2/5 dcl.ref]. Reference to reference declarations
   16098              :                  are only allowed indirectly through typedefs and template
   16099              :                  type arguments. Example:
   16100              : 
   16101              :                    void foo(int & &);      // invalid ref-to-ref decl
   16102              : 
   16103              :                    typedef int & int_ref;
   16104              :                    void foo(int_ref &);    // valid ref-to-ref decl
   16105              :               */
   16106    134114172 :               if (inner_declarator && inner_declarator->kind == cdk_reference)
   16107            2 :                 error ("cannot declare reference to %q#T, which is not "
   16108              :                        "a typedef or a template type argument", type);
   16109              :             }
   16110     65808015 :           else if (TREE_CODE (type) == METHOD_TYPE)
   16111       923738 :             type = build_ptrmemfunc_type (build_pointer_type (type));
   16112     64884277 :           else if (declarator->kind == cdk_ptrmem)
   16113              :             {
   16114       217839 :               gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
   16115              :                           != NAMESPACE_DECL);
   16116       217839 :               if (declarator->u.pointer.class_type == error_mark_node)
   16117              :                 /* We will already have complained.  */
   16118            3 :                 type = error_mark_node;
   16119              :               else
   16120       217836 :                 type = build_ptrmem_type (declarator->u.pointer.class_type,
   16121              :                                           type);
   16122              :             }
   16123              :           else
   16124     64666438 :             type = build_pointer_type (type);
   16125              : 
   16126              :           /* Process a list of type modifier keywords (such as
   16127              :              const or volatile) that were given inside the `*' or `&'.  */
   16128              : 
   16129    199922187 :           if (declarator->u.pointer.qualifiers)
   16130              :             {
   16131      8729403 :               type
   16132      8729403 :                 = cp_build_qualified_type (type,
   16133              :                                            declarator->u.pointer.qualifiers);
   16134      8729403 :               type_quals = cp_type_quals (type);
   16135              :             }
   16136              : 
   16137              :           /* Apply C++11 attributes to the pointer, and not to the
   16138              :              type pointed to.  This is unlike what is done for GNU
   16139              :              attributes above.  It is to comply with [dcl.ptr]/1:
   16140              : 
   16141              :                  [the optional attribute-specifier-seq (7.6.1) appertains
   16142              :                   to the pointer and not to the object pointed to].  */
   16143    199922187 :           if (declarator->std_attributes)
   16144          189 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   16145              : 
   16146              :           ctype = NULL_TREE;
   16147              :           break;
   16148              : 
   16149              :         case cdk_error:
   16150              :           break;
   16151              : 
   16152            0 :         default:
   16153            0 :           gcc_unreachable ();
   16154              :         }
   16155              :     }
   16156              : 
   16157   1076016858 :   id_loc = declarator ? declarator->id_loc : input_location;
   16158              : 
   16159   1076016858 :   if (innermost_code != cdk_function
   16160              :     /* Don't check this if it can be the artificial decltype(auto)
   16161              :        we created when building a constraint in a compound-requirement:
   16162              :        that the type-constraint is plain is going to be checked in
   16163              :        cp_parser_compound_requirement.  */
   16164   1076016858 :       && decl_context != TYPENAME
   16165   1076016858 :       && check_decltype_auto (id_loc, type))
   16166           20 :     return error_mark_node;
   16167              : 
   16168              :   /* A `constexpr' specifier used in an object declaration declares
   16169              :      the object as `const'.  */
   16170   1076016838 :   if (constexpr_p && innermost_code != cdk_function)
   16171              :     {
   16172              :       /* DR1688 says that a `constexpr' specifier in combination with
   16173              :          `volatile' is valid.  */
   16174              : 
   16175     20665499 :       if (!TYPE_REF_P (type))
   16176              :         {
   16177     20653659 :           type_quals |= TYPE_QUAL_CONST;
   16178     20653659 :           type = cp_build_qualified_type (type, type_quals);
   16179              :         }
   16180              :     }
   16181              : 
   16182    605054696 :   if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
   16183      3158922 :       && !FUNC_OR_METHOD_TYPE_P (type)
   16184   1078203043 :       && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
   16185              :     {
   16186            0 :       error ("template-id %qD used as a declarator",
   16187              :              unqualified_id);
   16188            0 :       unqualified_id = dname;
   16189              :     }
   16190              : 
   16191              :   /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
   16192              :      qualified with a class-name, turn it into a METHOD_TYPE, unless
   16193              :      we know that the function is static.  We take advantage of this
   16194              :      opportunity to do other processing that pertains to entities
   16195              :      explicitly declared to be class members.  Note that if DECLARATOR
   16196              :      is non-NULL, we know it is a cdk_id declarator; otherwise, we
   16197              :      would not have exited the loop above.  */
   16198   1076016838 :   if (declarator
   16199    605300269 :       && declarator->kind == cdk_id
   16200    605054696 :       && declarator->u.id.qualifying_scope
   16201   1086170955 :       && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
   16202              :     {
   16203      9722287 :       ctype = declarator->u.id.qualifying_scope;
   16204      9722287 :       ctype = TYPE_MAIN_VARIANT (ctype);
   16205      9722287 :       template_count = num_template_headers_for_class (ctype);
   16206              : 
   16207      9722287 :       if (ctype == current_class_type)
   16208              :         {
   16209           54 :           if (friendp)
   16210              :             {
   16211           15 :               permerror (declspecs->locations[ds_friend],
   16212              :                          "member functions are implicitly "
   16213              :                          "friends of their class");
   16214           15 :               friendp = 0;
   16215              :             }
   16216              :           else
   16217           39 :             permerror (id_loc, "extra qualification %<%T::%> on member %qs",
   16218              :                        ctype, name);
   16219              :         }
   16220      9722233 :       else if (/* If the qualifying type is already complete, then we
   16221              :                   can skip the following checks.  */
   16222      9722233 :                !COMPLETE_TYPE_P (ctype)
   16223          154 :                && (/* If the function is being defined, then
   16224              :                       qualifying type must certainly be complete.  */
   16225              :                    funcdef_flag
   16226              :                    /* A friend declaration of "T::f" is OK, even if
   16227              :                       "T" is a template parameter.  But, if this
   16228              :                       function is not a friend, the qualifying type
   16229              :                       must be a class.  */
   16230          117 :                    || (!friendp && !CLASS_TYPE_P (ctype))
   16231              :                    /* For a declaration, the type need not be
   16232              :                       complete, if either it is dependent (since there
   16233              :                       is no meaningful definition of complete in that
   16234              :                       case) or the qualifying class is currently being
   16235              :                       defined.  */
   16236          129 :                    || !(dependent_type_p (ctype)
   16237           24 :                         || currently_open_class (ctype)))
   16238              :                /* Check that the qualifying type is complete.  */
   16239      9722297 :                && !complete_type_or_else (ctype, NULL_TREE))
   16240           64 :         return error_mark_node;
   16241      9722169 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   16242              :         {
   16243      9215202 :           if (current_class_type
   16244          289 :               && (!friendp || funcdef_flag || initialized))
   16245              :             {
   16246           57 :               error_at (id_loc, funcdef_flag || initialized
   16247              :                         ? G_("cannot define member function %<%T::%s%> "
   16248              :                              "within %qT")
   16249              :                         : G_("cannot declare member function %<%T::%s%> "
   16250              :                              "within %qT"),
   16251              :                         ctype, name, current_class_type);
   16252           48 :               return error_mark_node;
   16253              :             }
   16254              :         }
   16255       506967 :       else if (typedef_p && current_class_type)
   16256              :         {
   16257            0 :           error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
   16258              :                     ctype, name, current_class_type);
   16259            0 :           return error_mark_node;
   16260              :         }
   16261              :     }
   16262              : 
   16263   1076016726 :   if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
   16264     60074918 :     ctype = current_class_type;
   16265              : 
   16266              :   /* Now TYPE has the actual type.  */
   16267              : 
   16268   1076016726 :   if (returned_attrs)
   16269              :     {
   16270         2974 :       if (attrlist)
   16271         2974 :         *attrlist = attr_chainon (returned_attrs, *attrlist);
   16272              :       else
   16273              :         attrlist = &returned_attrs;
   16274              :     }
   16275              : 
   16276   1076016726 :   if (declarator
   16277    605300157 :       && declarator->kind == cdk_id
   16278    605054584 :       && declarator->std_attributes
   16279       593880 :       && attrlist != NULL)
   16280              :     {
   16281              :       /* [dcl.meaning]/1: The optional attribute-specifier-seq following
   16282              :          a declarator-id appertains to the entity that is declared.  */
   16283       593877 :       if (declarator->std_attributes != error_mark_node)
   16284              :         {
   16285       593859 :           if (flag_reflection
   16286              :               && declarator->std_attributes != error_mark_node
   16287        29366 :               && lookup_annotation (declarator->std_attributes)
   16288           40 :               && *attrlist != error_mark_node
   16289       593899 :               && lookup_annotation (*attrlist))
   16290              :             /* If there are annotations in both lists, ensure
   16291              :                declarator->std_attributes go after *attrlist.  See
   16292              :                PR124399.  */
   16293           14 :             *attrlist = chainon (copy_list (*attrlist),
   16294           14 :                                  declarator->std_attributes);
   16295              :           else
   16296       593845 :             *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
   16297              :         }
   16298              :       else
   16299              :         /* We should have already diagnosed the issue (c++/78344).  */
   16300           18 :         gcc_assert (seen_error ());
   16301              :     }
   16302              : 
   16303              :   /* Handle parameter packs. */
   16304   1076016726 :   if (parameter_pack_p)
   16305              :     {
   16306      3188841 :       if (decl_context == PARM)
   16307              :         /* Turn the type into a pack expansion.*/
   16308      3188841 :         type = make_pack_expansion (type);
   16309              :       else
   16310            0 :         error ("non-parameter %qs cannot be a parameter pack", name);
   16311              :     }
   16312              : 
   16313   1076016726 :   if ((decl_context == FIELD || decl_context == PARM)
   16314    477189824 :       && !processing_template_decl
   16315   1227892950 :       && variably_modified_type_p (type, NULL_TREE))
   16316              :     {
   16317           12 :       if (decl_context == FIELD)
   16318            6 :         error_at (id_loc,
   16319              :                   "data member may not have variably modified type %qT", type);
   16320              :       else
   16321            6 :         error_at (id_loc,
   16322              :                   "parameter may not have variably modified type %qT", type);
   16323           12 :       type = error_mark_node;
   16324              :     }
   16325              : 
   16326   1076016726 :   if (explicitp == 1 || (explicitp && friendp))
   16327              :     {
   16328              :       /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
   16329              :          in the declaration of a constructor or conversion function within
   16330              :          a class definition.  */
   16331           74 :       if (!current_class_type)
   16332           59 :         error_at (declspecs->locations[ds_explicit],
   16333              :                   "%<explicit%> outside class declaration");
   16334           15 :       else if (friendp)
   16335           12 :         error_at (declspecs->locations[ds_explicit],
   16336              :                   "%<explicit%> in friend declaration");
   16337              :       else
   16338            3 :         error_at (declspecs->locations[ds_explicit],
   16339              :                   "only declarations of constructors and conversion operators "
   16340              :                   "can be %<explicit%>");
   16341              :       explicitp = 0;
   16342              :     }
   16343              : 
   16344   1076016726 :   if (storage_class == sc_mutable)
   16345              :     {
   16346       138858 :       location_t sloc = declspecs->locations[ds_storage_class];
   16347       138858 :       if (decl_context != FIELD || friendp)
   16348              :         {
   16349           30 :           error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
   16350              :                     name);
   16351           30 :           storage_class = sc_none;
   16352              :         }
   16353       138828 :       else if (decl_context == TYPENAME || typedef_p)
   16354              :         {
   16355            0 :           error_at (sloc,
   16356              :                     "non-object member %qs cannot be declared %<mutable%>",
   16357              :                     name);
   16358            0 :           storage_class = sc_none;
   16359              :         }
   16360       138828 :       else if (FUNC_OR_METHOD_TYPE_P (type))
   16361              :         {
   16362            3 :           error_at (sloc, "function %qs cannot be declared %<mutable%>",
   16363              :                     name);
   16364            3 :           storage_class = sc_none;
   16365              :         }
   16366       138825 :       else if (staticp)
   16367              :         {
   16368            0 :           error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
   16369              :                     name);
   16370            0 :           storage_class = sc_none;
   16371              :         }
   16372       138825 :       else if (type_quals & TYPE_QUAL_CONST)
   16373              :         {
   16374            9 :           error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
   16375              :                     name);
   16376            9 :           storage_class = sc_none;
   16377              :         }
   16378       138816 :       else if (TYPE_REF_P (type))
   16379              :         {
   16380            6 :           permerror (sloc, "reference %qs cannot be declared %<mutable%>",
   16381              :                      name);
   16382            6 :           storage_class = sc_none;
   16383              :         }
   16384              :     }
   16385              : 
   16386              :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
   16387   1076016726 :   if (typedef_p && decl_context != TYPENAME)
   16388              :     {
   16389     48716788 :       bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
   16390     48716788 :       tree decl;
   16391              : 
   16392     48716788 :       if (funcdef_flag)
   16393              :         {
   16394            6 :           if (decl_context == NORMAL)
   16395            3 :             error_at (id_loc,
   16396              :                       "typedef may not be a function definition");
   16397              :           else
   16398            3 :             error_at (id_loc,
   16399              :                       "typedef may not be a member function definition");
   16400            6 :           return error_mark_node;
   16401              :         }
   16402              : 
   16403              :       /* This declaration:
   16404              : 
   16405              :            typedef void f(int) const;
   16406              : 
   16407              :          declares a function type which is not a member of any
   16408              :          particular class, but which is cv-qualified; for
   16409              :          example "f S::*" declares a pointer to a const-qualified
   16410              :          member function of S.  We record the cv-qualification in the
   16411              :          function type.  */
   16412     48716782 :       if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
   16413              :         {
   16414           62 :           type = apply_memfn_quals (type, memfn_quals, rqual);
   16415              : 
   16416              :           /* We have now dealt with these qualifiers.  */
   16417           62 :           memfn_quals = TYPE_UNQUALIFIED;
   16418           62 :           rqual = REF_QUAL_NONE;
   16419              :         }
   16420              : 
   16421     48716782 :       if (type_uses_auto (type))
   16422              :         {
   16423           62 :           if (alias_p)
   16424           20 :             error_at (declspecs->locations[ds_type_spec],
   16425              :                       "%<auto%> not allowed in alias declaration");
   16426              :           else
   16427           42 :             error_at (declspecs->locations[ds_type_spec],
   16428              :                       "typedef declared %<auto%>");
   16429           62 :           type = error_mark_node;
   16430              :         }
   16431              : 
   16432     48716782 :       if (reqs)
   16433            3 :         error_at (location_of (reqs), "requires-clause on typedef");
   16434              : 
   16435     48716782 :       if (id_declarator && declarator->u.id.qualifying_scope)
   16436              :         {
   16437           21 :           error_at (id_loc, "typedef name may not be a nested-name-specifier");
   16438           21 :           type = error_mark_node;
   16439              :         }
   16440              : 
   16441     48716782 :       if (decl_context == FIELD)
   16442     26133857 :         decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
   16443              :       else
   16444     22582925 :         decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
   16445              : 
   16446     48716782 :       if (decl_context != FIELD)
   16447              :         {
   16448     22582925 :           if (!current_function_decl)
   16449      9912166 :             DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   16450     12670759 :           else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
   16451              :             /* The TYPE_DECL is "abstract" because there will be
   16452              :                clones of this constructor/destructor, and there will
   16453              :                be copies of this TYPE_DECL generated in those
   16454              :                clones.  The decloning optimization (for space) may
   16455              :                revert this subsequently if it determines that
   16456              :                the clones should share a common implementation.  */
   16457       164641 :             DECL_ABSTRACT_P (decl) = true;
   16458              : 
   16459     22582925 :           set_originating_module (decl);
   16460              :         }
   16461     26133857 :       else if (current_class_type
   16462     26133857 :                && constructor_name_p (unqualified_id, current_class_type))
   16463            3 :         permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
   16464              :                    "as enclosing class",
   16465              :                    unqualified_id);
   16466              : 
   16467              :       /* If the user declares "typedef struct {...} foo" then the
   16468              :          struct will have an anonymous name.  Fill that name in now.
   16469              :          Nothing can refer to it, so nothing needs know about the name
   16470              :          change.  */
   16471     48716782 :       if (type != error_mark_node
   16472     48716699 :           && unqualified_id
   16473     48716696 :           && TYPE_NAME (type)
   16474     45290870 :           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   16475     90444262 :           && (TYPE_UNNAMED_P (type)
   16476              :               /* An enum may have previously used an enumerator for linkage
   16477              :                  purposes, but we want the typedef name to take priority.  */
   16478     44887884 :               || enum_with_enumerator_for_linkage_p (type))
   16479       403408 :           && declspecs->type_definition_p
   16480       403325 :           && attributes_naming_typedef_ok (*attrlist)
   16481     49120104 :           && cp_type_quals (type) == TYPE_UNQUALIFIED)
   16482       403304 :         name_unnamed_type (type, decl);
   16483              : 
   16484     48716782 :       if (signed_p
   16485     48716782 :           || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
   16486       384388 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
   16487              : 
   16488     48716782 :       bad_specifiers (decl, BSP_TYPE, virtualp,
   16489              :                       memfn_quals != TYPE_UNQUALIFIED,
   16490              :                       inlinep, friendp, raises != NULL_TREE,
   16491              :                       declspecs->locations);
   16492              : 
   16493     48716782 :       if (alias_p)
   16494              :         /* Acknowledge that this was written:
   16495              :              `using analias = atype;'.  */
   16496     22138218 :         TYPE_DECL_ALIAS_P (decl) = 1;
   16497              : 
   16498              :       /* We use a flag so that dependent_opaque_alias_p doesn't have to
   16499              :          recompute the answer every single time.  */
   16500     48716782 :       TYPE_DECL_OPAQUE_ALIAS_P (decl) = any_lambdas_p (type);
   16501              : 
   16502     48716782 :       return decl;
   16503              :     }
   16504              : 
   16505              :   /* Detect the case of an array type of unspecified size
   16506              :      which came, as such, direct from a typedef name.
   16507              :      We must copy the type, so that the array's domain can be
   16508              :      individually set by the object's initializer.  */
   16509              : 
   16510   1027299938 :   if (type && typedef_type
   16511    996743969 :       && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
   16512   1027907522 :       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
   16513           83 :     type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   16514              : 
   16515              :   /* Detect where we're using a typedef of function type to declare a
   16516              :      function. PARMS will not be set, so we must create it now.  */
   16517              : 
   16518   1027299938 :   if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
   16519              :     {
   16520        16070 :       tree decls = NULL_TREE;
   16521        16070 :       tree args;
   16522              : 
   16523        16070 :       for (args = TYPE_ARG_TYPES (type);
   16524        34605 :            args && args != void_list_node;
   16525        18535 :            args = TREE_CHAIN (args))
   16526              :         {
   16527        18535 :           tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
   16528        18535 :                                           TREE_VALUE (args));
   16529              : 
   16530        18535 :           DECL_CHAIN (decl) = decls;
   16531        18535 :           decls = decl;
   16532              :         }
   16533              : 
   16534        16070 :       parms = nreverse (decls);
   16535              : 
   16536        16070 :       if (decl_context != TYPENAME)
   16537              :         {
   16538              :           /* The qualifiers on the function type become the qualifiers on
   16539              :              the non-static member function. */
   16540        15286 :           memfn_quals |= type_memfn_quals (type);
   16541        15286 :           rqual = type_memfn_rqual (type);
   16542        15286 :           type_quals = TYPE_UNQUALIFIED;
   16543        15286 :           raises = TYPE_RAISES_EXCEPTIONS (type);
   16544              :         }
   16545              :     }
   16546              : 
   16547              :   /* If this is a type name (such as, in a cast or sizeof),
   16548              :      compute the type and return it now.  */
   16549              : 
   16550   1027299154 :   if (decl_context == TYPENAME)
   16551              :     {
   16552              :       /* Note that here we don't care about type_quals.  */
   16553              : 
   16554              :       /* Special case: "friend class foo" looks like a TYPENAME context.  */
   16555    424133808 :       if (friendp)
   16556              :         {
   16557            0 :           if (inlinep)
   16558              :             {
   16559            0 :               error ("%<inline%> specified for friend class declaration");
   16560            0 :               inlinep = 0;
   16561              :             }
   16562              : 
   16563            0 :           if (!current_aggr)
   16564              :             {
   16565              :               /* Don't allow friend declaration without a class-key.  */
   16566            0 :               if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   16567            0 :                 permerror (input_location, "template parameters cannot be friends");
   16568            0 :               else if (TREE_CODE (type) == TYPENAME_TYPE)
   16569            0 :                 permerror (input_location, "friend declaration requires class-key, "
   16570              :                            "i.e. %<friend class %T::%D%>",
   16571            0 :                            TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
   16572              :               else
   16573            0 :                 permerror (input_location, "friend declaration requires class-key, "
   16574              :                            "i.e. %<friend %#T%>",
   16575              :                            type);
   16576              :             }
   16577              : 
   16578              :           /* Only try to do this stuff if we didn't already give up.  */
   16579            0 :           if (type != integer_type_node)
   16580              :             {
   16581              :               /* A friendly class?  */
   16582            0 :               if (current_class_type)
   16583            0 :                 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
   16584              :                                    /*complain=*/true);
   16585              :               else
   16586            0 :                 error ("trying to make class %qT a friend of global scope",
   16587              :                        type);
   16588              : 
   16589            0 :               type = void_type_node;
   16590              :             }
   16591              :         }
   16592    424133808 :       else if (memfn_quals || rqual)
   16593              :         {
   16594        14145 :           if (ctype == NULL_TREE
   16595        14145 :               && TREE_CODE (type) == METHOD_TYPE)
   16596            0 :             ctype = TYPE_METHOD_BASETYPE (type);
   16597              : 
   16598        14145 :           if (ctype)
   16599            0 :             type = build_memfn_type (type, ctype, memfn_quals, rqual);
   16600              :           /* Core issue #547: need to allow this in template type args.
   16601              :              Allow it in general in C++11 for alias-declarations.  */
   16602        14145 :           else if ((template_type_arg || cxx_dialect >= cxx11)
   16603        14143 :                    && TREE_CODE (type) == FUNCTION_TYPE)
   16604        14141 :             type = apply_memfn_quals (type, memfn_quals, rqual);
   16605              :           else
   16606            4 :             error ("invalid qualifiers on non-member function type");
   16607              :         }
   16608              : 
   16609    424133808 :       if (reqs)
   16610            3 :         error_at (location_of (reqs), "requires-clause on type-id");
   16611              : 
   16612    424133808 :       return type;
   16613              :     }
   16614    603166130 :   else if (unqualified_id == NULL_TREE && decl_context != PARM
   16615       862248 :            && decl_context != CATCHPARM
   16616       379840 :            && TREE_CODE (type) != UNION_TYPE
   16617       379457 :            && ! bitfield
   16618       379457 :            && innermost_code != cdk_decomp)
   16619              :     {
   16620            9 :       error ("abstract declarator %qT used as declaration", type);
   16621            9 :       return error_mark_node;
   16622              :     }
   16623              : 
   16624    603166121 :   if (!FUNC_OR_METHOD_TYPE_P (type))
   16625              :     {
   16626              :       /* Only functions may be declared using an operator-function-id.  */
   16627    408673786 :       if (dname && IDENTIFIER_ANY_OP_P (dname))
   16628              :         {
   16629            8 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   16630            8 :           return error_mark_node;
   16631              :         }
   16632              : 
   16633    408673778 :       if (reqs)
   16634           15 :         error_at (location_of (reqs),
   16635              :                   "requires-clause on declaration of non-function type %qT",
   16636              :                   type);
   16637              :     }
   16638              : 
   16639              :   /* We don't check parameter types here because we can emit a better
   16640              :      error message later.  */
   16641    603166113 :   if (decl_context != PARM)
   16642              :     {
   16643    299429369 :       type = check_var_type (unqualified_id, type, id_loc);
   16644    299429369 :       if (type == error_mark_node)
   16645              :         return error_mark_node;
   16646              :     }
   16647              : 
   16648              :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
   16649              :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
   16650              : 
   16651    603166029 :   if (decl_context == PARM || decl_context == CATCHPARM)
   16652              :     {
   16653    304233758 :       if (ctype || in_namespace)
   16654            0 :         error ("cannot use %<::%> in parameter declaration");
   16655              : 
   16656    304233758 :       tree auto_node = type_uses_auto (type);
   16657    304233758 :       if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
   16658              :         {
   16659          129 :           bool err_p = true;
   16660          129 :           if (cxx_dialect >= cxx14)
   16661              :             {
   16662          230 :               if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
   16663            3 :                 error_at (typespec_loc,
   16664              :                           "cannot declare a parameter with %<decltype(auto)%>");
   16665          118 :               else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   16666              :                 {
   16667           10 :                   auto_diagnostic_group g;
   16668           10 :                   gcc_rich_location richloc (typespec_loc);
   16669           10 :                   richloc.add_fixit_insert_after ("<>");
   16670           10 :                   error_at (&richloc,
   16671              :                             "missing template argument list after %qE; template "
   16672              :                             "placeholder not permitted in parameter", c);
   16673           10 :                   if (decl_context == PARM && cxx_dialect >= cxx20)
   16674            8 :                     inform (typespec_loc, "or use %<auto%> for an "
   16675              :                             "abbreviated function template");
   16676           10 :                   inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
   16677           10 :                 }
   16678          108 :               else if (decl_context == CATCHPARM || template_parm_flag)
   16679           14 :                 error_at (typespec_loc,
   16680              :                           "%<auto%> parameter not permitted in this context");
   16681              :               else
   16682              :                 /* Do not issue an error while tentatively parsing a function
   16683              :                    parameter: for T t(auto(a), 42);, when we just saw the 1st
   16684              :                    parameter, we don't know yet that this construct won't be
   16685              :                    a function declaration.  Defer the checking to
   16686              :                    cp_parser_parameter_declaration_clause.  */
   16687              :                 err_p = false;
   16688              :             }
   16689              :           else
   16690            8 :             error_at (typespec_loc, "parameter declared %<auto%>");
   16691           35 :           if (err_p)
   16692           35 :             type = error_mark_node;
   16693              :         }
   16694              : 
   16695              :       /* A parameter declared as an array of T is really a pointer to T.
   16696              :          One declared as a function is really a pointer to a function.
   16697              :          One declared as a member is really a pointer to member.  */
   16698              : 
   16699    304233758 :       if (TREE_CODE (type) == ARRAY_TYPE)
   16700              :         {
   16701              :           /* Transfer const-ness of array into that of type pointed to.  */
   16702       783117 :           type = build_pointer_type (TREE_TYPE (type));
   16703       783117 :           type_quals = TYPE_UNQUALIFIED;
   16704       783117 :           array_parameter_p = true;
   16705              :         }
   16706    303450641 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   16707       102938 :         type = build_pointer_type (type);
   16708              :     }
   16709              : 
   16710    150272279 :   if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
   16711              :       /* Don't convert xobj member functions to METHOD_TYPE.  */
   16712    115824116 :       && !is_xobj_member_function
   16713    708181751 :       && !(unqualified_id
   16714    210022368 :            && identifier_p (unqualified_id)
   16715    105015322 :            && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
   16716              :     {
   16717    105007046 :       cp_cv_quals real_quals = memfn_quals;
   16718    105007046 :       if (cxx_dialect < cxx14 && constexpr_p
   16719       647007 :           && sfk != sfk_constructor && sfk != sfk_destructor)
   16720         3743 :         real_quals |= TYPE_QUAL_CONST;
   16721    105007046 :       type = build_memfn_type (type, ctype, real_quals, rqual);
   16722              :     }
   16723              : 
   16724    603166029 :   {
   16725    603166029 :     tree decl = NULL_TREE;
   16726              : 
   16727    603166029 :     if (decl_context == PARM)
   16728              :       {
   16729    303736744 :         decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
   16730    303736744 :         DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
   16731              : 
   16732    303736744 :         bad_specifiers (decl, BSP_PARM, virtualp,
   16733              :                         memfn_quals != TYPE_UNQUALIFIED,
   16734              :                         inlinep, friendp, raises != NULL_TREE,
   16735              :                         declspecs->locations);
   16736              :       }
   16737    299429285 :     else if (decl_context == FIELD)
   16738              :       {
   16739    147319208 :         if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
   16740     20495738 :           if (tree auto_node = type_uses_auto (type))
   16741              :             {
   16742           24 :               location_t tloc = declspecs->locations[ds_type_spec];
   16743           24 :               if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   16744            6 :                 error_at (tloc, "invalid use of template-name %qE without an "
   16745              :                           "argument list",
   16746            6 :                           CLASS_PLACEHOLDER_TEMPLATE (auto_node));
   16747              :               else
   16748           18 :                 error_at (tloc, "non-static data member declared with "
   16749              :                           "placeholder %qT", auto_node);
   16750           24 :               type = error_mark_node;
   16751              :             }
   16752              : 
   16753              :         /* The C99 flexible array extension.  */
   16754    123160280 :         if (!staticp && TREE_CODE (type) == ARRAY_TYPE
   16755    148451346 :             && TYPE_DOMAIN (type) == NULL_TREE)
   16756              :           {
   16757         1401 :             if (ctype
   16758         1401 :                 && (TREE_CODE (ctype) == UNION_TYPE
   16759         1401 :                     || TREE_CODE (ctype) == QUAL_UNION_TYPE))
   16760           84 :               pedwarn (id_loc, OPT_Wpedantic,
   16761              :                        "flexible array member in union is a GCC extension");
   16762              : 
   16763              :             else
   16764              :               {
   16765              :                 /* Array is a flexible member.  */
   16766         1317 :                 if (name)
   16767         1317 :                   pedwarn (id_loc, OPT_Wpedantic,
   16768              :                            "ISO C++ forbids flexible array member %qs", name);
   16769              :                 else
   16770              :                   pedwarn (input_location, OPT_Wpedantic,
   16771              :                            "ISO C++ forbids flexible array members");
   16772              : 
   16773              :                 /* Flexible array member has a null domain.  */
   16774         1317 :                 type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   16775              :               }
   16776              :           }
   16777              : 
   16778    147319208 :         if (type == error_mark_node)
   16779              :           {
   16780              :             /* Happens when declaring arrays of sizes which
   16781              :                are error_mark_node, for example.  */
   16782           24 :             decl = NULL_TREE;
   16783              :           }
   16784    147319184 :         else if (in_namespace && !friendp)
   16785              :           {
   16786              :             /* Something like struct S { int N::j; };  */
   16787            6 :             error_at (id_loc, "invalid use of %<::%>");
   16788            6 :             return error_mark_node;
   16789              :           }
   16790    147319178 :         else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
   16791              :           {
   16792    113377970 :             int publicp = 0;
   16793    113377970 :             tree function_context;
   16794              : 
   16795    113377970 :             if (friendp == 0)
   16796              :               {
   16797              :                 /* This should never happen in pure C++ (the check
   16798              :                    could be an assert).  It could happen in
   16799              :                    Objective-C++ if someone writes invalid code that
   16800              :                    uses a function declaration for an instance
   16801              :                    variable or property (instance variables and
   16802              :                    properties are parsed as FIELD_DECLs, but they are
   16803              :                    part of an Objective-C class, not a C++ class).
   16804              :                    That code is invalid and is caught by this
   16805              :                    check.  */
   16806    106608962 :                 if (!ctype)
   16807              :                   {
   16808            0 :                     error ("declaration of function %qD in invalid context",
   16809              :                            unqualified_id);
   16810            0 :                     return error_mark_node;
   16811              :                   }
   16812              : 
   16813              :                 /* ``A union may [ ... ] not [ have ] virtual functions.''
   16814              :                    ARM 9.5 */
   16815    106608962 :                 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
   16816              :                   {
   16817            3 :                     error_at (declspecs->locations[ds_virtual],
   16818              :                               "function %qD declared %<virtual%> inside a union",
   16819              :                               unqualified_id);
   16820            3 :                     return error_mark_node;
   16821              :                   }
   16822              : 
   16823      4187857 :                 if (virtualp
   16824    117565824 :                     && identifier_p (unqualified_id)
   16825      4187857 :                     && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   16826              :                   {
   16827            9 :                     error_at (declspecs->locations[ds_virtual],
   16828              :                               "%qD cannot be declared %<virtual%>, since it "
   16829              :                               "is always static", unqualified_id);
   16830            9 :                     virtualp = 0;
   16831              :                   }
   16832              :               }
   16833              : 
   16834              :             /* Check that the name used for a destructor makes sense.  */
   16835    113377967 :             if (sfk == sfk_destructor)
   16836              :               {
   16837      3155203 :                 tree uqname = id_declarator->u.id.unqualified_name;
   16838              : 
   16839      3155203 :                 if (!ctype)
   16840              :                   {
   16841           12 :                     gcc_assert (friendp);
   16842           12 :                     error_at (id_loc, "expected qualified name in friend "
   16843              :                               "declaration for destructor %qD", uqname);
   16844           12 :                     return error_mark_node;
   16845              :                   }
   16846              : 
   16847      3155191 :                 if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
   16848              :                   {
   16849            9 :                     error_at (id_loc, "declaration of %qD as member of %qT",
   16850              :                               uqname, ctype);
   16851            9 :                     return error_mark_node;
   16852              :                   }
   16853      3155182 :                 if (concept_p)
   16854              :                   {
   16855            9 :                     error_at (declspecs->locations[ds_concept],
   16856              :                               "a destructor cannot be %qs", "concept");
   16857            9 :                     return error_mark_node;
   16858              :                   }
   16859      3155173 :                 if (constexpr_p && cxx_dialect < cxx20)
   16860              :                   {
   16861            6 :                     error_at (declspecs->locations[ds_constexpr],
   16862              :                               "%<constexpr%> destructors only available"
   16863              :                               " with %<-std=c++20%> or %<-std=gnu++20%>");
   16864            6 :                     return error_mark_node;
   16865              :                   }
   16866      3155167 :                 if (consteval_p)
   16867              :                   {
   16868            3 :                     error_at (declspecs->locations[ds_consteval],
   16869              :                               "a destructor cannot be %qs", "consteval");
   16870            3 :                     return error_mark_node;
   16871              :                   }
   16872              :               }
   16873    110222764 :             else if (sfk == sfk_constructor && friendp && !ctype)
   16874              :               {
   16875            0 :                 error ("expected qualified name in friend declaration "
   16876              :                        "for constructor %qD",
   16877            0 :                        id_declarator->u.id.unqualified_name);
   16878            0 :                 return error_mark_node;
   16879              :               }
   16880    113377928 :             if (sfk == sfk_constructor)
   16881     24112307 :               if (concept_p)
   16882              :                 {
   16883            9 :                   error_at (declspecs->locations[ds_concept],
   16884              :                             "a constructor cannot be %<concept%>");
   16885            9 :                   return error_mark_node;
   16886              :                 }
   16887     89265621 :             if (concept_p)
   16888              :               {
   16889            9 :                 error_at (declspecs->locations[ds_concept],
   16890              :                           "a concept cannot be a member function");
   16891            9 :                 concept_p = false;
   16892              :               }
   16893    113377910 :             else if (consteval_p
   16894    114172930 :                      && identifier_p (unqualified_id)
   16895    114172921 :                      && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   16896              :               {
   16897            9 :                 error_at (declspecs->locations[ds_consteval],
   16898              :                           "%qD cannot be %qs", unqualified_id, "consteval");
   16899            9 :                 consteval_p = false;
   16900              :               }
   16901              : 
   16902    113377919 :             if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   16903              :               {
   16904       109743 :                 tree tmpl = TREE_OPERAND (unqualified_id, 0);
   16905       109743 :                 if (variable_template_p (tmpl))
   16906              :                   {
   16907            3 :                     auto_diagnostic_group d;
   16908            3 :                     error_at (id_loc, "specialization of variable template "
   16909              :                               "%qD declared as function", tmpl);
   16910            3 :                     inform (DECL_SOURCE_LOCATION (tmpl),
   16911              :                             "variable template declared here");
   16912            3 :                     return error_mark_node;
   16913            3 :                   }
   16914              :               }
   16915              : 
   16916              :             /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
   16917    113377916 :             function_context
   16918              :               = (ctype != NULL_TREE
   16919    113377916 :                  ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
   16920    226755832 :             publicp = ((! friendp || ! staticp)
   16921    113377916 :                        && function_context == NULL_TREE);
   16922              : 
   16923    113377916 :             decl = grokfndecl (ctype, type,
   16924    113377916 :                                TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
   16925              :                                ? unqualified_id : dname,
   16926              :                                parms,
   16927              :                                unqualified_id,
   16928              :                                declspecs,
   16929              :                                reqs,
   16930              :                                virtualp, flags, memfn_quals, rqual, raises,
   16931              :                                friendp ? -1 : 0, friendp, publicp,
   16932    113377916 :                                inlinep | (2 * constexpr_p) | (4 * concept_p)
   16933    113377916 :                                        | (8 * consteval_p),
   16934              :                                initialized,
   16935              :                                is_xobj_member_function, sfk,
   16936              :                                funcdef_flag, late_return_type_p,
   16937              :                                template_count, in_namespace,
   16938              :                                attrlist, contract_specifiers, id_loc);
   16939    113377916 :             decl = set_virt_specifiers (decl, virt_specifiers);
   16940    113377916 :             if (decl == NULL_TREE)
   16941           97 :               return error_mark_node;
   16942              : #if 0
   16943              :             /* This clobbers the attrs stored in `decl' from `attrlist'.  */
   16944              :             /* The decl and setting of decl_attr is also turned off.  */
   16945              :             decl = build_decl_attribute_variant (decl, decl_attr);
   16946              : #endif
   16947              : 
   16948              :             /* [class.conv.ctor]
   16949              : 
   16950              :                A constructor declared without the function-specifier
   16951              :                explicit that can be called with a single parameter
   16952              :                specifies a conversion from the type of its first
   16953              :                parameter to the type of its class.  Such a constructor
   16954              :                is called a converting constructor.  */
   16955    113377819 :             if (explicitp == 2)
   16956      6126963 :               DECL_NONCONVERTING_P (decl) = 1;
   16957              : 
   16958    113377819 :             if (declspecs->explicit_specifier)
   16959       447483 :               store_explicit_specifier (decl, declspecs->explicit_specifier);
   16960              :           }
   16961     33941208 :         else if (!staticp
   16962     33941208 :                  && ((current_class_type
   16963     20495729 :                       && same_type_p (TYPE_MAIN_VARIANT (type),
   16964              :                                       current_class_type))
   16965     20495633 :                      || (!dependent_type_p (type)
   16966     12344741 :                          && !COMPLETE_TYPE_P (complete_type (type))
   16967         1449 :                          && (!complete_or_array_type_p (type)
   16968         1374 :                              || initialized == SD_UNINITIALIZED))))
   16969              :           {
   16970         1512 :             if (TREE_CODE (type) != ARRAY_TYPE
   16971         1512 :                 || !COMPLETE_TYPE_P (TREE_TYPE (type)))
   16972              :               {
   16973          171 :                 if (unqualified_id)
   16974              :                   {
   16975          126 :                     auto_diagnostic_group d;
   16976          126 :                     error_at (id_loc, "field %qD has incomplete type %qT",
   16977              :                               unqualified_id, type);
   16978          126 :                     cxx_incomplete_type_inform (strip_array_types (type));
   16979          126 :                   }
   16980              :                 else
   16981           45 :                   error ("name %qT has incomplete type", type);
   16982              : 
   16983          171 :                 type = error_mark_node;
   16984          171 :                 decl = NULL_TREE;
   16985              :               }
   16986              :           }
   16987     54433901 :         else if (!verify_type_context (input_location,
   16988              :                                        staticp
   16989              :                                        ? TCTX_STATIC_STORAGE
   16990              :                                        : TCTX_FIELD, type))
   16991              :           {
   16992            0 :             type = error_mark_node;
   16993            0 :             decl = NULL_TREE;
   16994              :           }
   16995              :         else
   16996              :           {
   16997     33939690 :             if (friendp)
   16998              :               {
   16999           12 :                 if (unqualified_id)
   17000            9 :                   error_at (id_loc,
   17001              :                             "%qE is neither function nor member function; "
   17002              :                             "cannot be declared friend", unqualified_id);
   17003              :                 else
   17004            3 :                   error ("unnamed field is neither function nor member "
   17005              :                          "function; cannot be declared friend");
   17006           12 :                 return error_mark_node;
   17007              :               }
   17008     33939678 :             decl = NULL_TREE;
   17009              :           }
   17010              : 
   17011    147319033 :         if (friendp)
   17012              :           {
   17013      6768977 :             if (flag_reflection && !funcdef_flag && decl)
   17014              :               {
   17015        17286 :                 if (attrlist && lookup_annotation (*attrlist))
   17016              :                   {
   17017              :                     /* Remove the annotations to avoid spurious warning
   17018              :                        below.  */
   17019            8 :                     *attrlist = remove_attribute ("internal ", "annotation ",
   17020              :                                                   *attrlist);
   17021            8 :                     error_at (id_loc, "annotation applied to non-defining "
   17022              :                                       "friend declaration %qD", decl);
   17023              :                   }
   17024        17286 :                 for (tree arg = DECL_ARGUMENTS (decl);
   17025        40343 :                      arg; arg = DECL_CHAIN (arg))
   17026        23057 :                   if (lookup_annotation (DECL_ATTRIBUTES (arg)))
   17027            8 :                     error_at (DECL_SOURCE_LOCATION (arg),
   17028              :                               "annotation applied to parameter %qD of "
   17029              :                               "non-defining friend declaration", arg);
   17030              :               }
   17031              :             /* Packages tend to use GNU attributes on friends, so we only
   17032              :                warn for standard attributes.  */
   17033      6768977 :             if (attrlist
   17034      6768977 :                 && !funcdef_flag
   17035      6768977 :                 && cxx11_attribute_p (*attrlist))
   17036              :               {
   17037           27 :                 *attrlist = NULL_TREE;
   17038           27 :                 auto_diagnostic_group d;
   17039           27 :                 if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
   17040           27 :                   inform (id_loc, "an attribute that appertains to a friend "
   17041              :                           "declaration that is not a definition is ignored");
   17042           27 :               }
   17043              :             /* Friends are treated specially.  */
   17044      6768977 :             if (ctype == current_class_type)
   17045              :               ;  /* We already issued a permerror.  */
   17046      6768977 :             else if (decl && DECL_NAME (decl))
   17047              :               {
   17048      6768974 :                 set_originating_module (decl, true);
   17049              : 
   17050      6768974 :                 if (initialized)
   17051              :                   /* Kludge: We need funcdef_flag to be true in do_friend for
   17052              :                      in-class defaulted functions, but that breaks grokfndecl.
   17053              :                      So set it here.  */
   17054       218597 :                   funcdef_flag = true;
   17055              : 
   17056      6768974 :                 cplus_decl_attributes (&decl, *attrlist, 0);
   17057      6768974 :                 *attrlist = NULL_TREE;
   17058              : 
   17059      6768974 :                 tree scope = ctype ? ctype : in_namespace;
   17060      6768974 :                 decl = do_friend (scope, unqualified_id, decl,
   17061              :                                   flags, funcdef_flag);
   17062      6768974 :                 return decl;
   17063              :               }
   17064              :             else
   17065            3 :               return error_mark_node;
   17066              :           }
   17067              : 
   17068              :         /* Structure field.  It may not be a function, except for C++.  */
   17069              : 
   17070    140550056 :         if (decl == NULL_TREE)
   17071              :           {
   17072     33941211 :             if (staticp)
   17073              :               {
   17074              :                 /* C++ allows static class members.  All other work
   17075              :                    for this is done by grokfield.  */
   17076     13445479 :                 decl = build_lang_decl_loc (id_loc, VAR_DECL,
   17077              :                                             dname, type);
   17078     13445479 :                 if (unqualified_id
   17079     13445476 :                     && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   17080              :                   {
   17081        44262 :                     decl = check_explicit_specialization (unqualified_id, decl,
   17082              :                                                           template_count,
   17083              :                                                           concept_p * 8);
   17084        44262 :                     if (decl == error_mark_node)
   17085              :                       return error_mark_node;
   17086              :                   }
   17087     13445479 :                 set_linkage_for_static_data_member (decl);
   17088     13445479 :                 if (concept_p)
   17089           15 :                   error_at (declspecs->locations[ds_concept],
   17090              :                             "static data member %qE declared %qs",
   17091              :                             unqualified_id, "concept");
   17092     13445464 :                 else if (constexpr_p && !initialized)
   17093              :                   {
   17094            9 :                     error_at (DECL_SOURCE_LOCATION (decl),
   17095              :                               "%<constexpr%> static data member %qD must "
   17096              :                               "have an initializer", decl);
   17097            9 :                     constexpr_p = false;
   17098              :                   }
   17099     13445479 :                 if (consteval_p)
   17100            3 :                   error_at (declspecs->locations[ds_consteval],
   17101              :                             "static data member %qE declared %qs",
   17102              :                             unqualified_id, "consteval");
   17103              : 
   17104     13445479 :                 if (inlinep)
   17105        24284 :                   mark_inline_variable (decl, declspecs->locations[ds_inline]);
   17106              : 
   17107     13445479 :                 if (!DECL_VAR_DECLARED_INLINE_P (decl)
   17108     13445479 :                     && !(cxx_dialect >= cxx17 && constexpr_p))
   17109              :                   /* Even if there is an in-class initialization, DECL
   17110              :                      is considered undefined until an out-of-class
   17111              :                      definition is provided, unless this is an inline
   17112              :                      variable.  */
   17113      1863727 :                   DECL_EXTERNAL (decl) = 1;
   17114              : 
   17115     13445479 :                 if (thread_p)
   17116              :                   {
   17117          422 :                     CP_DECL_THREAD_LOCAL_P (decl) = true;
   17118          422 :                     if (!processing_template_decl)
   17119          376 :                       set_decl_tls_model (decl, decl_default_tls_model (decl));
   17120          422 :                     if (declspecs->gnu_thread_keyword_p)
   17121           34 :                       SET_DECL_GNU_TLS_P (decl);
   17122              :                   }
   17123              : 
   17124              :                 /* Set the constraints on the declaration.  */
   17125     13445479 :                 bool memtmpl = (current_template_depth
   17126     13445479 :                                 > template_class_depth (current_class_type));
   17127     13445479 :                 if (memtmpl)
   17128              :                   {
   17129       394411 :                     tree ci = current_template_constraints ();
   17130       394411 :                     set_constraints (decl, ci);
   17131              :                   }
   17132              :               }
   17133              :             else
   17134              :               {
   17135     20495732 :                 if (concept_p)
   17136              :                   {
   17137           12 :                     error_at (declspecs->locations[ds_concept],
   17138              :                               "non-static data member %qE declared %qs",
   17139              :                               unqualified_id, "concept");
   17140           12 :                     concept_p = false;
   17141           12 :                     constexpr_p = false;
   17142              :                   }
   17143     20495720 :                 else if (constexpr_p)
   17144              :                   {
   17145            9 :                     error_at (declspecs->locations[ds_constexpr],
   17146              :                               "non-static data member %qE declared %qs",
   17147              :                               unqualified_id, "constexpr");
   17148            9 :                     constexpr_p = false;
   17149              :                   }
   17150     20495732 :                 if (constinit_p)
   17151              :                   {
   17152            6 :                     error_at (declspecs->locations[ds_constinit],
   17153              :                               "non-static data member %qE declared %qs",
   17154              :                               unqualified_id, "constinit");
   17155            6 :                     constinit_p = false;
   17156              :                   }
   17157     20495732 :                 if (consteval_p)
   17158              :                   {
   17159            3 :                     error_at (declspecs->locations[ds_consteval],
   17160              :                               "non-static data member %qE declared %qs",
   17161              :                               unqualified_id, "consteval");
   17162            3 :                     consteval_p = false;
   17163              :                   }
   17164     20495732 :                 decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
   17165     20495732 :                 DECL_NONADDRESSABLE_P (decl) = bitfield;
   17166     20495732 :                 if (bitfield && !unqualified_id)
   17167       133866 :                   DECL_PADDING_P (decl) = 1;
   17168              : 
   17169     20495732 :                 if (storage_class == sc_mutable)
   17170              :                   {
   17171       138810 :                     DECL_MUTABLE_P (decl) = 1;
   17172       138810 :                     storage_class = sc_none;
   17173              :                   }
   17174              : 
   17175     20495732 :                 if (initialized)
   17176              :                   {
   17177              :                     /* An attempt is being made to initialize a non-static
   17178              :                        member.  This is new in C++11.  */
   17179      2399560 :                     maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
   17180              : 
   17181              :                     /* If this has been parsed with static storage class, but
   17182              :                        errors forced staticp to be cleared, ensure NSDMI is
   17183              :                        not present.  */
   17184      2399560 :                     if (declspecs->storage_class == sc_static)
   17185            3 :                       DECL_INITIAL (decl) = error_mark_node;
   17186              :                   }
   17187              :               }
   17188              : 
   17189     54436943 :             bad_specifiers (decl, BSP_FIELD, virtualp,
   17190              :                             memfn_quals != TYPE_UNQUALIFIED,
   17191              :                             staticp ? false : inlinep, friendp,
   17192              :                             raises != NULL_TREE,
   17193              :                             declspecs->locations);
   17194              :           }
   17195              :       }
   17196    152110077 :     else if (FUNC_OR_METHOD_TYPE_P (type))
   17197              :       {
   17198     81011421 :         tree original_name;
   17199     81011421 :         int publicp = 0;
   17200              : 
   17201     81011421 :         if (!unqualified_id)
   17202            0 :           return error_mark_node;
   17203              : 
   17204     81011421 :         if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   17205              :           original_name = dname;
   17206              :         else
   17207     80148453 :           original_name = unqualified_id;
   17208              :         // FIXME:gcc_assert (original_name == dname);
   17209              : 
   17210     81011421 :         if (storage_class == sc_auto)
   17211            1 :           error_at (declspecs->locations[ds_storage_class],
   17212              :                     "storage class %<auto%> invalid for function %qs", name);
   17213     81011420 :         else if (storage_class == sc_register)
   17214            7 :           error_at (declspecs->locations[ds_storage_class],
   17215              :                     "storage class %<register%> invalid for function %qs",
   17216              :                     name);
   17217     81011413 :         else if (thread_p)
   17218              :           {
   17219           12 :             if (declspecs->gnu_thread_keyword_p)
   17220           12 :               error_at (declspecs->locations[ds_thread],
   17221              :                         "storage class %<__thread%> invalid for function %qs",
   17222              :                         name);
   17223              :             else
   17224            0 :               error_at (declspecs->locations[ds_thread],
   17225              :                         "storage class %<thread_local%> invalid for "
   17226              :                         "function %qs", name);
   17227              :           }
   17228     81011401 :         else if (constinit_p)
   17229            3 :           error_at (declspecs->locations[ds_constinit],
   17230              :                     "%<constinit%> specifier invalid for function %qs", name);
   17231              : 
   17232     81011421 :         if (virt_specifiers)
   17233            6 :           error ("virt-specifiers in %qs not allowed outside a class "
   17234              :                  "definition", name);
   17235              :         /* Function declaration not at top level.
   17236              :            Storage classes other than `extern' are not allowed
   17237              :            and `extern' makes no difference.  */
   17238     81011421 :         if (! toplevel_bindings_p ()
   17239        61471 :             && (storage_class == sc_static
   17240        61462 :                 || decl_spec_seq_has_spec_p (declspecs, ds_inline))
   17241     81011433 :             && pedantic)
   17242              :           {
   17243            9 :             if (storage_class == sc_static)
   17244            6 :               pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic,
   17245              :                        "%<static%> specifier invalid for function %qs "
   17246              :                        "declared out of global scope", name);
   17247              :             else
   17248            3 :               pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic,
   17249              :                        "%<inline%> specifier invalid for function %qs "
   17250              :                        "declared out of global scope", name);
   17251              :           }
   17252              : 
   17253     81011421 :         if (ctype == NULL_TREE)
   17254              :           {
   17255     71796514 :             if (virtualp)
   17256              :               {
   17257            0 :                 error ("virtual non-class function %qs", name);
   17258            0 :                 virtualp = 0;
   17259              :               }
   17260     71796514 :             else if (sfk == sfk_constructor
   17261     71796514 :                      || sfk == sfk_destructor)
   17262              :               {
   17263            3 :                 error (funcdef_flag
   17264              :                        ? G_("%qs defined in a non-class scope")
   17265              :                        : G_("%qs declared in a non-class scope"), name);
   17266            3 :                 sfk = sfk_none;
   17267              :               }
   17268              :           }
   17269     81011421 :         if (consteval_p
   17270     81380001 :             && identifier_p (unqualified_id)
   17271     81380001 :             && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   17272              :           {
   17273            9 :             error_at (declspecs->locations[ds_consteval],
   17274              :                       "%qD cannot be %qs", unqualified_id, "consteval");
   17275            9 :             consteval_p = false;
   17276              :           }
   17277              : 
   17278              :         /* Record whether the function is public.  */
   17279     81011421 :         publicp = (ctype != NULL_TREE
   17280     81011421 :                    || storage_class != sc_static);
   17281              : 
   17282    162022842 :         decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
   17283              :                            declspecs, reqs, virtualp, flags, memfn_quals, rqual, raises,
   17284              :                            1, friendp,
   17285              :                            publicp,
   17286     81011421 :                            inlinep | (2 * constexpr_p) | (4 * concept_p)
   17287     81011421 :                                    | (8 * consteval_p),
   17288              :                            initialized,
   17289              :                            is_xobj_member_function, sfk,
   17290              :                            funcdef_flag,
   17291              :                            late_return_type_p,
   17292              :                            template_count, in_namespace, attrlist,
   17293              :                            contract_specifiers, id_loc);
   17294     81011421 :         if (decl == NULL_TREE)
   17295          622 :           return error_mark_node;
   17296              : 
   17297     81010799 :         if (explicitp == 2)
   17298        11363 :           DECL_NONCONVERTING_P (decl) = 1;
   17299     81010799 :         if (staticp == 1)
   17300              :           {
   17301       116231 :             int invalid_static = 0;
   17302              : 
   17303              :             /* Don't allow a static member function in a class, and forbid
   17304              :                declaring main to be static.  */
   17305       116231 :             if (TREE_CODE (type) == METHOD_TYPE)
   17306              :               {
   17307            0 :                 permerror (input_location, "cannot declare member function %qD to have "
   17308              :                            "static linkage", decl);
   17309            0 :                 invalid_static = 1;
   17310              :               }
   17311       116231 :             else if (current_function_decl)
   17312              :               {
   17313              :                 /* 7.1.1: There can be no static function declarations within a
   17314              :                    block.  */
   17315            9 :                 error_at (declspecs->locations[ds_storage_class],
   17316              :                           "cannot declare static function inside another function");
   17317            9 :                 invalid_static = 1;
   17318              :               }
   17319              : 
   17320            9 :             if (invalid_static)
   17321              :               {
   17322     81010799 :                 staticp = 0;
   17323              :                 storage_class = sc_none;
   17324              :               }
   17325              :           }
   17326     81010799 :         if (declspecs->explicit_specifier)
   17327            3 :           store_explicit_specifier (decl, declspecs->explicit_specifier);
   17328              :       }
   17329              :     else
   17330              :       {
   17331              :         /* It's a variable.  */
   17332              : 
   17333              :         /* An uninitialized decl with `extern' is a reference.  */
   17334    141690366 :         decl = grokvardecl (type, dname, unqualified_id,
   17335              :                             declspecs,
   17336              :                             initialized,
   17337              :                             type_quals,
   17338              :                             inlinep,
   17339              :                             concept_p,
   17340              :                             template_count,
   17341              :                             ctype ? ctype : in_namespace,
   17342              :                             id_loc);
   17343     71098656 :         if (decl == NULL_TREE)
   17344           92 :           return error_mark_node;
   17345              : 
   17346     71098564 :         bad_specifiers (decl, BSP_VAR, virtualp,
   17347              :                         memfn_quals != TYPE_UNQUALIFIED,
   17348              :                         inlinep, friendp, raises != NULL_TREE,
   17349              :                         declspecs->locations);
   17350              : 
   17351     71098564 :         if (ctype)
   17352              :           {
   17353       506940 :             DECL_CONTEXT (decl) = ctype;
   17354       506940 :             if (staticp == 1)
   17355              :               {
   17356            6 :                 permerror (declspecs->locations[ds_storage_class],
   17357              :                            "%<static%> may not be used when defining "
   17358              :                            "(as opposed to declaring) a static data member");
   17359            6 :                 staticp = 0;
   17360            6 :                 storage_class = sc_none;
   17361              :               }
   17362       506940 :             if (storage_class == sc_register && TREE_STATIC (decl))
   17363              :               {
   17364            0 :                 error ("static member %qD declared %<register%>", decl);
   17365            0 :                 storage_class = sc_none;
   17366              :               }
   17367       506940 :             if (storage_class == sc_extern && pedantic)
   17368              :               {
   17369            0 :                 pedwarn (input_location, OPT_Wpedantic,
   17370              :                          "cannot explicitly declare member %q#D to have "
   17371              :                          "extern linkage", decl);
   17372            0 :                 storage_class = sc_none;
   17373              :               }
   17374              :           }
   17375     70591624 :         else if (constexpr_p && DECL_EXTERNAL (decl))
   17376              :           {
   17377           14 :             error_at (DECL_SOURCE_LOCATION (decl),
   17378              :                       "declaration of %<constexpr%> variable %qD "
   17379              :                       "is not a definition", decl);
   17380           14 :             constexpr_p = false;
   17381              :           }
   17382     71098564 :         if (consteval_p)
   17383              :           {
   17384           13 :             error_at (DECL_SOURCE_LOCATION (decl),
   17385              :                       "a variable cannot be declared %<consteval%>");
   17386           13 :             consteval_p = false;
   17387              :           }
   17388              : 
   17389     71098564 :         if (inlinep)
   17390      6795688 :           mark_inline_variable (decl, declspecs->locations[ds_inline]);
   17391     71098564 :         if (innermost_code == cdk_decomp)
   17392              :           {
   17393       245573 :             gcc_assert (declarator && declarator->kind == cdk_decomp);
   17394       245573 :             DECL_SOURCE_LOCATION (decl) = id_loc;
   17395       245573 :             DECL_ARTIFICIAL (decl) = 1;
   17396       245573 :             fit_decomposition_lang_decl (decl, NULL_TREE);
   17397              :           }
   17398              :       }
   17399              : 
   17400    596396163 :     if (VAR_P (decl) && !initialized)
   17401      7588445 :       if (tree auto_node = type_uses_auto (type))
   17402          104 :         if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   17403              :           {
   17404           21 :             location_t loc = declspecs->locations[ds_type_spec];
   17405           21 :             error_at (loc, "declaration of %q#D has no initializer", decl);
   17406           21 :             TREE_TYPE (decl) = error_mark_node;
   17407              :           }
   17408              : 
   17409    596396163 :     if (storage_class == sc_extern && initialized && !funcdef_flag)
   17410              :       {
   17411          277 :         if (toplevel_bindings_p ())
   17412              :           {
   17413              :             /* It's common practice (and completely valid) to have a const
   17414              :                be initialized and declared extern.  */
   17415          253 :             if (!(type_quals & TYPE_QUAL_CONST))
   17416           20 :               warning_at (DECL_SOURCE_LOCATION (decl), 0,
   17417              :                           "%qs initialized and declared %<extern%>", name);
   17418              :           }
   17419              :         else
   17420              :           {
   17421           24 :             error_at (DECL_SOURCE_LOCATION (decl),
   17422              :                       "%qs has both %<extern%> and initializer", name);
   17423           24 :             return error_mark_node;
   17424              :           }
   17425              :       }
   17426              : 
   17427              :     /* Record `register' declaration for warnings on &
   17428              :        and in case doing stupid register allocation.  */
   17429              : 
   17430    596396139 :     if (storage_class == sc_register)
   17431              :       {
   17432         2069 :         DECL_REGISTER (decl) = 1;
   17433              :         /* Warn about register storage specifiers on PARM_DECLs.  */
   17434         2069 :         if (TREE_CODE (decl) == PARM_DECL)
   17435              :           {
   17436           35 :             if (cxx_dialect >= cxx17)
   17437           24 :               pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   17438              :                        "ISO C++17 does not allow %<register%> storage "
   17439              :                        "class specifier");
   17440              :             else
   17441           11 :               warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   17442              :                           "%<register%> storage class specifier used");
   17443              :           }
   17444              :       }
   17445    596394070 :     else if (storage_class == sc_extern)
   17446     31777920 :       DECL_THIS_EXTERN (decl) = 1;
   17447    564616150 :     else if (storage_class == sc_static)
   17448     24509355 :       DECL_THIS_STATIC (decl) = 1;
   17449              : 
   17450    596396139 :     if (VAR_P (decl))
   17451              :       {
   17452              :         /* Set constexpr flag on vars (functions got it in grokfndecl).  */
   17453     84544019 :         if (constexpr_p)
   17454     20665425 :           DECL_DECLARED_CONSTEXPR_P (decl) = true;
   17455              :         /* And the constinit flag (which only applies to variables).  */
   17456     63878594 :         else if (constinit_p)
   17457          453 :           DECL_DECLARED_CONSTINIT_P (decl) = true;
   17458              :       }
   17459    511852120 :     else if (TREE_CODE (decl) == FUNCTION_DECL)
   17460              :       {
   17461              :         /* If we saw a return type, record its location.  */
   17462    187619644 :         location_t loc = declspecs->locations[ds_type_spec];
   17463    187619644 :         if (loc == UNKNOWN_LOCATION)
   17464              :           /* Build DECL_RESULT in start_preparsed_function.  */;
   17465    153464956 :         else if (!DECL_RESULT (decl))
   17466              :           {
   17467    153425527 :             tree restype = TREE_TYPE (TREE_TYPE (decl));
   17468    153425527 :             tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   17469    153425527 :             DECL_ARTIFICIAL (resdecl) = 1;
   17470    153425527 :             DECL_IGNORED_P (resdecl) = 1;
   17471    153425527 :             DECL_RESULT (decl) = resdecl;
   17472              :           }
   17473        39429 :         else if (funcdef_flag)
   17474          869 :           DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
   17475              :       }
   17476              : 
   17477              :     /* Record constancy and volatility on the DECL itself .  There's
   17478              :        no need to do this when processing a template; we'll do this
   17479              :        for the instantiated declaration based on the type of DECL.  */
   17480    596396139 :     if (!processing_template_decl
   17481              :         /* Don't do it for instantiated variable templates either,
   17482              :            cp_apply_type_quals_to_decl should have been called on it
   17483              :            already and might have been overridden in cp_finish_decl
   17484              :            if initializer needs runtime initialization.  */
   17485    596396139 :         && (!VAR_P (decl) || !DECL_TEMPLATE_INSTANTIATED (decl)))
   17486    198811049 :       cp_apply_type_quals_to_decl (type_quals, decl);
   17487              : 
   17488    596396139 :     return decl;
   17489              :   }
   17490   1076017508 : }
   17491              : 
   17492              : /* Subroutine of start_function.  Ensure that each of the parameter
   17493              :    types (as listed in PARMS) is complete, as is required for a
   17494              :    function definition.  */
   17495              : 
   17496              : static void
   17497    166972196 : require_complete_types_for_parms (tree parms)
   17498              : {
   17499    493937512 :   for (; parms; parms = DECL_CHAIN (parms))
   17500              :     {
   17501    326965316 :       if (dependent_type_p (TREE_TYPE (parms)))
   17502    183491391 :         continue;
   17503    143473925 :       if (!VOID_TYPE_P (TREE_TYPE (parms))
   17504    143473925 :           && complete_type_or_else (TREE_TYPE (parms), parms))
   17505              :         {
   17506    143473844 :           relayout_decl (parms);
   17507    143473844 :           DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
   17508              : 
   17509    143473844 :           abstract_virtuals_error (parms, TREE_TYPE (parms));
   17510    143473844 :           maybe_warn_parm_abi (TREE_TYPE (parms),
   17511    143473844 :                                DECL_SOURCE_LOCATION (parms));
   17512              :         }
   17513              :       else
   17514              :         /* grokparms or complete_type_or_else will have already issued
   17515              :            an error.  */
   17516           81 :         TREE_TYPE (parms) = error_mark_node;
   17517              :     }
   17518    166972196 : }
   17519              : 
   17520              : /* Returns nonzero if T is a local variable.  */
   17521              : 
   17522              : int
   17523    179530159 : local_variable_p (const_tree t)
   17524              : {
   17525    179530159 :   if ((VAR_P (t)
   17526     69625074 :        && (DECL_LOCAL_DECL_P (t)
   17527     69625074 :            || !DECL_CONTEXT (t)
   17528     69582026 :            || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
   17529    185381147 :       || (TREE_CODE (t) == PARM_DECL))
   17530    159777576 :     return 1;
   17531              : 
   17532              :   return 0;
   17533              : }
   17534              : 
   17535              : /* Like local_variable_p, but suitable for use as a tree-walking
   17536              :    function.  */
   17537              : 
   17538              : static tree
   17539      5652743 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
   17540              :                          void * /*data*/)
   17541              : {
   17542      5652743 :   if (unevaluated_p (TREE_CODE (*tp)))
   17543              :     {
   17544              :       /* DR 2082 permits local variables in unevaluated contexts
   17545              :          within a default argument.  */
   17546           70 :       *walk_subtrees = 0;
   17547           70 :       return NULL_TREE;
   17548              :     }
   17549              : 
   17550      5652673 :   if (local_variable_p (*tp)
   17551      5652673 :       && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
   17552              :     return *tp;
   17553      5652673 :   else if (TYPE_P (*tp))
   17554           30 :     *walk_subtrees = 0;
   17555              : 
   17556              :   return NULL_TREE;
   17557              : }
   17558              : 
   17559              : /* Check that ARG, which is a default-argument expression for a
   17560              :    parameter DECL, is valid.  Returns ARG, or ERROR_MARK_NODE, if
   17561              :    something goes wrong.  DECL may also be a _TYPE node, rather than a
   17562              :    DECL, if there is no DECL available.  */
   17563              : 
   17564              : tree
   17565      2792164 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
   17566              : {
   17567      2792164 :   tree var;
   17568      2792164 :   tree decl_type;
   17569              : 
   17570      2792164 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
   17571              :     /* We get a DEFERRED_PARSE when looking at an in-class declaration
   17572              :        with a default argument.  Ignore the argument for now; we'll
   17573              :        deal with it after the class is complete.  */
   17574              :     return arg;
   17575              : 
   17576      1979966 :   if (TYPE_P (decl))
   17577              :     {
   17578              :       decl_type = decl;
   17579              :       decl = NULL_TREE;
   17580              :     }
   17581              :   else
   17582       602821 :     decl_type = TREE_TYPE (decl);
   17583              : 
   17584      1979966 :   if (arg == error_mark_node
   17585      1979825 :       || decl == error_mark_node
   17586      1979816 :       || TREE_TYPE (arg) == error_mark_node
   17587      3959782 :       || decl_type == error_mark_node)
   17588              :     /* Something already went wrong.  There's no need to check
   17589              :        further.  */
   17590              :     return error_mark_node;
   17591              : 
   17592              :   /* [dcl.fct.default]
   17593              : 
   17594              :      A default argument expression is implicitly converted to the
   17595              :      parameter type.  */
   17596      1979816 :   ++cp_unevaluated_operand;
   17597              :   /* Avoid digest_init clobbering the initializer.  */
   17598      1979816 :   tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
   17599      1979816 :   perform_implicit_conversion_flags (decl_type, carg, complain,
   17600              :                                      LOOKUP_IMPLICIT);
   17601      1979816 :   --cp_unevaluated_operand;
   17602              : 
   17603              :   /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
   17604              :      the call sites.  */
   17605      1575737 :   if (TYPE_PTR_OR_PTRMEM_P (decl_type)
   17606       404094 :       && null_ptr_cst_p (arg)
   17607              :       /* Don't lose side-effects as in PR90473.  */
   17608      2348920 :       && !TREE_SIDE_EFFECTS (arg))
   17609       369101 :     return nullptr_node;
   17610              : 
   17611              :   /* [dcl.fct.default]
   17612              : 
   17613              :      Local variables shall not be used in default argument
   17614              :      expressions.
   17615              : 
   17616              :      The keyword `this' shall not be used in a default argument of a
   17617              :      member function.  */
   17618      1610715 :   var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
   17619      1610715 :   if (var)
   17620              :     {
   17621            0 :       if (complain & tf_warning_or_error)
   17622              :         {
   17623            0 :           if (DECL_NAME (var) == this_identifier)
   17624            0 :             permerror (input_location, "default argument %qE uses %qD",
   17625              :                        arg, var);
   17626              :           else
   17627            0 :             error ("default argument %qE uses local variable %qD", arg, var);
   17628              :         }
   17629            0 :       return error_mark_node;
   17630              :     }
   17631              : 
   17632              :   /* All is well.  */
   17633      1610715 :   return arg;
   17634              : }
   17635              : 
   17636              : /* Returns a deprecated type used within TYPE, or NULL_TREE if none.  */
   17637              : 
   17638              : static tree
   17639    290296331 : type_is_deprecated (tree type)
   17640              : {
   17641    427576958 :   enum tree_code code;
   17642    427576958 :   if (TREE_DEPRECATED (type))
   17643              :     return type;
   17644    427536325 :   if (TYPE_NAME (type))
   17645              :     {
   17646    285882724 :       if (TREE_DEPRECATED (TYPE_NAME (type)))
   17647              :         return type;
   17648              :       else
   17649              :         {
   17650    285882718 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   17651    285882718 :           return NULL_TREE;
   17652              :         }
   17653              :     }
   17654              : 
   17655              :   /* Do warn about using typedefs to a deprecated class.  */
   17656    141653601 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   17657            0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   17658              : 
   17659    141653601 :   code = TREE_CODE (type);
   17660              : 
   17661    141653601 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   17662    141653601 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   17663              :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   17664    137161319 :     return type_is_deprecated (TREE_TYPE (type));
   17665              : 
   17666       119308 :   if (TYPE_PTRMEMFUNC_P (type))
   17667       119308 :     return type_is_deprecated
   17668       119308 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   17669              : 
   17670              :   return NULL_TREE;
   17671              : }
   17672              : 
   17673              : /* Returns an unavailable type used within TYPE, or NULL_TREE if none.  */
   17674              : 
   17675              : static tree
   17676    291536002 : type_is_unavailable (tree type)
   17677              : {
   17678    429555153 :   enum tree_code code;
   17679    429555153 :   if (TREE_UNAVAILABLE (type))
   17680              :     return type;
   17681    429555147 :   if (TYPE_NAME (type))
   17682              :     {
   17683    287162965 :       if (TREE_UNAVAILABLE (TYPE_NAME (type)))
   17684              :         return type;
   17685              :       else
   17686              :         {
   17687    287162959 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   17688    287162959 :           return NULL_TREE;
   17689              :         }
   17690              :     }
   17691              : 
   17692              :   /* Do warn about using typedefs to a deprecated class.  */
   17693    142392182 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   17694            0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   17695              : 
   17696    142392182 :   code = TREE_CODE (type);
   17697              : 
   17698    142392182 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   17699    142392182 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   17700              :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   17701    137786891 :     return type_is_unavailable (TREE_TYPE (type));
   17702              : 
   17703       232260 :   if (TYPE_PTRMEMFUNC_P (type))
   17704       232260 :     return type_is_unavailable
   17705       232260 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   17706              : 
   17707              :   return NULL_TREE;
   17708              : }
   17709              : 
   17710              : /* Decode the list of parameter types for a function type.
   17711              :    Given the list of things declared inside the parens,
   17712              :    return a list of types.
   17713              : 
   17714              :    If this parameter does not end with an ellipsis, we append
   17715              :    void_list_node.
   17716              : 
   17717              :    *PARMS is set to the chain of PARM_DECLs created.  */
   17718              : 
   17719              : tree
   17720    199842466 : grokparms (tree parmlist, tree *parms)
   17721              : {
   17722    199842466 :   tree result = NULL_TREE;
   17723    199842466 :   tree decls = NULL_TREE;
   17724    199842466 :   tree parm;
   17725    199842466 :   int any_error = 0;
   17726              : 
   17727    492012923 :   for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
   17728              :     {
   17729    489476589 :       tree type = NULL_TREE;
   17730    489476589 :       tree init = TREE_PURPOSE (parm);
   17731    489476589 :       tree decl = TREE_VALUE (parm);
   17732              : 
   17733    489476589 :       if (parm == void_list_node || parm == explicit_void_list_node)
   17734              :         break;
   17735              : 
   17736    292170473 :       if (! decl || TREE_TYPE (decl) == error_mark_node)
   17737              :         {
   17738          201 :           any_error = 1;
   17739          201 :           continue;
   17740              :         }
   17741              : 
   17742    292170272 :       type = TREE_TYPE (decl);
   17743    292170272 :       if (VOID_TYPE_P (type))
   17744              :         {
   17745           82 :           if (same_type_p (type, void_type_node)
   17746           73 :               && !init
   17747           61 :               && !DECL_NAME (decl) && !result
   17748          110 :               && TREE_CHAIN (parm) == void_list_node)
   17749              :             /* DR 577: A parameter list consisting of a single
   17750              :                unnamed parameter of non-dependent type 'void'.  */
   17751              :             break;
   17752           66 :           else if (cv_qualified_p (type))
   17753            9 :             error_at (DECL_SOURCE_LOCATION (decl),
   17754              :                       "invalid use of cv-qualified type %qT in "
   17755              :                       "parameter declaration", type);
   17756              :           else
   17757           57 :             error_at (DECL_SOURCE_LOCATION (decl),
   17758              :                       "invalid use of type %<void%> in parameter "
   17759              :                       "declaration");
   17760              :           /* It's not a good idea to actually create parameters of
   17761              :              type `void'; other parts of the compiler assume that a
   17762              :              void type terminates the parameter list.  */
   17763           66 :           type = error_mark_node;
   17764           66 :           TREE_TYPE (decl) = error_mark_node;
   17765              :         }
   17766              : 
   17767    292170256 :       if (type != error_mark_node)
   17768              :         {
   17769    292170190 :           if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   17770              :             {
   17771    291536002 :               tree unavailtype = type_is_unavailable (type);
   17772    291536002 :               if (unavailtype)
   17773           12 :                 cp_handle_deprecated_or_unavailable (unavailtype);
   17774              :             }
   17775    292170190 :           if (deprecated_state != DEPRECATED_SUPPRESS
   17776    292170190 :               && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   17777              :             {
   17778    290296331 :               tree deptype = type_is_deprecated (type);
   17779    290296331 :               if (deptype)
   17780        40639 :                 cp_handle_deprecated_or_unavailable (deptype);
   17781              :             }
   17782              : 
   17783              :           /* [dcl.fct] "A parameter with volatile-qualified type is
   17784              :              deprecated."  */
   17785    292170190 :           if (CP_TYPE_VOLATILE_P (type))
   17786          564 :             warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
   17787              :                         "%<volatile%>-qualified parameter is "
   17788              :                         "deprecated");
   17789              : 
   17790              :           /* Top-level qualifiers on the parameters are
   17791              :              ignored for function types.  */
   17792    292170190 :           type = cp_build_qualified_type (type, TYPE_UNQUALIFIED);
   17793    292170190 :           if (TREE_CODE (type) == METHOD_TYPE)
   17794              :             {
   17795            0 :               error ("parameter %qD invalidly declared method type", decl);
   17796            0 :               type = build_pointer_type (type);
   17797            0 :               TREE_TYPE (decl) = type;
   17798              :             }
   17799    292170190 :           else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
   17800              :             {
   17801              :               /* Before C++17 DR 393:
   17802              :                  [dcl.fct]/6, parameter types cannot contain pointers
   17803              :                  (references) to arrays of unknown bound.  */
   17804      1619992 :               tree t = TREE_TYPE (type);
   17805      1619992 :               int ptr = TYPE_PTR_P (type);
   17806              : 
   17807      1776186 :               while (1)
   17808              :                 {
   17809      1698089 :                   if (TYPE_PTR_P (t))
   17810              :                     ptr = 1;
   17811      1623172 :                   else if (TREE_CODE (t) != ARRAY_TYPE)
   17812              :                     break;
   17813         3190 :                   else if (!TYPE_DOMAIN (t))
   17814              :                     break;
   17815        78097 :                   t = TREE_TYPE (t);
   17816              :                 }
   17817      1619992 :               if (TREE_CODE (t) == ARRAY_TYPE)
   17818           16 :                 pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   17819              :                          ptr
   17820              :                          ? G_("parameter %qD includes pointer to array of "
   17821              :                               "unknown bound %qT")
   17822              :                          : G_("parameter %qD includes reference to array of "
   17823              :                               "unknown bound %qT"),
   17824              :                          decl, t);
   17825              :             }
   17826              : 
   17827    292170190 :           if (init && !processing_template_decl)
   17828      1415010 :             init = check_default_argument (decl, init, tf_warning_or_error);
   17829              :         }
   17830              : 
   17831    292170256 :       DECL_CHAIN (decl) = decls;
   17832    292170256 :       decls = decl;
   17833    292170256 :       result = tree_cons (init, type, result);
   17834              :     }
   17835    199842466 :   decls = nreverse (decls);
   17836    199842466 :   result = nreverse (result);
   17837    199842466 :   if (parm)
   17838    197306132 :     result = chainon (result, void_list_node);
   17839    199842466 :   *parms = decls;
   17840    199842466 :   if (any_error)
   17841          186 :     result = NULL_TREE;
   17842              : 
   17843          186 :   if (any_error)
   17844              :     /* We had parm errors, recover by giving the function (...) type.  */
   17845          186 :     result = NULL_TREE;
   17846              : 
   17847    199842466 :   return result;
   17848              : }
   17849              : 
   17850              : 
   17851              : /* D is a constructor or overloaded `operator='.
   17852              : 
   17853              :    Let T be the class in which D is declared. Then, this function
   17854              :    returns:
   17855              : 
   17856              :    -1 if D's is an ill-formed constructor or copy assignment operator
   17857              :       whose first parameter is of type `T'.
   17858              :    0  if D is not a copy constructor or copy assignment
   17859              :       operator.
   17860              :    1  if D is a copy constructor or copy assignment operator whose
   17861              :       first parameter is a reference to non-const qualified T.
   17862              :    2  if D is a copy constructor or copy assignment operator whose
   17863              :       first parameter is a reference to const qualified T.
   17864              : 
   17865              :    This function can be used as a predicate. Positive values indicate
   17866              :    a copy constructor and nonzero values indicate a copy assignment
   17867              :    operator.  */
   17868              : 
   17869              : int
   17870    352831689 : copy_fn_p (const_tree d)
   17871              : {
   17872    352831689 :   tree args;
   17873    352831689 :   tree arg_type;
   17874    352831689 :   int result = 1;
   17875              : 
   17876    352831689 :   gcc_assert (DECL_FUNCTION_MEMBER_P (d));
   17877              : 
   17878    352831689 :   if (TREE_CODE (d) == TEMPLATE_DECL
   17879    352831689 :       || (DECL_TEMPLATE_INFO (d)
   17880    156241920 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   17881              :     /* Instantiations of template member functions are never copy
   17882              :        functions.  Note that member functions of templated classes are
   17883              :        represented as template functions internally, and we must
   17884              :        accept those as copy functions.  */
   17885              :     return 0;
   17886              : 
   17887    297710733 :   if (!DECL_CONSTRUCTOR_P (d)
   17888    297710733 :       && DECL_NAME (d) != assign_op_identifier)
   17889              :     return 0;
   17890              : 
   17891    296885746 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   17892              :     {
   17893          282 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17894          282 :       if (!TYPE_REF_P (object_param)
   17895          255 :           || TYPE_REF_IS_RVALUE (object_param)
   17896              :           /* Reject unrelated object parameters. */
   17897          237 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   17898          519 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   17899              :         return 0;
   17900          228 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17901              :     }
   17902              :   else
   17903    296885464 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   17904    296885692 :   if (!args)
   17905              :     return 0;
   17906              : 
   17907    296877828 :   arg_type = TREE_VALUE (args);
   17908    296877828 :   if (arg_type == error_mark_node)
   17909              :     return 0;
   17910              : 
   17911    296877793 :   if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
   17912              :     {
   17913              :       /* Pass by value copy assignment operator.  */
   17914              :       result = -1;
   17915              :     }
   17916    296876233 :   else if (TYPE_REF_P (arg_type)
   17917    188238561 :            && !TYPE_REF_IS_RVALUE (arg_type)
   17918    416041856 :            && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
   17919              :     {
   17920     96083769 :       if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
   17921     95913375 :         result = 2;
   17922              :     }
   17923              :   else
   17924              :     return 0;
   17925              : 
   17926     96085329 :   args = TREE_CHAIN (args);
   17927              : 
   17928     98968580 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   17929              :     /* There are more non-optional args.  */
   17930      2882737 :     return 0;
   17931              : 
   17932              :   return result;
   17933              : }
   17934              : 
   17935              : /* D is a constructor or overloaded `operator='.
   17936              : 
   17937              :    Let T be the class in which D is declared. Then, this function
   17938              :    returns true when D is a move constructor or move assignment
   17939              :    operator, false otherwise.  */
   17940              : 
   17941              : bool
   17942    163912629 : move_fn_p (const_tree d)
   17943              : {
   17944    163912629 :   if (cxx_dialect == cxx98)
   17945              :     /* There are no move constructors if we are in C++98 mode.  */
   17946              :     return false;
   17947              : 
   17948    163849709 :   if (TREE_CODE (d) == TEMPLATE_DECL
   17949    163849709 :       || (DECL_TEMPLATE_INFO (d)
   17950     66148143 :          && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   17951              :     /* Instantiations of template member functions are never move
   17952              :        functions.  Note that member functions of templated classes are
   17953              :        represented as template functions internally, and we must
   17954              :        accept those as move functions.  */
   17955              :     return 0;
   17956              : 
   17957    132957575 :   return move_signature_fn_p (d);
   17958              : }
   17959              : 
   17960              : /* D is a constructor or overloaded `operator='.
   17961              : 
   17962              :    Then, this function returns true when D has the same signature as a move
   17963              :    constructor or move assignment operator (because either it is such a
   17964              :    ctor/op= or it is a template specialization with the same signature),
   17965              :    false otherwise.  */
   17966              : 
   17967              : bool
   17968    132957575 : move_signature_fn_p (const_tree d)
   17969              : {
   17970    132957575 :   tree args;
   17971    132957575 :   tree arg_type;
   17972    132957575 :   bool result = false;
   17973              : 
   17974    132957575 :   if (!DECL_CONSTRUCTOR_P (d)
   17975    132957575 :       && DECL_NAME (d) != assign_op_identifier)
   17976              :     return 0;
   17977              : 
   17978    132957349 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   17979              :     {
   17980          126 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17981          126 :       if (!TYPE_REF_P (object_param)
   17982          102 :           || TYPE_REF_IS_RVALUE (object_param)
   17983              :           /* Reject unrelated object parameters. */
   17984           90 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   17985          216 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   17986              :         return 0;
   17987           84 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17988              :     }
   17989              :   else
   17990    132957223 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   17991    132957307 :   if (!args)
   17992              :     return 0;
   17993              : 
   17994    132954317 :   arg_type = TREE_VALUE (args);
   17995    132954317 :   if (arg_type == error_mark_node)
   17996              :     return 0;
   17997              : 
   17998    132954309 :   if (TYPE_REF_P (arg_type)
   17999     67684431 :       && TYPE_REF_IS_RVALUE (arg_type)
   18000    186031915 :       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
   18001              :                       DECL_CONTEXT (d)))
   18002              :     result = true;
   18003              : 
   18004    132954309 :   args = TREE_CHAIN (args);
   18005              : 
   18006    148460181 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   18007              :     /* There are more non-optional args.  */
   18008     12324064 :     return false;
   18009              : 
   18010              :   return result;
   18011              : }
   18012              : 
   18013              : /* Remember any special properties of member function DECL.  */
   18014              : 
   18015              : void
   18016    361920814 : grok_special_member_properties (tree decl)
   18017              : {
   18018    361920814 :   tree class_type;
   18019              : 
   18020    361920814 :   if (TREE_CODE (decl) == USING_DECL
   18021    361920814 :       || !DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   18022              :     return;
   18023              : 
   18024    339345046 :   class_type = DECL_CONTEXT (decl);
   18025    339345046 :   if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
   18026              :     {
   18027    153354216 :       int ctor = copy_fn_p (decl);
   18028              : 
   18029    153354216 :       if (!DECL_ARTIFICIAL (decl))
   18030    106390257 :         TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
   18031              : 
   18032    153354216 :       if (ctor > 0)
   18033              :         {
   18034              :           /* [class.copy]
   18035              : 
   18036              :              A non-template constructor for class X is a copy
   18037              :              constructor if its first parameter is of type X&, const
   18038              :              X&, volatile X& or const volatile X&, and either there
   18039              :              are no other parameters or else all other parameters have
   18040              :              default arguments.  */
   18041     31242831 :           TYPE_HAS_COPY_CTOR (class_type) = 1;
   18042     31242831 :           if (ctor > 1)
   18043     31163827 :             TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
   18044              :         }
   18045              : 
   18046    153354216 :       if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
   18047     32704380 :         TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
   18048              : 
   18049    153354216 :       if (is_list_ctor (decl))
   18050      1550922 :         TYPE_HAS_LIST_CTOR (class_type) = 1;
   18051              : 
   18052    153354216 :       if (maybe_constexpr_fn (decl)
   18053    153354216 :           && !ctor && !move_fn_p (decl))
   18054     56023550 :         TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
   18055              :     }
   18056    185990830 :   else if (DECL_NAME (decl) == assign_op_identifier)
   18057              :     {
   18058              :       /* [class.copy]
   18059              : 
   18060              :          A non-template assignment operator for class X is a copy
   18061              :          assignment operator if its parameter is of type X, X&, const
   18062              :          X&, volatile X& or const volatile X&.  */
   18063              : 
   18064     15509255 :       int assop = copy_fn_p (decl);
   18065              : 
   18066     15509255 :       if (assop)
   18067              :         {
   18068      7884451 :           TYPE_HAS_COPY_ASSIGN (class_type) = 1;
   18069      7884451 :           if (assop != 1)
   18070      7855735 :             TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
   18071              :         }
   18072              :     }
   18073    170481575 :   else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
   18074      2801118 :     TYPE_HAS_CONVERSION (class_type) = true;
   18075              : 
   18076              :   /* Destructors are handled in check_methods.  */
   18077              : }
   18078              : 
   18079              : /* Check a constructor DECL has the correct form.  Complains
   18080              :    if the class has a constructor of the form X(X).  */
   18081              : 
   18082              : bool
   18083     49266548 : grok_ctor_properties (const_tree ctype, const_tree decl)
   18084              : {
   18085     49266548 :   int ctor_parm = copy_fn_p (decl);
   18086              : 
   18087     49266548 :   if (ctor_parm < 0)
   18088              :     {
   18089              :       /* [class.copy]
   18090              : 
   18091              :          A declaration of a constructor for a class X is ill-formed if
   18092              :          its first parameter is of type (optionally cv-qualified) X
   18093              :          and either there are no other parameters or else all other
   18094              :          parameters have default arguments.
   18095              : 
   18096              :          We *don't* complain about member template instantiations that
   18097              :          have this form, though; they can occur as we try to decide
   18098              :          what constructor to use during overload resolution.  Since
   18099              :          overload resolution will never prefer such a constructor to
   18100              :          the non-template copy constructor (which is either explicitly
   18101              :          or implicitly defined), there's no need to worry about their
   18102              :          existence.  Theoretically, they should never even be
   18103              :          instantiated, but that's hard to forestall.  */
   18104            9 :       error_at (DECL_SOURCE_LOCATION (decl),
   18105              :                 "invalid constructor; you probably meant %<%T (const %T&)%>",
   18106              :                 ctype, ctype);
   18107            9 :       return false;
   18108              :     }
   18109              : 
   18110              :   return true;
   18111              : }
   18112              : 
   18113              : /* DECL is a declaration for an overloaded or conversion operator.  If
   18114              :    COMPLAIN is true, errors are issued for invalid declarations.  */
   18115              : 
   18116              : bool
   18117     61386545 : grok_op_properties (tree decl, bool complain)
   18118              : {
   18119     61386545 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   18120     61386545 :   bool const methodp = DECL_IOBJ_MEMBER_FUNCTION_P (decl);
   18121     61386545 :   tree name = DECL_NAME (decl);
   18122     61386545 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   18123              : 
   18124     61386545 :   tree class_type = DECL_CONTEXT (decl);
   18125     61386545 :   if (class_type && !CLASS_TYPE_P (class_type))
   18126              :     class_type = NULL_TREE;
   18127              : 
   18128     61386545 :   tree_code operator_code;
   18129     61386545 :   unsigned op_flags;
   18130     61386545 :   if (IDENTIFIER_CONV_OP_P (name))
   18131              :     {
   18132              :       /* Conversion operators are TYPE_EXPR for the purposes of this
   18133              :          function.  */
   18134              :       operator_code = TYPE_EXPR;
   18135              :       op_flags = OVL_OP_FLAG_UNARY;
   18136              :     }
   18137              :   else
   18138              :     {
   18139     58979923 :       const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
   18140              : 
   18141     58979923 :       operator_code = ovl_op->tree_code;
   18142     58979923 :       op_flags = ovl_op->flags;
   18143     58979923 :       gcc_checking_assert (operator_code != ERROR_MARK);
   18144     58979923 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   18145              :     }
   18146              : 
   18147     58979923 :   if (op_flags & OVL_OP_FLAG_ALLOC)
   18148              :     {
   18149              :       /* operator new and operator delete are quite special.  */
   18150       351398 :       if (class_type)
   18151         9930 :         switch (op_flags)
   18152              :           {
   18153         6803 :           case OVL_OP_FLAG_ALLOC:
   18154         6803 :             TYPE_HAS_NEW_OPERATOR (class_type) = 1;
   18155         6803 :             break;
   18156              : 
   18157         2811 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
   18158         2811 :             TYPE_GETS_DELETE (class_type) |= 1;
   18159         2811 :             break;
   18160              : 
   18161          135 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
   18162          135 :             TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
   18163          135 :             break;
   18164              : 
   18165          181 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
   18166          181 :             TYPE_GETS_DELETE (class_type) |= 2;
   18167          181 :             break;
   18168              : 
   18169            0 :           default:
   18170            0 :             gcc_unreachable ();
   18171              :           }
   18172              : 
   18173              :       /* [basic.std.dynamic.allocation]/1:
   18174              : 
   18175              :          A program is ill-formed if an allocation function is declared
   18176              :          in a namespace scope other than global scope or declared
   18177              :          static in global scope.
   18178              : 
   18179              :          The same also holds true for deallocation functions.  */
   18180       351398 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   18181              :         {
   18182       341468 :           if (CP_DECL_CONTEXT (decl) != global_namespace)
   18183              :             {
   18184            6 :               error_at (loc, "%qD may not be declared within a namespace",
   18185              :                         decl);
   18186            6 :               return false;
   18187              :             }
   18188              : 
   18189       341462 :           if (!TREE_PUBLIC (decl))
   18190              :             {
   18191            6 :               error_at (loc, "%qD may not be declared as static", decl);
   18192            6 :               return false;
   18193              :             }
   18194              :         }
   18195              : 
   18196              :       /* Check for replaceable global new/delete operators with
   18197              :          const std::nothrow_t & last argument, other replaceable global
   18198              :          new/delete operators are marked in cxx_init_decl_processing.  */
   18199       351386 :       if (CP_DECL_CONTEXT (decl) == global_namespace)
   18200              :         {
   18201       341456 :           tree args = argtypes;
   18202       341456 :           if (args
   18203       341444 :               && args != void_list_node
   18204      1024326 :               && same_type_p (TREE_VALUE (args),
   18205              :                               (op_flags & OVL_OP_FLAG_DELETE)
   18206              :                               ? ptr_type_node : size_type_node))
   18207              :             {
   18208       341414 :               args = TREE_CHAIN (args);
   18209       341414 :               if (aligned_allocation_fn_p (decl))
   18210       110172 :                 args = TREE_CHAIN (args);
   18211       341414 :               if (args
   18212       341408 :                   && args != void_list_node
   18213       569353 :                   && TREE_CHAIN (args) == void_list_node)
   18214              :                 {
   18215       200241 :                   tree t = TREE_VALUE (args);
   18216       200241 :                   if (TYPE_REF_P (t)
   18217       113617 :                       && !TYPE_REF_IS_RVALUE (t)
   18218       113617 :                       && (t = TREE_TYPE (t))
   18219       113617 :                       && TYPE_QUALS (t) == TYPE_QUAL_CONST
   18220       313360 :                       && is_std_class (t, "nothrow_t"))
   18221       113119 :                     DECL_IS_REPLACEABLE_OPERATOR (decl) = 1;
   18222              :                 }
   18223              :             }
   18224              :         }
   18225              : 
   18226       351386 :       if (op_flags & OVL_OP_FLAG_DELETE)
   18227              :         {
   18228       200708 :           DECL_SET_IS_OPERATOR_DELETE (decl, true);
   18229       200708 :           coerce_delete_type (decl, loc);
   18230              :         }
   18231              :       else
   18232              :         {
   18233       150678 :           DECL_SET_IS_OPERATOR_NEW (decl, true);
   18234       150678 :           TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
   18235              :         }
   18236              : 
   18237              :       return true;
   18238              :     }
   18239              : 
   18240              :   /* An operator function must either be a non-static member function
   18241              :      or have at least one parameter of a class, a reference to a class,
   18242              :      an enumeration, or a reference to an enumeration.  13.4.0.6 */
   18243     61035147 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   18244              :     {
   18245     15671466 :       if (operator_code == TYPE_EXPR
   18246     15671466 :           || operator_code == COMPONENT_REF
   18247     15671445 :           || operator_code == NOP_EXPR)
   18248              :         {
   18249           33 :           error_at (loc, "%qD must be a non-static member function", decl);
   18250           33 :           return false;
   18251              :         }
   18252              : 
   18253     15671433 :       if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
   18254              :         {
   18255       137825 :           if (! DECL_STATIC_FUNCTION_P (decl))
   18256              :             {
   18257           12 :               error_at (loc, "%qD must be a member function", decl);
   18258           12 :               return false;
   18259              :             }
   18260       137813 :           if (cxx_dialect < cxx23
   18261              :               /* For lambdas we diagnose static lambda specifier elsewhere.  */
   18262       208478 :               && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
   18263              :               /* For instantiations, we have diagnosed this already.  */
   18264       242038 :               && ! DECL_USE_TEMPLATE (decl))
   18265       104219 :             pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
   18266              :                      "function only with %<-std=c++23%> or %<-std=gnu++23%>",
   18267              :                      decl);
   18268       137813 :           if (operator_code == ARRAY_REF)
   18269              :             /* static operator[] should have exactly one argument
   18270              :                for C++20 and earlier, so that it isn't multidimensional.  */
   18271              :             op_flags = OVL_OP_FLAG_UNARY;
   18272              :         }
   18273     15533608 :       else if (DECL_STATIC_FUNCTION_P (decl))
   18274              :         {
   18275            9 :           error_at (loc, "%qD must be either a non-static member "
   18276              :                     "function or a non-member function", decl);
   18277            9 :           return false;
   18278              :         }
   18279              :       else
   18280       417523 :         for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
   18281              :           {
   18282     15951122 :             if (!arg || arg == void_list_node)
   18283              :               {
   18284           18 :                 if (complain)
   18285           15 :                   error_at (loc, "%qD must have an argument of class or "
   18286              :                             "enumerated type", decl);
   18287              :                 return false;
   18288              :               }
   18289              : 
   18290     15951104 :             tree type = non_reference (TREE_VALUE (arg));
   18291     15951104 :             if (type == error_mark_node)
   18292              :               return false;
   18293              : 
   18294              :             /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
   18295              :                because these checks are performed even on template
   18296              :                functions.  */
   18297     15951101 :             if (MAYBE_CLASS_TYPE_P (type)
   18298      1430270 :                 || TREE_CODE (type) == ENUMERAL_TYPE)
   18299              :               break;
   18300       417523 :           }
   18301              :     }
   18302              : 
   18303     61031718 :   if (operator_code == CALL_EXPR)
   18304              :     /* There are no further restrictions on the arguments to an overloaded
   18305              :        "operator ()".  */
   18306              :     return true;
   18307              : 
   18308              :   /* C++23 allows an arbitrary number of parameters and default arguments for
   18309              :      operator[], and none of the other checks below apply.  */
   18310     50817356 :   if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
   18311              :     return true;
   18312              : 
   18313     50494573 :   if (operator_code == COND_EXPR)
   18314              :     {
   18315              :       /* 13.4.0.3 */
   18316            6 :       error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
   18317            6 :       return false;
   18318              :     }
   18319              : 
   18320              :   /* Count the number of arguments and check for ellipsis.  */
   18321              :   int arity = 0;
   18322    143497675 :   for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
   18323              :     {
   18324     93003123 :       if (!arg)
   18325              :         {
   18326           15 :           error_at (loc, "%qD must not have variable number of arguments",
   18327              :                     decl);
   18328           15 :           return false;
   18329              :         }
   18330     93003108 :       ++arity;
   18331              :     }
   18332              :   /* FIXME: We need tests for these errors with xobj member functions.  */
   18333              :   /* Verify correct number of arguments.  */
   18334     50494552 :   switch (op_flags)
   18335              :     {
   18336     10492248 :     case OVL_OP_FLAG_AMBIARY:
   18337     10492248 :       if (arity == 1)
   18338              :         {
   18339              :           /* We have a unary instance of an ambi-ary op.  Remap to the
   18340              :              unary one.  */
   18341      4521304 :           unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
   18342      4521304 :           const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
   18343      4521304 :           gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
   18344      4521304 :           operator_code = ovl_op->tree_code;
   18345      4521304 :           DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   18346              :         }
   18347      5970944 :       else if (arity != 2)
   18348              :         {
   18349              :           /* This was an ambiguous operator but is invalid. */
   18350            3 :           error_at (loc,
   18351              :                     methodp
   18352              :                     ? G_("%qD must have either zero or one argument")
   18353              :                     : G_("%qD must have either one or two arguments"), decl);
   18354            3 :           return false;
   18355              :         }
   18356      5970941 :       else if ((operator_code == POSTINCREMENT_EXPR
   18357      5970941 :                 || operator_code == POSTDECREMENT_EXPR)
   18358      2774165 :                && ! processing_template_decl
   18359              :                /* x++ and x--'s second argument must be an int.  */
   18360      7771672 :                && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
   18361              :                                  integer_type_node))
   18362              :         {
   18363           15 :           error_at (loc,
   18364              :                     methodp
   18365              :                     ? G_("postfix %qD must have %<int%> as its argument")
   18366              :                     : G_("postfix %qD must have %<int%> as its second argument"),
   18367              :                     decl);
   18368           15 :           return false;
   18369              :         }
   18370              :       break;
   18371              : 
   18372      3464722 :     case OVL_OP_FLAG_UNARY:
   18373      3464722 :       if (arity != 1)
   18374              :         {
   18375            9 :           error_at (loc,
   18376              :                     methodp
   18377              :                     ? G_("%qD must have no arguments")
   18378              :                     : G_("%qD must have exactly one argument"), decl);
   18379            9 :           return false;
   18380              :         }
   18381              :       break;
   18382              : 
   18383     36537582 :     case OVL_OP_FLAG_BINARY:
   18384     36537582 :       if (arity != 2)
   18385              :         {
   18386            3 :           error_at (loc,
   18387              :                     methodp
   18388              :                     ? G_("%qD must have exactly one argument")
   18389              :                     : G_("%qD must have exactly two arguments"), decl);
   18390            3 :           return false;
   18391              :         }
   18392              :       break;
   18393              : 
   18394            0 :     default:
   18395            0 :       gcc_unreachable ();
   18396              :     }
   18397              : 
   18398              :   /* There can be no default arguments.  */
   18399    143497534 :   for (tree arg = argtypes; arg && arg != void_list_node;
   18400     93003012 :        arg = TREE_CHAIN (arg))
   18401     93003027 :     if (TREE_PURPOSE (arg))
   18402              :       {
   18403           15 :         TREE_PURPOSE (arg) = NULL_TREE;
   18404           15 :         error_at (loc, "%qD cannot have default arguments", decl);
   18405           15 :         return false;
   18406              :       }
   18407              : 
   18408              :   /* At this point the declaration is well-formed.  It may not be
   18409              :      sensible though.  */
   18410              : 
   18411              :   /* Check member function warnings only on the in-class declaration.
   18412              :      There's no point warning on an out-of-class definition.  */
   18413     50494507 :   if (class_type && class_type != current_class_type)
   18414              :     return true;
   18415              : 
   18416              :   /* Warn about conversion operators that will never be used.  */
   18417     48598253 :   if (IDENTIFIER_CONV_OP_P (name)
   18418      2406216 :       && ! DECL_TEMPLATE_INFO (decl)
   18419     49648681 :       && warn_class_conversion)
   18420              :     {
   18421      1050395 :       tree t = TREE_TYPE (name);
   18422      1050395 :       int ref = TYPE_REF_P (t);
   18423              : 
   18424      1050395 :       if (ref)
   18425        21768 :         t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
   18426              : 
   18427      1050395 :       if (VOID_TYPE_P (t))
   18428            9 :         warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
   18429              :                     "will never use a type conversion operator", class_type);
   18430      1050386 :       else if (class_type)
   18431              :         {
   18432      1050386 :           if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
   18433           24 :             warning_at (loc, OPT_Wclass_conversion,
   18434              :                         ref
   18435              :                         ? G_("converting %qT to a reference to the same type "
   18436              :                              "will never use a type conversion operator")
   18437              :                         : G_("converting %qT to the same type "
   18438              :                              "will never use a type conversion operator"),
   18439              :                         class_type);
   18440              :           /* Don't force t to be complete here.  */
   18441      1050371 :           else if (MAYBE_CLASS_TYPE_P (t)
   18442       599097 :                    && COMPLETE_TYPE_P (t)
   18443       159945 :                    && DERIVED_FROM_P (t, class_type))
   18444           30 :             warning_at (loc, OPT_Wclass_conversion,
   18445              :                         ref
   18446              :                         ? G_("converting %qT to a reference to a base class "
   18447              :                              "%qT will never use a type conversion operator")
   18448              :                         : G_("converting %qT to a base class %qT "
   18449              :                              "will never use a type conversion operator"),
   18450              :                         class_type, t);
   18451              :         }
   18452              :     }
   18453              : 
   18454     48598253 :   if (!warn_ecpp)
   18455              :     return true;
   18456              : 
   18457              :   /* Effective C++ rules below.  */
   18458              : 
   18459              :   /* More Effective C++ rule 7.  */
   18460           54 :   if (operator_code == TRUTH_ANDIF_EXPR
   18461           54 :       || operator_code == TRUTH_ORIF_EXPR
   18462           54 :       || operator_code == COMPOUND_EXPR)
   18463            0 :     warning_at (loc, OPT_Weffc__,
   18464              :                 "user-defined %qD always evaluates both arguments", decl);
   18465              : 
   18466              :   /* More Effective C++ rule 6.  */
   18467           54 :   if (operator_code == POSTINCREMENT_EXPR
   18468              :       || operator_code == POSTDECREMENT_EXPR
   18469              :       || operator_code == PREINCREMENT_EXPR
   18470           54 :       || operator_code == PREDECREMENT_EXPR)
   18471              :     {
   18472            0 :       tree arg = TREE_VALUE (argtypes);
   18473            0 :       tree ret = TREE_TYPE (TREE_TYPE (decl));
   18474            0 :       if (methodp || TYPE_REF_P (arg))
   18475            0 :         arg = TREE_TYPE (arg);
   18476            0 :       arg = TYPE_MAIN_VARIANT (arg);
   18477              : 
   18478            0 :       if (operator_code == PREINCREMENT_EXPR
   18479              :           || operator_code == PREDECREMENT_EXPR)
   18480              :         {
   18481            0 :           if (!TYPE_REF_P (ret)
   18482            0 :               || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
   18483            0 :             warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
   18484              :                         build_reference_type (arg));
   18485              :         }
   18486              :       else
   18487              :         {
   18488            0 :           if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
   18489            0 :             warning_at (loc, OPT_Weffc__,
   18490              :                         "postfix %qD should return %qT", decl, arg);
   18491              :         }
   18492              :     }
   18493              : 
   18494              :   /* Effective C++ rule 23.  */
   18495           54 :   if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
   18496              :       && (operator_code == PLUS_EXPR
   18497            9 :           || operator_code == MINUS_EXPR
   18498            9 :           || operator_code == TRUNC_DIV_EXPR
   18499              :           || operator_code == MULT_EXPR
   18500              :           || operator_code == TRUNC_MOD_EXPR)
   18501           60 :       && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
   18502            3 :     warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
   18503              : 
   18504              :   return true;
   18505              : }
   18506              : 
   18507              : /* Return a string giving the keyword associate with CODE.  */
   18508              : 
   18509              : const char *
   18510         3578 : tag_name (enum tag_types code)
   18511              : {
   18512         3578 :   switch (code)
   18513              :     {
   18514              :     case record_type:
   18515              :       return "struct";
   18516          114 :     case class_type:
   18517          114 :       return "class";
   18518            3 :     case union_type:
   18519            3 :       return "union";
   18520            9 :     case enum_type:
   18521            9 :       return "enum";
   18522         3363 :     case typename_type:
   18523         3363 :     case none_type:
   18524         3363 :       return "typename";
   18525           29 :     case scope_type:
   18526           29 :       return nullptr;
   18527              :     }
   18528            0 :   gcc_unreachable ();
   18529              : }
   18530              : 
   18531              : /* Name lookup in an elaborated-type-specifier (after the keyword
   18532              :    indicated by TAG_CODE) has found the TYPE_DECL DECL.  If the
   18533              :    elaborated-type-specifier is invalid, issue a diagnostic and return
   18534              :    error_mark_node; otherwise, return the *_TYPE to which it referred.
   18535              :    If ALLOW_TEMPLATE_P is true, TYPE may be a class template.  */
   18536              : 
   18537              : tree
   18538     12453106 : check_elaborated_type_specifier (enum tag_types tag_code,
   18539              :                                  tree decl,
   18540              :                                  bool allow_template_p)
   18541              : {
   18542     12453106 :   tree type;
   18543              : 
   18544              :   /* In the case of:
   18545              : 
   18546              :        struct S { struct S *p; };
   18547              : 
   18548              :      name lookup will find the TYPE_DECL for the implicit "S::S"
   18549              :      typedef.  Adjust for that here.  */
   18550     12453106 :   if (DECL_SELF_REFERENCE_P (decl))
   18551       429258 :     decl = TYPE_NAME (TREE_TYPE (decl));
   18552              : 
   18553     12453106 :   type = TREE_TYPE (decl);
   18554              : 
   18555              :   /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
   18556              :      is false for this case as well.  */
   18557     12453106 :   if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   18558              :     {
   18559            9 :       error ("using template type parameter %qT after %qs",
   18560              :              type, tag_name (tag_code));
   18561            9 :       return error_mark_node;
   18562              :     }
   18563              :   /* Accept template template parameters.  */
   18564     12453097 :   else if (allow_template_p
   18565      7046556 :            && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
   18566      7046544 :                || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
   18567              :     ;
   18568              :   /*   [dcl.type.elab]
   18569              : 
   18570              :        If the identifier resolves to a typedef-name or the
   18571              :        simple-template-id resolves to an alias template
   18572              :        specialization, the elaborated-type-specifier is ill-formed.
   18573              : 
   18574              :      In other words, the only legitimate declaration to use in the
   18575              :      elaborated type specifier is the implicit typedef created when
   18576              :      the type is declared.  */
   18577     12453082 :   else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
   18578       429387 :            && !DECL_SELF_REFERENCE_P (decl)
   18579     12453211 :            && tag_code != typename_type)
   18580              :     {
   18581           78 :       auto_diagnostic_group d;
   18582           78 :       if (alias_template_specialization_p (type, nt_opaque))
   18583           21 :         error ("using alias template specialization %qT after %qs",
   18584              :                type, tag_name (tag_code));
   18585              :       else
   18586           57 :         error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
   18587           78 :       inform (DECL_SOURCE_LOCATION (decl),
   18588              :               "%qD has a previous declaration here", decl);
   18589           78 :       return error_mark_node;
   18590           78 :     }
   18591     12453004 :   else if (TREE_CODE (type) != RECORD_TYPE
   18592     12453004 :            && TREE_CODE (type) != UNION_TYPE
   18593              :            && tag_code != enum_type
   18594        72225 :            && tag_code != typename_type)
   18595              :     {
   18596            6 :       auto_diagnostic_group d;
   18597            6 :       error ("%qT referred to as %qs", type, tag_name (tag_code));
   18598            6 :       inform (location_of (type), "%qT has a previous declaration here", type);
   18599            6 :       return error_mark_node;
   18600            6 :     }
   18601     12452998 :   else if (TREE_CODE (type) != ENUMERAL_TYPE
   18602     12380818 :            && tag_code == enum_type)
   18603              :     {
   18604            3 :       auto_diagnostic_group d;
   18605            3 :       error ("%qT referred to as enum", type);
   18606            3 :       inform (location_of (type), "%qT has a previous declaration here", type);
   18607            3 :       return error_mark_node;
   18608            3 :     }
   18609     12452995 :   else if (!allow_template_p
   18610      5406481 :            && TREE_CODE (type) == RECORD_TYPE
   18611     17734028 :            && CLASSTYPE_IS_TEMPLATE (type))
   18612              :     {
   18613              :       /* If a class template appears as elaborated type specifier
   18614              :          without a template header such as:
   18615              : 
   18616              :            template <class T> class C {};
   18617              :            void f(class C);             // No template header here
   18618              : 
   18619              :          then the required template argument is missing.  */
   18620           18 :       error ("template argument required for %<%s %T%>",
   18621              :              tag_name (tag_code),
   18622           18 :              DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
   18623           18 :       return error_mark_node;
   18624              :     }
   18625              : 
   18626              :   return type;
   18627              : }
   18628              : 
   18629              : /* Lookup NAME of an elaborated type specifier according to SCOPE and
   18630              :    issue diagnostics if necessary.  Return *_TYPE node upon success,
   18631              :    NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
   18632              :    error.  */
   18633              : 
   18634              : static tree
   18635     27034383 : lookup_and_check_tag (enum tag_types tag_code, tree name,
   18636              :                       TAG_how how, bool template_header_p)
   18637              : {
   18638     27034383 :   tree decl;
   18639     27034383 :   if (how == TAG_how::GLOBAL)
   18640              :     {
   18641              :       /* First try ordinary name lookup, ignoring hidden class name
   18642              :          injected via friend declaration.  */
   18643      2159862 :       decl = lookup_name (name, LOOK_want::TYPE);
   18644              :       /* If that fails, the name will be placed in the smallest
   18645              :          non-class, non-function-prototype scope according to 3.3.1/5.
   18646              :          We may already have a hidden name declared as friend in this
   18647              :          scope.  So lookup again but not ignoring hidden names.
   18648              :          If we find one, that name will be made visible rather than
   18649              :          creating a new tag.  */
   18650      2159862 :       if (!decl)
   18651        18855 :         decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
   18652              :     }
   18653              :   else
   18654     24874521 :     decl = lookup_elaborated_type (name, how);
   18655              : 
   18656     24893376 :   if (!decl)
   18657              :     /* We found nothing.  */
   18658              :     return NULL_TREE;
   18659              : 
   18660      6120249 :   if (TREE_CODE (decl) == TREE_LIST)
   18661              :     {
   18662            3 :       auto_diagnostic_group d;
   18663            3 :       error ("reference to %qD is ambiguous", name);
   18664            3 :       print_candidates (input_location, decl);
   18665            3 :       return error_mark_node;
   18666            3 :     }
   18667              : 
   18668      2514464 :   if (DECL_CLASS_TEMPLATE_P (decl)
   18669      2514458 :       && !template_header_p
   18670      8634704 :       && how == TAG_how::CURRENT_ONLY)
   18671              :     {
   18672           12 :       auto_diagnostic_group d;
   18673           12 :       error ("class template %qD redeclared as non-template", name);
   18674           12 :       inform (location_of (decl), "previous declaration here");
   18675           12 :       CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
   18676           12 :       return error_mark_node;
   18677           12 :     }
   18678              : 
   18679      2514452 :   if (DECL_CLASS_TEMPLATE_P (decl)
   18680              :       /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
   18681              :          so ignore a template template parameter.  */
   18682      6120240 :       || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
   18683      2514449 :     decl = DECL_TEMPLATE_RESULT (decl);
   18684              : 
   18685      6120234 :   if (TREE_CODE (decl) == USING_DECL)
   18686              :     {
   18687           24 :       tree u = decl;
   18688           24 :       decl = strip_using_decl (decl);
   18689           24 :       if (how == TAG_how::CURRENT_ONLY
   18690           24 :           && TREE_CODE (decl) == TYPE_DECL
   18691           51 :           && !(DECL_IMPLICIT_TYPEDEF_P (decl)
   18692           24 :                && CP_DECL_CONTEXT (decl) == CP_DECL_CONTEXT (u)
   18693            3 :                && redefinable_import_p (decl)))
   18694              :         {
   18695           21 :           auto_diagnostic_group _;
   18696           21 :           error ("%qD conflicts with a previous declaration", name);
   18697           21 :           inform (location_of (u), "previous declaration %qD", u);
   18698           21 :           inform (location_of (decl), "%qD declared here", decl);
   18699           21 :           return error_mark_node;
   18700           21 :         }
   18701              :     }
   18702              : 
   18703      6120213 :   if (TREE_CODE (decl) != TYPE_DECL)
   18704              :     /* Found not-a-type.  */
   18705              :     return NULL_TREE;
   18706              : 
   18707              :   /* Look for invalid nested type:
   18708              :      class C {
   18709              :      class C {};
   18710              :      };  */
   18711      6120192 :   if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
   18712              :     {
   18713            6 :       error ("%qD has the same name as the class in which it is "
   18714              :              "declared", decl);
   18715            6 :       return error_mark_node;
   18716              :     }
   18717              : 
   18718              :   /* Two cases we need to consider when deciding if a class
   18719              :      template is allowed as an elaborated type specifier:
   18720              :      1. It is a self reference to its own class.
   18721              :      2. It comes with a template header.
   18722              : 
   18723              :      For example:
   18724              : 
   18725              :      template <class T> class C {
   18726              :        class C *c1;             // DECL_SELF_REFERENCE_P is true
   18727              :        class D;
   18728              :      };
   18729              :      template <class U> class C; // template_header_p is true
   18730              :      template <class T> class C<T>::D {
   18731              :        class C *c2;             // DECL_SELF_REFERENCE_P is true
   18732              :      };  */
   18733              : 
   18734     18360558 :   tree t = check_elaborated_type_specifier (tag_code, decl,
   18735              :                                             template_header_p
   18736     11811129 :                                             | DECL_SELF_REFERENCE_P (decl));
   18737      2697742 :   if (template_header_p && t && CLASS_TYPE_P (t)
   18738      8817916 :       && (!CLASSTYPE_TEMPLATE_INFO (t)
   18739      2697712 :           || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
   18740              :     {
   18741           21 :       auto_diagnostic_group d;
   18742           21 :       error ("%qT is not a template", t);
   18743           21 :       inform (location_of (t), "previous declaration here");
   18744           42 :       if (TYPE_CLASS_SCOPE_P (t)
   18745           24 :           && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
   18746            3 :         inform (input_location,
   18747              :                 "perhaps you want to explicitly add %<%T::%>",
   18748            3 :                 TYPE_CONTEXT (t));
   18749           21 :       return error_mark_node;
   18750           21 :     }
   18751              : 
   18752              :   return t;
   18753              : }
   18754              : 
   18755              : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
   18756              :    Define the tag as a forward-reference if it is not defined.
   18757              : 
   18758              :    If a declaration is given, process it here, and report an error if
   18759              :    multiple declarations are not identical.
   18760              : 
   18761              :    SCOPE is TS_CURRENT when this is also a definition.  Only look in
   18762              :    the current frame for the name (since C++ allows new names in any
   18763              :    scope.)  It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
   18764              :    declaration.  Only look beginning from the current scope outward up
   18765              :    till the nearest non-class scope.  Otherwise it is TS_GLOBAL.
   18766              : 
   18767              :    TEMPLATE_HEADER_P is true when this declaration is preceded by
   18768              :    a set of template parameters.  */
   18769              : 
   18770              : tree
   18771     27046048 : xref_tag (enum tag_types tag_code, tree name,
   18772              :           TAG_how how, bool template_header_p)
   18773              : {
   18774     27046048 :   enum tree_code code;
   18775     27046048 :   tree context = NULL_TREE;
   18776              : 
   18777     27046048 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
   18778              : 
   18779     27046048 :   gcc_assert (identifier_p (name));
   18780              : 
   18781     27046048 :   switch (tag_code)
   18782              :     {
   18783              :     case record_type:
   18784              :     case class_type:
   18785              :       code = RECORD_TYPE;
   18786              :       break;
   18787              :     case union_type:
   18788              :       code = UNION_TYPE;
   18789              :       break;
   18790              :     case enum_type:
   18791              :       code = ENUMERAL_TYPE;
   18792              :       break;
   18793            0 :     default:
   18794            0 :       gcc_unreachable ();
   18795              :     }
   18796              : 
   18797              :   /* In case of anonymous name, xref_tag is only called to
   18798              :      make type node and push name.  Name lookup is not required.  */
   18799     27046048 :   tree t = NULL_TREE;
   18800     27046048 :   if (!IDENTIFIER_ANON_P (name))
   18801     24627006 :     t = lookup_and_check_tag  (tag_code, name, how, template_header_p);
   18802              : 
   18803     27046048 :   if (t == error_mark_node)
   18804              :     return error_mark_node;
   18805              : 
   18806      2890411 :   if (how != TAG_how::CURRENT_ONLY && t && current_class_type
   18807      1382240 :       && template_class_depth (current_class_type)
   18808     27659342 :       && template_header_p)
   18809              :     {
   18810       357379 :       if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
   18811              :         return t;
   18812              : 
   18813              :       /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
   18814              :          a definition of this tag.  Since, in addition, we are
   18815              :          currently processing a (member) template declaration of a
   18816              :          template class, we must be very careful; consider:
   18817              : 
   18818              :            template <class X> struct S1
   18819              : 
   18820              :            template <class U> struct S2
   18821              :            {
   18822              :              template <class V> friend struct S1;
   18823              :            };
   18824              : 
   18825              :          Here, the S2::S1 declaration should not be confused with the
   18826              :          outer declaration.  In particular, the inner version should
   18827              :          have a template parameter of level 2, not level 1.
   18828              : 
   18829              :          On the other hand, when presented with:
   18830              : 
   18831              :            template <class T> struct S1
   18832              :            {
   18833              :              template <class U> struct S2 {};
   18834              :              template <class U> friend struct S2;
   18835              :            };
   18836              : 
   18837              :          the friend must find S1::S2 eventually.  We accomplish this
   18838              :          by making sure that the new type we create to represent this
   18839              :          declaration has the right TYPE_CONTEXT.  */
   18840       357376 :       context = TYPE_CONTEXT (t);
   18841       357376 :       t = NULL_TREE;
   18842              :     }
   18843              : 
   18844     27045922 :   if (! t)
   18845              :     {
   18846              :       /* If no such tag is yet defined, create a forward-reference node
   18847              :          and record it as the "definition".
   18848              :          When a real declaration of this type is found,
   18849              :          the forward-reference will be altered into a real type.  */
   18850     21319295 :       if (code == ENUMERAL_TYPE)
   18851              :         {
   18852           13 :           error ("use of enum %q#D without previous declaration", name);
   18853           13 :           return error_mark_node;
   18854              :         }
   18855              : 
   18856     21319282 :       t = make_class_type (code);
   18857     21319282 :       TYPE_CONTEXT (t) = context;
   18858     21319282 :       if (IDENTIFIER_LAMBDA_P (name))
   18859              :         /* Mark it as a lambda type right now.  Our caller will
   18860              :            correct the value.  */
   18861      1669339 :         SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node);
   18862     21319282 :       t = pushtag (name, t, how);
   18863              :     }
   18864              :   else
   18865              :     {
   18866      5726627 :       if (template_header_p && MAYBE_CLASS_TYPE_P (t))
   18867              :         {
   18868              :           /* Check that we aren't trying to overload a class with different
   18869              :              constraints.  */
   18870      2340333 :           if (!redeclare_class_template (t, current_template_parms,
   18871              :                                          current_template_constraints ()))
   18872           60 :             return error_mark_node;
   18873              :         }
   18874      3386294 :       else if (!processing_template_decl
   18875      3043819 :                && CLASS_TYPE_P (t)
   18876      6403774 :                && CLASSTYPE_IS_TEMPLATE (t))
   18877              :         {
   18878            0 :           auto_diagnostic_group d;
   18879            0 :           error ("redeclaration of %qT as a non-template", t);
   18880            0 :           inform (location_of (t), "previous declaration %qD", t);
   18881            0 :           return error_mark_node;
   18882            0 :         }
   18883              : 
   18884      5726567 :       if (modules_p ()
   18885      5726567 :           && how == TAG_how::CURRENT_ONLY)
   18886              :         {
   18887        13751 :           tree decl = TYPE_NAME (t);
   18888        13751 :           if (!module_may_redeclare (decl))
   18889           15 :             return error_mark_node;
   18890              : 
   18891        13736 :           tree not_tmpl = STRIP_TEMPLATE (decl);
   18892        13736 :           if (DECL_LANG_SPECIFIC (not_tmpl)
   18893         5513 :               && DECL_MODULE_ATTACH_P (not_tmpl)
   18894           57 :               && !DECL_MODULE_EXPORT_P (not_tmpl)
   18895        13778 :               && module_exporting_p ())
   18896              :             {
   18897            6 :               auto_diagnostic_group d;
   18898            6 :               error ("conflicting exporting for declaration %qD", decl);
   18899            6 :               inform (DECL_SOURCE_LOCATION (decl),
   18900              :                       "previously declared here without exporting");
   18901            6 :             }
   18902              : 
   18903        13736 :           tree maybe_tmpl = decl;
   18904        13736 :           if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
   18905        10244 :             maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
   18906              : 
   18907              :           /* FIXME: we should do a more precise check for redefinitions
   18908              :              of a conflicting using-declaration here, as these diagnostics
   18909              :              are not ideal.  */
   18910        13736 :           if (DECL_LANG_SPECIFIC (decl)
   18911         5513 :               && DECL_MODULE_IMPORT_P (decl)
   18912        14495 :               && CP_DECL_CONTEXT (decl) == current_namespace)
   18913              :             {
   18914              :               /* Push it into this TU's symbol slot.  */
   18915          759 :               if (maybe_tmpl != decl)
   18916              :                 /* We're in the template parm binding level.
   18917              :                    Pushtag has logic to slide under that, but we're
   18918              :                    not pushing a *new* type.  */
   18919          551 :                 push_nested_namespace (CP_DECL_CONTEXT (decl));
   18920              : 
   18921          759 :               pushdecl (maybe_tmpl);
   18922          759 :               if (maybe_tmpl != decl)
   18923          551 :                 pop_nested_namespace (CP_DECL_CONTEXT (decl));
   18924              :             }
   18925              : 
   18926        13736 :           set_instantiating_module (maybe_tmpl);
   18927              :         }
   18928              :     }
   18929              : 
   18930              :   return t;
   18931     27046048 : }
   18932              : 
   18933              : /* Create the binfo hierarchy for REF with (possibly NULL) base list
   18934              :    BASE_LIST.  For each element on BASE_LIST the TREE_PURPOSE is an
   18935              :    access_* node, and the TREE_VALUE is the type of the base-class.
   18936              :    Non-NULL TREE_TYPE indicates virtual inheritance.  */
   18937              : 
   18938              : void
   18939     72535642 : xref_basetypes (tree ref, tree base_list)
   18940              : {
   18941     72535642 :   tree *basep;
   18942     72535642 :   tree binfo, base_binfo;
   18943     72535642 :   unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases.  */
   18944     72535642 :   unsigned max_bases = 0;  /* Maximum direct bases.  */
   18945     72535642 :   unsigned max_dvbases = 0; /* Maximum direct virtual bases.  */
   18946              :   /* Highest direct base index with annotations.  */
   18947     72535642 :   unsigned max_annotated_base = 0;
   18948     72535642 :   int i;
   18949     72535642 :   tree default_access;
   18950     72535642 :   tree igo_prev; /* Track Inheritance Graph Order.  */
   18951              : 
   18952     72535642 :   if (ref == error_mark_node)
   18953           12 :     return;
   18954              : 
   18955              :   /* The base of a derived class is private by default, all others are
   18956              :      public.  */
   18957     72535642 :   default_access = (TREE_CODE (ref) == RECORD_TYPE
   18958     71902910 :                     && CLASSTYPE_DECLARED_CLASS (ref)
   18959     72535642 :                     ? access_private_node : access_public_node);
   18960              : 
   18961              :   /* First, make sure that any templates in base-classes are
   18962              :      instantiated.  This ensures that if we call ourselves recursively
   18963              :      we do not get confused about which classes are marked and which
   18964              :      are not.  */
   18965     72535642 :   basep = &base_list;
   18966    106141734 :   while (*basep)
   18967              :     {
   18968     33606092 :       tree basetype = TREE_VALUE (*basep);
   18969              : 
   18970              :       /* The dependent_type_p call below should really be dependent_scope_p
   18971              :          so that we give a hard error about using an incomplete type as a
   18972              :          base, but we allow it with a pedwarn for backward
   18973              :          compatibility.  */
   18974     33606092 :       if (processing_template_decl
   18975     33606092 :           && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
   18976            3 :         cxx_incomplete_type_diagnostic (NULL_TREE, basetype,
   18977              :                                         diagnostics::kind::pedwarn);
   18978     33606092 :       if (!dependent_type_p (basetype)
   18979     33606092 :           && !complete_type_or_else (basetype, NULL))
   18980              :         /* An incomplete type.  Remove it from the list.  */
   18981           15 :         *basep = TREE_CHAIN (*basep);
   18982              :       else
   18983              :         {
   18984     33606077 :           max_bases++;
   18985     33606077 :           if (TREE_CODE (TREE_PURPOSE (*basep)) == TREE_LIST)
   18986           28 :             max_annotated_base = max_bases;
   18987     33606077 :           if (TREE_TYPE (*basep))
   18988        68846 :             max_dvbases++;
   18989     33606077 :           if (CLASS_TYPE_P (basetype))
   18990     32790424 :             max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   18991     33606077 :           basep = &TREE_CHAIN (*basep);
   18992              :         }
   18993              :     }
   18994     72535642 :   max_vbases += max_dvbases;
   18995              : 
   18996     72535642 :   TYPE_MARKED_P (ref) = 1;
   18997              : 
   18998              :   /* The binfo slot should be empty, unless this is an (ill-formed)
   18999              :      redefinition.  */
   19000     72535642 :   gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
   19001              : 
   19002     72535642 :   gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
   19003              : 
   19004     72535642 :   binfo = make_tree_binfo (max_bases);
   19005              : 
   19006     72535642 :   TYPE_BINFO (ref) = binfo;
   19007     72535642 :   BINFO_OFFSET (binfo) = size_zero_node;
   19008     72535642 :   BINFO_TYPE (binfo) = ref;
   19009              : 
   19010              :   /* Apply base-class info set up to the variants of this type.  */
   19011     72535642 :   fixup_type_variants (ref);
   19012              : 
   19013     72535642 :   if (max_bases)
   19014              :     {
   19015     32684844 :       vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases + max_annotated_base);
   19016     32684844 :       BINFO_BASE_ACCESSES (binfo)->quick_grow (max_bases + max_annotated_base);
   19017              :       /* A C++98 POD cannot have base classes.  */
   19018     32684844 :       CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
   19019              : 
   19020     32684844 :       if (TREE_CODE (ref) == UNION_TYPE)
   19021              :         {
   19022           12 :           error ("derived union %qT invalid", ref);
   19023           12 :           return;
   19024              :         }
   19025              :     }
   19026              : 
   19027     32684832 :   if (max_bases > 1)
   19028       727629 :     warning (OPT_Wmultiple_inheritance,
   19029              :              "%qT defined with multiple direct bases", ref);
   19030              : 
   19031     72535630 :   if (max_vbases)
   19032              :     {
   19033              :       /* An aggregate can't have virtual base classes.  */
   19034       205538 :       CLASSTYPE_NON_AGGREGATE (ref) = true;
   19035              : 
   19036       205538 :       vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
   19037              : 
   19038       205538 :       if (max_dvbases)
   19039        67419 :         warning (OPT_Wvirtual_inheritance,
   19040              :                  "%qT defined with direct virtual base", ref);
   19041              :     }
   19042              : 
   19043    106141695 :   for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
   19044              :     {
   19045     33606065 :       tree access = TREE_PURPOSE (base_list);
   19046     33606065 :       tree annotations = NULL_TREE;
   19047     33606065 :       if (TREE_CODE (access) == TREE_LIST)
   19048              :         {
   19049           28 :           annotations = TREE_VALUE (access);
   19050           28 :           access = TREE_PURPOSE (access);
   19051           78 :           for (tree *d = &annotations; *d; )
   19052              :             {
   19053           50 :               if (annotation_p (*d))
   19054              :                 {
   19055           50 :                   tree name = get_attribute_name (*d);
   19056           50 :                   tree args = TREE_VALUE (*d);
   19057           50 :                   const attribute_spec *as
   19058           50 :                     = lookup_attribute_spec (TREE_PURPOSE (*d));
   19059           50 :                   bool no_add_attrs = false;
   19060           50 :                   as->handler (&binfo, name, args, 0, &no_add_attrs);
   19061           50 :                   if (no_add_attrs)
   19062              :                     {
   19063            2 :                       *d = TREE_CHAIN (*d);
   19064            2 :                       continue;
   19065              :                     }
   19066              :                 }
   19067           48 :               d = &TREE_CHAIN (*d);
   19068              :             }
   19069              :         }
   19070     33606065 :       int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
   19071     33606065 :       tree basetype = TREE_VALUE (base_list);
   19072              : 
   19073     33606065 :       if (access == access_default_node)
   19074      4589837 :         access = default_access;
   19075              : 
   19076              :       /* Before C++17, an aggregate cannot have base classes.  In C++17, an
   19077              :          aggregate can't have virtual, private, or protected base classes.  */
   19078     33606065 :       if (cxx_dialect < cxx17
   19079     33392128 :           || access != access_public_node
   19080     32430197 :           || via_virtual)
   19081      1241510 :         CLASSTYPE_NON_AGGREGATE (ref) = true;
   19082              : 
   19083     33606065 :       if (PACK_EXPANSION_P (basetype))
   19084        29765 :         basetype = PACK_EXPANSION_PATTERN (basetype);
   19085     33606065 :       if (TREE_CODE (basetype) == TYPE_DECL)
   19086            0 :         basetype = TREE_TYPE (basetype);
   19087     33606065 :       if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
   19088              :         {
   19089           24 :           error ("base type %qT fails to be a struct or class type",
   19090              :                  basetype);
   19091           24 :           goto dropped_base;
   19092              :         }
   19093     33606041 :       else if (ANON_AGGR_TYPE_P (basetype))
   19094              :         {
   19095            2 :           error ("base type %qT is anonymous struct type", basetype);
   19096            2 :           goto dropped_base;
   19097              :         }
   19098              : 
   19099     33606039 :       base_binfo = NULL_TREE;
   19100     33606039 :       if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
   19101              :         {
   19102     26493109 :           base_binfo = TYPE_BINFO (basetype);
   19103              :           /* The original basetype could have been a typedef'd type.  */
   19104     26493109 :           basetype = BINFO_TYPE (base_binfo);
   19105              : 
   19106              :           /* Inherit flags from the base.  */
   19107     79479327 :           TYPE_HAS_NEW_OPERATOR (ref)
   19108     26493109 :             |= TYPE_HAS_NEW_OPERATOR (basetype);
   19109     79479327 :           TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
   19110     26493109 :             |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
   19111     26493109 :           TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
   19112     26493109 :           TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
   19113     79479327 :           CLASSTYPE_DIAMOND_SHAPED_P (ref)
   19114     26493109 :             |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
   19115     79479327 :           CLASSTYPE_REPEATED_BASE_P (ref)
   19116     26493109 :             |= CLASSTYPE_REPEATED_BASE_P (basetype);
   19117              :         }
   19118              : 
   19119              :       /* We must do this test after we've seen through a typedef
   19120              :          type.  */
   19121     33606039 :       if (TYPE_MARKED_P (basetype))
   19122              :         {
   19123           18 :           if (basetype == ref)
   19124            0 :             error ("recursive type %qT undefined", basetype);
   19125              :           else
   19126           18 :             error ("duplicate base type %qT invalid", basetype);
   19127           18 :           goto dropped_base;
   19128              :         }
   19129              : 
   19130     33606021 :       if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
   19131              :         /* Regenerate the pack expansion for the bases. */
   19132        29765 :         basetype = make_pack_expansion (basetype);
   19133              : 
   19134     33606021 :       TYPE_MARKED_P (basetype) = 1;
   19135              : 
   19136     33606021 :       base_binfo = copy_binfo (base_binfo, basetype, ref,
   19137              :                                &igo_prev, via_virtual);
   19138     33606021 :       if (!BINFO_INHERITANCE_CHAIN (base_binfo))
   19139     33537190 :         BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
   19140              : 
   19141     33606021 :       unsigned len;
   19142     33606021 :       len = BINFO_N_BASE_BINFOS (binfo);
   19143     33606021 :       BINFO_BASE_APPEND (binfo, base_binfo);
   19144     33606021 :       BINFO_BASE_ACCESS (binfo, len) = access;
   19145     33606021 :       if (len < max_annotated_base)
   19146           34 :         BINFO_BASE_ACCESS (binfo, max_bases + len) = annotations;
   19147     33606021 :       continue;
   19148              : 
   19149           44 :     dropped_base:
   19150              :       /* Update max_vbases to reflect the reality that we are dropping
   19151              :          this base:  if it reaches zero we want to undo the vec_alloc
   19152              :          above to avoid inconsistencies during error-recovery: eg, in
   19153              :          build_special_member_call, CLASSTYPE_VBASECLASSES non null
   19154              :          and vtt null (c++/27952).  */
   19155           44 :       if (via_virtual)
   19156           12 :         max_vbases--;
   19157           44 :       if (CLASS_TYPE_P (basetype))
   19158           32 :         max_vbases
   19159           35 :           -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   19160     33606021 :     }
   19161              : 
   19162     72535630 :   unsigned len = BINFO_N_BASE_BINFOS (binfo);
   19163     72535630 :   if (len < max_bases)
   19164              :     {
   19165           44 :       if (len && max_annotated_base)
   19166            0 :         memmove (&BINFO_BASE_ACCESS (binfo, len),
   19167            0 :                  &BINFO_BASE_ACCESS (binfo, max_bases),
   19168            0 :                  MIN (max_annotated_base, len) * sizeof (tree));
   19169           44 :       BINFO_BASE_ACCESSES (binfo)->truncate (len + MIN (max_annotated_base,
   19170              :                                                         len));
   19171              :     }
   19172              : 
   19173     72535630 :   if (CLASSTYPE_VBASECLASSES (ref)
   19174     72535630 :       && max_vbases == 0)
   19175           24 :     vec_free (CLASSTYPE_VBASECLASSES (ref));
   19176              : 
   19177     72741156 :   if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
   19178              :     /* If we didn't get max_vbases vbases, we must have shared at
   19179              :        least one of them, and are therefore diamond shaped.  */
   19180        22276 :     CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
   19181              : 
   19182              :   /* Unmark all the types.  */
   19183    106141651 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   19184     33606021 :     TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   19185     72535630 :   TYPE_MARKED_P (ref) = 0;
   19186              : 
   19187              :   /* Now see if we have a repeated base type.  */
   19188     72535630 :   if (!CLASSTYPE_REPEATED_BASE_P (ref))
   19189              :     {
   19190    182843466 :       for (base_binfo = binfo; base_binfo;
   19191    110308272 :            base_binfo = TREE_CHAIN (base_binfo))
   19192              :         {
   19193    110309021 :           if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   19194              :             {
   19195          749 :               CLASSTYPE_REPEATED_BASE_P (ref) = 1;
   19196          749 :               break;
   19197              :             }
   19198    110308272 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
   19199              :         }
   19200    182843466 :       for (base_binfo = binfo; base_binfo;
   19201    110308272 :            base_binfo = TREE_CHAIN (base_binfo))
   19202    110309021 :         if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   19203    110308272 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   19204              :         else
   19205              :           break;
   19206              :     }
   19207              : }
   19208              : 
   19209              : 
   19210              : /* Copies the enum-related properties from type SRC to type DST.
   19211              :    Used with the underlying type of an enum and the enum itself.  */
   19212              : static void
   19213      2041882 : copy_type_enum (tree dst, tree src)
   19214              : {
   19215      2041882 :   tree t;
   19216      4083788 :   for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
   19217              :     {
   19218      2041906 :       TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
   19219      2041906 :       TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
   19220      2041906 :       TYPE_SIZE (t) = TYPE_SIZE (src);
   19221      2041906 :       TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
   19222      2041906 :       SET_TYPE_MODE (dst, TYPE_MODE (src));
   19223      2041906 :       TYPE_PRECISION (t) = TYPE_PRECISION (src);
   19224      2041906 :       unsigned valign = TYPE_ALIGN (src);
   19225      2041906 :       if (TYPE_USER_ALIGN (t))
   19226           12 :         valign = MAX (valign, TYPE_ALIGN (t));
   19227              :       else
   19228      2041894 :         TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
   19229      2041906 :       SET_TYPE_ALIGN (t, valign);
   19230      2041906 :       TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
   19231              :     }
   19232      2041882 : }
   19233              : 
   19234              : /* Begin compiling the definition of an enumeration type.
   19235              :    NAME is its name,
   19236              : 
   19237              :    if ENUMTYPE is not NULL_TREE then the type has already been found.
   19238              : 
   19239              :    UNDERLYING_TYPE is the type that will be used as the storage for
   19240              :    the enumeration type. This should be NULL_TREE if no storage type
   19241              :    was specified.
   19242              : 
   19243              :    ATTRIBUTES are any attributes specified after the enum-key.
   19244              : 
   19245              :    SCOPED_ENUM_P is true if this is a scoped enumeration type.
   19246              : 
   19247              :    if IS_NEW is not NULL, gets TRUE iff a new type is created.
   19248              : 
   19249              :    Returns the type object, as yet incomplete.
   19250              :    Also records info about it so that build_enumerator
   19251              :    may be used to declare the individual values as they are read.  */
   19252              : 
   19253              : tree
   19254      2407522 : start_enum (tree name, tree enumtype, tree underlying_type,
   19255              :             tree attributes, bool scoped_enum_p, bool *is_new)
   19256              : {
   19257      2407522 :   tree prevtype = NULL_TREE;
   19258      2407522 :   gcc_assert (identifier_p (name));
   19259              : 
   19260      2407522 :   if (is_new)
   19261      1941751 :     *is_new = false;
   19262              :   /* [C++0x dcl.enum]p5:
   19263              : 
   19264              :     If not explicitly specified, the underlying type of a scoped
   19265              :     enumeration type is int.  */
   19266      2407522 :   if (!underlying_type && scoped_enum_p)
   19267       179000 :     underlying_type = integer_type_node;
   19268              : 
   19269      2407522 :   if (underlying_type)
   19270       608609 :     underlying_type = cv_unqualified (underlying_type);
   19271              : 
   19272              :   /* If this is the real definition for a previous forward reference,
   19273              :      fill in the contents in the same object that used to be the
   19274              :      forward reference.  */
   19275      2407522 :   if (!enumtype)
   19276      2407377 :     enumtype = lookup_and_check_tag (enum_type, name,
   19277              :                                      /*tag_scope=*/TAG_how::CURRENT_ONLY,
   19278              :                                      /*template_header_p=*/false);
   19279              : 
   19280              :   /* In case of a template_decl, the only check that should be deferred
   19281              :      to instantiation time is the comparison of underlying types.  */
   19282      2407522 :   if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   19283              :     {
   19284              :       /* Attempt to set the declaring module.  */
   19285        36232 :       if (modules_p ())
   19286              :         {
   19287          252 :           tree decl = TYPE_NAME (enumtype);
   19288          252 :           if (!module_may_redeclare (decl))
   19289            3 :             enumtype = error_mark_node;
   19290          249 :           else if (COMPLETE_TYPE_P (enumtype)
   19291          249 :                    && redefinable_import_p (decl))
   19292           36 :             return enumtype;
   19293              :           else
   19294          213 :             set_instantiating_module (decl);
   19295              :         }
   19296              : 
   19297        36196 :       if (enumtype == error_mark_node)
   19298              :         ;
   19299        36409 :       else if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
   19300              :         {
   19301            6 :           auto_diagnostic_group d;
   19302            6 :           error_at (input_location, "scoped/unscoped mismatch "
   19303              :                     "in enum %q#T", enumtype);
   19304            6 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   19305              :                   "previous definition here");
   19306            6 :           enumtype = error_mark_node;
   19307            6 :         }
   19308        36187 :       else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
   19309              :         {
   19310            0 :           auto_diagnostic_group d;
   19311            0 :           error_at (input_location, "underlying type mismatch "
   19312              :                     "in enum %q#T", enumtype);
   19313            0 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   19314              :                   "previous definition here");
   19315            0 :           enumtype = error_mark_node;
   19316            0 :         }
   19317        36181 :       else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
   19318        72368 :                && !same_type_p (underlying_type,
   19319              :                                 ENUM_UNDERLYING_TYPE (enumtype)))
   19320              :         {
   19321           29 :           auto_diagnostic_group d;
   19322           29 :           error_at (input_location, "different underlying type "
   19323              :                     "in enum %q#T", enumtype);
   19324           29 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   19325              :                   "previous definition here");
   19326           29 :           underlying_type = NULL_TREE;
   19327           29 :         }
   19328              :     }
   19329              : 
   19330      2407486 :   if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
   19331        36187 :       || processing_template_decl)
   19332              :     {
   19333              :       /* In case of error, make a dummy enum to allow parsing to
   19334              :          continue.  */
   19335      2371400 :       if (enumtype == error_mark_node)
   19336              :         {
   19337           18 :           name = make_anon_name ();
   19338           18 :           enumtype = NULL_TREE;
   19339              :         }
   19340              : 
   19341              :       /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
   19342              :          of an opaque enum, or an opaque enum of an already defined
   19343              :          enumeration (C++11).
   19344              :          In any other case, it'll be NULL_TREE. */
   19345      2371400 :       if (!enumtype)
   19346              :         {
   19347      2371296 :           if (is_new)
   19348      1905525 :             *is_new = true;
   19349              :         }
   19350      2371400 :       prevtype = enumtype;
   19351              : 
   19352              :       /* Do not push the decl more than once.  */
   19353      2371400 :       if (!enumtype
   19354          104 :           || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   19355              :         {
   19356      2371299 :           enumtype = cxx_make_type (ENUMERAL_TYPE);
   19357      2371299 :           enumtype = pushtag (name, enumtype);
   19358              : 
   19359      2371299 :           if (enumtype != error_mark_node)
   19360              :             {
   19361              :               /* ??? We wouldn't need to repeat this if lookup_elaborated_type
   19362              :                  found (and pushed) mergeable types.  */
   19363      2371281 :               if (COMPLETE_TYPE_P (enumtype)
   19364      2371281 :                   && redefinable_import_p (TYPE_NAME (enumtype)))
   19365           42 :                 return enumtype;
   19366              : 
   19367              :               /* The enum is considered opaque until the opening '{' of the
   19368              :                  enumerator list.  */
   19369      2371239 :               SET_OPAQUE_ENUM_P (enumtype, true);
   19370      2371239 :               ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
   19371              : 
   19372              :               /* std::byte aliases anything.  */
   19373      2371239 :               if (TYPE_CONTEXT (enumtype) == std_node
   19374      2735187 :                   && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
   19375        13521 :                 TYPE_ALIAS_SET (enumtype) = 0;
   19376              :             }
   19377              :         }
   19378              :       else
   19379          101 :           enumtype = xref_tag (enum_type, name);
   19380              : 
   19381      2371358 :       if (enumtype == error_mark_node)
   19382              :         return error_mark_node;
   19383              :     }
   19384              : 
   19385      2407426 :   SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
   19386              : 
   19387      2407426 :   cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
   19388              : 
   19389      2407426 :   if (underlying_type)
   19390              :     {
   19391       608515 :       if (ENUM_UNDERLYING_TYPE (enumtype))
   19392              :         /* We already checked that it matches, don't change it to a different
   19393              :            typedef variant.  */;
   19394       572363 :       else if (CP_INTEGRAL_TYPE_P (underlying_type))
   19395              :         {
   19396       572289 :           copy_type_enum (enumtype, underlying_type);
   19397       572289 :           ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   19398              :         }
   19399           74 :       else if (dependent_type_p (underlying_type))
   19400           61 :         ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   19401              :       else
   19402              :         {
   19403           13 :           error ("underlying type %qT of %qT must be an integral type",
   19404              :                  underlying_type, enumtype);
   19405           13 :           copy_type_enum (enumtype, integer_type_node);
   19406           13 :           ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
   19407              :         }
   19408              :     }
   19409              : 
   19410              :   /* If into a template class, the returned enum is always the first
   19411              :      declaration (opaque or not) seen. This way all the references to
   19412              :      this type will be to the same declaration. The following ones are used
   19413              :      only to check for definition errors.  */
   19414      2407426 :   if (prevtype && processing_template_decl)
   19415              :     return prevtype;
   19416              :   else
   19417      2407325 :     return enumtype;
   19418              : }
   19419              : 
   19420              : /* Returns true if TYPE is an enum that uses an enumerator name for
   19421              :    linkage purposes at namespace scope.  The term is defined in [dcl.enum]/12
   19422              :    for all enums, not just those at namespace scope, but for backward ABI
   19423              :    compatibility we want to treat those not at namespace scope the old way
   19424              :    and e.g. mangle the class scope ones based on their position within the
   19425              :    class rather than the first enumerator.  */
   19426              : 
   19427              : bool
   19428    415164910 : enum_with_enumerator_for_linkage_p (tree type)
   19429              : {
   19430    415164910 :   return (cxx_dialect >= cxx20
   19431    410743992 :           && UNSCOPED_ENUM_P (type)
   19432     20134984 :           && TYPE_ANON_P (type)
   19433      3088088 :           && TYPE_VALUES (type)
   19434    417062289 :           && TYPE_NAMESPACE_SCOPE_P (type));
   19435              : }
   19436              : 
   19437              : /* After processing and defining all the values of an enumeration type,
   19438              :    install their decls in the enumeration type.
   19439              :    ENUMTYPE is the type object.  */
   19440              : 
   19441              : void
   19442      2301414 : finish_enum_value_list (tree enumtype)
   19443              : {
   19444      2301414 :   tree values;
   19445      2301414 :   tree underlying_type;
   19446      2301414 :   tree decl;
   19447      2301414 :   tree value;
   19448      2301414 :   tree minnode, maxnode;
   19449      2301414 :   tree t;
   19450              : 
   19451      2301414 :   ENUM_BEING_DEFINED_P (enumtype) = 0;
   19452              : 
   19453      2301414 :   bool fixed_underlying_type_p
   19454      2301414 :     = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
   19455              : 
   19456              :   /* We built up the VALUES in reverse order.  */
   19457      2301414 :   TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
   19458              : 
   19459              :   /* For an enum defined in a template, just set the type of the values;
   19460              :      all further processing is postponed until the template is
   19461              :      instantiated.  We need to set the type so that tsubst of a CONST_DECL
   19462              :      works.  */
   19463      2301414 :   if (processing_template_decl)
   19464              :     {
   19465       436005 :       for (values = TYPE_VALUES (enumtype);
   19466       784721 :            values;
   19467       436005 :            values = TREE_CHAIN (values))
   19468       436005 :         TREE_TYPE (TREE_VALUE (values)) = enumtype;
   19469              :       return;
   19470              :     }
   19471              : 
   19472              :   /* Determine the minimum and maximum values of the enumerators.  */
   19473      1952698 :   if (TYPE_VALUES (enumtype))
   19474              :     {
   19475              :       minnode = maxnode = NULL_TREE;
   19476              : 
   19477     11722870 :       for (values = TYPE_VALUES (enumtype);
   19478     13638703 :            values;
   19479     11722870 :            values = TREE_CHAIN (values))
   19480              :         {
   19481     11722870 :           decl = TREE_VALUE (values);
   19482              : 
   19483              :           /* [dcl.enum]: Following the closing brace of an enum-specifier,
   19484              :              each enumerator has the type of its enumeration.  Prior to the
   19485              :              closing brace, the type of each enumerator is the type of its
   19486              :              initializing value.  */
   19487     11722870 :           TREE_TYPE (decl) = enumtype;
   19488              : 
   19489              :           /* Update the minimum and maximum values, if appropriate.  */
   19490     11722870 :           value = DECL_INITIAL (decl);
   19491     11722870 :           if (!value || TREE_CODE (value) != INTEGER_CST)
   19492            7 :             value = integer_zero_node;
   19493              :           /* Figure out what the minimum and maximum values of the
   19494              :              enumerators are.  */
   19495     11722870 :           if (!minnode)
   19496              :             minnode = maxnode = value;
   19497      9807037 :           else if (tree_int_cst_lt (maxnode, value))
   19498              :             maxnode = value;
   19499      1506914 :           else if (tree_int_cst_lt (value, minnode))
   19500       171109 :             minnode = value;
   19501              :         }
   19502              :     }
   19503              :   else
   19504              :     /* [dcl.enum]
   19505              : 
   19506              :        If the enumerator-list is empty, the underlying type is as if
   19507              :        the enumeration had a single enumerator with value 0.  */
   19508        36865 :     minnode = maxnode = integer_zero_node;
   19509              : 
   19510      1952698 :   if (!fixed_underlying_type_p)
   19511              :     {
   19512              :       /* Compute the number of bits require to represent all values of the
   19513              :          enumeration.  We must do this before the type of MINNODE and
   19514              :          MAXNODE are transformed, since tree_int_cst_min_precision relies
   19515              :          on the TREE_TYPE of the value it is passed.  */
   19516      1469580 :       signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
   19517      1469580 :       int lowprec = tree_int_cst_min_precision (minnode, sgn);
   19518      1469580 :       int highprec = tree_int_cst_min_precision (maxnode, sgn);
   19519      1469580 :       int precision = MAX (lowprec, highprec);
   19520      1469580 :       unsigned int itk;
   19521      1469580 :       bool use_short_enum;
   19522              : 
   19523              :       /* Determine the underlying type of the enumeration.
   19524              : 
   19525              :          [dcl.enum]
   19526              : 
   19527              :          The underlying type of an enumeration is an integral type that
   19528              :          can represent all the enumerator values defined in the
   19529              :          enumeration.  It is implementation-defined which integral type is
   19530              :          used as the underlying type for an enumeration except that the
   19531              :          underlying type shall not be larger than int unless the value of
   19532              :          an enumerator cannot fit in an int or unsigned int.
   19533              : 
   19534              :          We use "int" or an "unsigned int" as the underlying type, even if
   19535              :          a smaller integral type would work, unless the user has
   19536              :          explicitly requested that we use the smallest possible type.  The
   19537              :          user can request that for all enumerations with a command line
   19538              :          flag, or for just one enumeration with an attribute.  */
   19539              : 
   19540      2939160 :       use_short_enum = flag_short_enums
   19541      1469580 :         || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
   19542              : 
   19543              :       /* If the precision of the type was specified with an attribute and it
   19544              :          was too small, give an error.  Otherwise, use it.  */
   19545      1469580 :       if (TYPE_PRECISION (enumtype))
   19546              :         {
   19547           11 :           if (precision > TYPE_PRECISION (enumtype))
   19548            0 :             error ("specified mode too small for enumerated values");
   19549              :           else
   19550              :             {
   19551           11 :               use_short_enum = true;
   19552           11 :               precision = TYPE_PRECISION (enumtype);
   19553              :             }
   19554              :         }
   19555              : 
   19556      2858132 :       for (itk = (use_short_enum ? itk_char : itk_int);
   19557      2858132 :            itk != itk_none;
   19558              :            itk++)
   19559              :         {
   19560      2858129 :           underlying_type = integer_types[itk];
   19561      2858129 :           if (underlying_type != NULL_TREE
   19562      2858111 :               && TYPE_PRECISION (underlying_type) >= precision
   19563      5714095 :               && TYPE_SIGN (underlying_type) == sgn)
   19564              :             break;
   19565              :         }
   19566      1469580 :       if (itk == itk_none)
   19567              :         {
   19568              :           /* DR 377
   19569              : 
   19570              :              IF no integral type can represent all the enumerator values, the
   19571              :              enumeration is ill-formed.  */
   19572            3 :           error ("no integral type can represent all of the enumerator values "
   19573              :                  "for %qT", enumtype);
   19574            3 :           precision = TYPE_PRECISION (long_long_integer_type_node);
   19575            3 :           underlying_type = integer_types[itk_unsigned_long_long];
   19576              :         }
   19577              : 
   19578              :       /* [dcl.enum]
   19579              : 
   19580              :          The value of sizeof() applied to an enumeration type, an object
   19581              :          of an enumeration type, or an enumerator, is the value of sizeof()
   19582              :          applied to the underlying type.  */
   19583      1469580 :       copy_type_enum (enumtype, underlying_type);
   19584              : 
   19585              :       /* Compute the minimum and maximum values for the type.
   19586              : 
   19587              :          [dcl.enum]
   19588              : 
   19589              :          For an enumeration where emin is the smallest enumerator and emax
   19590              :          is the largest, the values of the enumeration are the values of the
   19591              :          underlying type in the range bmin to bmax, where bmin and bmax are,
   19592              :          respectively, the smallest and largest values of the smallest bit-
   19593              :          field that can store emin and emax.  */
   19594              : 
   19595              :       /* The middle-end currently assumes that types with TYPE_PRECISION
   19596              :          narrower than their underlying type are suitably zero or sign
   19597              :          extended to fill their mode.  Similarly, it assumes that the front
   19598              :          end assures that a value of a particular type must be within
   19599              :          TYPE_MIN_VALUE and TYPE_MAX_VALUE.
   19600              : 
   19601              :          We used to set these fields based on bmin and bmax, but that led
   19602              :          to invalid assumptions like optimizing away bounds checking.  So
   19603              :          now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
   19604              :          TYPE_MAX_VALUE to the values for the mode above and only restrict
   19605              :          the ENUM_UNDERLYING_TYPE for the benefit of diagnostics.  */
   19606      1469580 :       ENUM_UNDERLYING_TYPE (enumtype)
   19607      1469580 :         = build_distinct_type_copy (underlying_type);
   19608      1469580 :       TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
   19609      1469580 :       set_min_and_max_values_for_integral_type
   19610      1469580 :         (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
   19611              : 
   19612              :       /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
   19613      1469580 :       if (flag_strict_enums)
   19614           38 :         set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
   19615              : 
   19616      1469580 :       if (use_short_enum)
   19617              :         {
   19618          126 :           TYPE_PACKED (enumtype) = use_short_enum;
   19619          126 :           fixup_attribute_variants (enumtype);
   19620              :         }
   19621              :     }
   19622              :   else
   19623       483118 :     underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
   19624              : 
   19625              :   /* If the enum is exported, mark the consts too.  */
   19626      1952698 :   bool export_p = (UNSCOPED_ENUM_P (enumtype)
   19627      1546460 :                    && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
   19628      1953286 :                    && at_namespace_scope_p ());
   19629              : 
   19630              :   /* Convert each of the enumerators to the type of the underlying
   19631              :      type of the enumeration.  */
   19632     13675568 :   for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
   19633              :     {
   19634     11722870 :       decl = TREE_VALUE (values);
   19635     11722870 :       iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
   19636     11722870 :       if (fixed_underlying_type_p)
   19637              :         /* If the enumeration type has a fixed underlying type, we
   19638              :            already checked all of the enumerator values.  */
   19639      4142126 :         value = DECL_INITIAL (decl);
   19640              :       else
   19641      7580744 :         value = perform_implicit_conversion (underlying_type,
   19642      7580744 :                                              DECL_INITIAL (decl),
   19643              :                                              tf_warning_or_error);
   19644     11722870 :       if (!value)
   19645            3 :         value = integer_zero_node;
   19646              :       /* Do not clobber shared ints.  But do share identical enumerators.  */
   19647     11722870 :       value = fold_convert (enumtype, value);
   19648              : 
   19649     11722870 :       DECL_INITIAL (decl) = value;
   19650     11722870 :       if (export_p)
   19651         3594 :         DECL_MODULE_EXPORT_P (decl) = true;
   19652     11722870 :     }
   19653              : 
   19654              :   /* Fix up all variant types of this enum type.  */
   19655      3905442 :   for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
   19656      1952744 :     TYPE_VALUES (t) = TYPE_VALUES (enumtype);
   19657              : 
   19658      1952698 :   if (at_class_scope_p ()
   19659      1039784 :       && COMPLETE_TYPE_P (current_class_type)
   19660      1952768 :       && UNSCOPED_ENUM_P (enumtype))
   19661              :     {
   19662           51 :       insert_late_enum_def_bindings (current_class_type, enumtype);
   19663              :       /* TYPE_FIELDS needs fixup.  */
   19664           51 :       fixup_type_variants (current_class_type);
   19665              :     }
   19666              : 
   19667              :   /* P2115: An unnamed enum uses the name of its first enumerator for
   19668              :      linkage purposes; reset the type linkage if that is the case.  */
   19669      1952698 :   if (enum_with_enumerator_for_linkage_p (enumtype))
   19670       348748 :     reset_type_linkage (enumtype);
   19671              : 
   19672              :   /* Finish debugging output for this type.  */
   19673      1952698 :   rest_of_type_compilation (enumtype, namespace_bindings_p ());
   19674              : 
   19675              :   /* Each enumerator now has the type of its enumeration.  Clear the cache
   19676              :      so that this change in types doesn't confuse us later on.  */
   19677      1952698 :   clear_cv_and_fold_caches ();
   19678              : }
   19679              : 
   19680              : /* Finishes the enum type. This is called only the first time an
   19681              :    enumeration is seen, be it opaque or odinary.
   19682              :    ENUMTYPE is the type object.  */
   19683              : 
   19684              : void
   19685      2290022 : finish_enum (tree enumtype)
   19686              : {
   19687      2290022 :   if (processing_template_decl)
   19688              :     {
   19689       348744 :       if (at_function_scope_p ())
   19690         9573 :         add_stmt (build_min (TAG_DEFN, enumtype));
   19691              :       return;
   19692              :     }
   19693              : 
   19694              :   /* If this is a forward declaration, there should not be any variants,
   19695              :      though we can get a variant in the middle of an enum-specifier with
   19696              :      wacky code like 'enum E { e = sizeof(const E*) };'  */
   19697      3882556 :   gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
   19698              :               && (TYPE_VALUES (enumtype)
   19699              :                   || !TYPE_NEXT_VARIANT (enumtype)));
   19700              : }
   19701              : 
   19702              : /* Build and install a CONST_DECL for an enumeration constant of the
   19703              :    enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
   19704              :    Apply ATTRIBUTES if available.  LOC is the location of NAME.
   19705              :    Assignment of sequential values by default is handled here.  */
   19706              : 
   19707              : tree
   19708     12158858 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
   19709              :                   location_t loc)
   19710              : {
   19711     12158858 :   tree decl;
   19712     12158858 :   tree context;
   19713     12158858 :   tree type;
   19714              : 
   19715              :   /* scalar_constant_value will pull out this expression, so make sure
   19716              :      it's folded as appropriate.
   19717              : 
   19718              :      Creating a TARGET_EXPR in a template breaks when substituting, and
   19719              :      here we would create it for instance when using a class prvalue with
   19720              :      a user-defined conversion function.  So don't use such a tree.  We
   19721              :      instantiate VALUE here to get errors about bad enumerators even in
   19722              :      a template that does not get instantiated.  */
   19723     12158858 :   if (processing_template_decl)
   19724       436005 :     value = maybe_fold_non_dependent_expr (value);
   19725              : 
   19726              :   /* If the VALUE was erroneous, pretend it wasn't there; that will
   19727              :      result in the enum being assigned the next value in sequence.  */
   19728     12158858 :   if (value == error_mark_node)
   19729              :     value = NULL_TREE;
   19730              : 
   19731              :   /* Remove no-op casts from the value.  */
   19732     12158820 :   if (value)
   19733      9319937 :     STRIP_TYPE_NOPS (value);
   19734              : 
   19735     12158858 :   if (! processing_template_decl)
   19736              :     {
   19737              :       /* Validate and default VALUE.  */
   19738     11722853 :       if (value != NULL_TREE)
   19739              :         {
   19740      5325848 :           if (!ENUM_UNDERLYING_TYPE (enumtype))
   19741              :             {
   19742      2685975 :               tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   19743              :                                                            value, true);
   19744      2685975 :               if (tmp_value)
   19745      5325848 :                 value = tmp_value;
   19746              :             }
   19747      2639873 :           else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   19748              :                    (TREE_TYPE (value)))
   19749           39 :             value = perform_implicit_conversion_flags
   19750           39 :               (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
   19751              :                LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
   19752              : 
   19753      5325848 :           if (value == error_mark_node)
   19754              :             value = NULL_TREE;
   19755              : 
   19756      5325827 :           if (value != NULL_TREE)
   19757              :             {
   19758      5325827 :               if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   19759              :                   (TREE_TYPE (value)))
   19760              :                 {
   19761           17 :                   error_at (cp_expr_loc_or_input_loc (value),
   19762              :                             "enumerator value for %qD must have integral or "
   19763              :                             "unscoped enumeration type", name);
   19764           17 :                   value = NULL_TREE;
   19765              :                 }
   19766              :               else
   19767              :                 {
   19768      5325810 :                   value = cxx_constant_value (value);
   19769              : 
   19770      5325810 :                   if (TREE_CODE (value) != INTEGER_CST)
   19771              :                     {
   19772           48 :                       error ("enumerator value for %qD is not an integer "
   19773              :                              "constant", name);
   19774           48 :                       value = NULL_TREE;
   19775              :                     }
   19776              :                 }
   19777              :             }
   19778              :         }
   19779              : 
   19780              :       /* Default based on previous value.  */
   19781           65 :       if (value == NULL_TREE)
   19782              :         {
   19783      6397091 :           if (TYPE_VALUES (enumtype))
   19784              :             {
   19785      5857493 :               tree prev_value;
   19786              : 
   19787              :               /* C++03 7.2/4: If no initializer is specified for the first
   19788              :                  enumerator, the type is an unspecified integral
   19789              :                  type. Otherwise the type is the same as the type of the
   19790              :                  initializing value of the preceding enumerator unless the
   19791              :                  incremented value is not representable in that type, in
   19792              :                  which case the type is an unspecified integral type
   19793              :                  sufficient to contain the incremented value.  */
   19794      5857493 :               prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
   19795      5857493 :               if (TREE_CODE (prev_value) != INTEGER_CST)
   19796            2 :                 value = error_mark_node;
   19797              :               else
   19798              :                 {
   19799      5857491 :                   wi::overflow_type overflowed;
   19800      5857491 :                   tree type = TREE_TYPE (prev_value);
   19801      5857491 :                   signop sgn = TYPE_SIGN (type);
   19802      5857491 :                   widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
   19803      5857491 :                                            &overflowed);
   19804      5857491 :                   if (!overflowed)
   19805              :                     {
   19806      5857491 :                       bool pos = !wi::neg_p (wi, sgn);
   19807      5857491 :                       if (!wi::fits_to_tree_p (wi, type))
   19808              :                         {
   19809              :                           unsigned int itk;
   19810           53 :                           for (itk = itk_int; itk != itk_none; itk++)
   19811              :                             {
   19812           53 :                               type = integer_types[itk];
   19813           53 :                               if (type != NULL_TREE
   19814           53 :                                   && (pos || !TYPE_UNSIGNED (type))
   19815          106 :                                   && wi::fits_to_tree_p (wi, type))
   19816              :                                 break;
   19817              :                             }
   19818           17 :                           if (type && cxx_dialect < cxx11
   19819            6 :                               && itk > itk_unsigned_long)
   19820            3 :                             pedwarn (input_location, OPT_Wlong_long,
   19821              :                                      pos ? G_("\
   19822              : incremented enumerator value is too large for %<unsigned long%>") : G_("\
   19823              : incremented enumerator value is too large for %<long%>"));
   19824              :                         }
   19825      5857491 :                       if (type == NULL_TREE)
   19826            0 :                         overflowed = wi::OVF_UNKNOWN;
   19827              :                       else
   19828      5857491 :                         value = wide_int_to_tree (type, wi);
   19829              :                     }
   19830              : 
   19831      5857491 :                   if (overflowed)
   19832              :                     {
   19833            0 :                       error ("overflow in enumeration values at %qD", name);
   19834            0 :                       value = error_mark_node;
   19835              :                     }
   19836      5857491 :                 }
   19837              :             }
   19838              :           else
   19839       539598 :             value = integer_zero_node;
   19840              :         }
   19841              : 
   19842              :       /* Remove no-op casts from the value.  */
   19843     11722853 :       STRIP_TYPE_NOPS (value);
   19844              : 
   19845              :       /* If the underlying type of the enum is fixed, check whether
   19846              :          the enumerator values fits in the underlying type.  If it
   19847              :          does not fit, the program is ill-formed [C++0x dcl.enum].  */
   19848     11722853 :       if (ENUM_UNDERLYING_TYPE (enumtype)
   19849              :           && value
   19850     11722853 :           && TREE_CODE (value) == INTEGER_CST)
   19851              :         {
   19852      4142107 :           if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
   19853            9 :             error ("enumerator value %qE is outside the range of underlying "
   19854            9 :                    "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
   19855              : 
   19856              :           /* Convert the value to the appropriate type.  */
   19857      4142107 :           value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
   19858              :         }
   19859              :     }
   19860              : 
   19861              :   /* C++ associates enums with global, function, or class declarations.  */
   19862     12158858 :   context = current_scope ();
   19863              : 
   19864              :   /* Build the actual enumeration constant.  Note that the enumeration
   19865              :      constants have the underlying type of the enum (if it is fixed)
   19866              :      or the type of their initializer (if the underlying type of the
   19867              :      enum is not fixed):
   19868              : 
   19869              :       [ C++0x dcl.enum ]
   19870              : 
   19871              :         If the underlying type is fixed, the type of each enumerator
   19872              :         prior to the closing brace is the underlying type; if the
   19873              :         initializing value of an enumerator cannot be represented by
   19874              :         the underlying type, the program is ill-formed. If the
   19875              :         underlying type is not fixed, the type of each enumerator is
   19876              :         the type of its initializing value.
   19877              : 
   19878              :     If the underlying type is not fixed, it will be computed by
   19879              :     finish_enum and we will reset the type of this enumerator.  Of
   19880              :     course, if we're processing a template, there may be no value.  */
   19881     12158858 :   type = value ? TREE_TYPE (value) : NULL_TREE;
   19882              : 
   19883     12158858 :   decl = build_decl (loc, CONST_DECL, name, type);
   19884              : 
   19885     12158858 :   DECL_CONTEXT (decl) = enumtype;
   19886     12158858 :   TREE_CONSTANT (decl) = 1;
   19887     12158858 :   TREE_READONLY (decl) = 1;
   19888     12158858 :   DECL_INITIAL (decl) = value;
   19889              : 
   19890     12158858 :   if (attributes)
   19891       141850 :     cplus_decl_attributes (&decl, attributes, 0);
   19892              : 
   19893     12158858 :   if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
   19894              :     {
   19895              :       /* In something like `struct S { enum E { i = 7 }; };' we put `i'
   19896              :          on the TYPE_FIELDS list for `S'.  (That's so that you can say
   19897              :          things like `S::i' later.)  */
   19898              : 
   19899              :       /* The enumerator may be getting declared outside of its enclosing
   19900              :          class, like so:
   19901              : 
   19902              :            class S { public: enum E : int; }; enum S::E : int { i = 7; };
   19903              : 
   19904              :          For which case we need to make sure that the access of `S::i'
   19905              :          matches the access of `S::E'.  */
   19906      2099233 :       auto cas = make_temp_override (current_access_specifier);
   19907      2099233 :       set_current_access_from_decl (TYPE_NAME (enumtype));
   19908      2099233 :       finish_member_declaration (decl);
   19909      2099233 :     }
   19910              :   else
   19911     10059625 :     pushdecl (decl);
   19912              : 
   19913              :   /* Add this enumeration constant to the list for this type.  */
   19914     12158858 :   TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
   19915              : 
   19916     12158858 :   return decl;
   19917              : }
   19918              : 
   19919              : /* Look for an enumerator with the given NAME within the enumeration
   19920              :    type ENUMTYPE.  This routine is used primarily for qualified name
   19921              :    lookup into an enumerator in C++0x, e.g.,
   19922              : 
   19923              :      enum class Color { Red, Green, Blue };
   19924              : 
   19925              :      Color color = Color::Red;
   19926              : 
   19927              :    Returns the value corresponding to the enumerator, or
   19928              :    NULL_TREE if no such enumerator was found.  */
   19929              : tree
   19930     29415871 : lookup_enumerator (tree enumtype, tree name)
   19931              : {
   19932     29415871 :   tree e;
   19933     29415871 :   gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
   19934              : 
   19935     29415871 :   e = purpose_member (name, TYPE_VALUES (enumtype));
   19936     58831644 :   return e? TREE_VALUE (e) : NULL_TREE;
   19937              : }
   19938              : 
   19939              : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   19940              : 
   19941              : tree
   19942            0 : cxx_simulate_enum_decl (location_t loc, const char *name,
   19943              :                         vec<string_int_pair> *values)
   19944              : {
   19945            0 :   location_t saved_loc = input_location;
   19946            0 :   input_location = loc;
   19947              : 
   19948            0 :   tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
   19949              :                               NULL_TREE, false, NULL);
   19950            0 :   if (!OPAQUE_ENUM_P (enumtype))
   19951              :     {
   19952            0 :       auto_diagnostic_group d;
   19953            0 :       error_at (loc, "multiple definition of %q#T", enumtype);
   19954            0 :       inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   19955              :               "previous definition here");
   19956            0 :       return enumtype;
   19957            0 :     }
   19958            0 :   SET_OPAQUE_ENUM_P (enumtype, false);
   19959            0 :   DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
   19960              : 
   19961            0 :   for (const string_int_pair &value : values)
   19962            0 :     build_enumerator (get_identifier (value.first),
   19963            0 :                       build_int_cst (integer_type_node, value.second),
   19964              :                       enumtype, NULL_TREE, loc);
   19965              : 
   19966            0 :   finish_enum_value_list (enumtype);
   19967            0 :   finish_enum (enumtype);
   19968              : 
   19969            0 :   input_location = saved_loc;
   19970            0 :   return enumtype;
   19971              : }
   19972              : 
   19973              : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   19974              : 
   19975              : tree
   19976            0 : cxx_simulate_record_decl (location_t loc, const char *name,
   19977              :                           array_slice<const tree> fields)
   19978              : {
   19979            0 :   iloc_sentinel ils (loc);
   19980              : 
   19981            0 :   tree ident = get_identifier (name);
   19982            0 :   tree type = xref_tag (/*tag_code=*/record_type, ident);
   19983            0 :   if (type != error_mark_node
   19984            0 :       && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
   19985              :     {
   19986            0 :       error ("redefinition of %q#T", type);
   19987            0 :       type = error_mark_node;
   19988              :     }
   19989            0 :   if (type == error_mark_node)
   19990            0 :     return lhd_simulate_record_decl (loc, name, fields);
   19991              : 
   19992            0 :   xref_basetypes (type, NULL_TREE);
   19993            0 :   type = begin_class_definition (type);
   19994            0 :   if (type == error_mark_node)
   19995            0 :     return lhd_simulate_record_decl (loc, name, fields);
   19996              : 
   19997            0 :   for (tree field : fields)
   19998            0 :     finish_member_declaration (field);
   19999              : 
   20000            0 :   type = finish_struct (type, NULL_TREE);
   20001              : 
   20002            0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   20003            0 :   set_underlying_type (decl);
   20004            0 :   lang_hooks.decls.pushdecl (decl);
   20005              : 
   20006            0 :   return type;
   20007            0 : }
   20008              : 
   20009              : /* We're defining DECL.  Make sure that its type is OK.  */
   20010              : 
   20011              : static void
   20012    166972196 : check_function_type (tree decl, tree current_function_parms)
   20013              : {
   20014    166972196 :   tree fntype = TREE_TYPE (decl);
   20015    166972196 :   tree return_type = complete_type (TREE_TYPE (fntype));
   20016              : 
   20017              :   /* In a function definition, arg types must be complete.  */
   20018    166972196 :   require_complete_types_for_parms (current_function_parms);
   20019              : 
   20020    166972196 :   if (dependent_type_p (return_type)
   20021    166972196 :       || type_uses_auto (return_type))
   20022              :     return;
   20023    113934122 :   if (!COMPLETE_OR_VOID_TYPE_P (return_type))
   20024              :     {
   20025           12 :       tree args = TYPE_ARG_TYPES (fntype);
   20026              : 
   20027           12 :       error ("return type %q#T is incomplete", return_type);
   20028              : 
   20029              :       /* Make it return void instead.  */
   20030           12 :       if (TREE_CODE (fntype) == METHOD_TYPE)
   20031            3 :         fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
   20032              :                                              void_type_node,
   20033            3 :                                              TREE_CHAIN (args));
   20034              :       else
   20035           18 :         fntype = build_function_type (void_type_node, args,
   20036            9 :                                       TYPE_NO_NAMED_ARGS_STDARG_P (fntype));
   20037           12 :       fntype = (cp_build_type_attribute_variant
   20038           12 :                 (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
   20039           12 :       fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
   20040           12 :       TREE_TYPE (decl) = fntype;
   20041              :     }
   20042              :   else
   20043              :     {
   20044    113934110 :       abstract_virtuals_error (decl, TREE_TYPE (fntype));
   20045    113934110 :       maybe_warn_parm_abi (TREE_TYPE (fntype),
   20046    113934110 :                            DECL_SOURCE_LOCATION (decl));
   20047              :     }
   20048              : }
   20049              : 
   20050              : /* True iff FN is an implicitly-defined default constructor.  */
   20051              : 
   20052              : static bool
   20053     17399932 : implicit_default_ctor_p (tree fn)
   20054              : {
   20055     17399932 :   return (DECL_CONSTRUCTOR_P (fn)
   20056     17399932 :           && !user_provided_p (fn)
   20057     19374090 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
   20058              : }
   20059              : 
   20060              : /* Clobber the contents of *this to let the back end know that the object
   20061              :    storage is dead when we enter the constructor or leave the destructor.  */
   20062              : 
   20063              : static tree
   20064      1514594 : build_clobber_this (clobber_kind kind)
   20065              : {
   20066              :   /* Clobbering an empty base is pointless, and harmful if its one byte
   20067              :      TYPE_SIZE overlays real data.  */
   20068      1514594 :   if (is_empty_class (current_class_type))
   20069            0 :     return void_node;
   20070              : 
   20071              :   /* If we have virtual bases, clobber the whole object, but only if we're in
   20072              :      charge.  If we don't have virtual bases, clobber the as-base type so we
   20073              :      don't mess with tail padding.  */
   20074      1514594 :   bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
   20075              : 
   20076      1514594 :   tree ctype = current_class_type;
   20077      1514594 :   if (!vbases)
   20078      1507089 :     ctype = CLASSTYPE_AS_BASE (ctype);
   20079              : 
   20080      1514594 :   tree clobber = build_clobber (ctype, kind);
   20081              : 
   20082      1514594 :   tree thisref = current_class_ref;
   20083      1514594 :   if (ctype != current_class_type)
   20084              :     {
   20085       173282 :       thisref = build_nop (build_reference_type (ctype), current_class_ptr);
   20086       173282 :       thisref = convert_from_reference (thisref);
   20087              :     }
   20088              : 
   20089      1514594 :   tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
   20090      1514594 :   if (kind == CLOBBER_OBJECT_BEGIN)
   20091            0 :     TREE_SET_CODE (exprstmt, INIT_EXPR);
   20092      1514594 :   if (vbases)
   20093         7505 :     exprstmt = build_if_in_charge (exprstmt);
   20094              : 
   20095              :   return exprstmt;
   20096              : }
   20097              : 
   20098              : /* Create the FUNCTION_DECL for a function definition.
   20099              :    DECLSPECS and DECLARATOR are the parts of the declaration;
   20100              :    they describe the function's name and the type it returns,
   20101              :    but twisted together in a fashion that parallels the syntax of C.
   20102              : 
   20103              :    FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
   20104              :    DECLARATOR is really the DECL for the function we are about to
   20105              :    process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
   20106              :    indicating that the function is an inline defined in-class.
   20107              : 
   20108              :    This function creates a binding context for the function body
   20109              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   20110              : 
   20111              :    For C++, we must first check whether that datum makes any sense.
   20112              :    For example, "class A local_a(1,2);" means that variable local_a
   20113              :    is an aggregate of type A, which should have a constructor
   20114              :    applied to it with the argument list [1, 2].
   20115              : 
   20116              :    On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
   20117              :    or may be a BLOCK if the function has been defined previously
   20118              :    in this translation unit.  On exit, DECL_INITIAL (decl1) will be
   20119              :    error_mark_node if the function has never been defined, or
   20120              :    a BLOCK if the function has been defined somewhere.  */
   20121              : 
   20122              : bool
   20123    166972232 : start_preparsed_function (tree decl1, tree attrs, int flags)
   20124              : {
   20125    166972232 :   tree ctype = NULL_TREE;
   20126    166972232 :   bool doing_friend = false;
   20127              : 
   20128              :   /* Sanity check.  */
   20129    166972232 :   gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
   20130    166972232 :   gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
   20131              : 
   20132    166972232 :   tree fntype = TREE_TYPE (decl1);
   20133    166972232 :   if (DECL_CLASS_SCOPE_P (decl1))
   20134    123035500 :     ctype = DECL_CONTEXT (decl1);
   20135              :   else
   20136              :     {
   20137     87873464 :       ctype = DECL_FRIEND_CONTEXT (decl1);
   20138              : 
   20139     43936731 :       if (ctype)
   20140    166972232 :         doing_friend = true;
   20141              :     }
   20142              : 
   20143              :   /* Adjust for #pragma target/optimize if this is an artificial function that
   20144              :      (probably) didn't go through grokfndecl.  We particularly don't want this
   20145              :      for deferred instantiations, which should match their template.  */
   20146    166972232 :   if (DECL_ARTIFICIAL (decl1))
   20147      3947393 :     decl_attributes (&decl1, NULL_TREE, 0);
   20148              : 
   20149    166972232 :   if (DECL_DECLARED_INLINE_P (decl1)
   20150    166972232 :       && lookup_attribute ("noinline", attrs))
   20151              :     {
   20152            0 :       auto_urlify_attributes sentinel;
   20153            0 :       warning_at (DECL_SOURCE_LOCATION (decl1), 0,
   20154              :                   "inline function %qD given attribute %qs", decl1, "noinline");
   20155            0 :     }
   20156              : 
   20157              :   /* Handle gnu_inline attribute.  */
   20158    166972232 :   if (GNU_INLINE_P (decl1))
   20159              :     {
   20160      2009796 :       DECL_EXTERNAL (decl1) = 1;
   20161      2009796 :       DECL_NOT_REALLY_EXTERN (decl1) = 0;
   20162      2009796 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   20163      2009796 :       DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
   20164              :     }
   20165              : 
   20166    166972232 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
   20167              :     /* This is a constructor, we must ensure that any default args
   20168              :        introduced by this definition are propagated to the clones
   20169              :        now. The clones are used directly in overload resolution.  */
   20170     20796417 :     adjust_clone_args (decl1);
   20171              : 
   20172              :   /* Sometimes we don't notice that a function is a static member, and
   20173              :      build a METHOD_TYPE for it.  Fix that up now.  */
   20174    166972232 :   gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
   20175              :                 && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
   20176              : 
   20177              :   /* Set up current_class_type, and enter the scope of the class, if
   20178              :      appropriate.  */
   20179    166972232 :   if (ctype)
   20180    127796584 :     push_nested_class (ctype);
   20181              : 
   20182              :   /* Now that we have entered the scope of the class, we must restore
   20183              :      the bindings for any template parameters surrounding DECL1, if it
   20184              :      is an inline member template.  (Order is important; consider the
   20185              :      case where a template parameter has the same name as a field of
   20186              :      the class.)  It is not until after this point that
   20187              :      PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly.  */
   20188    166972232 :   if (flags & SF_INCLASS_INLINE)
   20189     85716197 :     maybe_begin_member_template_processing (decl1);
   20190              : 
   20191              :   /* Effective C++ rule 15.  */
   20192    166972232 :   if (warn_ecpp
   20193          123 :       && DECL_ASSIGNMENT_OPERATOR_P (decl1)
   20194           30 :       && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
   20195    166972262 :       && VOID_TYPE_P (TREE_TYPE (fntype)))
   20196            0 :     warning (OPT_Weffc__,
   20197              :              "%<operator=%> should return a reference to %<*this%>");
   20198              : 
   20199              :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   20200              :      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
   20201    166972232 :   if (!DECL_INITIAL (decl1))
   20202     36356973 :     DECL_INITIAL (decl1) = error_mark_node;
   20203              : 
   20204              :   /* This function exists in static storage.
   20205              :      (This does not mean `static' in the C sense!)  */
   20206    166972232 :   TREE_STATIC (decl1) = 1;
   20207              : 
   20208              :   /* We must call push_template_decl after current_class_type is set
   20209              :      up.  (If we are processing inline definitions after exiting a
   20210              :      class scope, current_class_type will be NULL_TREE until set above
   20211              :      by push_nested_class.)  */
   20212    166972232 :   if (processing_template_decl)
   20213              :     {
   20214     98003681 :       tree newdecl1 = push_template_decl (decl1, doing_friend);
   20215     98003681 :       if (newdecl1 == error_mark_node)
   20216              :         {
   20217           36 :           if (ctype)
   20218            9 :             pop_nested_class ();
   20219              :           return false;
   20220              :         }
   20221     98003645 :       decl1 = newdecl1;
   20222              :     }
   20223              : 
   20224              :   /* Make sure the parameter and return types are reasonable.  When
   20225              :      you declare a function, these types can be incomplete, but they
   20226              :      must be complete when you define the function.  */
   20227    166972196 :   check_function_type (decl1, DECL_ARGUMENTS (decl1));
   20228              : 
   20229              :   /* Build the return declaration for the function.  */
   20230    166972196 :   tree restype = TREE_TYPE (fntype);
   20231              : 
   20232    166972196 :   if (DECL_RESULT (decl1) == NULL_TREE)
   20233              :     {
   20234              :       /* In a template instantiation, copy the return type location.  When
   20235              :          parsing, the location will be set in grokdeclarator.  */
   20236     68995107 :       location_t loc = input_location;
   20237     68995107 :       if (DECL_TEMPLATE_INSTANTIATION (decl1))
   20238              :         {
   20239     32734477 :           tree tmpl = template_for_substitution (decl1);
   20240     32734477 :           if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
   20241     31780505 :             loc = DECL_SOURCE_LOCATION (res);
   20242              :         }
   20243              : 
   20244     68995107 :       tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   20245     68995107 :       DECL_ARTIFICIAL (resdecl) = 1;
   20246     68995107 :       DECL_IGNORED_P (resdecl) = 1;
   20247     68995107 :       DECL_RESULT (decl1) = resdecl;
   20248              : 
   20249     68995107 :       cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
   20250              :     }
   20251              : 
   20252              :   /* Record the decl so that the function name is defined.
   20253              :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   20254              :      use the old decl.  */
   20255    166972196 :   if (!processing_template_decl && !(flags & SF_PRE_PARSED))
   20256              :     {
   20257              :       /* A specialization is not used to guide overload resolution.  */
   20258     20648459 :       if (!DECL_FUNCTION_MEMBER_P (decl1)
   20259     20628621 :           && !(DECL_USE_TEMPLATE (decl1) &&
   20260        13354 :                PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
   20261              :         {
   20262      9889048 :           tree olddecl = pushdecl (decl1);
   20263              : 
   20264      9889048 :           if (olddecl == error_mark_node)
   20265              :             /* If something went wrong when registering the declaration,
   20266              :                use DECL1; we have to have a FUNCTION_DECL to use when
   20267              :                parsing the body of the function.  */
   20268              :             ;
   20269              :           else
   20270              :             {
   20271              :               /* Otherwise, OLDDECL is either a previous declaration
   20272              :                  of the same function or DECL1 itself.  */
   20273              : 
   20274      9888835 :               if (warn_missing_declarations
   20275           21 :                   && olddecl == decl1
   20276           15 :                   && !DECL_MAIN_P (decl1)
   20277           15 :                   && TREE_PUBLIC (decl1)
   20278      9888847 :                   && !DECL_DECLARED_INLINE_P (decl1))
   20279              :                 {
   20280            9 :                   tree context;
   20281              : 
   20282              :                   /* Check whether DECL1 is in an anonymous
   20283              :                      namespace.  */
   20284            9 :                   for (context = DECL_CONTEXT (decl1);
   20285           18 :                        context;
   20286            9 :                        context = DECL_CONTEXT (context))
   20287              :                     {
   20288           12 :                       if (TREE_CODE (context) == NAMESPACE_DECL
   20289           12 :                           && DECL_NAME (context) == NULL_TREE)
   20290              :                         break;
   20291              :                     }
   20292              : 
   20293            9 :                   if (context == NULL)
   20294            6 :                     warning_at (DECL_SOURCE_LOCATION (decl1),
   20295            6 :                                 OPT_Wmissing_declarations,
   20296              :                                 "no previous declaration for %qD", decl1);
   20297              :                 }
   20298              : 
   20299      9888835 :               decl1 = olddecl;
   20300              :             }
   20301              :         }
   20302              :       else
   20303              :         {
   20304              :           /* We need to set the DECL_CONTEXT.  */
   20305       837171 :           if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
   20306            0 :             DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
   20307              :         }
   20308     10726219 :       fntype = TREE_TYPE (decl1);
   20309     10726219 :       restype = TREE_TYPE (fntype);
   20310              : 
   20311              :       /* If #pragma weak applies, mark the decl appropriately now.
   20312              :          The pragma only applies to global functions.  Because
   20313              :          determining whether or not the #pragma applies involves
   20314              :          computing the mangled name for the declaration, we cannot
   20315              :          apply the pragma until after we have merged this declaration
   20316              :          with any previous declarations; if the original declaration
   20317              :          has a linkage specification, that specification applies to
   20318              :          the definition as well, and may affect the mangled name.  */
   20319     10726219 :       if (DECL_FILE_SCOPE_P (decl1))
   20320      2555185 :         maybe_apply_pragma_weak (decl1);
   20321              :     }
   20322              : 
   20323              :   /* We are now in the scope of the function being defined.  */
   20324    166972196 :   current_function_decl = decl1;
   20325              : 
   20326              :   /* Save the parm names or decls from this function's declarator
   20327              :      where store_parm_decls will find them.  */
   20328    166972196 :   tree current_function_parms = DECL_ARGUMENTS (decl1);
   20329              : 
   20330              :   /* Let the user know we're compiling this function.  */
   20331    166972196 :   announce_function (decl1);
   20332              : 
   20333    166972196 :   gcc_assert (DECL_INITIAL (decl1));
   20334              : 
   20335              :   /* This function may already have been parsed, in which case just
   20336              :      return; our caller will skip over the body without parsing.  */
   20337    166972196 :   if (DECL_INITIAL (decl1) != error_mark_node)
   20338              :     return true;
   20339              : 
   20340              :   /* Initialize RTL machinery.  We cannot do this until
   20341              :      CURRENT_FUNCTION_DECL and DECL_RESULT are set up.  We do this
   20342              :      even when processing a template; this is how we get
   20343              :      CFUN set up, and our per-function variables initialized.
   20344              :      FIXME factor out the non-RTL stuff.  */
   20345    166967365 :   cp_binding_level *bl = current_binding_level;
   20346    166967365 :   allocate_struct_function (decl1, processing_template_decl);
   20347              : 
   20348              :   /* Initialize the language data structures.  Whenever we start
   20349              :      a new function, we destroy temporaries in the usual way.  */
   20350    166967365 :   cfun->language = ggc_cleared_alloc<language_function> ();
   20351    166967365 :   current_stmt_tree ()->stmts_are_full_exprs_p = 1;
   20352    166967365 :   current_binding_level = bl;
   20353              : 
   20354              :   /* If we are (erroneously) defining a function that we have already
   20355              :      defined before, wipe out what we knew before.  */
   20356    166967365 :   gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
   20357    166967365 :   FNDECL_USED_AUTO (decl1) = false;
   20358    166967365 :   DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
   20359              : 
   20360    166967365 :   if (!processing_template_decl && type_uses_auto (restype))
   20361              :     {
   20362      1200094 :       FNDECL_USED_AUTO (decl1) = true;
   20363      1200094 :       DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
   20364              :     }
   20365              : 
   20366              :   /* Start the statement-tree, start the tree now.  */
   20367    166967365 :   DECL_SAVED_TREE (decl1) = push_stmt_list ();
   20368              : 
   20369    166967365 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (decl1))
   20370              :     {
   20371              :       /* We know that this was set up by `grokclassfn'.  We do not
   20372              :          wait until `store_parm_decls', since evil parse errors may
   20373              :          never get us to that point.  Here we keep the consistency
   20374              :          between `current_class_type' and `current_class_ptr'.  */
   20375    108320007 :       tree t = DECL_ARGUMENTS (decl1);
   20376              : 
   20377    108320007 :       gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
   20378    108320007 :       gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
   20379              : 
   20380    108320007 :       cp_function_chain->x_current_class_ref
   20381    108320007 :         = cp_build_fold_indirect_ref (t);
   20382              :       /* Set this second to avoid shortcut in cp_build_indirect_ref.  */
   20383    108320007 :       cp_function_chain->x_current_class_ptr = t;
   20384              : 
   20385              :       /* Constructors and destructors need to know whether they're "in
   20386              :          charge" of initializing virtual base classes.  */
   20387    108320007 :       t = DECL_CHAIN (t);
   20388    108320007 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
   20389              :         {
   20390        17767 :           current_in_charge_parm = t;
   20391        17767 :           t = DECL_CHAIN (t);
   20392              :         }
   20393    108320007 :       if (DECL_HAS_VTT_PARM_P (decl1))
   20394              :         {
   20395        35589 :           gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
   20396        35589 :           current_vtt_parm = t;
   20397              :         }
   20398              :     }
   20399              : 
   20400    301182736 :   bool honor_interface = (!DECL_TEMPLOID_INSTANTIATION (decl1)
   20401              :                           /* Implicitly-defined methods (like the
   20402              :                              destructor for a class in which no destructor
   20403              :                              is explicitly declared) must not be defined
   20404              :                              until their definition is needed.  So, we
   20405              :                              ignore interface specifications for
   20406              :                              compiler-generated functions.  */
   20407    203115311 :                           && !DECL_ARTIFICIAL (decl1));
   20408    166967365 :   struct c_fileinfo *finfo
   20409    166967365 :     = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
   20410              : 
   20411    166967365 :   if (processing_template_decl)
   20412              :     /* Don't mess with interface flags.  */;
   20413     68967177 :   else if (DECL_INTERFACE_KNOWN (decl1))
   20414              :     {
   20415     20103365 :       tree ctx = decl_function_context (decl1);
   20416              : 
   20417     20103365 :       if (DECL_NOT_REALLY_EXTERN (decl1))
   20418     16013261 :         DECL_EXTERNAL (decl1) = 0;
   20419              : 
   20420     20103365 :       if (ctx != NULL_TREE && vague_linkage_p (ctx))
   20421              :         /* This is a function in a local class in an extern inline
   20422              :            or template function.  */
   20423      3131908 :         comdat_linkage (decl1);
   20424              :     }
   20425              :   /* If this function belongs to an interface, it is public.
   20426              :      If it belongs to someone else's interface, it is also external.
   20427              :      This only affects inlines and template instantiations.  */
   20428     48863812 :   else if (!finfo->interface_unknown && honor_interface)
   20429              :     {
   20430          106 :       if (DECL_DECLARED_INLINE_P (decl1)
   20431          106 :           || DECL_TEMPLOID_INSTANTIATION (decl1))
   20432              :         {
   20433           82 :           DECL_EXTERNAL (decl1)
   20434          164 :             = (finfo->interface_only
   20435           82 :                || (DECL_DECLARED_INLINE_P (decl1)
   20436           36 :                    && ! flag_implement_inlines
   20437            0 :                    && !DECL_VINDEX (decl1)));
   20438              : 
   20439              :           /* For WIN32 we also want to put these in linkonce sections.  */
   20440           82 :           maybe_make_one_only (decl1);
   20441              :         }
   20442              :       else
   20443           24 :         DECL_EXTERNAL (decl1) = 0;
   20444          106 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   20445              :       /* If this function is in an interface implemented in this file,
   20446              :          make sure that the back end knows to emit this function
   20447              :          here.  */
   20448          106 :       if (!DECL_EXTERNAL (decl1))
   20449           60 :         mark_needed (decl1);
   20450              :     }
   20451     48863706 :   else if (finfo->interface_unknown && finfo->interface_only
   20452            0 :            && honor_interface)
   20453              :     {
   20454              :       /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
   20455              :          interface, we will have both finfo->interface_unknown and
   20456              :          finfo->interface_only set.  In that case, we don't want to
   20457              :          use the normal heuristics because someone will supply a
   20458              :          #pragma implementation elsewhere, and deducing it here would
   20459              :          produce a conflict.  */
   20460            0 :       comdat_linkage (decl1);
   20461            0 :       DECL_EXTERNAL (decl1) = 0;
   20462            0 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   20463            0 :       DECL_DEFER_OUTPUT (decl1) = 1;
   20464              :     }
   20465              :   else
   20466              :     {
   20467              :       /* This is a definition, not a reference.
   20468              :          So clear DECL_EXTERNAL, unless this is a GNU extern inline.  */
   20469     48863706 :       if (!GNU_INLINE_P (decl1))
   20470     48863703 :         DECL_EXTERNAL (decl1) = 0;
   20471              : 
   20472     48863706 :       if ((DECL_DECLARED_INLINE_P (decl1)
   20473      1907405 :            || DECL_TEMPLOID_INSTANTIATION (decl1))
   20474     50528371 :           && ! DECL_INTERFACE_KNOWN (decl1))
   20475     48620966 :         DECL_DEFER_OUTPUT (decl1) = 1;
   20476              :       else
   20477       242740 :         DECL_INTERFACE_KNOWN (decl1) = 1;
   20478              :     }
   20479              : 
   20480              :   /* Determine the ELF visibility attribute for the function.  We must not
   20481              :      do this before calling "pushdecl", as we must allow "duplicate_decls"
   20482              :      to merge any attributes appropriately.  We also need to wait until
   20483              :      linkage is set.  */
   20484    166967365 :   if (!DECL_CLONED_FUNCTION_P (decl1))
   20485    150445444 :     determine_visibility (decl1);
   20486              : 
   20487    166967365 :   if (!processing_template_decl)
   20488     68967177 :     maybe_instantiate_noexcept (decl1);
   20489              : 
   20490    166967365 :   begin_scope (sk_function_parms, decl1);
   20491              : 
   20492    166967365 :   ++function_depth;
   20493              : 
   20494    166967365 :   start_fname_decls ();
   20495              : 
   20496    166967365 :   store_parm_decls (current_function_parms);
   20497              : 
   20498    166967365 :   start_function_contracts (decl1);
   20499              : 
   20500    166967365 :   if (!processing_template_decl
   20501     68967177 :       && flag_lifetime_dse > 1
   20502    137924972 :       && DECL_CONSTRUCTOR_P (decl1)
   20503              :       /* Clobbering an empty base is harmful if it overlays real data.  */
   20504     19312313 :       && !is_empty_class (current_class_type)
   20505              :       /* We can't clobber safely for an implicitly-defined default constructor
   20506              :          because part of the initialization might happen before we enter the
   20507              :          constructor, via AGGR_INIT_ZERO_FIRST (c++/68006).  */
   20508     17399287 :       && !implicit_default_ctor_p (decl1)
   20509    183151354 :       && !lookup_attribute ("clobber *this",
   20510     16183989 :                             DECL_ATTRIBUTES (current_class_ptr)))
   20511     16174721 :     DECL_ATTRIBUTES (current_class_ptr)
   20512     32349442 :       = tree_cons (get_identifier ("clobber *this"), NULL_TREE,
   20513     16174721 :                    DECL_ATTRIBUTES (current_class_ptr));
   20514              : 
   20515    166967365 :   if (!processing_template_decl
   20516    137934354 :       && DECL_CONSTRUCTOR_P (decl1)
   20517     19313561 :       && sanitize_flags_p (SANITIZE_VPTR)
   20518         1935 :       && !DECL_CLONED_FUNCTION_P (decl1)
   20519    166968010 :       && !implicit_default_ctor_p (decl1))
   20520          485 :     cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
   20521              : 
   20522    166967365 :   if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
   20523    166966786 :     start_lambda_scope (decl1);
   20524              : 
   20525              :   return true;
   20526              : }
   20527              : 
   20528              : 
   20529              : /* Like start_preparsed_function, except that instead of a
   20530              :    FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
   20531              : 
   20532              :    Returns true on success.  If the DECLARATOR is not suitable
   20533              :    for a function, we return false, which tells the parser to
   20534              :    skip the entire function.  */
   20535              : 
   20536              : bool
   20537     39983278 : start_function (cp_decl_specifier_seq *declspecs,
   20538              :                 const cp_declarator *declarator,
   20539              :                 tree attrs)
   20540              : {
   20541     39983278 :   tree decl1;
   20542              : 
   20543     39983278 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
   20544     39983278 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   20545     39983278 :   if (decl1 == error_mark_node)
   20546              :     return false;
   20547              : 
   20548     39982912 :   if (DECL_MAIN_P (decl1))
   20549              :     /* main must return int.  grokfndecl should have corrected it
   20550              :        (and issued a diagnostic) if the user got it wrong.  */
   20551        34950 :     gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
   20552              :                              integer_type_node));
   20553              : 
   20554     39982912 :   return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
   20555              : }
   20556              : 
   20557              : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
   20558              :    FN.  */
   20559              : 
   20560              : bool
   20561    319815486 : use_eh_spec_block (tree fn)
   20562              : {
   20563    317836090 :   return (flag_exceptions && flag_enforce_eh_specs
   20564    317836090 :           && !processing_template_decl
   20565              :           /* We insert the EH_SPEC_BLOCK only in the original
   20566              :              function; then, it is copied automatically to the
   20567              :              clones.  */
   20568    120489574 :           && !DECL_CLONED_FUNCTION_P (fn)
   20569              :           /* Implicitly-generated constructors and destructors have
   20570              :              exception specifications.  However, those specifications
   20571              :              are the union of the possible exceptions specified by the
   20572              :              constructors/destructors for bases and members, so no
   20573              :              unallowed exception will ever reach this function.  By
   20574              :              not creating the EH_SPEC_BLOCK we save a little memory,
   20575              :              and we avoid spurious warnings about unreachable
   20576              :              code.  */
   20577    104009432 :           && !DECL_DEFAULTED_FN (fn)
   20578    421259882 :           && !type_throw_all_p (TREE_TYPE (fn)));
   20579              : }
   20580              : 
   20581              : /* Helper function to push ARGS into the current lexical scope.  DECL
   20582              :    is the function declaration.  NONPARMS is used to handle enum
   20583              :    constants.  */
   20584              : 
   20585              : void
   20586    161903568 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
   20587              : {
   20588              :   /* If we're doing semantic analysis, then we'll call pushdecl
   20589              :      for each of these.  We must do them in reverse order so that
   20590              :      they end in the correct forward order.  */
   20591    161903568 :   args = nreverse (args);
   20592              : 
   20593    161903568 :   tree next;
   20594    658363847 :   for (tree parm = args; parm; parm = next)
   20595              :     {
   20596    334556711 :       next = DECL_CHAIN (parm);
   20597    334556711 :       if (TREE_CODE (parm) == PARM_DECL)
   20598    334556711 :         pushdecl (parm);
   20599            0 :       else if (nonparms)
   20600              :         {
   20601              :           /* If we find an enum constant or a type tag, put it aside for
   20602              :              the moment.  */
   20603            0 :           TREE_CHAIN (parm) = NULL_TREE;
   20604            0 :           *nonparms = chainon (*nonparms, parm);
   20605              :         }
   20606              :     }
   20607              : 
   20608              :   /* Get the decls in their original chain order and record in the
   20609              :      function.  This is all and only the PARM_DECLs that were
   20610              :      pushed into scope by the loop above.  */
   20611    161903568 :   DECL_ARGUMENTS (decl) = get_local_decls ();
   20612    161903568 : }
   20613              : 
   20614              : /* Store the parameter declarations into the current function declaration.
   20615              :    This is called after parsing the parameter declarations, before
   20616              :    digesting the body of the function.
   20617              : 
   20618              :    Also install to binding contour return value identifier, if any.  */
   20619              : 
   20620              : static void
   20621    166967365 : store_parm_decls (tree current_function_parms)
   20622              : {
   20623    166967365 :   tree fndecl = current_function_decl;
   20624              : 
   20625              :   /* This is a chain of any other decls that came in among the parm
   20626              :      declarations.  If a parm is declared with  enum {foo, bar} x;
   20627              :      then CONST_DECLs for foo and bar are put here.  */
   20628    166967365 :   tree nonparms = NULL_TREE;
   20629              : 
   20630    166967365 :   if (current_function_parms)
   20631              :     {
   20632              :       /* This case is when the function was defined with an ANSI prototype.
   20633              :          The parms already have decls, so we need not do anything here
   20634              :          except record them as in effect
   20635              :          and complain if any redundant old-style parm decls were written.  */
   20636              : 
   20637    158308346 :       tree specparms = current_function_parms;
   20638              : 
   20639              :       /* Must clear this because it might contain TYPE_DECLs declared
   20640              :              at class level.  */
   20641    158308346 :       current_binding_level->names = NULL;
   20642              : 
   20643    158308346 :       do_push_parm_decls (fndecl, specparms, &nonparms);
   20644              :     }
   20645              :   else
   20646      8659019 :     DECL_ARGUMENTS (fndecl) = NULL_TREE;
   20647              : 
   20648              :   /* Now store the final chain of decls for the arguments
   20649              :      as the decl-chain of the current lexical scope.
   20650              :      Put the enumerators in as well, at the front so that
   20651              :      DECL_ARGUMENTS is not modified.  */
   20652    166967365 :   current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
   20653              : 
   20654              :   /* Register cleanups for parameters with trivial_abi attribute, the cleanup
   20655              :      of which is the callee's responsibility.  */
   20656    166967365 :   if (!processing_template_decl && !DECL_CLONED_FUNCTION_P (fndecl))
   20657    135374610 :     for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
   20658              :       {
   20659     82929354 :         if (TREE_CODE (parm) == PARM_DECL)
   20660              :           {
   20661     82929354 :             tree parm_type = TREE_TYPE (parm);
   20662     82929354 :             if (has_trivial_abi_attribute (parm_type))
   20663              :               {
   20664           18 :                 tree cleanup
   20665           18 :                   = cxx_maybe_build_cleanup (parm, tf_warning_or_error);
   20666           18 :                 if (cleanup && cleanup != error_mark_node)
   20667           18 :                   finish_decl_cleanup (parm, cleanup);
   20668              :               }
   20669              :           }
   20670              :       }
   20671              : 
   20672    166967365 :   if (use_eh_spec_block (current_function_decl))
   20673     25362500 :     current_eh_spec_block = begin_eh_spec_block ();
   20674    166967365 : }
   20675              : 
   20676              : 
   20677              : /* Mark CDTOR's implicit THIS argument for returning, if required by
   20678              :    the ABI..  Return the decl for THIS, if it is to be returned, and
   20679              :    NULL otherwise.  */
   20680              : 
   20681              : tree
   20682    143104978 : maybe_prepare_return_this (tree cdtor)
   20683              : {
   20684    143104978 :   if (targetm.cxx.cdtor_returns_this ())
   20685            0 :     if (tree val = DECL_ARGUMENTS (cdtor))
   20686              :       {
   20687            0 :         suppress_warning (val, OPT_Wuse_after_free_);
   20688            0 :         return val;
   20689              :       }
   20690              : 
   20691              :   return NULL_TREE;
   20692              : }
   20693              : 
   20694              : /* Set the return value of the [cd]tor if the ABI wants that.  */
   20695              : 
   20696              : void
   20697      8412754 : maybe_return_this ()
   20698              : {
   20699      8412754 :   if (tree val = maybe_prepare_return_this (current_function_decl))
   20700              :     {
   20701              :       /* Return the address of the object.  */
   20702            0 :       val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
   20703            0 :       val = build2 (MODIFY_EXPR, TREE_TYPE (val),
   20704            0 :                     DECL_RESULT (current_function_decl), val);
   20705            0 :       tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
   20706            0 :       add_stmt (exprstmt);
   20707              :     }
   20708      8412754 : }
   20709              : 
   20710              : /* Do all the processing for the beginning of a destructor; set up the
   20711              :    vtable pointers and cleanups for bases and members.  */
   20712              : 
   20713              : static void
   20714      1657932 : begin_destructor_body (void)
   20715              : {
   20716      1657932 :   tree compound_stmt;
   20717              : 
   20718              :   /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
   20719              :      issued an error message.  We still want to try to process the
   20720              :      body of the function, but initialize_vtbl_ptrs will crash if
   20721              :      TYPE_BINFO is NULL.  */
   20722      1657932 :   if (COMPLETE_TYPE_P (current_class_type))
   20723              :     {
   20724      1657932 :       compound_stmt = begin_compound_stmt (0);
   20725              :       /* Make all virtual function table pointers in non-virtual base
   20726              :          classes point to CURRENT_CLASS_TYPE's virtual function
   20727              :          tables.  */
   20728      1657932 :       initialize_vtbl_ptrs (current_class_ptr);
   20729      1657932 :       finish_compound_stmt (compound_stmt);
   20730              : 
   20731      1657932 :       if (flag_lifetime_dse
   20732              :           /* Clobbering an empty base is harmful if it overlays real data.  */
   20733      1657932 :           && !is_empty_class (current_class_type))
   20734              :       {
   20735      1514657 :         if (sanitize_flags_p (SANITIZE_VPTR)
   20736          239 :             && (flag_sanitize_recover & SANITIZE_VPTR) == 0
   20737      1514720 :             && TYPE_CONTAINS_VPTR_P (current_class_type))
   20738              :           {
   20739           63 :             tree binfo = TYPE_BINFO (current_class_type);
   20740           63 :             tree ref
   20741           63 :               = cp_build_fold_indirect_ref (current_class_ptr);
   20742              : 
   20743           63 :             tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
   20744           63 :             tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
   20745           63 :             tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
   20746              :                                               NOP_EXPR, vtbl,
   20747              :                                               tf_warning_or_error);
   20748              :             /* If the vptr is shared with some virtual nearly empty base,
   20749              :                don't clear it if not in charge, the dtor of the virtual
   20750              :                nearly empty base will do that later.  */
   20751           63 :             if (CLASSTYPE_VBASECLASSES (current_class_type))
   20752              :               {
   20753              :                 tree c = current_class_type;
   20754           66 :                 while (CLASSTYPE_PRIMARY_BINFO (c))
   20755              :                   {
   20756           63 :                     if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
   20757              :                       {
   20758           36 :                         stmt = convert_to_void (stmt, ICV_STATEMENT,
   20759              :                                                 tf_warning_or_error);
   20760           36 :                         stmt = build_if_in_charge (stmt);
   20761           36 :                         break;
   20762              :                       }
   20763           27 :                     c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
   20764              :                   }
   20765              :               }
   20766           63 :             finish_decl_cleanup (NULL_TREE, stmt);
   20767              :           }
   20768              :         else
   20769      1514594 :           finish_decl_cleanup (NULL_TREE,
   20770              :                                build_clobber_this (CLOBBER_OBJECT_END));
   20771              :       }
   20772              : 
   20773              :       /* And insert cleanups for our bases and members so that they
   20774              :          will be properly destroyed if we throw.  */
   20775      1657932 :       push_base_cleanups ();
   20776              :     }
   20777      1657932 : }
   20778              : 
   20779              : /* Do the necessary processing for the beginning of a function body, which
   20780              :    in this case includes member-initializers, but not the catch clauses of
   20781              :    a function-try-block.  Currently, this means opening a binding level
   20782              :    for the member-initializers (in a ctor), member cleanups (in a dtor),
   20783              :    and capture proxies (in a lambda operator()).  */
   20784              : 
   20785              : tree
   20786    131246220 : begin_function_body (void)
   20787              : {
   20788    270204146 :   if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
   20789              :     return NULL_TREE;
   20790              : 
   20791     25661330 :   if (processing_template_decl)
   20792              :     /* Do nothing now.  */;
   20793              :   else
   20794              :     /* Always keep the BLOCK node associated with the outermost pair of
   20795              :        curly braces of a function.  These are needed for correct
   20796              :        operation of dwarfout.c.  */
   20797      8587603 :     keep_next_level (true);
   20798              : 
   20799     25661330 :   tree stmt = begin_compound_stmt (BCS_FN_BODY);
   20800     25661330 :   current_binding_level->artificial = 1;
   20801              : 
   20802     25661330 :   if (processing_template_decl)
   20803              :     /* Do nothing now.  */;
   20804     17175206 :   else if (DECL_DESTRUCTOR_P (current_function_decl))
   20805      1657932 :     begin_destructor_body ();
   20806              : 
   20807              :   return stmt;
   20808              : }
   20809              : 
   20810              : /* Do the processing for the end of a function body.  Currently, this means
   20811              :    closing out the cleanups for fully-constructed bases and members, and in
   20812              :    the case of the destructor, deleting the object if desired.  Again, this
   20813              :    is only meaningful for [cd]tors, since they are the only functions where
   20814              :    there is a significant distinction between the main body and any
   20815              :    function catch clauses.  Handling, say, main() return semantics here
   20816              :    would be wrong, as flowing off the end of a function catch clause for
   20817              :    main() would also need to return 0.  */
   20818              : 
   20819              : void
   20820    131246194 : finish_function_body (tree compstmt)
   20821              : {
   20822    131246194 :   if (compstmt == NULL_TREE)
   20823              :     return;
   20824              : 
   20825              :   /* Close the block.  */
   20826     25661328 :   finish_compound_stmt (compstmt);
   20827              : 
   20828     25661328 :   if (processing_template_decl)
   20829              :     /* Do nothing now.  */;
   20830      8587601 :   else if (DECL_CONSTRUCTOR_P (current_function_decl)
   20831      8587601 :            || DECL_DESTRUCTOR_P (current_function_decl))
   20832      8091281 :     maybe_return_this ();
   20833              : }
   20834              : 
   20835              : /* Given a function, returns the BLOCK corresponding to the outermost level
   20836              :    of curly braces, skipping the artificial block created for constructor
   20837              :    initializers.  */
   20838              : 
   20839              : tree
   20840       357908 : outer_curly_brace_block (tree fndecl)
   20841              : {
   20842       357908 :   tree block = DECL_INITIAL (fndecl);
   20843       357908 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   20844              :     return block;
   20845         1223 :   block = BLOCK_SUBBLOCKS (block);
   20846         1223 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   20847              :     return block;
   20848            0 :   block = BLOCK_SUBBLOCKS (block);
   20849            0 :   gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
   20850              :   return block;
   20851              : }
   20852              : 
   20853              : /* If FNDECL is a class's key method, add the class to the list of
   20854              :    keyed classes that should be emitted.  */
   20855              : 
   20856              : static void
   20857    166971317 : record_key_method_defined (tree fndecl)
   20858              : {
   20859    225622605 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   20860    108416088 :       && DECL_VIRTUAL_P (fndecl)
   20861    169799314 :       && !processing_template_decl)
   20862              :     {
   20863      1478969 :       tree fnclass = DECL_CONTEXT (fndecl);
   20864      1478969 :       if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
   20865              :         {
   20866        31422 :           tree classdecl = TYPE_NAME (fnclass);
   20867              :           /* Classes attached to a named module are already handled.  */
   20868        31422 :           if (!DECL_LANG_SPECIFIC (classdecl)
   20869        31745 :               || !DECL_MODULE_ATTACH_P (classdecl))
   20870        31377 :             vec_safe_push (keyed_classes, fnclass);
   20871              :         }
   20872              :     }
   20873    166971317 : }
   20874              : 
   20875              : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
   20876              :    of "return *this;" immediately before its location, using FNDECL's
   20877              :    first statement (if any) to give the indentation, if appropriate.  */
   20878              : 
   20879              : static void
   20880           18 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
   20881              : {
   20882           18 :   location_t indent = UNKNOWN_LOCATION;
   20883           18 :   tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
   20884           18 :   if (stmts)
   20885            9 :     indent = EXPR_LOCATION (stmts);
   20886           18 :   richloc->add_fixit_insert_formatted ("return *this;",
   20887              :                                        richloc->get_loc (),
   20888              :                                        indent);
   20889           18 : }
   20890              : 
   20891              : /* Finish up a function declaration and compile that function
   20892              :    all the way to assembler language output.  The free the storage
   20893              :    for the function definition. INLINE_P is TRUE if we just
   20894              :    finished processing the body of an in-class inline function
   20895              :    definition.  (This processing will have taken place after the
   20896              :    class definition is complete.)  */
   20897              : 
   20898              : tree
   20899    166967325 : finish_function (bool inline_p)
   20900              : {
   20901    166967325 :   tree fndecl = current_function_decl;
   20902    166967325 :   tree fntype, ctype = NULL_TREE;
   20903    166967325 :   tree resumer = NULL_TREE, destroyer = NULL_TREE;
   20904              : 
   20905              :   /* When we get some parse errors, we can end up without a
   20906              :      current_function_decl, so cope.  */
   20907    166967325 :   if (fndecl == NULL_TREE || fndecl == error_mark_node)
   20908            0 :     return error_mark_node;
   20909              : 
   20910    166967325 :   if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   20911    166966746 :     finish_lambda_scope ();
   20912              : 
   20913    166967325 :   if (c_dialect_objc ())
   20914            0 :     objc_finish_function ();
   20915              : 
   20916    166967325 :   record_key_method_defined (fndecl);
   20917              : 
   20918    166967325 :   fntype = TREE_TYPE (fndecl);
   20919              : 
   20920              :   /*  TREE_READONLY (fndecl) = 1;
   20921              :       This caused &foo to be of type ptr-to-const-function
   20922              :       which then got a warning when stored in a ptr-to-function variable.  */
   20923              : 
   20924    166967325 :   gcc_assert (building_stmt_list_p ());
   20925              :   /* The current function is being defined, so its DECL_INITIAL should
   20926              :      be set, and unless there's a multiple definition, it should be
   20927              :      error_mark_node.  */
   20928    166967325 :   gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
   20929              : 
   20930    166967325 :   cp_coroutine_transform *coroutine = nullptr;
   20931    166967325 :   if (flag_coroutines
   20932    164217331 :       && !processing_template_decl
   20933     67179195 :       && DECL_COROUTINE_P (fndecl)
   20934    166972335 :       && !DECL_RAMP_FN (fndecl))
   20935              :     {
   20936         1722 :       gcc_checking_assert (!DECL_CLONED_FUNCTION_P (fndecl)
   20937              :                            && !DECL_DEFAULTED_FN (fndecl));
   20938         1722 :       coroutine = new cp_coroutine_transform (fndecl, inline_p);
   20939         1722 :       if (coroutine && coroutine->cp_valid_coroutine ())
   20940         1722 :         coroutine->apply_transforms ();
   20941              : 
   20942              :       /* We should handle coroutine IFNs in middle end lowering.  */
   20943         1722 :       cfun->coroutine_component = true;
   20944              : 
   20945              :       /* Do not try to process the ramp's EH unless outlining succeeded.  */
   20946         1722 :       if (coroutine->cp_valid_coroutine () && use_eh_spec_block (fndecl))
   20947          360 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   20948              :                               (TREE_TYPE (fndecl)),
   20949          360 :                               current_eh_spec_block);
   20950              : 
   20951              :      /* If outlining succeeded, then add contracts handling if needed.  */
   20952         1722 :      if (coroutine->cp_valid_coroutine ())
   20953         1644 :         maybe_apply_function_contracts (fndecl);
   20954              :     }
   20955              :   else
   20956              :   /* For a cloned function, we've already got all the code we need;
   20957              :      there's no need to add any extra bits.  */
   20958    166965603 :   if (!DECL_CLONED_FUNCTION_P (fndecl))
   20959              :     {
   20960              :       /* Make it so that `main' always returns 0 by default.  */
   20961    150443682 :       if (DECL_MAIN_FREESTANDING_P (current_function_decl)
   20962    150478617 :           && !TREE_THIS_VOLATILE (current_function_decl))
   20963        34935 :         finish_return_stmt (integer_zero_node);
   20964              : 
   20965    150443682 :       if (use_eh_spec_block (current_function_decl))
   20966     25362137 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   20967              :                               (TREE_TYPE (current_function_decl)),
   20968     25362137 :                               current_eh_spec_block);
   20969              : 
   20970    150443682 :       maybe_apply_function_contracts (current_function_decl);
   20971              : 
   20972              :     }
   20973              : 
   20974              :   /* If we're saving up tree structure, tie off the function now.  */
   20975    166967325 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   20976              : 
   20977    166967325 :   finish_fname_decls ();
   20978              : 
   20979              :   /* This must come after expand_function_end because cleanups might
   20980              :      have declarations (from inline functions) that need to go into
   20981              :      this function's blocks.  */
   20982              : 
   20983              :   /* If the current binding level isn't the outermost binding level
   20984              :      for this function, either there is a bug, or we have experienced
   20985              :      syntax errors and the statement tree is malformed.  */
   20986    166967325 :   if (current_binding_level->kind != sk_function_parms)
   20987              :     {
   20988              :       /* Make sure we have already experienced errors.  */
   20989           12 :       gcc_assert (errorcount);
   20990              : 
   20991              :       /* Throw away the broken statement tree and extra binding
   20992              :          levels.  */
   20993           12 :       DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
   20994              : 
   20995           27 :       while (current_binding_level->kind != sk_function_parms)
   20996              :         {
   20997           15 :           if (current_binding_level->kind == sk_class)
   20998            0 :             pop_nested_class ();
   20999              :           else
   21000           15 :             poplevel (0, 0, 0);
   21001              :         }
   21002              :     }
   21003    166967325 :   poplevel (1, 0, 1);
   21004              : 
   21005              :   /* Statements should always be full-expressions at the outermost set
   21006              :      of curly braces for a function.  */
   21007    166967325 :   gcc_assert (stmts_are_full_exprs_p ());
   21008              : 
   21009              :   /* If there are no return statements in a function with auto return type,
   21010              :      the return type is void.  But if the declared type is something like
   21011              :      auto*, this is an error.  */
   21012     68967137 :   if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
   21013    168167417 :       && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   21014              :     {
   21015       148834 :       if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   21016       148819 :           && !current_function_returns_value
   21017       297414 :           && !current_function_returns_null)
   21018              :         {
   21019              :           /* We haven't applied return type deduction because we haven't
   21020              :              seen any return statements. Do that now.  */
   21021       148580 :           tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   21022       148580 :           do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
   21023              :                              void_node, node, tf_warning_or_error,
   21024              :                              adc_return_type);
   21025              : 
   21026       148580 :           apply_deduced_return_type (fndecl, void_type_node);
   21027       148580 :           fntype = TREE_TYPE (fndecl);
   21028              :         }
   21029          254 :       else if (!current_function_returns_value
   21030            6 :                && !current_function_returns_null)
   21031              :         {
   21032            6 :           auto_diagnostic_group d;
   21033           12 :           error ("no return statements in function returning %qT",
   21034            6 :                  DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   21035            6 :           inform (input_location, "only plain %<auto%> return type can be "
   21036              :                   "deduced to %<void%>");
   21037            6 :         }
   21038              :     }
   21039              : 
   21040    166967325 :   if (FNDECL_USED_AUTO (fndecl)
   21041    166967325 :       && TREE_TYPE (fntype) != DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   21042      1199838 :     if (location_t fcloc = failed_completion_location (fndecl))
   21043              :       {
   21044            6 :         auto_diagnostic_group adg;
   21045            6 :         if (warning (OPT_Wsfinae_incomplete_,
   21046              :                      "defining %qD, which previously failed to be deduced "
   21047              :                      "in a SFINAE context", fndecl)
   21048            6 :             && warn_sfinae_incomplete == 1)
   21049            6 :           inform (fcloc, "here.  Use %qs for a diagnostic at that point",
   21050              :                   "-Wsfinae-incomplete=2");
   21051            6 :       }
   21052              : 
   21053              :   /* Remember that we were in class scope.  */
   21054    166967325 :   if (current_class_name)
   21055    127795605 :     ctype = current_class_type;
   21056              : 
   21057    166967325 :   if (DECL_DELETED_FN (fndecl))
   21058              :     {
   21059           93 :       DECL_INITIAL (fndecl) = error_mark_node;
   21060           93 :       DECL_SAVED_TREE (fndecl) = NULL_TREE;
   21061           93 :       goto cleanup;
   21062              :     }
   21063              : 
   21064    166967232 :   if (flag_openmp)
   21065       335689 :     if (tree attr = lookup_attribute ("omp declare variant base",
   21066       335689 :                                       DECL_ATTRIBUTES (fndecl)))
   21067          280 :       omp_declare_variant_finalize (fndecl, attr);
   21068              : 
   21069              :   /* Complain if there's just no return statement.  */
   21070    166967232 :   if ((warn_return_type
   21071        47436 :        || (cxx_dialect >= cxx14
   21072        39400 :            && DECL_DECLARED_CONSTEXPR_P (fndecl)))
   21073    166937857 :       && !VOID_TYPE_P (TREE_TYPE (fntype))
   21074    105083625 :       && !dependent_type_p (TREE_TYPE (fntype))
   21075     53252676 :       && !current_function_returns_value && !current_function_returns_null
   21076              :       /* Don't complain if we abort or throw.  */
   21077        38051 :       && !current_function_returns_abnormally
   21078              :       /* Don't complain if there's an infinite loop.  */
   21079          944 :       && !current_function_infinite_loop
   21080              :       /* Don't complain if we are declared noreturn.  */
   21081          876 :       && !TREE_THIS_VOLATILE (fndecl)
   21082          870 :       && !DECL_NAME (DECL_RESULT (fndecl))
   21083          870 :       && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
   21084              :       /* Structor return values (if any) are set by the compiler.  */
   21085         1264 :       && !DECL_CONSTRUCTOR_P (fndecl)
   21086          632 :       && !DECL_DESTRUCTOR_P (fndecl)
   21087    166967864 :       && targetm.warn_func_return (fndecl))
   21088              :     {
   21089          626 :       gcc_rich_location richloc (input_location);
   21090              :       /* Potentially add a "return *this;" fix-it hint for
   21091              :          assignment operators.  */
   21092          626 :       if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
   21093              :         {
   21094           39 :           tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
   21095           39 :           if (TREE_CODE (valtype) == REFERENCE_TYPE
   21096           32 :               && current_class_ref
   21097           26 :               && same_type_ignoring_top_level_qualifiers_p
   21098           26 :                   (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
   21099           71 :               && global_dc->option_enabled_p (OPT_Wreturn_type))
   21100           18 :             add_return_star_this_fixit (&richloc, fndecl);
   21101              :         }
   21102          626 :       if (cxx_dialect >= cxx14
   21103          626 :           && DECL_DECLARED_CONSTEXPR_P (fndecl))
   21104            2 :         error_at (&richloc, "no return statement in %<constexpr%> function "
   21105              :                             "returning non-void");
   21106          624 :       else if (warning_at (&richloc, OPT_Wreturn_type,
   21107              :                            "no return statement in function returning "
   21108              :                            "non-void"))
   21109          166 :         suppress_warning (fndecl, OPT_Wreturn_type);
   21110          626 :     }
   21111              : 
   21112              :   /* Lambda closure members are implicitly constexpr if possible.  */
   21113    166967232 :   if (cxx_dialect >= cxx17
   21114    288796979 :       && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
   21115      2028084 :     DECL_DECLARED_CONSTEXPR_P (fndecl)
   21116      2028084 :       = ((processing_template_decl
   21117       657100 :           || is_valid_constexpr_fn (fndecl, /*complain*/false))
   21118      4055088 :          && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
   21119              : 
   21120              :   /* Invoke the pre-genericize plugin before we start munging things.  */
   21121    166967232 :   if (!processing_template_decl)
   21122     68967044 :     invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   21123              : 
   21124              :   /* Fold away non-ODR usages of constants so that we don't need to
   21125              :      try and stream them in modules if they're internal.  */
   21126    166967232 :   if (!processing_template_decl)
   21127     68967044 :     cp_fold_function_non_odr_use (fndecl);
   21128              : 
   21129              :   /* Save constexpr function body before it gets munged by
   21130              :      the NRV transformation.   */
   21131    166967232 :   maybe_save_constexpr_fundef (fndecl);
   21132              : 
   21133              :   /* Perform delayed folding before NRV transformation.  */
   21134    166967232 :   if (!processing_template_decl
   21135    137934088 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   21136    234889704 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   21137     67922023 :     cp_fold_function (fndecl);
   21138              : 
   21139              :   /* Set up the named return value optimization, if we can.  Candidate
   21140              :      variables are selected in check_return_expr.  */
   21141    166967232 :   if (tree r = current_function_return_value)
   21142              :     {
   21143     44022464 :       if (r != error_mark_node)
   21144       229554 :         finalize_nrv (fndecl, r);
   21145     44022464 :       current_function_return_value = NULL_TREE;
   21146              :     }
   21147              : 
   21148              :   /* Must mark the RESULT_DECL as being in this function.  */
   21149    166967232 :   DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   21150              : 
   21151              :   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
   21152              :      to the FUNCTION_DECL node itself.  */
   21153    166967232 :   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   21154              : 
   21155              :   /* Store the end of the function, so that we get good line number
   21156              :      info for the epilogue.  */
   21157    166967232 :   cfun->function_end_locus = input_location;
   21158              : 
   21159              :   /* Complain about parameters that are only set, but never otherwise used.  */
   21160    166967232 :   if (warn_unused_but_set_parameter
   21161      1001455 :       && !processing_template_decl
   21162       511480 :       && errorcount == unused_but_set_errorcount
   21163    167478709 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   21164              :     {
   21165       399634 :       tree decl;
   21166              : 
   21167       399634 :       for (decl = DECL_ARGUMENTS (fndecl);
   21168      1064787 :            decl;
   21169       665153 :            decl = DECL_CHAIN (decl))
   21170       665153 :         if (TREE_USED (decl)
   21171       552108 :             && TREE_CODE (decl) == PARM_DECL
   21172       552108 :             && !DECL_READ_P (decl)
   21173          225 :             && DECL_NAME (decl)
   21174          225 :             && !DECL_ARTIFICIAL (decl)
   21175          225 :             && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_)
   21176          225 :             && !DECL_IN_SYSTEM_HEADER (decl)
   21177          225 :             && TREE_TYPE (decl) != error_mark_node
   21178          225 :             && !TYPE_REF_P (TREE_TYPE (decl))
   21179       665378 :             && (!CLASS_TYPE_P (TREE_TYPE (decl))
   21180            0 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
   21181          225 :           warning_at (DECL_SOURCE_LOCATION (decl),
   21182          225 :                       OPT_Wunused_but_set_parameter_,
   21183              :                       "parameter %qD set but not used", decl);
   21184       399634 :       unused_but_set_errorcount = errorcount;
   21185              :     }
   21186              : 
   21187              :   /* Complain about locally defined typedefs that are not used in this
   21188              :      function.  */
   21189    166967232 :   maybe_warn_unused_local_typedefs ();
   21190              : 
   21191              :   /* Possibly warn about unused parameters.  */
   21192    166967232 :   if (warn_unused_parameter
   21193       732069 :       && !processing_template_decl
   21194    167321312 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   21195       272087 :     do_warn_unused_parameter (fndecl);
   21196              : 
   21197              :   /* Genericize before inlining.  */
   21198    166967232 :   if (!processing_template_decl
   21199    137934088 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   21200    234889214 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   21201     67921533 :     cp_genericize (fndecl);
   21202              : 
   21203              :   /* If this function can't throw any exceptions, remember that.  */
   21204    166967232 :   if (!processing_template_decl
   21205     68967044 :       && !cp_function_chain->can_throw
   21206     52617095 :       && !flag_non_call_exceptions
   21207     52608139 :       && !decl_replaceable_p (fndecl,
   21208     52608139 :                               opt_for_fn (fndecl, flag_semantic_interposition))
   21209    219330476 :       && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
   21210     52360146 :     TREE_NOTHROW (fndecl) = 1;
   21211              : 
   21212    166967325 :  cleanup:
   21213              : 
   21214              :   /* We're leaving the context of this function, so zap cfun.  It's still in
   21215              :      DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation.  */
   21216    166967325 :   set_cfun (NULL);
   21217    166967325 :   current_function_decl = NULL;
   21218              : 
   21219              :   /* If this is an in-class inline definition, we may have to pop the
   21220              :      bindings for the template parameters that we added in
   21221              :      maybe_begin_member_template_processing when start_function was
   21222              :      called.  */
   21223    166967325 :   if (inline_p)
   21224     85716633 :     maybe_end_member_template_processing ();
   21225              : 
   21226              :   /* Leave the scope of the class.  */
   21227    166967325 :   if (ctype)
   21228    127795605 :     pop_nested_class ();
   21229              : 
   21230    166967325 :   --function_depth;
   21231              : 
   21232              :   /* Clean up.  */
   21233    166967325 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
   21234              : 
   21235              :   /* Build outlined functions for coroutines and contracts.  */
   21236              : 
   21237    166967325 :   if (coroutine)
   21238              :     {
   21239              :       /* Emit the resumer and destroyer functions now, providing that we have
   21240              :          not encountered some fatal error.  */
   21241         1722 :       if (coroutine->cp_valid_coroutine ())
   21242              :         {
   21243         1644 :           coroutine->finish_transforms ();
   21244         1644 :           resumer = coroutine->get_resumer ();
   21245         1644 :           destroyer = coroutine->get_destroyer ();
   21246         1644 :           expand_or_defer_fn (resumer);
   21247         1644 :           expand_or_defer_fn (destroyer);
   21248              :         }
   21249         1722 :       delete coroutine;
   21250              :     }
   21251              : 
   21252              :   /* If we have used outlined contracts checking functions, build and emit
   21253              :      them here.  */
   21254    166967325 :   finish_function_outlined_contracts (fndecl);
   21255              : 
   21256    166967325 :   return fndecl;
   21257              : }
   21258              : 
   21259              : /* Create the FUNCTION_DECL for a function definition.
   21260              :    DECLSPECS and DECLARATOR are the parts of the declaration;
   21261              :    they describe the return type and the name of the function,
   21262              :    but twisted together in a fashion that parallels the syntax of C.
   21263              : 
   21264              :    This function creates a binding context for the function body
   21265              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   21266              : 
   21267              :    Returns a FUNCTION_DECL on success.
   21268              : 
   21269              :    If the DECLARATOR is not suitable for a function (it defines a datum
   21270              :    instead), we return 0, which tells yyparse to report a parse error.
   21271              : 
   21272              :    May return void_type_node indicating that this method is actually
   21273              :    a friend.  See grokfield for more details.
   21274              : 
   21275              :    Came here with a `.pushlevel' .
   21276              : 
   21277              :    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
   21278              :    CHANGES TO CODE IN `grokfield'.  */
   21279              : 
   21280              : tree
   21281     85937311 : grokmethod (cp_decl_specifier_seq *declspecs,
   21282              :             const cp_declarator *declarator, tree attrlist)
   21283              : {
   21284     85937311 :   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
   21285     85937311 :                                 &attrlist);
   21286              : 
   21287     85937311 :   if (fndecl == error_mark_node)
   21288              :     return error_mark_node;
   21289              : 
   21290     85937206 :   if (attrlist)
   21291            0 :     cplus_decl_attributes (&fndecl, attrlist, 0);
   21292              : 
   21293              :   /* Pass friends other than inline friend functions back.  */
   21294     85937206 :   if (fndecl == void_type_node)
   21295              :     return fndecl;
   21296              : 
   21297     85937206 :   if (DECL_IN_AGGR_P (fndecl))
   21298              :     {
   21299            0 :       if (DECL_CLASS_SCOPE_P (fndecl))
   21300            0 :         error ("%qD is already defined in class %qT", fndecl,
   21301            0 :                DECL_CONTEXT (fndecl));
   21302            0 :       return error_mark_node;
   21303              :     }
   21304              : 
   21305     85937206 :   check_template_shadow (fndecl);
   21306              : 
   21307              :   /* p1779 ABI-Isolation makes inline not a default for in-class
   21308              :      definitions attached to a named module.  If the user explicitly
   21309              :      made it inline, grokdeclarator will already have done the right
   21310              :      things.  */
   21311     85937206 :   if ((!named_module_attach_p ()
   21312         1132 :        || flag_module_implicit_inline
   21313              :       /* Lambda's operator function remains inline.  */
   21314         2228 :        || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
   21315              :       /* If the user explicitly asked for this to be inline, we don't
   21316              :          need to do more, but more importantly we want to warn if we
   21317              :          can't inline it.  */
   21318     85936743 :       && !DECL_DECLARED_INLINE_P (fndecl))
   21319              :     {
   21320     47603013 :       if (TREE_PUBLIC (fndecl))
   21321     45360901 :         DECL_COMDAT (fndecl) = 1;
   21322     47603013 :       DECL_DECLARED_INLINE_P (fndecl) = 1;
   21323              :       /* It's ok if we can't inline this.  */
   21324     47603013 :       DECL_NO_INLINE_WARNING_P (fndecl) = 1;
   21325              :     }
   21326              : 
   21327              :   /* We process method specializations in finish_struct_1.  */
   21328     85937206 :   if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
   21329              :     {
   21330              :       /* Avoid calling decl_spec_seq... until we have to.  */
   21331     69075082 :       bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   21332     69075082 :       fndecl = push_template_decl (fndecl, friendp);
   21333     69075082 :       if (fndecl == error_mark_node)
   21334              :         return fndecl;
   21335              :     }
   21336              : 
   21337     85937198 :   if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
   21338              :     {
   21339            0 :       fndecl = copy_node (fndecl);
   21340            0 :       TREE_CHAIN (fndecl) = NULL_TREE;
   21341              :     }
   21342              : 
   21343     85937198 :   cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
   21344              : 
   21345     85937198 :   DECL_IN_AGGR_P (fndecl) = 1;
   21346     85937198 :   return fndecl;
   21347              : }
   21348              : 
   21349              : 
   21350              : /* VAR is a VAR_DECL.  If its type is incomplete, remember VAR so that
   21351              :    we can lay it out later, when and if its type becomes complete.
   21352              : 
   21353              :    Also handle constexpr variables where the initializer involves
   21354              :    an unlowered PTRMEM_CST because the class isn't complete yet.  */
   21355              : 
   21356              : void
   21357    106661482 : maybe_register_incomplete_var (tree var)
   21358              : {
   21359    106661482 :   gcc_assert (VAR_P (var));
   21360              : 
   21361              :   /* Keep track of variables with incomplete types.  */
   21362     46733092 :   if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
   21363    153392779 :       && DECL_EXTERNAL (var))
   21364              :     {
   21365      6637156 :       tree inner_type = TREE_TYPE (var);
   21366              : 
   21367      6791906 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   21368       154750 :         inner_type = TREE_TYPE (inner_type);
   21369      6637156 :       inner_type = TYPE_MAIN_VARIANT (inner_type);
   21370              : 
   21371      6789883 :       if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
   21372              :           /* RTTI TD entries are created while defining the type_info.  */
   21373      6637156 :           || (TYPE_LANG_SPECIFIC (inner_type)
   21374      2360209 :               && TYPE_BEING_DEFINED (inner_type)))
   21375              :         {
   21376       152727 :           incomplete_var iv = {var, inner_type};
   21377       152727 :           vec_safe_push (incomplete_vars, iv);
   21378              :         }
   21379     12667835 :       else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
   21380      3529179 :                && DECL_CLASS_SCOPE_P (var)
   21381      1093069 :                && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
   21382      1093069 :                && decl_constant_var_p (var)
   21383      7184756 :                && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
   21384              :         {
   21385              :           /* When the outermost open class is complete we can resolve any
   21386              :              pointers-to-members.  */
   21387           27 :           tree context = outermost_open_class ();
   21388           27 :           incomplete_var iv = {var, context};
   21389           27 :           vec_safe_push (incomplete_vars, iv);
   21390              :         }
   21391              :     }
   21392    106661482 : }
   21393              : 
   21394              : /* Called when a class type (given by TYPE) is defined.  If there are
   21395              :    any existing VAR_DECLs whose type has been completed by this
   21396              :    declaration, update them now.  */
   21397              : 
   21398              : void
   21399     72396657 : complete_vars (tree type)
   21400              : {
   21401     72396657 :   unsigned ix;
   21402     72396657 :   incomplete_var *iv;
   21403              : 
   21404     73066050 :   for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
   21405              :     {
   21406       669393 :       if (same_type_p (type, iv->incomplete_type))
   21407              :         {
   21408       151523 :           tree var = iv->decl;
   21409       151523 :           tree type = TREE_TYPE (var);
   21410              : 
   21411       151523 :           if (type != error_mark_node
   21412       151523 :               && (TYPE_MAIN_VARIANT (strip_array_types (type))
   21413       151520 :                   == iv->incomplete_type))
   21414              :             {
   21415              :               /* Complete the type of the variable.  */
   21416       151493 :               complete_type (type);
   21417       151493 :               cp_apply_type_quals_to_decl (cp_type_quals (type), var);
   21418       151493 :               if (COMPLETE_TYPE_P (type))
   21419       151478 :                 layout_var_decl (var);
   21420              :             }
   21421              : 
   21422              :           /* Remove this entry from the list.  */
   21423       151523 :           incomplete_vars->unordered_remove (ix);
   21424              :         }
   21425              :       else
   21426       517870 :         ix++;
   21427              :     }
   21428     72396657 : }
   21429              : 
   21430              : /* If DECL is of a type which needs a cleanup, build and return an
   21431              :    expression to perform that cleanup here.  Return NULL_TREE if no
   21432              :    cleanup need be done.  DECL can also be a _REF when called from
   21433              :    split_nonconstant_init_1.  */
   21434              : 
   21435              : tree
   21436     91796907 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
   21437              : {
   21438     91796907 :   tree type;
   21439     91796907 :   tree attr;
   21440     91796907 :   tree cleanup;
   21441              : 
   21442              :   /* Assume no cleanup is required.  */
   21443     91796907 :   cleanup = NULL_TREE;
   21444              : 
   21445     91796907 :   if (!decl || error_operand_p (decl))
   21446              :     return cleanup;
   21447              : 
   21448              :   /* Handle "__attribute__((cleanup))".  We run the cleanup function
   21449              :      before the destructor since the destructor is what actually
   21450              :      terminates the lifetime of the object.  */
   21451     91796907 :   if (DECL_P (decl))
   21452     91438846 :     attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
   21453              :   else
   21454              :     attr = NULL_TREE;
   21455     91438846 :   if (attr)
   21456              :     {
   21457          166 :       tree id;
   21458          166 :       tree fn;
   21459          166 :       tree arg;
   21460              : 
   21461              :       /* Get the name specified by the user for the cleanup function.  */
   21462          166 :       id = TREE_VALUE (TREE_VALUE (attr));
   21463              :       /* Look up the name to find the cleanup function to call.  It is
   21464              :          important to use lookup_name here because that is what is
   21465              :          used in c-common.cc:handle_cleanup_attribute when performing
   21466              :          initial checks on the attribute.  Note that those checks
   21467              :          include ensuring that the function found is not an overloaded
   21468              :          function, or an object with an overloaded call operator,
   21469              :          etc.; we can rely on the fact that the function found is an
   21470              :          ordinary FUNCTION_DECL.  */
   21471          166 :       fn = lookup_name (id);
   21472          166 :       arg = build_address (decl);
   21473          166 :       if (!mark_used (decl, complain) && !(complain & tf_error))
   21474            0 :         return error_mark_node;
   21475          166 :       cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
   21476          166 :       if (cleanup == error_mark_node)
   21477              :         return error_mark_node;
   21478              :     }
   21479              :   /* Handle ordinary C++ destructors.  */
   21480     91796895 :   type = TREE_TYPE (decl);
   21481     91796895 :   if (type_build_dtor_call (type))
   21482              :     {
   21483      6912469 :       int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
   21484      6912469 :       tree addr;
   21485      6912469 :       tree call;
   21486              : 
   21487      6912469 :       if (TREE_CODE (type) == ARRAY_TYPE)
   21488              :         addr = decl;
   21489              :       else
   21490      6907199 :         addr = build_address (decl);
   21491              : 
   21492      6912469 :       call = build_delete (input_location, TREE_TYPE (addr), addr,
   21493              :                            sfk_complete_destructor, flags, 0, complain);
   21494      6912469 :       if (call == error_mark_node)
   21495              :         cleanup = error_mark_node;
   21496      6912406 :       else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   21497              :         /* Discard the call.  */;
   21498      4224614 :       else if (decl_maybe_constant_destruction (decl, type)
   21499      4224816 :                && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   21500          202 :         cxx_constant_dtor (call, decl);
   21501      4224412 :       else if (cleanup)
   21502            3 :         cleanup = cp_build_compound_expr (cleanup, call, complain);
   21503              :       else
   21504              :         cleanup = call;
   21505              :     }
   21506              : 
   21507              :   /* build_delete sets the location of the destructor call to the
   21508              :      current location, even though the destructor is going to be
   21509              :      called later, at the end of the current scope.  This can lead to
   21510              :      a "jumpy" behavior for users of debuggers when they step around
   21511              :      the end of the block.  So let's unset the location of the
   21512              :      destructor call instead.  */
   21513     91796895 :   protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
   21514     91796895 :   if (cleanup && CONVERT_EXPR_P (cleanup))
   21515            0 :     protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
   21516              : 
   21517            0 :   if (cleanup
   21518      4224626 :       && DECL_P (decl)
   21519      4224160 :       && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
   21520              :       /* Treat objects with destructors as used; the destructor may do
   21521              :          something substantive.  */
   21522      4224154 :       && !mark_used (decl, complain) && !(complain & tf_error))
   21523            0 :     return error_mark_node;
   21524              : 
   21525      4224626 :   if (cleanup && cfun && !processing_template_decl
   21526     95586061 :       && !expr_noexcept_p (cleanup, tf_none))
   21527         5436 :     cp_function_chain->throwing_cleanup = true;
   21528              : 
   21529              :   return cleanup;
   21530              : }
   21531              : 
   21532              : 
   21533              : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
   21534              :    FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
   21535              :    METHOD_TYPE or FUNCTION_TYPE, or pointer to member function.  */
   21536              : 
   21537              : tree
   21538       790135 : static_fn_type (tree memfntype)
   21539              : {
   21540       790135 :   tree fntype;
   21541       790135 :   tree args;
   21542              : 
   21543       790135 :   if (TYPE_PTRMEMFUNC_P (memfntype))
   21544        20899 :     memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
   21545       790135 :   if (INDIRECT_TYPE_P (memfntype)
   21546       676945 :       || TREE_CODE (memfntype) == FUNCTION_DECL)
   21547       618525 :     memfntype = TREE_TYPE (memfntype);
   21548       790135 :   if (TREE_CODE (memfntype) == FUNCTION_TYPE)
   21549              :     return memfntype;
   21550       622185 :   gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
   21551       622185 :   args = TYPE_ARG_TYPES (memfntype);
   21552       622185 :   fntype = cp_build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
   21553       622185 :   fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
   21554       622185 :   fntype = (cp_build_type_attribute_variant
   21555       622185 :             (fntype, TYPE_ATTRIBUTES (memfntype)));
   21556       622185 :   fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
   21557       622185 :   return fntype;
   21558              : }
   21559              : 
   21560              : /* DECL was originally constructed as a non-static member function,
   21561              :    but turned out to be static.  Update it accordingly.  */
   21562              : 
   21563              : void
   21564       179322 : revert_static_member_fn (tree decl)
   21565              : {
   21566       179322 :   tree stype = static_fn_type (decl);
   21567       179322 :   cp_cv_quals quals = type_memfn_quals (stype);
   21568       179322 :   cp_ref_qualifier rqual = type_memfn_rqual (stype);
   21569              : 
   21570       179322 :   if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
   21571            9 :     stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
   21572              : 
   21573       179322 :   TREE_TYPE (decl) = stype;
   21574              : 
   21575       179322 :   if (DECL_ARGUMENTS (decl))
   21576       179322 :     DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
   21577       179322 :   DECL_STATIC_FUNCTION_P (decl) = 1;
   21578       179322 : }
   21579              : 
   21580              : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
   21581              :    one of the language-independent trees.  */
   21582              : 
   21583              : enum cp_tree_node_structure_enum
   21584  39159331272 : cp_tree_node_structure (union lang_tree_node * t)
   21585              : {
   21586  39159331272 :   switch (TREE_CODE (&t->generic))
   21587              :     {
   21588              :     case ARGUMENT_PACK_SELECT:  return TS_CP_ARGUMENT_PACK_SELECT;
   21589    160745341 :     case BASELINK:              return TS_CP_BASELINK;
   21590     84242042 :     case CONSTRAINT_INFO:       return TS_CP_CONSTRAINT_INFO;
   21591     11597055 :     case DEFERRED_NOEXCEPT:     return TS_CP_DEFERRED_NOEXCEPT;
   21592      6319645 :     case DEFERRED_PARSE:        return TS_CP_DEFERRED_PARSE;
   21593   2102094730 :     case IDENTIFIER_NODE:       return TS_CP_IDENTIFIER;
   21594      3534107 :     case LAMBDA_EXPR:           return TS_CP_LAMBDA_EXPR;
   21595       213525 :     case BINDING_VECTOR:        return TS_CP_BINDING_VECTOR;
   21596    725167444 :     case OVERLOAD:              return TS_CP_OVERLOAD;
   21597          727 :     case PTRMEM_CST:            return TS_CP_PTRMEM;
   21598     16204846 :     case STATIC_ASSERT:         return TS_CP_STATIC_ASSERT;
   21599    692144245 :     case TEMPLATE_DECL:         return TS_CP_TEMPLATE_DECL;
   21600   1607164128 :     case TEMPLATE_INFO:         return TS_CP_TEMPLATE_INFO;
   21601    706891811 :     case TEMPLATE_PARM_INDEX:   return TS_CP_TPI;
   21602     15576877 :     case TRAIT_EXPR:            return TS_CP_TRAIT_EXPR;
   21603            6 :     case TU_LOCAL_ENTITY:       return TS_CP_TU_LOCAL_ENTITY;
   21604      3614255 :     case USERDEF_LITERAL:       return TS_CP_USERDEF_LITERAL;
   21605     14620823 :     case REQUIRES_EXPR:         return TS_CP_REQUIRES_EXPR;
   21606  33009199665 :     default:                    return TS_CP_GENERIC;
   21607              :     }
   21608              : }
   21609              : 
   21610              : bool
   21611         9099 : cp_missing_noreturn_ok_p (tree decl)
   21612              : {
   21613              :   /* A missing noreturn is ok for the `main' function.  */
   21614         9099 :   return DECL_MAIN_P (decl);
   21615              : }
   21616              : 
   21617              : /* Return the decl used to identify the COMDAT group into which DECL should
   21618              :    be placed.  */
   21619              : 
   21620              : tree
   21621    128398037 : cxx_comdat_group (tree decl)
   21622              : {
   21623              :   /* Virtual tables, construction virtual tables, and virtual table
   21624              :      tables all go in a single COMDAT group, named after the primary
   21625              :      virtual table.  */
   21626    128398037 :   if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
   21627       534439 :     decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
   21628              :   /* For all other DECLs, the COMDAT group is the mangled name of the
   21629              :      declaration itself.  */
   21630              :   else
   21631              :     {
   21632    127863598 :       while (DECL_THUNK_P (decl))
   21633              :         {
   21634              :           /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
   21635              :              into the same section as the target function.  In that case
   21636              :              we must return target's name.  */
   21637            0 :           tree target = THUNK_TARGET (decl);
   21638            0 :           if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
   21639            0 :               && DECL_SECTION_NAME (target) != NULL
   21640            0 :               && DECL_ONE_ONLY (target))
   21641              :             decl = target;
   21642              :           else
   21643              :             break;
   21644              :         }
   21645              :       /* If a ctor/dtor has already set the comdat group by
   21646              :          maybe_clone_body, don't override it.  */
   21647    127863598 :       if (SUPPORTS_ONE_ONLY
   21648    127863598 :           && TREE_CODE (decl) == FUNCTION_DECL
   21649    127863598 :           && DECL_CLONED_FUNCTION_P (decl))
   21650     18581858 :         if (tree comdat = DECL_COMDAT_GROUP (decl))
   21651      2706075 :           return comdat;
   21652              :     }
   21653              : 
   21654              :   return decl;
   21655              : }
   21656              : 
   21657              : /* Returns the return type for FN as written by the user, which may include
   21658              :    a placeholder for a deduced return type.  */
   21659              : 
   21660              : tree
   21661    562733435 : fndecl_declared_return_type (tree fn)
   21662              : {
   21663    562733435 :   fn = STRIP_TEMPLATE (fn);
   21664    562733435 :   if (FNDECL_USED_AUTO (fn))
   21665       403269 :     return DECL_SAVED_AUTO_RETURN_TYPE (fn);
   21666              : 
   21667    562330166 :   return TREE_TYPE (TREE_TYPE (fn));
   21668              : }
   21669              : 
   21670              : /* Returns true iff DECL is a variable or function declared with an auto type
   21671              :    that has not yet been deduced to a real type.  */
   21672              : 
   21673              : bool
   21674   1011634897 : undeduced_auto_decl (tree decl)
   21675              : {
   21676   1011634897 :   if (cxx_dialect < cxx11)
   21677              :     return false;
   21678   1009347606 :   STRIP_ANY_LOCATION_WRAPPER (decl);
   21679    460673894 :   return ((VAR_OR_FUNCTION_DECL_P (decl)
   21680     96759673 :            || TREE_CODE (decl) == TEMPLATE_DECL)
   21681   1373521762 :           && type_uses_auto (TREE_TYPE (decl)));
   21682              : }
   21683              : 
   21684              : /* Complain if DECL has an undeduced return type.  */
   21685              : 
   21686              : bool
   21687    335547527 : require_deduced_type (tree decl, tsubst_flags_t complain)
   21688              : {
   21689    335547527 :   if (undeduced_auto_decl (decl))
   21690              :     {
   21691        14387 :       if (TREE_CODE (decl) == FUNCTION_DECL
   21692        14387 :           && fndecl_built_in_p (decl, CP_BUILT_IN_SOURCE_LOCATION,
   21693              :                                 BUILT_IN_FRONTEND))
   21694              :         {
   21695              :           /* Set the return type of __builtin_source_location.  */
   21696        10264 :           tree type = get_source_location_impl_type ();
   21697        10264 :           if (type == error_mark_node)
   21698              :             {
   21699           33 :               inform (input_location, "using %qs", "__builtin_source_location");
   21700           33 :               return false;
   21701              :             }
   21702        10231 :           type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
   21703        10231 :           type = build_pointer_type (type);
   21704        10231 :           apply_deduced_return_type (decl, type);
   21705        10231 :           return true;
   21706              :         }
   21707              : 
   21708         4123 :       if (TREE_CODE (decl) == FUNCTION_DECL
   21709         4123 :           && fndecl_built_in_p (decl, CP_BUILT_IN_CURRENT_EXCEPTION,
   21710              :                                 BUILT_IN_FRONTEND))
   21711              :         {
   21712              :           /* Set the return type of __builtin_current_exception.  */
   21713         2123 :           tree name = get_identifier ("exception_ptr");
   21714         2123 :           tree eptr = lookup_qualified_name (std_node, name);
   21715         2123 :           tree fld;
   21716         2123 :           if (TREE_CODE (eptr) != TYPE_DECL
   21717         2123 :               || !CLASS_TYPE_P (TREE_TYPE (eptr))
   21718         2123 :               || !COMPLETE_TYPE_P (TREE_TYPE (eptr))
   21719         2123 :               || !(fld = next_aggregate_field (TYPE_FIELDS (TREE_TYPE (eptr))))
   21720         2123 :               || DECL_ARTIFICIAL (fld)
   21721         2123 :               || TREE_CODE (TREE_TYPE (fld)) != POINTER_TYPE
   21722         2123 :               || next_aggregate_field (DECL_CHAIN (fld))
   21723         4246 :               || !tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (eptr)),
   21724         2123 :                                       TYPE_SIZE (TREE_TYPE (fld))))
   21725              :             {
   21726            0 :               error ("%qs used without %qs declaration",
   21727              :                      "__builtin_current_exception", "std::exception_ptr");
   21728            0 :               return false;
   21729              :             }
   21730              : 
   21731         2123 :           apply_deduced_return_type (decl, TREE_TYPE (eptr));
   21732         2123 :           return true;
   21733              :         }
   21734              : 
   21735         2000 :       if (warning_suppressed_p (decl) && seen_error ())
   21736              :         /* We probably already complained about deduction failure.  */;
   21737         1815 :       else if (complain & tf_error)
   21738           74 :         error ("use of %qD before deduction of %<auto%>", decl);
   21739         2000 :       note_failed_type_completion (decl, complain);
   21740         2000 :       return false;
   21741              :     }
   21742              :   return true;
   21743              : }
   21744              : 
   21745              : /* Create a representation of the explicit-specifier with
   21746              :    constant-expression of EXPR.  COMPLAIN is as for tsubst.  */
   21747              : 
   21748              : tree
   21749      8472364 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
   21750              : {
   21751      8472364 :   if (check_for_bare_parameter_packs (expr))
   21752            3 :     return error_mark_node;
   21753              : 
   21754      8472361 :   if (instantiation_dependent_expression_p (expr))
   21755              :     /* Wait for instantiation, tsubst_function_decl will handle it.  */
   21756              :     return expr;
   21757              : 
   21758      6800070 :   expr = build_converted_constant_bool_expr (expr, complain);
   21759      6800070 :   expr = instantiate_non_dependent_expr (expr, complain);
   21760      6800070 :   expr = cxx_constant_value (expr, complain);
   21761      6800070 :   return expr;
   21762              : }
   21763              : 
   21764              : #include "gt-cp-decl.h"
        

Generated by: LCOV version 2.6-beta

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