LCOV - code coverage report
Current view: top level - gcc/cp - decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.4 % 8991 8487
Test Date: 2025-07-26 09:32:30 Functions: 97.4 % 231 225
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Process declarations and variables for -*- C++ -*- compiler.
       2                 :             :    Copyright (C) 1988-2025 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 "gcc-urlifier.h"
      64                 :             : #include "diagnostic-highlight-colors.h"
      65                 :             : #include "pretty-print-markup.h"
      66                 :             : 
      67                 :             : /* Possible cases of bad specifiers type used by bad_specifiers. */
      68                 :             : enum bad_spec_place {
      69                 :             :   BSP_VAR,    /* variable */
      70                 :             :   BSP_PARM,   /* parameter */
      71                 :             :   BSP_TYPE,   /* type */
      72                 :             :   BSP_FIELD   /* field */
      73                 :             : };
      74                 :             : 
      75                 :             : static const char *redeclaration_error_message (tree, tree);
      76                 :             : 
      77                 :             : static bool decl_jump_unsafe (tree);
      78                 :             : static void require_complete_types_for_parms (tree);
      79                 :             : static tree grok_reference_init (tree, tree, tree, int);
      80                 :             : static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
      81                 :             :                          int, int, int, bool, int, tree, location_t);
      82                 :             : static void check_static_variable_definition (tree, tree);
      83                 :             : static void record_unknown_type (tree, const char *);
      84                 :             : static int member_function_or_else (tree, tree, enum overload_flags);
      85                 :             : static tree local_variable_p_walkfn (tree *, int *, void *);
      86                 :             : static const char *tag_name (enum tag_types);
      87                 :             : static tree lookup_and_check_tag (enum tag_types, tree, TAG_how, bool);
      88                 :             : static void maybe_deduce_size_from_array_init (tree, tree);
      89                 :             : static void layout_var_decl (tree);
      90                 :             : static tree check_initializer (tree, tree, int, vec<tree, va_gc> **);
      91                 :             : static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
      92                 :             : static void copy_type_enum (tree , tree);
      93                 :             : static void check_function_type (tree, tree);
      94                 :             : static void begin_destructor_body (void);
      95                 :             : static void record_key_method_defined (tree);
      96                 :             : static tree create_array_type_for_decl (tree, tree, tree, location_t);
      97                 :             : static tree get_atexit_node (void);
      98                 :             : static tree get_dso_handle_node (void);
      99                 :             : static tree start_cleanup_fn (tree, bool, bool);
     100                 :             : static void end_cleanup_fn (void);
     101                 :             : static tree cp_make_fname_decl (location_t, tree, int);
     102                 :             : static void initialize_predefined_identifiers (void);
     103                 :             : static tree check_special_function_return_type
     104                 :             :        (special_function_kind, tree, tree, int, const cp_declarator**,
     105                 :             :         const location_t*);
     106                 :             : static tree push_cp_library_fn (enum tree_code, tree, int);
     107                 :             : static tree build_cp_library_fn (tree, enum tree_code, tree, int);
     108                 :             : static void store_parm_decls (tree);
     109                 :             : static void initialize_local_var (tree, tree, bool);
     110                 :             : static void expand_static_init (tree, tree);
     111                 :             : static location_t smallest_type_location (const cp_decl_specifier_seq*);
     112                 :             : static bool identify_goto (tree, location_t, const location_t *,
     113                 :             :                            enum diagnostics::kind, bool);
     114                 :             : 
     115                 :             : /* The following symbols are subsumed in the cp_global_trees array, and
     116                 :             :    listed here individually for documentation purposes.
     117                 :             : 
     118                 :             :    C++ extensions
     119                 :             :         tree wchar_decl_node;
     120                 :             : 
     121                 :             :         tree vtable_entry_type;
     122                 :             :         tree delta_type_node;
     123                 :             :         tree __t_desc_type_node;
     124                 :             : 
     125                 :             :         tree class_type_node;
     126                 :             :         tree unknown_type_node;
     127                 :             : 
     128                 :             :    Array type `vtable_entry_type[]'
     129                 :             : 
     130                 :             :         tree vtbl_type_node;
     131                 :             :         tree vtbl_ptr_type_node;
     132                 :             : 
     133                 :             :    Namespaces,
     134                 :             : 
     135                 :             :         tree std_node;
     136                 :             :         tree abi_node;
     137                 :             : 
     138                 :             :    A FUNCTION_DECL which can call `abort'.  Not necessarily the
     139                 :             :    one that the user will declare, but sufficient to be called
     140                 :             :    by routines that want to abort the program.
     141                 :             : 
     142                 :             :         tree abort_fndecl;
     143                 :             : 
     144                 :             :    Used by RTTI
     145                 :             :         tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
     146                 :             :         tree tinfo_var_id;  */
     147                 :             : 
     148                 :             : tree cp_global_trees[CPTI_MAX];
     149                 :             : 
     150                 :             : /* A list of objects which have constructors or destructors
     151                 :             :    which reside in namespace scope.  The decl is stored in
     152                 :             :    the TREE_VALUE slot and the initializer is stored
     153                 :             :    in the TREE_PURPOSE slot.  */
     154                 :             : tree static_aggregates;
     155                 :             : 
     156                 :             : /* Like static_aggregates, but for thread_local variables.  */
     157                 :             : tree tls_aggregates;
     158                 :             : 
     159                 :             : /* A hash-map mapping from variable decls to the dynamic initializer for
     160                 :             :    the decl.  This is currently only used by OpenMP.  */
     161                 :             : decl_tree_map *dynamic_initializers;
     162                 :             : 
     163                 :             : /* -- end of C++ */
     164                 :             : 
     165                 :             : /* A node for the integer constant 2.  */
     166                 :             : 
     167                 :             : tree integer_two_node;
     168                 :             : 
     169                 :             : /* vector of static decls.  */
     170                 :             : vec<tree, va_gc> *static_decls;
     171                 :             : 
     172                 :             : /* vector of keyed classes.  */
     173                 :             : vec<tree, va_gc> *keyed_classes;
     174                 :             : 
     175                 :             : /* Used only for jumps to as-yet undefined labels, since jumps to
     176                 :             :    defined labels can have their validity checked immediately.  */
     177                 :             : 
     178                 :             : struct GTY((chain_next ("%h.next"))) named_label_use_entry {
     179                 :             :   struct named_label_use_entry *next;
     180                 :             :   /* The binding level to which this entry is *currently* attached.
     181                 :             :      This is initially the binding level in which the goto appeared,
     182                 :             :      but is modified as scopes are closed.  */
     183                 :             :   cp_binding_level *binding_level;
     184                 :             :   /* The head of the names list that was current when the goto appeared,
     185                 :             :      or the inner scope popped.  These are the decls that will *not* be
     186                 :             :      skipped when jumping to the label.  */
     187                 :             :   tree names_in_scope;
     188                 :             :   /* If the use is a possible destination of a computed goto, a vec of decls
     189                 :             :      that aren't destroyed, filled in by poplevel_named_label_1.  */
     190                 :             :   vec<tree,va_gc> *computed_goto;
     191                 :             :   /* The location of the goto, for error reporting.  */
     192                 :             :   location_t o_goto_locus;
     193                 :             :   /* True if an OpenMP structured block scope has been closed since
     194                 :             :      the goto appeared.  This means that the branch from the label will
     195                 :             :      illegally exit an OpenMP scope.  */
     196                 :             :   bool in_omp_scope;
     197                 :             : };
     198                 :             : 
     199                 :             : /* A list of all LABEL_DECLs in the function that have names.  Here so
     200                 :             :    we can clear out their names' definitions at the end of the
     201                 :             :    function, and so we can check the validity of jumps to these labels.  */
     202                 :             : 
     203                 :             : struct GTY((for_user)) named_label_entry {
     204                 :             : 
     205                 :             :   tree name;  /* Name of decl. */
     206                 :             : 
     207                 :             :   tree label_decl; /* LABEL_DECL, unless deleted local label. */
     208                 :             : 
     209                 :             :   named_label_entry *outer; /* Outer shadowed chain.  */
     210                 :             : 
     211                 :             :   /* The binding level to which the label is *currently* attached.
     212                 :             :      This is initially set to the binding level in which the label
     213                 :             :      is defined, but is modified as scopes are closed.  */
     214                 :             :   cp_binding_level *binding_level;
     215                 :             : 
     216                 :             :   /* The head of the names list that was current when the label was
     217                 :             :      defined, or the inner scope popped.  These are the decls that will
     218                 :             :      be skipped when jumping to the label.  */
     219                 :             :   tree names_in_scope;
     220                 :             : 
     221                 :             :   /* A vector of all decls from all binding levels that would be
     222                 :             :      crossed by a backward branch to the label.  */
     223                 :             :   vec<tree, va_gc> *bad_decls;
     224                 :             : 
     225                 :             :   /* A list of uses of the label, before the label is defined.  */
     226                 :             :   named_label_use_entry *uses;
     227                 :             : 
     228                 :             :   /* True if we've seen &&label.  Appalently we can't use TREE_ADDRESSABLE for
     229                 :             :      this, it has a more specific meaning for LABEL_DECL.  */
     230                 :             :   bool addressed;
     231                 :             : 
     232                 :             :   /* The following bits are set after the label is defined, and are
     233                 :             :      updated as scopes are popped.  They indicate that a jump to the
     234                 :             :      label will illegally enter a scope of the given flavor.  */
     235                 :             :   bool in_try_scope;
     236                 :             :   bool in_catch_scope;
     237                 :             :   bool in_omp_scope;
     238                 :             :   bool in_transaction_scope;
     239                 :             :   bool in_constexpr_if;
     240                 :             :   bool in_consteval_if;
     241                 :             :   bool in_stmt_expr;
     242                 :             : };
     243                 :             : 
     244                 :             : #define named_labels cp_function_chain->x_named_labels
     245                 :             : 
     246                 :             : /* The number of function bodies which we are currently processing.
     247                 :             :    (Zero if we are at namespace scope, one inside the body of a
     248                 :             :    function, two inside the body of a function in a local class, etc.)  */
     249                 :             : int function_depth;
     250                 :             : 
     251                 :             : /* Whether the exception-specifier is part of a function type (i.e. C++17).  */
     252                 :             : bool flag_noexcept_type;
     253                 :             : 
     254                 :             : /* States indicating how grokdeclarator() should handle declspecs marked
     255                 :             :    with __attribute__((deprecated)).  An object declared as
     256                 :             :    __attribute__((deprecated)) suppresses warnings of uses of other
     257                 :             :    deprecated items.  */
     258                 :             : enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
     259                 :             : 
     260                 :             : 
     261                 :             : /* A list of VAR_DECLs whose type was incomplete at the time the
     262                 :             :    variable was declared.  */
     263                 :             : 
     264                 :             : struct GTY(()) incomplete_var {
     265                 :             :   tree decl;
     266                 :             :   tree incomplete_type;
     267                 :             : };
     268                 :             : 
     269                 :             : 
     270                 :             : static GTY(()) vec<incomplete_var, va_gc> *incomplete_vars;
     271                 :             : 
     272                 :             : /* Returns the kind of template specialization we are currently
     273                 :             :    processing, given that it's declaration contained N_CLASS_SCOPES
     274                 :             :    explicit scope qualifications.  */
     275                 :             : 
     276                 :             : tmpl_spec_kind
     277                 :   226442596 : current_tmpl_spec_kind (int n_class_scopes)
     278                 :             : {
     279                 :   226442596 :   int n_template_parm_scopes = 0;
     280                 :   226442596 :   int seen_specialization_p = 0;
     281                 :   226442596 :   int innermost_specialization_p = 0;
     282                 :   226442596 :   cp_binding_level *b;
     283                 :             : 
     284                 :             :   /* Scan through the template parameter scopes.  */
     285                 :   226442596 :   for (b = current_binding_level;
     286                 :   283979072 :        b->kind == sk_template_parms;
     287                 :    57536476 :        b = b->level_chain)
     288                 :             :     {
     289                 :             :       /* If we see a specialization scope inside a parameter scope,
     290                 :             :          then something is wrong.  That corresponds to a declaration
     291                 :             :          like:
     292                 :             : 
     293                 :             :             template <class T> template <> ...
     294                 :             : 
     295                 :             :          which is always invalid since [temp.expl.spec] forbids the
     296                 :             :          specialization of a class member template if the enclosing
     297                 :             :          class templates are not explicitly specialized as well.  */
     298                 :    57536476 :       if (b->explicit_spec_p)
     299                 :             :         {
     300                 :      963112 :           if (n_template_parm_scopes == 0)
     301                 :             :             innermost_specialization_p = 1;
     302                 :             :           else
     303                 :        1325 :             seen_specialization_p = 1;
     304                 :             :         }
     305                 :    56573364 :       else if (seen_specialization_p == 1)
     306                 :             :         return tsk_invalid_member_spec;
     307                 :             : 
     308                 :    57536476 :       ++n_template_parm_scopes;
     309                 :             :     }
     310                 :             : 
     311                 :             :   /* Handle explicit instantiations.  */
     312                 :   226442596 :   if (processing_explicit_instantiation)
     313                 :             :     {
     314                 :     2066356 :       if (n_template_parm_scopes != 0)
     315                 :             :         /* We've seen a template parameter list during an explicit
     316                 :             :            instantiation.  For example:
     317                 :             : 
     318                 :             :              template <class T> template void f(int);
     319                 :             : 
     320                 :             :            This is erroneous.  */
     321                 :             :         return tsk_invalid_expl_inst;
     322                 :             :       else
     323                 :     2066356 :         return tsk_expl_inst;
     324                 :             :     }
     325                 :             : 
     326                 :   224376240 :   if (n_template_parm_scopes < n_class_scopes)
     327                 :             :     /* We've not seen enough template headers to match all the
     328                 :             :        specialized classes present.  For example:
     329                 :             : 
     330                 :             :          template <class T> void R<T>::S<T>::f(int);
     331                 :             : 
     332                 :             :        This is invalid; there needs to be one set of template
     333                 :             :        parameters for each class.  */
     334                 :             :     return tsk_insufficient_parms;
     335                 :   224376240 :   else if (n_template_parm_scopes == n_class_scopes)
     336                 :             :     /* We're processing a non-template declaration (even though it may
     337                 :             :        be a member of a template class.)  For example:
     338                 :             : 
     339                 :             :          template <class T> void S<T>::f(int);
     340                 :             : 
     341                 :             :        The `class T' matches the `S<T>', leaving no template headers
     342                 :             :        corresponding to the `f'.  */
     343                 :             :     return tsk_none;
     344                 :    49152749 :   else if (n_template_parm_scopes > n_class_scopes + 1)
     345                 :             :     /* We've got too many template headers.  For example:
     346                 :             : 
     347                 :             :          template <> template <class T> void f (T);
     348                 :             : 
     349                 :             :        There need to be more enclosing classes.  */
     350                 :             :     return tsk_excessive_parms;
     351                 :             :   else
     352                 :             :     /* This must be a template.  It's of the form:
     353                 :             : 
     354                 :             :          template <class T> template <class U> void S<T>::f(U);
     355                 :             : 
     356                 :             :        This is a specialization if the innermost level was a
     357                 :             :        specialization; otherwise it's just a definition of the
     358                 :             :        template.  */
     359                 :    97856676 :     return innermost_specialization_p ? tsk_expl_spec : tsk_template;
     360                 :             : }
     361                 :             : 
     362                 :             : /* Exit the current scope.  */
     363                 :             : 
     364                 :             : void
     365                 :    87861053 : finish_scope (void)
     366                 :             : {
     367                 :    87861053 :   poplevel (0, 0, 0);
     368                 :    87861053 : }
     369                 :             : 
     370                 :             : /* When a label goes out of scope, check to see if that label was used
     371                 :             :    in a valid manner, and issue any appropriate warnings or errors.  */
     372                 :             : 
     373                 :             : static void
     374                 :       19946 : check_label_used (tree label)
     375                 :             : {
     376                 :       19946 :   if (!processing_template_decl)
     377                 :             :     {
     378                 :       19673 :       if (DECL_INITIAL (label) == NULL_TREE)
     379                 :             :         {
     380                 :           9 :           location_t location;
     381                 :             : 
     382                 :           9 :           error ("label %q+D used but not defined", label);
     383                 :           9 :           location = input_location;
     384                 :             :             /* FIXME want (LOCATION_FILE (input_location), (line)0) */
     385                 :             :           /* Avoid crashing later.  */
     386                 :           9 :           define_label (location, DECL_NAME (label));
     387                 :             :         }
     388                 :             :       else
     389                 :       19664 :         warn_for_unused_label (label);
     390                 :             :     }
     391                 :       19946 : }
     392                 :             : 
     393                 :             : /* Helper function to sort named label entries in a vector by DECL_UID.  */
     394                 :             : 
     395                 :             : static int
     396                 :      220042 : sort_labels (const void *a, const void *b)
     397                 :             : {
     398                 :      220042 :   tree label1 = *(tree const *) a;
     399                 :      220042 :   tree label2 = *(tree const *) b;
     400                 :             : 
     401                 :             :   /* DECL_UIDs can never be equal.  */
     402                 :      220042 :   return DECL_UID (label1) > DECL_UID (label2) ? -1 : +1;
     403                 :             : }
     404                 :             : 
     405                 :             : /* At the end of a function, all labels declared within the function
     406                 :             :    go out of scope.  BLOCK is the top-level block for the
     407                 :             :    function.  */
     408                 :             : 
     409                 :             : static void
     410                 :   143956557 : pop_labels (tree block)
     411                 :             : {
     412                 :   143956557 :   if (!named_labels)
     413                 :   143952019 :     return;
     414                 :             : 
     415                 :             :   /* We need to add the labels to the block chain, so debug
     416                 :             :      information is emitted.  But, we want the order to be stable so
     417                 :             :      need to sort them first.  Otherwise the debug output could be
     418                 :             :      randomly ordered.  I guess it's mostly stable, unless the hash
     419                 :             :      table implementation changes.  */
     420                 :        4538 :   auto_vec<tree, 32> labels (named_labels->elements ());
     421                 :        4538 :   hash_table<named_label_hash>::iterator end (named_labels->end ());
     422                 :       24463 :   for (hash_table<named_label_hash>::iterator iter
     423                 :       48926 :          (named_labels->begin ()); iter != end; ++iter)
     424                 :             :     {
     425                 :       19925 :       named_label_entry *ent = *iter;
     426                 :             : 
     427                 :       19925 :       gcc_checking_assert (!ent->outer);
     428                 :       19925 :       if (ent->label_decl)
     429                 :       19739 :         labels.quick_push (ent->label_decl);
     430                 :       19925 :       ggc_free (ent);
     431                 :             :     }
     432                 :        4538 :   named_labels = NULL;
     433                 :        4538 :   labels.qsort (sort_labels);
     434                 :             : 
     435                 :       24277 :   while (labels.length ())
     436                 :             :     {
     437                 :       19739 :       tree label = labels.pop ();
     438                 :             : 
     439                 :       19739 :       DECL_CHAIN (label) = BLOCK_VARS (block);
     440                 :       19739 :       BLOCK_VARS (block) = label;
     441                 :             : 
     442                 :       19739 :       check_label_used (label);
     443                 :             :     }
     444                 :        4538 : }
     445                 :             : 
     446                 :             : /* At the end of a block with local labels, restore the outer definition.  */
     447                 :             : 
     448                 :             : static void
     449                 :         207 : pop_local_label (tree id, tree label)
     450                 :             : {
     451                 :         207 :   check_label_used (label);
     452                 :         207 :   named_label_entry **slot = named_labels->find_slot_with_hash
     453                 :         207 :     (id, IDENTIFIER_HASH_VALUE (id), NO_INSERT);
     454                 :         207 :   named_label_entry *ent = *slot;
     455                 :             : 
     456                 :         207 :   if (ent->outer)
     457                 :             :     ent = ent->outer;
     458                 :             :   else
     459                 :             :     {
     460                 :         198 :       ent = ggc_cleared_alloc<named_label_entry> ();
     461                 :         198 :       ent->name = id;
     462                 :             :     }
     463                 :         207 :   *slot = ent;
     464                 :         207 : }
     465                 :             : 
     466                 :             : /* The following two routines are used to interface to Objective-C++.
     467                 :             :    The binding level is purposely treated as an opaque type.  */
     468                 :             : 
     469                 :             : void *
     470                 :           0 : objc_get_current_scope (void)
     471                 :             : {
     472                 :           0 :   return current_binding_level;
     473                 :             : }
     474                 :             : 
     475                 :             : /* The following routine is used by the NeXT-style SJLJ exceptions;
     476                 :             :    variables get marked 'volatile' so as to not be clobbered by
     477                 :             :    _setjmp()/_longjmp() calls.  All variables in the current scope,
     478                 :             :    as well as parent scopes up to (but not including) ENCLOSING_BLK
     479                 :             :    shall be thusly marked.  */
     480                 :             : 
     481                 :             : void
     482                 :           0 : objc_mark_locals_volatile (void *enclosing_blk)
     483                 :             : {
     484                 :           0 :   cp_binding_level *scope;
     485                 :             : 
     486                 :           0 :   for (scope = current_binding_level;
     487                 :           0 :        scope && scope != enclosing_blk;
     488                 :           0 :        scope = scope->level_chain)
     489                 :             :     {
     490                 :           0 :       tree decl;
     491                 :             : 
     492                 :           0 :       for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
     493                 :           0 :         objc_volatilize_decl (decl);
     494                 :             : 
     495                 :             :       /* Do not climb up past the current function.  */
     496                 :           0 :       if (scope->kind == sk_function_parms)
     497                 :             :         break;
     498                 :             :     }
     499                 :           0 : }
     500                 :             : 
     501                 :             : /* True if B is the level for the condition of a constexpr if.  */
     502                 :             : 
     503                 :             : static bool
     504                 :     1963716 : level_for_constexpr_if (cp_binding_level *b)
     505                 :             : {
     506                 :     1960811 :   return (b->kind == sk_cond && b->this_entity
     507                 :         262 :           && TREE_CODE (b->this_entity) == IF_STMT
     508                 :     1963978 :           && IF_STMT_CONSTEXPR_P (b->this_entity));
     509                 :             : }
     510                 :             : 
     511                 :             : /* True if B is the level for the condition of a consteval if.  */
     512                 :             : 
     513                 :             : static bool
     514                 :     1963692 : level_for_consteval_if (cp_binding_level *b)
     515                 :             : {
     516                 :     1960787 :   return (b->kind == sk_cond && b->this_entity
     517                 :         238 :           && TREE_CODE (b->this_entity) == IF_STMT
     518                 :     1963930 :           && IF_STMT_CONSTEVAL_P (b->this_entity));
     519                 :             : }
     520                 :             : 
     521                 :             : /* True if T is a non-static VAR_DECL that has a non-trivial destructor.
     522                 :             :    See [stmt.dcl]/2.  */
     523                 :             : 
     524                 :             : static bool
     525                 :          25 : automatic_var_with_nontrivial_dtor_p (const_tree t)
     526                 :             : {
     527                 :          25 :   if (error_operand_p (t))
     528                 :             :     return false;
     529                 :             : 
     530                 :          19 :   return (VAR_P (t)
     531                 :          19 :           && decl_storage_duration (CONST_CAST_TREE (t)) == dk_auto
     532                 :          38 :           && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t)));
     533                 :             : }
     534                 :             : 
     535                 :             : /* Update data for defined and undefined labels when leaving a scope.  */
     536                 :             : 
     537                 :             : int
     538                 :      146035 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
     539                 :             : {
     540                 :      146035 :   named_label_entry *ent = *slot;
     541                 :      146035 :   cp_binding_level *obl = bl->level_chain;
     542                 :             : 
     543                 :      146035 :   if (ent->binding_level == bl)
     544                 :             :     {
     545                 :        8728 :       tree decl;
     546                 :             : 
     547                 :             :       /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
     548                 :             :          TREE_LISTs representing OVERLOADs, so be careful.  */
     549                 :       12467 :       for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
     550                 :        3812 :                                                      ? DECL_CHAIN (decl)
     551                 :          73 :                                                      : TREE_CHAIN (decl)))
     552                 :        3739 :         if (decl_jump_unsafe (decl))
     553                 :        1454 :           vec_safe_push (ent->bad_decls, decl);
     554                 :             : 
     555                 :        8728 :       ent->binding_level = obl;
     556                 :        8728 :       ent->names_in_scope = obl->names;
     557                 :        8728 :       switch (bl->kind)
     558                 :             :         {
     559                 :          42 :         case sk_try:
     560                 :          42 :           ent->in_try_scope = true;
     561                 :          42 :           break;
     562                 :          27 :         case sk_catch:
     563                 :          27 :           ent->in_catch_scope = true;
     564                 :          27 :           break;
     565                 :         348 :         case sk_omp:
     566                 :         348 :           ent->in_omp_scope = true;
     567                 :         348 :           break;
     568                 :           3 :         case sk_transaction:
     569                 :           3 :           ent->in_transaction_scope = true;
     570                 :           3 :           break;
     571                 :          45 :         case sk_stmt_expr:
     572                 :          45 :           ent->in_stmt_expr = true;
     573                 :          45 :           break;
     574                 :        3098 :         case sk_block:
     575                 :        3098 :           if (level_for_constexpr_if (bl->level_chain))
     576                 :          15 :             ent->in_constexpr_if = true;
     577                 :        3083 :           else if (level_for_consteval_if (bl->level_chain))
     578                 :          30 :             ent->in_consteval_if = true;
     579                 :             :           break;
     580                 :             :         default:
     581                 :             :           break;
     582                 :             :         }
     583                 :             :     }
     584                 :      137307 :   else if (ent->uses)
     585                 :             :     {
     586                 :             :       struct named_label_use_entry *use;
     587                 :             : 
     588                 :       13229 :       for (use = ent->uses; use ; use = use->next)
     589                 :        8830 :         if (use->binding_level == bl)
     590                 :             :           {
     591                 :        2944 :             if (auto &cg = use->computed_goto)
     592                 :             :               {
     593                 :          57 :                 if (bl->kind == sk_catch)
     594                 :           3 :                   vec_safe_push (cg, get_identifier ("catch"));
     595                 :          66 :                 for (tree d = use->names_in_scope; d; d = DECL_CHAIN (d))
     596                 :           9 :                   if (automatic_var_with_nontrivial_dtor_p (d))
     597                 :           6 :                     vec_safe_push (cg, d);
     598                 :             :               }
     599                 :             : 
     600                 :        2944 :             use->binding_level = obl;
     601                 :        2944 :             use->names_in_scope = obl->names;
     602                 :        2944 :             if (bl->kind == sk_omp)
     603                 :          12 :               use->in_omp_scope = true;
     604                 :             :           }
     605                 :             :     }
     606                 :             : 
     607                 :      146035 :   return 1;
     608                 :             : }
     609                 :             : 
     610                 :             : /* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
     611                 :             :    when errors were reported, except for -Werror-unused-but-set-*.  */
     612                 :             : static int unused_but_set_errorcount;
     613                 :             : 
     614                 :             : /* Exit a binding level.
     615                 :             :    Pop the level off, and restore the state of the identifier-decl mappings
     616                 :             :    that were in effect when this level was entered.
     617                 :             : 
     618                 :             :    If KEEP == 1, this level had explicit declarations, so
     619                 :             :    and create a "block" (a BLOCK node) for the level
     620                 :             :    to record its declarations and subblocks for symbol table output.
     621                 :             : 
     622                 :             :    If FUNCTIONBODY is nonzero, this level is the body of a function,
     623                 :             :    so create a block as if KEEP were set and also clear out all
     624                 :             :    label names.
     625                 :             : 
     626                 :             :    If REVERSE is nonzero, reverse the order of decls before putting
     627                 :             :    them into the BLOCK.  */
     628                 :             : 
     629                 :             : tree
     630                 :   579942165 : poplevel (int keep, int reverse, int functionbody)
     631                 :             : {
     632                 :   579942165 :   tree link;
     633                 :             :   /* The chain of decls was accumulated in reverse order.
     634                 :             :      Put it into forward order, just for cleanliness.  */
     635                 :   579942165 :   tree decls;
     636                 :   579942165 :   tree subblocks;
     637                 :   579942165 :   tree block;
     638                 :   579942165 :   tree decl;
     639                 :   579942165 :   scope_kind kind;
     640                 :             : 
     641                 :   579942165 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     642                 :   579942609 :  restart:
     643                 :             : 
     644                 :   579942609 :   block = NULL_TREE;
     645                 :             : 
     646                 :   579942609 :   gcc_assert (current_binding_level->kind != sk_class
     647                 :             :               && current_binding_level->kind != sk_namespace);
     648                 :             : 
     649                 :   579942609 :   if (current_binding_level->kind == sk_cleanup)
     650                 :             :     functionbody = 0;
     651                 :   579942609 :   subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
     652                 :             : 
     653                 :   579942609 :   gcc_assert (!vec_safe_length (current_binding_level->class_shadowed));
     654                 :             : 
     655                 :             :   /* We used to use KEEP == 2 to indicate that the new block should go
     656                 :             :      at the beginning of the list of blocks at this binding level,
     657                 :             :      rather than the end.  This hack is no longer used.  */
     658                 :   579942609 :   gcc_assert (keep == 0 || keep == 1);
     659                 :             : 
     660                 :   579942609 :   if (current_binding_level->keep)
     661                 :     7399840 :     keep = 1;
     662                 :             : 
     663                 :             :   /* Any uses of undefined labels, and any defined labels, now operate
     664                 :             :      under constraints of next binding contour.  */
     665                 :   579942609 :   if (cfun && !functionbody && named_labels)
     666                 :       41652 :     named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
     667                 :      187687 :                    (current_binding_level);
     668                 :             : 
     669                 :             :   /* Get the decls in the order they were written.
     670                 :             :      Usually current_binding_level->names is in reverse order.
     671                 :             :      But parameter decls were previously put in forward order.  */
     672                 :             : 
     673                 :   579942609 :   decls = current_binding_level->names;
     674                 :   579942609 :   if (reverse)
     675                 :             :     {
     676                 :   311279259 :       decls = nreverse (decls);
     677                 :   311279259 :       current_binding_level->names = decls;
     678                 :             :     }
     679                 :             : 
     680                 :             :   /* If there were any declarations or structure tags in that level,
     681                 :             :      or if this level is a function body,
     682                 :             :      create a BLOCK to record them for the life of this function.  */
     683                 :   579942609 :   block = NULL_TREE;
     684                 :             :   /* Avoid function body block if possible.  */
     685                 :   615437103 :   if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
     686                 :             :     keep = 0;
     687                 :   544448370 :   else if (keep == 1 || functionbody)
     688                 :   179159072 :     block = make_node (BLOCK);
     689                 :   179159072 :   if (block != NULL_TREE)
     690                 :             :     {
     691                 :   179159072 :       BLOCK_VARS (block) = decls;
     692                 :   179159072 :       BLOCK_SUBBLOCKS (block) = subblocks;
     693                 :             :     }
     694                 :             : 
     695                 :             :   /* In each subblock, record that this is its superior.  */
     696                 :   579942609 :   if (keep >= 0)
     697                 :   650638611 :     for (link = subblocks; link; link = BLOCK_CHAIN (link))
     698                 :    70696002 :       BLOCK_SUPERCONTEXT (link) = block;
     699                 :             : 
     700                 :             :   /* Before we remove the declarations first check for unused variables.  */
     701                 :   579942609 :   if ((warn_unused_variable || warn_unused_but_set_variable)
     702                 :     6178774 :       && current_binding_level->kind != sk_template_parms
     703                 :     5230852 :       && !processing_template_decl)
     704                 :     6161461 :     for (tree d = get_local_decls (); d; d = TREE_CHAIN (d))
     705                 :             :       {
     706                 :             :         /* There are cases where D itself is a TREE_LIST.  See in
     707                 :             :            push_local_binding where the list of decls returned by
     708                 :             :            getdecls is built.  */
     709                 :     3158967 :         tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
     710                 :     3158967 :         decl = strip_using_decl (udecl);
     711                 :             : 
     712                 :     3158967 :         tree type = TREE_TYPE (decl);
     713                 :     3158967 :         if (VAR_P (decl)
     714                 :      364353 :             && (!TREE_USED (decl) || !DECL_READ_P (decl))
     715                 :        3249 :             && !DECL_IN_SYSTEM_HEADER (udecl)
     716                 :             :             /* For structured bindings, consider only real variables, not
     717                 :             :                subobjects.  */
     718                 :        3237 :             && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
     719                 :        2991 :                 : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
     720                 :             :             /* Don't warn about name-independent declarations.  */
     721                 :         885 :             && !name_independent_decl_p (decl)
     722                 :         729 :             && type != error_mark_node
     723                 :     3162901 :             && (!CLASS_TYPE_P (type)
     724                 :          51 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
     725                 :           3 :                 || lookup_attribute ("warn_unused",
     726                 :           3 :                                      TYPE_ATTRIBUTES (TREE_TYPE (decl)))))
     727                 :             :           {
     728                 :         697 :             if (!TREE_USED (decl))
     729                 :             :               {
     730                 :         302 :                 if (TREE_CODE (udecl) == USING_DECL)
     731                 :           3 :                   warning_at (DECL_SOURCE_LOCATION (udecl),
     732                 :           3 :                               OPT_Wunused_variable,
     733                 :             :                               "unused using-declaration %qD", udecl);
     734                 :         299 :                 else if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     735                 :           3 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     736                 :           3 :                               OPT_Wunused_variable,
     737                 :             :                               "unused structured binding declaration");
     738                 :             :                 else
     739                 :         296 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     740                 :         296 :                               OPT_Wunused_variable, "unused variable %qD", decl);
     741                 :         302 :                 suppress_warning (decl, OPT_Wunused_variable);
     742                 :             :               }
     743                 :         395 :             else if (DECL_CONTEXT (decl) == current_function_decl
     744                 :             :                      // For -Wunused-but-set-variable leave references alone.
     745                 :         371 :                      && !TYPE_REF_P (TREE_TYPE (decl))
     746                 :         766 :                      && errorcount == unused_but_set_errorcount)
     747                 :             :               {
     748                 :         362 :                 if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     749                 :          12 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     750                 :          12 :                               OPT_Wunused_but_set_variable_, "structured "
     751                 :             :                               "binding declaration set but not used");
     752                 :             :                 else
     753                 :         350 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     754                 :         350 :                               OPT_Wunused_but_set_variable_,
     755                 :             :                               "variable %qD set but not used", decl);
     756                 :         362 :                 unused_but_set_errorcount = errorcount;
     757                 :             :               }
     758                 :             :           }
     759                 :             :       }
     760                 :             : 
     761                 :             :   /* Remove declarations for all the DECLs in this level.  */
     762                 :  1183949190 :   for (link = decls; link; link = TREE_CHAIN (link))
     763                 :             :     {
     764                 :   604006581 :       tree name;
     765                 :   604006581 :       if (TREE_CODE (link) == TREE_LIST)
     766                 :             :         {
     767                 :     3884336 :           decl = TREE_VALUE (link);
     768                 :     3884336 :           name = TREE_PURPOSE (link);
     769                 :     3884336 :           gcc_checking_assert (name);
     770                 :             :         }
     771                 :             :       else
     772                 :             :         {
     773                 :   600122245 :           decl = link;
     774                 :   600122245 :           name = DECL_NAME (decl);
     775                 :             :         }
     776                 :             : 
     777                 :             :       /* Remove the binding.  */
     778                 :   604006581 :       if (TREE_CODE (decl) == LABEL_DECL)
     779                 :         207 :         pop_local_label (name, decl);
     780                 :             :       else
     781                 :   604006374 :         pop_local_binding (name, decl);
     782                 :             :     }
     783                 :             : 
     784                 :             :   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
     785                 :   579942609 :   for (link = current_binding_level->type_shadowed;
     786                 :   789273415 :        link; link = TREE_CHAIN (link))
     787                 :   209330806 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
     788                 :             : 
     789                 :             :   /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
     790                 :             :      list if a `using' declaration put them there.  The debugging
     791                 :             :      back ends won't understand OVERLOAD, so we remove them here.
     792                 :             :      Because the BLOCK_VARS are (temporarily) shared with
     793                 :             :      CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
     794                 :             :      popped all the bindings.  Also remove undeduced 'auto' decls,
     795                 :             :      which LTO doesn't understand, and can't have been used by anything.  */
     796                 :   579942609 :   if (block)
     797                 :             :     {
     798                 :   179159072 :       tree* d;
     799                 :             : 
     800                 :   471717352 :       for (d = &BLOCK_VARS (block); *d; )
     801                 :             :         {
     802                 :   292558280 :           if (TREE_CODE (*d) == TREE_LIST
     803                 :   292558280 :               || (!processing_template_decl
     804                 :    92959662 :                   && undeduced_auto_decl (*d)))
     805                 :     3884370 :             *d = TREE_CHAIN (*d);
     806                 :             :           else
     807                 :   288673910 :             d = &DECL_CHAIN (*d);
     808                 :             :         }
     809                 :             :     }
     810                 :             : 
     811                 :             :   /* If the level being exited is the top level of a function,
     812                 :             :      check over all the labels.  */
     813                 :   579942609 :   if (functionbody)
     814                 :             :     {
     815                 :   143956557 :       if (block)
     816                 :             :         {
     817                 :             :           /* Since this is the top level block of a function, the vars are
     818                 :             :              the function's parameters.  Don't leave them in the BLOCK
     819                 :             :              because they are found in the FUNCTION_DECL instead.  */
     820                 :   108462318 :           BLOCK_VARS (block) = 0;
     821                 :   108462318 :           pop_labels (block);
     822                 :             :         }
     823                 :             :       else
     824                 :    35494239 :         pop_labels (subblocks);
     825                 :             :     }
     826                 :             : 
     827                 :   579942609 :   kind = current_binding_level->kind;
     828                 :   579942609 :   if (kind == sk_cleanup)
     829                 :             :     {
     830                 :         444 :       tree stmt;
     831                 :             : 
     832                 :             :       /* If this is a temporary binding created for a cleanup, then we'll
     833                 :             :          have pushed a statement list level.  Pop that, create a new
     834                 :             :          BIND_EXPR for the block, and insert it into the stream.  */
     835                 :         444 :       stmt = pop_stmt_list (current_binding_level->statement_list);
     836                 :         444 :       stmt = c_build_bind_expr (input_location, block, stmt);
     837                 :         444 :       add_stmt (stmt);
     838                 :             :     }
     839                 :             : 
     840                 :   579942609 :   leave_scope ();
     841                 :   579942609 :   if (functionbody)
     842                 :             :     {
     843                 :             :       /* The current function is being defined, so its DECL_INITIAL
     844                 :             :          should be error_mark_node.  */
     845                 :   143956557 :       gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
     846                 :   179450796 :       DECL_INITIAL (current_function_decl) = block ? block : subblocks;
     847                 :   143956557 :       if (subblocks)
     848                 :             :         {
     849                 :    66756570 :           if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl)
     850                 :    43943000 :               && BLOCK_SUBBLOCKS (subblocks))
     851                 :     1195387 :             BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
     852                 :             :           else
     853                 :    34299107 :             BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
     854                 :             :         }
     855                 :             :     }
     856                 :   435986052 :   else if (block)
     857                 :    70696754 :     current_binding_level->blocks
     858                 :   141393508 :       = block_chainon (current_binding_level->blocks, block);
     859                 :             : 
     860                 :             :   /* If we did not make a block for the level just exited,
     861                 :             :      any blocks made for inner levels
     862                 :             :      (since they cannot be recorded as subblocks in that level)
     863                 :             :      must be carried forward so they will later become subblocks
     864                 :             :      of something else.  */
     865                 :   365289298 :   else if (subblocks)
     866                 :           9 :     current_binding_level->blocks
     867                 :          18 :       = block_chainon (current_binding_level->blocks, subblocks);
     868                 :             : 
     869                 :             :   /* Each and every BLOCK node created here in `poplevel' is important
     870                 :             :      (e.g. for proper debugging information) so if we created one
     871                 :             :      earlier, mark it as "used".  */
     872                 :   579942609 :   if (block)
     873                 :   179159072 :     TREE_USED (block) = 1;
     874                 :             : 
     875                 :             :   /* All temporary bindings created for cleanups are popped silently.  */
     876                 :   579942609 :   if (kind == sk_cleanup)
     877                 :         444 :     goto restart;
     878                 :             : 
     879                 :  1159884330 :   return block;
     880                 :   579942165 : }
     881                 :             : 
     882                 :             : /* Call wrapup_globals_declarations for the globals in NAMESPACE.  */
     883                 :             : /* Diagnose odr-used extern inline variables without definitions
     884                 :             :    in the current TU.  */
     885                 :             : 
     886                 :             : int
     887                 :      141735 : wrapup_namespace_globals ()
     888                 :             : {
     889                 :      141735 :   if (vec<tree, va_gc> *statics = static_decls)
     890                 :             :     {
     891                 :    15172872 :       for (tree decl : *statics)
     892                 :             :         {
     893                 :    15056735 :           if (warn_unused_function
     894                 :      984720 :               && TREE_CODE (decl) == FUNCTION_DECL
     895                 :      739644 :               && DECL_INITIAL (decl) == 0
     896                 :        7431 :               && DECL_EXTERNAL (decl)
     897                 :        7431 :               && !TREE_PUBLIC (decl)
     898                 :          29 :               && !DECL_ARTIFICIAL (decl)
     899                 :          29 :               && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
     900                 :    15056741 :               && !warning_suppressed_p (decl, OPT_Wunused_function))
     901                 :           6 :             warning_at (DECL_SOURCE_LOCATION (decl),
     902                 :           6 :                         OPT_Wunused_function,
     903                 :             :                         "%qF declared %<static%> but never defined", decl);
     904                 :             : 
     905                 :    15056735 :           if (VAR_P (decl)
     906                 :     4346092 :               && DECL_EXTERNAL (decl)
     907                 :     2037703 :               && DECL_INLINE_VAR_P (decl)
     908                 :    15056753 :               && DECL_ODR_USED (decl))
     909                 :           3 :             error_at (DECL_SOURCE_LOCATION (decl),
     910                 :             :                       "odr-used inline variable %qD is not defined", decl);
     911                 :             :         }
     912                 :             : 
     913                 :             :       /* Clear out the list, so we don't rescan next time.  */
     914                 :      116137 :       static_decls = NULL;
     915                 :             : 
     916                 :             :       /* Write out any globals that need to be output.  */
     917                 :      116137 :       return wrapup_global_declarations (statics->address (),
     918                 :      116137 :                                          statics->length ());
     919                 :             :     }
     920                 :             :   return 0;
     921                 :             : }
     922                 :             : 
     923                 :             : /* In C++, you don't have to write `struct S' to refer to `S'; you
     924                 :             :    can just use `S'.  We accomplish this by creating a TYPE_DECL as
     925                 :             :    if the user had written `typedef struct S S'.  Create and return
     926                 :             :    the TYPE_DECL for TYPE.  */
     927                 :             : 
     928                 :             : tree
     929                 :   151849601 : create_implicit_typedef (tree name, tree type)
     930                 :             : {
     931                 :   151849601 :   tree decl;
     932                 :             : 
     933                 :   151849601 :   decl = build_decl (input_location, TYPE_DECL, name, type);
     934                 :   151849601 :   DECL_ARTIFICIAL (decl) = 1;
     935                 :             :   /* There are other implicit type declarations, like the one *within*
     936                 :             :      a class that allows you to write `S::S'.  We must distinguish
     937                 :             :      amongst these.  */
     938                 :   151849601 :   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
     939                 :   151849601 :   TYPE_NAME (type) = decl;
     940                 :   151849601 :   TYPE_STUB_DECL (type) = decl;
     941                 :             : 
     942                 :   151849601 :   return decl;
     943                 :             : }
     944                 :             : 
     945                 :             : /* Function-scope local entities that need discriminators.  Each entry
     946                 :             :    is a {decl,name} pair.  VAR_DECLs for anon unions get their name
     947                 :             :    smashed, so we cannot rely on DECL_NAME.  */
     948                 :             : 
     949                 :             : static GTY((deletable)) vec<tree, va_gc> *local_entities;
     950                 :             : 
     951                 :             : /* Determine the mangling discriminator of local DECL.  There are
     952                 :             :    generally very few of these in any particular function.  */
     953                 :             : 
     954                 :             : void
     955                 :      719449 : determine_local_discriminator (tree decl, tree name)
     956                 :             : {
     957                 :      719449 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     958                 :      719449 :   retrofit_lang_decl (decl);
     959                 :      719449 :   tree ctx = DECL_CONTEXT (decl);
     960                 :      719449 :   size_t nelts = vec_safe_length (local_entities);
     961                 :      719449 :   if (name == NULL_TREE)
     962                 :      719260 :     name = (TREE_CODE (decl) == TYPE_DECL
     963                 :     1157899 :             && TYPE_UNNAMED_P (TREE_TYPE (decl))
     964                 :     1294608 :             ? NULL_TREE : DECL_NAME (decl));
     965                 :    21470176 :   for (size_t i = 0; i < nelts; i += 2)
     966                 :             :     {
     967                 :    20751110 :       tree *pair = &(*local_entities)[i];
     968                 :    20751110 :       tree d = pair[0];
     969                 :    20751110 :       tree n = pair[1];
     970                 :    20751110 :       gcc_checking_assert (d != decl);
     971                 :    20751110 :       if (name == n
     972                 :     3732720 :           && TREE_CODE (decl) == TREE_CODE (d)
     973                 :    24483821 :           && ctx == DECL_CONTEXT (d))
     974                 :             :         {
     975                 :         383 :           tree disc = integer_one_node;
     976                 :         383 :           if (DECL_DISCRIMINATOR (d))
     977                 :         193 :             disc = build_int_cst (TREE_TYPE (disc),
     978                 :         193 :                                   TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
     979                 :         383 :           DECL_DISCRIMINATOR (decl) = disc;
     980                 :             :           /* Replace the saved decl.  */
     981                 :         383 :           pair[0] = decl;
     982                 :         383 :           decl = NULL_TREE;
     983                 :         383 :           break;
     984                 :             :         }
     985                 :             :     }
     986                 :             : 
     987                 :      719449 :   if (decl)
     988                 :             :     {
     989                 :      719066 :       vec_safe_reserve (local_entities, 2);
     990                 :      719066 :       local_entities->quick_push (decl);
     991                 :      719066 :       local_entities->quick_push (name);
     992                 :             :     }
     993                 :      719449 : }
     994                 :             : 
     995                 :             : 
     996                 :             : /* True if DECL is a constrained hidden friend as per [temp.friend]/9:
     997                 :             : 
     998                 :             :    A non-template friend declaration with a requires-clause shall be a
     999                 :             :    definition. A friend function template with a constraint that depends on a
    1000                 :             :    template parameter from an enclosing template shall be a definition. Such a
    1001                 :             :    constrained friend function or function template declaration does not
    1002                 :             :    declare the same function or function template as a declaration in any other
    1003                 :             :    scope.
    1004                 :             : 
    1005                 :             :    The ABI calls this a "member-like constrained friend" and mangles it like a
    1006                 :             :    member function to avoid collisions.  */
    1007                 :             : 
    1008                 :             : bool
    1009                 :  1989659738 : member_like_constrained_friend_p (tree decl)
    1010                 :             : {
    1011                 :  1989659738 :   return (TREE_CODE (decl) == FUNCTION_DECL
    1012                 :   599319188 :           && DECL_UNIQUE_FRIEND_P (decl)
    1013                 :    85427516 :           && DECL_FRIEND_CONTEXT (decl)
    1014                 :    38156813 :           && get_constraints (decl)
    1015                 :  1990143675 :           && (!DECL_TEMPLATE_INFO (decl)
    1016                 :      483937 :               || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
    1017                 :        3317 :               || (uses_outer_template_parms_in_constraints
    1018                 :        3317 :                   (most_general_template (decl)))));
    1019                 :             : }
    1020                 :             : 
    1021                 :             : /* Returns true if functions FN1 and FN2 have equivalent trailing
    1022                 :             :    requires clauses.  */
    1023                 :             : 
    1024                 :             : static bool
    1025                 :    23266817 : function_requirements_equivalent_p (tree newfn, tree oldfn)
    1026                 :             : {
    1027                 :             :   /* [temp.friend]/9 "Such a constrained friend function does not declare the
    1028                 :             :      same function as a declaration in any other scope."  So no need to
    1029                 :             :      actually compare the requirements.  */
    1030                 :    23266817 :   if (member_like_constrained_friend_p (newfn)
    1031                 :    23266817 :       || member_like_constrained_friend_p (oldfn))
    1032                 :         107 :     return false;
    1033                 :             : 
    1034                 :             :   /* Compare only trailing requirements.  */
    1035                 :    23266710 :   tree reqs1 = get_trailing_function_requirements (newfn);
    1036                 :    23266710 :   tree reqs2 = get_trailing_function_requirements (oldfn);
    1037                 :    23266710 :   if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
    1038                 :             :     return false;
    1039                 :             : 
    1040                 :             :   /* Substitution is needed when friends are involved.  */
    1041                 :    23217718 :   reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
    1042                 :    23217718 :   reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
    1043                 :             : 
    1044                 :    23217718 :   return cp_tree_equal (reqs1, reqs2);
    1045                 :             : }
    1046                 :             : 
    1047                 :             : /* Two functions of the same name correspond [basic.scope.scope] if
    1048                 :             : 
    1049                 :             :    + both declare functions with the same non-object-parameter-type-list,
    1050                 :             :    equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
    1051                 :             :    specified in [temp.friend]), and, if both are non-static members, they have
    1052                 :             :    corresponding object parameters, or
    1053                 :             : 
    1054                 :             :    + both declare function templates with equivalent
    1055                 :             :    non-object-parameter-type-lists, return types (if any), template-heads, and
    1056                 :             :    trailing requires-clauses (if any), and, if both are non-static members,
    1057                 :             :    they have corresponding object parameters.
    1058                 :             : 
    1059                 :             :    This is a subset of decls_match: it identifies declarations that cannot be
    1060                 :             :    overloaded with one another.  This function does not consider DECL_NAME.  */
    1061                 :             : 
    1062                 :             : bool
    1063                 :   632382202 : fns_correspond (tree newdecl, tree olddecl)
    1064                 :             : {
    1065                 :   632382202 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1066                 :             :     return false;
    1067                 :             : 
    1068                 :   586806504 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1069                 :             :     {
    1070                 :   586780431 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1071                 :             :         return 0;
    1072                 :   135357647 :       newdecl = DECL_TEMPLATE_RESULT (newdecl);
    1073                 :   135357647 :       olddecl = DECL_TEMPLATE_RESULT (olddecl);
    1074                 :             :     }
    1075                 :             : 
    1076                 :   135383720 :   tree f1 = TREE_TYPE (newdecl);
    1077                 :   135383720 :   tree f2 = TREE_TYPE (olddecl);
    1078                 :             : 
    1079                 :   135383720 :   int rq1 = type_memfn_rqual (f1);
    1080                 :   135383720 :   int rq2 = type_memfn_rqual (f2);
    1081                 :             : 
    1082                 :             :   /* If only one is a non-static member function, ignore ref-quals.  */
    1083                 :   135383720 :   if (TREE_CODE (f1) != TREE_CODE (f2))
    1084                 :             :     rq1 = rq2;
    1085                 :             :   /* Two non-static member functions have corresponding object parameters if:
    1086                 :             :      + exactly one is an implicit object member function with no ref-qualifier
    1087                 :             :      and the types of their object parameters ([dcl.fct]), after removing
    1088                 :             :      top-level references, are the same, or
    1089                 :             :      + their object parameters have the same type.  */
    1090                 :             :   /* ??? We treat member functions of different classes as corresponding even
    1091                 :             :      though that means the object parameters have different types.  */
    1092                 :   135383720 :   else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
    1093                 :           0 :     rq1 = rq2;
    1094                 :             : 
    1095                 :   135383720 :   bool types_match = rq1 == rq2;
    1096                 :             : 
    1097                 :   135383720 :   if (types_match)
    1098                 :             :     {
    1099                 :   135383720 :       tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1100                 :   135383720 :       tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    1101                 :   135383720 :       types_match = compparms (p1, p2);
    1102                 :             :     }
    1103                 :             : 
    1104                 :             :   /* Two function declarations match if either has a requires-clause
    1105                 :             :      then both have a requires-clause and their constraints-expressions
    1106                 :             :      are equivalent.  */
    1107                 :   135383720 :   if (types_match && flag_concepts)
    1108                 :    16689725 :     types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1109                 :             : 
    1110                 :             :   return types_match;
    1111                 :             : }
    1112                 :             : 
    1113                 :             : /* Subroutine of duplicate_decls: return truthvalue of whether
    1114                 :             :    or not types of these decls match.
    1115                 :             : 
    1116                 :             :    For C++, we must compare the parameter list so that `int' can match
    1117                 :             :    `int&' in a parameter position, but `int&' is not confused with
    1118                 :             :    `const int&'.  */
    1119                 :             : 
    1120                 :             : int
    1121                 :   947649621 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
    1122                 :             : {
    1123                 :   947649621 :   int types_match;
    1124                 :             : 
    1125                 :   947649621 :   if (newdecl == olddecl)
    1126                 :             :     return 1;
    1127                 :             : 
    1128                 :   947582995 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1129                 :             :     /* If the two DECLs are not even the same kind of thing, we're not
    1130                 :             :        interested in their types.  */
    1131                 :             :     return 0;
    1132                 :             : 
    1133                 :   468363088 :   gcc_assert (DECL_P (newdecl));
    1134                 :             : 
    1135                 :   468363088 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1136                 :             :     {
    1137                 :             :       /* Specializations of different templates are different functions
    1138                 :             :          even if they have the same type.  */
    1139                 :   262418833 :       tree t1 = (DECL_USE_TEMPLATE (newdecl)
    1140                 :   262418833 :                  ? DECL_TI_TEMPLATE (newdecl)
    1141                 :      590735 :                  : NULL_TREE);
    1142                 :   262418833 :       tree t2 = (DECL_USE_TEMPLATE (olddecl)
    1143                 :   262418833 :                  ? DECL_TI_TEMPLATE (olddecl)
    1144                 :     3232305 :                  : NULL_TREE);
    1145                 :   262418833 :       if (t1 != t2)
    1146                 :             :         return 0;
    1147                 :             : 
    1148                 :   259777197 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1149                 :   262932262 :           && ! (DECL_EXTERN_C_P (newdecl)
    1150                 :     3155065 :                 && DECL_EXTERN_C_P (olddecl)))
    1151                 :             :         return 0;
    1152                 :             : 
    1153                 :             :       /* A new declaration doesn't match a built-in one unless it
    1154                 :             :          is also extern "C".  */
    1155                 :   240179066 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1156                 :   240179066 :           && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
    1157                 :             :         return 0;
    1158                 :             : 
    1159                 :   239490920 :       tree f1 = TREE_TYPE (newdecl);
    1160                 :   239490920 :       tree f2 = TREE_TYPE (olddecl);
    1161                 :   239490920 :       if (TREE_CODE (f1) != TREE_CODE (f2))
    1162                 :             :         return 0;
    1163                 :             : 
    1164                 :             :       /* A declaration with deduced return type should use its pre-deduction
    1165                 :             :          type for declaration matching.  */
    1166                 :   239323129 :       tree r2 = fndecl_declared_return_type (olddecl);
    1167                 :   239323129 :       tree r1 = fndecl_declared_return_type (newdecl);
    1168                 :             : 
    1169                 :             :       /* For memchr et al, allow const void* return type (as specified by C++)
    1170                 :             :          when we expect void* (as in C).  */
    1171                 :   239323129 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1172                 :     6572364 :           && DECL_EXTERN_C_P (olddecl)
    1173                 :     4153065 :           && !same_type_p (r1, r2)
    1174                 :          70 :           && TREE_CODE (r1) == POINTER_TYPE
    1175                 :          15 :           && TREE_CODE (r2) == POINTER_TYPE
    1176                 :   239323141 :           && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
    1177                 :             :         r2 = r1;
    1178                 :             : 
    1179                 :   239323129 :       tree p1 = TYPE_ARG_TYPES (f1);
    1180                 :   239323129 :       tree p2 = TYPE_ARG_TYPES (f2);
    1181                 :             : 
    1182                 :   239323129 :       if (same_type_p (r1, r2))
    1183                 :             :         {
    1184                 :   175703198 :           if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
    1185                 :   175703168 :               && fndecl_built_in_p (olddecl))
    1186                 :             :             {
    1187                 :          50 :               types_match = self_promoting_args_p (p1);
    1188                 :          50 :               if (p1 == void_list_node)
    1189                 :           3 :                 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
    1190                 :             :             }
    1191                 :             :           else
    1192                 :   175703059 :             types_match =
    1193                 :   175703059 :               compparms (p1, p2)
    1194                 :    26820645 :               && type_memfn_rqual (f1) == type_memfn_rqual (f2)
    1195                 :   202523468 :               && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
    1196                 :     1247481 :                   || comp_type_attributes (TREE_TYPE (newdecl),
    1197                 :     1247481 :                                            TREE_TYPE (olddecl)) != 0);
    1198                 :             :         }
    1199                 :             :       else
    1200                 :             :         types_match = 0;
    1201                 :             : 
    1202                 :             :       /* Two function declarations match if either has a requires-clause
    1203                 :             :          then both have a requires-clause and their constraints-expressions
    1204                 :             :          are equivalent.  */
    1205                 :    26820450 :       if (types_match && flag_concepts)
    1206                 :     6577066 :         types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1207                 :             : 
    1208                 :             :       /* The decls dont match if they correspond to two different versions
    1209                 :             :          of the same function.   Disallow extern "C" functions to be
    1210                 :             :          versions for now.  */
    1211                 :    26820450 :       if (types_match
    1212                 :    26755956 :           && !DECL_EXTERN_C_P (newdecl)
    1213                 :    20595281 :           && !DECL_EXTERN_C_P (olddecl)
    1214                 :    47411759 :           && targetm.target_option.function_versions (newdecl, olddecl))
    1215                 :             :         {
    1216                 :        8574 :           if (record_versions)
    1217                 :        8487 :             maybe_version_functions (newdecl, olddecl);
    1218                 :        8574 :           return 0;
    1219                 :             :         }
    1220                 :             :     }
    1221                 :   205944255 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1222                 :             :     {
    1223                 :   204481956 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1224                 :             :         return 0;
    1225                 :             : 
    1226                 :    66168431 :       tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1227                 :    66168431 :       tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1228                 :             : 
    1229                 :    66168431 :       if (TREE_CODE (newres) != TREE_CODE (oldres))
    1230                 :             :         return 0;
    1231                 :             : 
    1232                 :             :       /* Two template types match if they are the same. Otherwise, compare
    1233                 :             :          the underlying declarations.  */
    1234                 :    66168425 :       if (TREE_CODE (newres) == TYPE_DECL)
    1235                 :          30 :         types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
    1236                 :             :       else
    1237                 :    66168395 :         types_match = decls_match (newres, oldres);
    1238                 :             :     }
    1239                 :             :   else
    1240                 :             :     {
    1241                 :             :       /* Need to check scope for variable declaration (VAR_DECL).
    1242                 :             :          For typedef (TYPE_DECL), scope is ignored.  */
    1243                 :     1462299 :       if (VAR_P (newdecl)
    1244                 :      979922 :           && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1245                 :             :           /* [dcl.link]
    1246                 :             :              Two declarations for an object with C language linkage
    1247                 :             :              with the same name (ignoring the namespace that qualify
    1248                 :             :              it) that appear in different namespace scopes refer to
    1249                 :             :              the same object.  */
    1250                 :     1640372 :           && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
    1251                 :             :         return 0;
    1252                 :             : 
    1253                 :     1284274 :       if (TREE_TYPE (newdecl) == error_mark_node)
    1254                 :           0 :         types_match = TREE_TYPE (olddecl) == error_mark_node;
    1255                 :     1284274 :       else if (TREE_TYPE (olddecl) == NULL_TREE)
    1256                 :           0 :         types_match = TREE_TYPE (newdecl) == NULL_TREE;
    1257                 :     1284274 :       else if (TREE_TYPE (newdecl) == NULL_TREE)
    1258                 :             :         types_match = 0;
    1259                 :             :       else
    1260                 :     1284274 :         types_match = comptypes (TREE_TYPE (newdecl),
    1261                 :     1284274 :                                  TREE_TYPE (olddecl),
    1262                 :             :                                  COMPARE_REDECLARATION);
    1263                 :             :     }
    1264                 :             : 
    1265                 :             :   return types_match;
    1266                 :             : }
    1267                 :             : 
    1268                 :             : /* Mark DECL as versioned if it isn't already.  */
    1269                 :             : 
    1270                 :             : static void
    1271                 :       17064 : maybe_mark_function_versioned (tree decl)
    1272                 :             : {
    1273                 :       17064 :   if (!DECL_FUNCTION_VERSIONED (decl))
    1274                 :             :     {
    1275                 :        1044 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    1276                 :             :       /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
    1277                 :             :          to include the version marker.  */
    1278                 :        1044 :       if (DECL_ASSEMBLER_NAME_SET_P (decl))
    1279                 :          42 :         mangle_decl (decl);
    1280                 :             :     }
    1281                 :       17064 : }
    1282                 :             : 
    1283                 :             : /* NEWDECL and OLDDECL have identical signatures.  If they are
    1284                 :             :    different versions adjust them, record function versions, and return
    1285                 :             :    true.  */
    1286                 :             : 
    1287                 :             : bool
    1288                 :      164990 : maybe_version_functions (tree newdecl, tree olddecl)
    1289                 :             : {
    1290                 :      164990 :   if (!targetm.target_option.function_versions (newdecl, olddecl))
    1291                 :             :     return false;
    1292                 :             : 
    1293                 :        8514 :   maybe_mark_function_versioned (olddecl);
    1294                 :        8514 :   if (DECL_LOCAL_DECL_P (olddecl))
    1295                 :             :     {
    1296                 :          18 :       olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
    1297                 :          18 :       maybe_mark_function_versioned (olddecl);
    1298                 :             :     }
    1299                 :             : 
    1300                 :        8514 :   maybe_mark_function_versioned (newdecl);
    1301                 :        8514 :   if (DECL_LOCAL_DECL_P (newdecl))
    1302                 :             :     {
    1303                 :             :       /* Unfortunately, we can get here before pushdecl naturally calls
    1304                 :             :          push_local_extern_decl_alias, so we need to call it directly.  */
    1305                 :          18 :       if (!DECL_LOCAL_DECL_ALIAS (newdecl))
    1306                 :           6 :         push_local_extern_decl_alias (newdecl);
    1307                 :          18 :       newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
    1308                 :          18 :       maybe_mark_function_versioned (newdecl);
    1309                 :             :     }
    1310                 :             : 
    1311                 :             :   /* Add the new version to the function version structure.  */
    1312                 :        8514 :   cgraph_node *fn_node = cgraph_node::get_create (olddecl);
    1313                 :        8514 :   cgraph_function_version_info *fn_v = fn_node->function_version ();
    1314                 :        8514 :   if (!fn_v)
    1315                 :         171 :     fn_v = fn_node->insert_new_function_version ();
    1316                 :             : 
    1317                 :        8514 :   cgraph_node::add_function_version (fn_v, newdecl);
    1318                 :             : 
    1319                 :        8514 :   return true;
    1320                 :             : }
    1321                 :             : 
    1322                 :             : /* If NEWDECL is `static' and an `extern' was seen previously,
    1323                 :             :    warn about it.  OLDDECL is the previous declaration.
    1324                 :             : 
    1325                 :             :    Note that this does not apply to the C++ case of declaring
    1326                 :             :    a variable `extern const' and then later `const'.
    1327                 :             : 
    1328                 :             :    Don't complain about built-in functions, since they are beyond
    1329                 :             :    the user's control.  */
    1330                 :             : 
    1331                 :             : void
    1332                 :    18523976 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
    1333                 :             : {
    1334                 :    18523976 :   if (TREE_CODE (newdecl) == TYPE_DECL
    1335                 :    18498663 :       || TREE_CODE (newdecl) == TEMPLATE_DECL
    1336                 :    14882748 :       || TREE_CODE (newdecl) == CONST_DECL
    1337                 :    14882748 :       || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1338                 :    18523964 :     return;
    1339                 :             : 
    1340                 :             :   /* Don't get confused by static member functions; that's a different
    1341                 :             :      use of `static'.  */
    1342                 :    14882748 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    1343                 :    14882748 :       && DECL_STATIC_FUNCTION_P (newdecl))
    1344                 :             :     return;
    1345                 :             : 
    1346                 :             :   /* If the old declaration was `static', or the new one isn't, then
    1347                 :             :      everything is OK.  */
    1348                 :    14719214 :   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
    1349                 :             :     return;
    1350                 :             : 
    1351                 :             :   /* It's OK to declare a builtin function as `static'.  */
    1352                 :          12 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1353                 :          12 :       && DECL_ARTIFICIAL (olddecl))
    1354                 :             :     return;
    1355                 :             : 
    1356                 :          12 :   auto_diagnostic_group d;
    1357                 :          12 :   if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1358                 :             :                  "%qD was declared %<extern%> and later %<static%>", newdecl))
    1359                 :          12 :     inform (DECL_SOURCE_LOCATION (olddecl),
    1360                 :             :             "previous declaration of %qD", olddecl);
    1361                 :          12 : }
    1362                 :             : 
    1363                 :             : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
    1364                 :             :    function templates.  If their exception specifications do not
    1365                 :             :    match, issue a diagnostic.  */
    1366                 :             : 
    1367                 :             : static void
    1368                 :    18098189 : check_redeclaration_exception_specification (tree new_decl,
    1369                 :             :                                              tree old_decl)
    1370                 :             : {
    1371                 :    18098189 :   tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1372                 :    18098189 :   tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1373                 :             : 
    1374                 :             :   /* Two default specs are equivalent, don't force evaluation.  */
    1375                 :     6392431 :   if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
    1376                 :    18251389 :       && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
    1377                 :             :     return;
    1378                 :             : 
    1379                 :    18087788 :   if (!type_dependent_expression_p (old_decl))
    1380                 :             :     {
    1381                 :    10433617 :       maybe_instantiate_noexcept (new_decl);
    1382                 :    10433617 :       maybe_instantiate_noexcept (old_decl);
    1383                 :             :     }
    1384                 :    18087788 :   new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1385                 :    18087788 :   old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1386                 :             : 
    1387                 :             :   /* [except.spec]
    1388                 :             : 
    1389                 :             :      If any declaration of a function has an exception-specification,
    1390                 :             :      all declarations, including the definition and an explicit
    1391                 :             :      specialization, of that function shall have an
    1392                 :             :      exception-specification with the same set of type-ids.  */
    1393                 :    18087788 :   if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
    1394                 :    14065021 :       && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
    1395                 :    32152671 :       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
    1396                 :             :     {
    1397                 :         326 :       const char *const msg
    1398                 :             :         = G_("declaration of %qF has a different exception specifier");
    1399                 :         326 :       bool complained = true;
    1400                 :         326 :       location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
    1401                 :         326 :       auto_diagnostic_group d;
    1402                 :             : 
    1403                 :             :       /* Be permissive about C++98 vs C++11 operator new declarations.  */
    1404                 :         652 :       bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
    1405                 :           1 :                          && CP_DECL_CONTEXT (new_decl) == global_namespace
    1406                 :         328 :                          && (nothrow_spec_p (new_exceptions)
    1407                 :           1 :                              == nothrow_spec_p (old_exceptions)));
    1408                 :             : 
    1409                 :         326 :       if (DECL_IN_SYSTEM_HEADER (old_decl)
    1410                 :         326 :           && (global_new || DECL_EXTERN_C_P (old_decl)))
    1411                 :             :         /* Don't fuss about the C library; the C library functions are not
    1412                 :             :            specified to have exception specifications (just behave as if they
    1413                 :             :            have them), but some implementations include them.  */
    1414                 :         233 :         complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
    1415                 :          93 :       else if (!flag_exceptions)
    1416                 :             :         /* We used to silently permit mismatched eh specs with
    1417                 :             :            -fno-exceptions, so only complain if -pedantic.  */
    1418                 :           3 :         complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
    1419                 :          90 :       else if (!new_exceptions || global_new)
    1420                 :             :         /* Reduce to pedwarn for omitted exception specification.  No warning
    1421                 :             :            flag for this; silence the warning by correcting the code.  */
    1422                 :          21 :         complained = pedwarn (new_loc, 0, msg, new_decl);
    1423                 :             :       else
    1424                 :          69 :         error_at (new_loc, msg, new_decl);
    1425                 :             : 
    1426                 :         326 :       if (complained)
    1427                 :          96 :         inform (DECL_SOURCE_LOCATION (old_decl),
    1428                 :             :                 "from previous declaration %qF", old_decl);
    1429                 :             : 
    1430                 :             :       /* Copy the old exception specification if new_decl has none.  Unless the
    1431                 :             :          old decl is extern "C", as obscure code might depend on the type of
    1432                 :             :          the new declaration (e.g. noexcept-type19.C).  */
    1433                 :         326 :       if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
    1434                 :          20 :         TREE_TYPE (new_decl)
    1435                 :          40 :           = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
    1436                 :         326 :     }
    1437                 :             : }
    1438                 :             : 
    1439                 :             : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
    1440                 :             :    Otherwise issue diagnostics.  */
    1441                 :             : 
    1442                 :             : bool
    1443                 :    18524457 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
    1444                 :             : {
    1445                 :    18524457 :   old_decl = STRIP_TEMPLATE (old_decl);
    1446                 :    18524457 :   new_decl = STRIP_TEMPLATE (new_decl);
    1447                 :    18524457 :   if (!VAR_OR_FUNCTION_DECL_P (old_decl)
    1448                 :    18499120 :       || !VAR_OR_FUNCTION_DECL_P (new_decl))
    1449                 :             :     return true;
    1450                 :    18499120 :   if (DECL_DECLARED_CONSTEXPR_P (old_decl)
    1451                 :    18499120 :       == DECL_DECLARED_CONSTEXPR_P (new_decl))
    1452                 :             :     {
    1453                 :    18457980 :       if (TREE_CODE (old_decl) != FUNCTION_DECL)
    1454                 :             :         return true;
    1455                 :    36197150 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1456                 :    18098575 :           == DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1457                 :             :         return true;
    1458                 :             :     }
    1459                 :       41146 :   if (TREE_CODE (old_decl) == FUNCTION_DECL)
    1460                 :             :     {
    1461                 :             :       /* With -fimplicit-constexpr, ignore changes in the constexpr
    1462                 :             :          keyword.  */
    1463                 :          61 :       if (flag_implicit_constexpr
    1464                 :          61 :           && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
    1465                 :           0 :               == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
    1466                 :             :         return true;
    1467                 :          61 :       if (fndecl_built_in_p (old_decl))
    1468                 :             :         {
    1469                 :             :           /* Hide a built-in declaration.  */
    1470                 :           0 :           DECL_DECLARED_CONSTEXPR_P (old_decl)
    1471                 :           0 :             = DECL_DECLARED_CONSTEXPR_P (new_decl);
    1472                 :           0 :           if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1473                 :           0 :             SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
    1474                 :           0 :           return true;
    1475                 :             :         }
    1476                 :             :       /* 7.1.5 [dcl.constexpr]
    1477                 :             :          Note: An explicit specialization can differ from the template
    1478                 :             :          declaration with respect to the constexpr specifier.  */
    1479                 :          61 :       if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
    1480                 :          61 :           && DECL_TEMPLATE_SPECIALIZATION (new_decl))
    1481                 :             :         return true;
    1482                 :             : 
    1483                 :          42 :       const char *kind = "constexpr";
    1484                 :          42 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1485                 :          72 :           || DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1486                 :             :         kind = "consteval";
    1487                 :          42 :       auto_diagnostic_group d;
    1488                 :          42 :       error_at (DECL_SOURCE_LOCATION (new_decl),
    1489                 :             :                 "redeclaration %qD differs in %qs "
    1490                 :             :                 "from previous declaration", new_decl,
    1491                 :             :                 kind);
    1492                 :          42 :       inform (DECL_SOURCE_LOCATION (old_decl),
    1493                 :             :               "previous declaration %qD", old_decl);
    1494                 :          42 :       return false;
    1495                 :          42 :     }
    1496                 :             :   return true;
    1497                 :             : }
    1498                 :             : 
    1499                 :             : /* DECL is a redeclaration of a function or function template.  If
    1500                 :             :    it does have default arguments issue a diagnostic.  Note: this
    1501                 :             :    function is used to enforce the requirements in C++11 8.3.6 about
    1502                 :             :    no default arguments in redeclarations.  */
    1503                 :             : 
    1504                 :             : static void
    1505                 :    11347842 : check_redeclaration_no_default_args (tree decl)
    1506                 :             : {
    1507                 :    11347842 :   gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
    1508                 :             : 
    1509                 :    11347842 :   for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
    1510                 :    33444586 :        t && t != void_list_node; t = TREE_CHAIN (t))
    1511                 :    22096798 :     if (TREE_PURPOSE (t))
    1512                 :             :       {
    1513                 :          54 :         permerror (DECL_SOURCE_LOCATION (decl),
    1514                 :             :                    "redeclaration of %q#D may not have default "
    1515                 :             :                    "arguments", decl);
    1516                 :          54 :         return;
    1517                 :             :       }
    1518                 :             : }
    1519                 :             : 
    1520                 :             : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
    1521                 :             :    in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
    1522                 :             :    the TEMPLATE_DECLs in case of function templates).  This function is used
    1523                 :             :    to enforce the final part of C++17 11.3.6/4, about a single declaration:
    1524                 :             :    "If a friend declaration specifies a default argument expression, that
    1525                 :             :    declaration shall be a definition and shall be the only declaration of
    1526                 :             :    the function or function template in the translation unit."  */
    1527                 :             : 
    1528                 :             : static void
    1529                 :     5705696 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
    1530                 :             : {
    1531                 :    11043499 :   if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
    1532                 :             :     return;
    1533                 :             : 
    1534                 :     2086100 :   for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
    1535                 :     1043050 :          t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1536                 :     2801798 :        t1 && t1 != void_list_node;
    1537                 :     1758748 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1538                 :     2453361 :     if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
    1539                 :     4835489 :         || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
    1540                 :             :       {
    1541                 :          36 :         auto_diagnostic_group d;
    1542                 :          36 :         if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1543                 :             :                        "friend declaration of %q#D specifies default "
    1544                 :             :                        "arguments and isn%'t the only declaration", newdecl))
    1545                 :          36 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1546                 :             :                   "previous declaration of %q#D", olddecl);
    1547                 :          36 :         return;
    1548                 :          36 :       }
    1549                 :             : }
    1550                 :             : 
    1551                 :             : /* Merge tree bits that correspond to attributes noreturn, nothrow,
    1552                 :             :    const,  malloc, and pure from NEWDECL with those of OLDDECL.  */
    1553                 :             : 
    1554                 :             : static void
    1555                 :    17507839 : merge_attribute_bits (tree newdecl, tree olddecl)
    1556                 :             : {
    1557                 :    17507839 :   TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    1558                 :    17507839 :   TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
    1559                 :    17507839 :   TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
    1560                 :    17507839 :   TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
    1561                 :    17507839 :   TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    1562                 :    17507839 :   TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
    1563                 :    17507839 :   DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    1564                 :    17507839 :   DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
    1565                 :    17507839 :   DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    1566                 :    17507839 :   DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
    1567                 :    17507839 :   DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
    1568                 :    17507839 :   DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
    1569                 :    17507839 :   TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
    1570                 :    17507839 :   TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
    1571                 :    17507839 :   TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
    1572                 :    17507839 :   TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
    1573                 :    17507839 : }
    1574                 :             : 
    1575                 :             : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)                   \
    1576                 :             :                           && lookup_attribute ("gnu_inline",          \
    1577                 :             :                                                DECL_ATTRIBUTES (fn)))
    1578                 :             : 
    1579                 :             : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
    1580                 :             :    ambiguates olddecl.  Returns true if an error occurs.  */
    1581                 :             : 
    1582                 :             : static bool
    1583                 :   200865975 : duplicate_function_template_decls (tree newdecl, tree olddecl)
    1584                 :             : {
    1585                 :   200865975 :   tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1586                 :   200865975 :   tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1587                 :             :   /* Function template declarations can be differentiated by parameter
    1588                 :             :      and return type.  */
    1589                 :   200865975 :   if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
    1590                 :   200865975 :                  TYPE_ARG_TYPES (TREE_TYPE (newres)))
    1591                 :   200865975 :        && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
    1592                 :             :                        TREE_TYPE (TREE_TYPE (olddecl))))
    1593                 :             :     {
    1594                 :             :       /* ... and also by their template-heads and requires-clauses.  */
    1595                 :        4107 :       if (template_heads_equivalent_p (newdecl, olddecl)
    1596                 :        4107 :           && function_requirements_equivalent_p (newres, oldres))
    1597                 :             :         {
    1598                 :           0 :           auto_diagnostic_group d;
    1599                 :           0 :           error ("ambiguating new declaration %q+#D", newdecl);
    1600                 :           0 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1601                 :             :                   "old declaration %q#D", olddecl);
    1602                 :           0 :           return true;
    1603                 :           0 :         }
    1604                 :             : 
    1605                 :             :       /* FIXME: The types are the same but the are differences
    1606                 :             :          in either the template heads or function requirements.
    1607                 :             :          We should be able to diagnose a set of common errors
    1608                 :             :          stemming from these declarations. For example:
    1609                 :             : 
    1610                 :             :            template<typename T> requires C void f(...);
    1611                 :             :            template<typename T> void f(...) requires C;
    1612                 :             : 
    1613                 :             :          These are functionally equivalent but not equivalent.  */
    1614                 :             :     }
    1615                 :             : 
    1616                 :             :   return false;
    1617                 :             : }
    1618                 :             : 
    1619                 :             : /* OLD_PARMS is the innermost set of template parameters for some template
    1620                 :             :    declaration, and NEW_PARMS is the corresponding set of template parameters
    1621                 :             :    for a redeclaration of that template.  Merge the default arguments within
    1622                 :             :    these two sets of parameters.  CLASS_P is true iff the template in
    1623                 :             :    question is a class template.  */
    1624                 :             : 
    1625                 :             : bool
    1626                 :     8135037 : merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
    1627                 :             : {
    1628                 :     8135037 :   gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
    1629                 :             :                        == TREE_VEC_LENGTH (old_parms));
    1630                 :    23037075 :   for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
    1631                 :             :     {
    1632                 :    14902050 :       tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
    1633                 :    14902050 :       tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
    1634                 :    14902050 :       tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
    1635                 :    14902050 :       tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
    1636                 :    14902050 :       if (error_operand_p (new_parm) || error_operand_p (old_parm))
    1637                 :             :         return false;
    1638                 :    14902047 :       if (new_default != NULL_TREE && old_default != NULL_TREE)
    1639                 :             :         {
    1640                 :           9 :           auto_diagnostic_group d;
    1641                 :           9 :           error ("redefinition of default argument for %q+#D", new_parm);
    1642                 :           9 :           inform (DECL_SOURCE_LOCATION (old_parm),
    1643                 :             :                   "original definition appeared here");
    1644                 :           9 :           return false;
    1645                 :           9 :         }
    1646                 :    14902038 :       else if (new_default != NULL_TREE)
    1647                 :             :         /* Update the previous template parameters (which are the ones
    1648                 :             :            that will really count) with the new default value.  */
    1649                 :      199038 :         old_default = new_default;
    1650                 :    14703000 :       else if (class_p && old_default != NULL_TREE)
    1651                 :             :         /* Update the new parameters, too; they'll be used as the
    1652                 :             :            parameters for any members.  */
    1653                 :     1021316 :         new_default = old_default;
    1654                 :             :     }
    1655                 :             :   return true;
    1656                 :             : }
    1657                 :             : 
    1658                 :             : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
    1659                 :             :    If the redeclaration is invalid, a diagnostic is issued, and the
    1660                 :             :    error_mark_node is returned.  Otherwise, OLDDECL is returned.
    1661                 :             : 
    1662                 :             :    If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
    1663                 :             :    returned.
    1664                 :             : 
    1665                 :             :    HIDING is true if the new decl is being hidden.  WAS_HIDDEN is true
    1666                 :             :    if the old decl was hidden.
    1667                 :             : 
    1668                 :             :    Hidden decls can be anticipated builtins, injected friends, or
    1669                 :             :    (coming soon) injected from a local-extern decl.   */
    1670                 :             : 
    1671                 :             : tree
    1672                 :   345249112 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
    1673                 :             : {
    1674                 :   345249112 :   unsigned olddecl_uid = DECL_UID (olddecl);
    1675                 :   345249112 :   int types_match = 0;
    1676                 :   345249112 :   int new_defines_function = 0;
    1677                 :   345249112 :   tree new_template_info;
    1678                 :   345249112 :   location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
    1679                 :   345249112 :   location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
    1680                 :             : 
    1681                 :   345249112 :   if (newdecl == olddecl)
    1682                 :             :     return olddecl;
    1683                 :             : 
    1684                 :   344373916 :   types_match = decls_match (newdecl, olddecl);
    1685                 :             : 
    1686                 :             :   /* If either the type of the new decl or the type of the old decl is an
    1687                 :             :      error_mark_node, then that implies that we have already issued an
    1688                 :             :      error (earlier) for some bogus type specification, and in that case,
    1689                 :             :      it is rather pointless to harass the user with yet more error message
    1690                 :             :      about the same declaration, so just pretend the types match here.  */
    1691                 :   344373916 :   if (TREE_TYPE (newdecl) == error_mark_node
    1692                 :   344373916 :       || TREE_TYPE (olddecl) == error_mark_node)
    1693                 :             :     return error_mark_node;
    1694                 :             : 
    1695                 :             :   /* Check for redeclaration and other discrepancies.  */
    1696                 :   344373881 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1697                 :   344373881 :       && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    1698                 :             :     {
    1699                 :     6402625 :       if (TREE_CODE (newdecl) != FUNCTION_DECL)
    1700                 :             :         {
    1701                 :             :           /* Avoid warnings redeclaring built-ins which have not been
    1702                 :             :              explicitly declared.  */
    1703                 :      192266 :           if (was_hidden)
    1704                 :             :             {
    1705                 :      192238 :               if (TREE_PUBLIC (newdecl)
    1706                 :      192238 :                   && CP_DECL_CONTEXT (newdecl) == global_namespace)
    1707                 :          12 :                 warning_at (newdecl_loc,
    1708                 :          12 :                             OPT_Wbuiltin_declaration_mismatch,
    1709                 :             :                             "built-in function %qD declared as non-function",
    1710                 :             :                             newdecl);
    1711                 :      192238 :               return NULL_TREE;
    1712                 :             :             }
    1713                 :             : 
    1714                 :             :           /* If you declare a built-in or predefined function name as static,
    1715                 :             :              the old definition is overridden, but optionally warn this was a
    1716                 :             :              bad choice of name.  */
    1717                 :          28 :           if (! TREE_PUBLIC (newdecl))
    1718                 :             :             {
    1719                 :          28 :               warning_at (newdecl_loc,
    1720                 :          28 :                           OPT_Wshadow,
    1721                 :          28 :                           fndecl_built_in_p (olddecl)
    1722                 :             :                           ? G_("shadowing built-in function %q#D")
    1723                 :             :                           : G_("shadowing library function %q#D"), olddecl);
    1724                 :             :               /* Discard the old built-in function.  */
    1725                 :          28 :               return NULL_TREE;
    1726                 :             :             }
    1727                 :             :           /* If the built-in is not ansi, then programs can override
    1728                 :             :              it even globally without an error.  */
    1729                 :           0 :           else if (! fndecl_built_in_p (olddecl))
    1730                 :           0 :             warning_at (newdecl_loc, 0,
    1731                 :             :                         "library function %q#D redeclared as non-function %q#D",
    1732                 :             :                         olddecl, newdecl);
    1733                 :             :           else
    1734                 :           0 :             error_at (newdecl_loc,
    1735                 :             :                       "declaration of %q#D conflicts with built-in "
    1736                 :             :                       "declaration %q#D", newdecl, olddecl);
    1737                 :           0 :           return NULL_TREE;
    1738                 :             :         }
    1739                 :     6210359 :       else if (!types_match)
    1740                 :             :         {
    1741                 :             :           /* Avoid warnings redeclaring built-ins which have not been
    1742                 :             :              explicitly declared.  */
    1743                 :     2187592 :           if (was_hidden)
    1744                 :             :             {
    1745                 :      833865 :               tree t1, t2;
    1746                 :             : 
    1747                 :             :               /* A new declaration doesn't match a built-in one unless it
    1748                 :             :                  is also extern "C".  */
    1749                 :      833865 :               gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
    1750                 :      833865 :               gcc_assert (DECL_EXTERN_C_P (olddecl));
    1751                 :      833865 :               if (!DECL_EXTERN_C_P (newdecl))
    1752                 :             :                 return NULL_TREE;
    1753                 :             : 
    1754                 :      145719 :               for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1755                 :      145719 :                    t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1756                 :      250948 :                    t1 || t2;
    1757                 :      105229 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1758                 :             :                 {
    1759                 :      250930 :                   if (!t1 || !t2)
    1760                 :             :                     break;
    1761                 :             :                   /* FILE, tm types are not known at the time
    1762                 :             :                      we create the builtins.  */
    1763                 :      780059 :                   for (unsigned i = 0;
    1764                 :     1030827 :                        i < sizeof (builtin_structptr_types)
    1765                 :             :                            / sizeof (builtin_structptr_type);
    1766                 :             :                        ++i)
    1767                 :      925592 :                     if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
    1768                 :             :                       {
    1769                 :      145533 :                         tree t = TREE_VALUE (t1);
    1770                 :             : 
    1771                 :      145533 :                         if (TYPE_PTR_P (t)
    1772                 :      291066 :                             && TYPE_IDENTIFIER (TREE_TYPE (t))
    1773                 :      145533 :                             == get_identifier (builtin_structptr_types[i].str)
    1774                 :      291051 :                             && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
    1775                 :             :                           {
    1776                 :      145518 :                             tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1777                 :             : 
    1778                 :      145518 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl))
    1779                 :      145518 :                               = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
    1780                 :      145518 :                             types_match = decls_match (newdecl, olddecl);
    1781                 :      145518 :                             if (types_match)
    1782                 :      145518 :                               return duplicate_decls (newdecl, olddecl,
    1783                 :      145518 :                                                       hiding, was_hidden);
    1784                 :           0 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
    1785                 :             :                           }
    1786                 :          15 :                         goto next_arg;
    1787                 :             :                       }
    1788                 :             : 
    1789                 :      105235 :                   if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    1790                 :             :                     break;
    1791                 :      105229 :                 next_arg:;
    1792                 :             :                 }
    1793                 :             : 
    1794                 :         201 :               warning_at (newdecl_loc,
    1795                 :         201 :                           OPT_Wbuiltin_declaration_mismatch,
    1796                 :             :                           "declaration of %q#D conflicts with built-in "
    1797                 :             :                           "declaration %q#D", newdecl, olddecl);
    1798                 :             :             }
    1799                 :     1353727 :           else if ((DECL_EXTERN_C_P (newdecl)
    1800                 :          15 :                     && DECL_EXTERN_C_P (olddecl))
    1801                 :     2707439 :                    || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1802                 :     1353712 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
    1803                 :             :             {
    1804                 :             :               /* Don't really override olddecl for __* prefixed builtins
    1805                 :             :                  except for __[^b]*_chk, the compiler might be using those
    1806                 :             :                  explicitly.  */
    1807                 :          15 :               if (fndecl_built_in_p (olddecl))
    1808                 :             :                 {
    1809                 :          15 :                   tree id = DECL_NAME (olddecl);
    1810                 :          15 :                   const char *name = IDENTIFIER_POINTER (id);
    1811                 :          15 :                   size_t len;
    1812                 :             : 
    1813                 :          15 :                   if (name[0] == '_'
    1814                 :          15 :                       && name[1] == '_'
    1815                 :          30 :                       && (startswith (name + 2, "builtin_")
    1816                 :           6 :                           || (len = strlen (name)) <= strlen ("___chk")
    1817                 :           6 :                           || memcmp (name + len - strlen ("_chk"),
    1818                 :             :                                      "_chk", strlen ("_chk") + 1) != 0))
    1819                 :             :                     {
    1820                 :          15 :                       if (DECL_INITIAL (newdecl))
    1821                 :             :                         {
    1822                 :           6 :                           error_at (newdecl_loc,
    1823                 :             :                                     "definition of %q#D ambiguates built-in "
    1824                 :             :                                     "declaration %q#D", newdecl, olddecl);
    1825                 :           6 :                           return error_mark_node;
    1826                 :             :                         }
    1827                 :           9 :                       auto_diagnostic_group d;
    1828                 :           9 :                       if (permerror (newdecl_loc,
    1829                 :             :                                      "new declaration %q#D ambiguates built-in"
    1830                 :             :                                      " declaration %q#D", newdecl, olddecl)
    1831                 :           9 :                           && flag_permissive)
    1832                 :           3 :                         inform (newdecl_loc,
    1833                 :             :                                 "ignoring the %q#D declaration", newdecl);
    1834                 :           9 :                       return flag_permissive ? olddecl : error_mark_node;
    1835                 :           9 :                     }
    1836                 :             :                 }
    1837                 :             : 
    1838                 :             :               /* A near match; override the builtin.  */
    1839                 :             : 
    1840                 :           0 :               if (TREE_PUBLIC (newdecl))
    1841                 :           0 :                 warning_at (newdecl_loc,
    1842                 :           0 :                             OPT_Wbuiltin_declaration_mismatch,
    1843                 :             :                             "new declaration %q#D ambiguates built-in "
    1844                 :             :                             "declaration %q#D", newdecl, olddecl);
    1845                 :             :               else
    1846                 :           0 :                 warning (OPT_Wshadow,
    1847                 :             :                          fndecl_built_in_p (olddecl)
    1848                 :             :                          ? G_("shadowing built-in function %q#D")
    1849                 :             :                          : G_("shadowing library function %q#D"), olddecl);
    1850                 :             :             }
    1851                 :             :           else
    1852                 :             :             /* Discard the old built-in function.  */
    1853                 :             :             return NULL_TREE;
    1854                 :             : 
    1855                 :             :           /* Replace the old RTL to avoid problems with inlining.  */
    1856                 :         201 :           COPY_DECL_RTL (newdecl, olddecl);
    1857                 :             :         }
    1858                 :             :       else
    1859                 :             :         {
    1860                 :             :           /* Even if the types match, prefer the new declarations type
    1861                 :             :              for built-ins which have not been explicitly declared,
    1862                 :             :              for exception lists, etc...  */
    1863                 :     4022767 :           tree type = TREE_TYPE (newdecl);
    1864                 :     4022767 :           tree attribs = (*targetm.merge_type_attributes)
    1865                 :     4022767 :             (TREE_TYPE (olddecl), type);
    1866                 :             : 
    1867                 :     4022767 :           type = cp_build_type_attribute_variant (type, attribs);
    1868                 :     4022767 :           TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
    1869                 :             :         }
    1870                 :             : 
    1871                 :             :       /* If a function is explicitly declared "throw ()", propagate that to
    1872                 :             :          the corresponding builtin.  */
    1873                 :     4022968 :       if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
    1874                 :     3861749 :           && was_hidden
    1875                 :     3861706 :           && TREE_NOTHROW (newdecl)
    1876                 :     7620443 :           && !TREE_NOTHROW (olddecl))
    1877                 :             :         {
    1878                 :       29161 :           enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
    1879                 :       29161 :           tree tmpdecl = builtin_decl_explicit (fncode);
    1880                 :       29161 :           if (tmpdecl && tmpdecl != olddecl && types_match)
    1881                 :       29161 :             TREE_NOTHROW (tmpdecl)  = 1;
    1882                 :             :         }
    1883                 :             : 
    1884                 :             :       /* Whether or not the builtin can throw exceptions has no
    1885                 :             :          bearing on this declarator.  */
    1886                 :     4022968 :       TREE_NOTHROW (olddecl) = 0;
    1887                 :             : 
    1888                 :     4022968 :       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
    1889                 :             :         {
    1890                 :             :           /* If a builtin function is redeclared as `static', merge
    1891                 :             :              the declarations, but make the original one static.  */
    1892                 :           3 :           DECL_THIS_STATIC (olddecl) = 1;
    1893                 :           3 :           TREE_PUBLIC (olddecl) = 0;
    1894                 :             : 
    1895                 :             :           /* Make the old declaration consistent with the new one so
    1896                 :             :              that all remnants of the builtin-ness of this function
    1897                 :             :              will be banished.  */
    1898                 :           3 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    1899                 :           3 :           COPY_DECL_RTL (newdecl, olddecl);
    1900                 :             :         }
    1901                 :             :     }
    1902                 :   337971256 :   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    1903                 :             :     {
    1904                 :             :       /* C++ Standard, 3.3, clause 4:
    1905                 :             :          "[Note: a namespace name or a class template name must be unique
    1906                 :             :          in its declarative region (7.3.2, clause 14). ]"  */
    1907                 :    85516518 :       if (TREE_CODE (olddecl) == NAMESPACE_DECL
    1908                 :    85516497 :           || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1909                 :             :         /* Namespace conflicts with not namespace.  */;
    1910                 :    49223585 :       else if (DECL_TYPE_TEMPLATE_P (olddecl)
    1911                 :   134740070 :                || DECL_TYPE_TEMPLATE_P (newdecl))
    1912                 :             :         /* Class template conflicts.  */;
    1913                 :    85516479 :       else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
    1914                 :    49223585 :                 && DECL_TEMPLATE_RESULT (olddecl)
    1915                 :    49223585 :                 && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
    1916                 :   134740058 :                || (TREE_CODE (newdecl) == TEMPLATE_DECL
    1917                 :    36249704 :                    && DECL_TEMPLATE_RESULT (newdecl)
    1918                 :    36249704 :                    && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
    1919                 :             :         /* Variable template conflicts.  */;
    1920                 :    85516470 :       else if (concept_definition_p (olddecl)
    1921                 :   171032934 :                || concept_definition_p (newdecl))
    1922                 :             :         /* Concept conflicts.  */;
    1923                 :    85516458 :       else if ((TREE_CODE (newdecl) == FUNCTION_DECL
    1924                 :    49264020 :                 && DECL_FUNCTION_TEMPLATE_P (olddecl))
    1925                 :    85556905 :                || (TREE_CODE (olddecl) == FUNCTION_DECL
    1926                 :    36249711 :                    && DECL_FUNCTION_TEMPLATE_P (newdecl)))
    1927                 :             :         {
    1928                 :             :           /* One is a function and the other is a template
    1929                 :             :              function.  */
    1930                 :    85473253 :           if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
    1931                 :             :             return NULL_TREE;
    1932                 :             : 
    1933                 :             :           /* There can only be one!  */
    1934                 :       60397 :           auto_diagnostic_group d;
    1935                 :       60397 :           if (TREE_CODE (newdecl) == TEMPLATE_DECL
    1936                 :       60397 :               && check_raw_literal_operator (olddecl))
    1937                 :           3 :             error_at (newdecl_loc,
    1938                 :             :                       "literal operator %q#D conflicts with"
    1939                 :             :                       " raw literal operator", newdecl);
    1940                 :       60394 :           else if (check_raw_literal_operator (newdecl))
    1941                 :           3 :             error_at (newdecl_loc,
    1942                 :             :                       "raw literal operator %q#D conflicts with"
    1943                 :             :                       " literal operator template", newdecl);
    1944                 :             :           else
    1945                 :             :             return NULL_TREE;
    1946                 :             : 
    1947                 :           6 :           inform (olddecl_loc, "previous declaration %q#D", olddecl);
    1948                 :           6 :           return error_mark_node;
    1949                 :       60397 :         }
    1950                 :       43205 :       else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
    1951                 :             :         /* A structured binding must be unique in its declarative region.  */;
    1952                 :       40585 :       else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    1953                 :       43202 :                || DECL_IMPLICIT_TYPEDEF_P (newdecl))
    1954                 :             :         /* One is an implicit typedef, that's ok.  */
    1955                 :             :         return NULL_TREE;
    1956                 :             : 
    1957                 :         147 :       auto_diagnostic_group d;
    1958                 :         147 :       error ("%q#D redeclared as different kind of entity", newdecl);
    1959                 :         147 :       inform (olddecl_loc, "previous declaration %q#D", olddecl);
    1960                 :             : 
    1961                 :         147 :       return error_mark_node;
    1962                 :         147 :     }
    1963                 :   252454738 :   else if (!types_match)
    1964                 :             :     {
    1965                 :   237921406 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
    1966                 :             :         /* These are certainly not duplicate declarations; they're
    1967                 :             :            from different scopes.  */
    1968                 :             :         return NULL_TREE;
    1969                 :             : 
    1970                 :   237921346 :       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1971                 :             :         {
    1972                 :   200865993 :           tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1973                 :   200865993 :           tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1974                 :             : 
    1975                 :             :           /* The name of a class template may not be declared to refer to
    1976                 :             :              any other template, class, function, object, namespace, value,
    1977                 :             :              or type in the same scope.  */
    1978                 :   200865993 :           if (TREE_CODE (oldres) == TYPE_DECL
    1979                 :   200865987 :               || TREE_CODE (newres) == TYPE_DECL)
    1980                 :             :             {
    1981                 :           9 :               auto_diagnostic_group d;
    1982                 :           9 :               error_at (newdecl_loc,
    1983                 :             :                         "conflicting declaration of template %q#D", newdecl);
    1984                 :           9 :               inform (olddecl_loc,
    1985                 :             :                       "previous declaration %q#D", olddecl);
    1986                 :           9 :               return error_mark_node;
    1987                 :           9 :             }
    1988                 :             : 
    1989                 :   200865984 :           else if (TREE_CODE (oldres) == FUNCTION_DECL
    1990                 :   200865975 :                    && TREE_CODE (newres) == FUNCTION_DECL)
    1991                 :             :             {
    1992                 :   200865975 :               if (duplicate_function_template_decls (newdecl, olddecl))
    1993                 :           0 :                 return error_mark_node;
    1994                 :             :               return NULL_TREE;
    1995                 :             :             }
    1996                 :             :           return NULL_TREE;
    1997                 :             :         }
    1998                 :    37055353 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1999                 :             :         {
    2000                 :    37055242 :           if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
    2001                 :             :             {
    2002                 :          57 :               auto_diagnostic_group d;
    2003                 :          57 :               error_at (newdecl_loc,
    2004                 :             :                         "conflicting declaration of C function %q#D",
    2005                 :             :                         newdecl);
    2006                 :          57 :               inform (olddecl_loc,
    2007                 :             :                       "previous declaration %q#D", olddecl);
    2008                 :          57 :               return error_mark_node;
    2009                 :          57 :             }
    2010                 :             :           /* For function versions, params and types match, but they
    2011                 :             :              are not ambiguous.  */
    2012                 :    37055185 :           else if (((!DECL_FUNCTION_VERSIONED (newdecl)
    2013                 :    37047157 :                      && !DECL_FUNCTION_VERSIONED (olddecl))
    2014                 :        8073 :                     || !same_type_p (fndecl_declared_return_type (newdecl),
    2015                 :             :                                      fndecl_declared_return_type (olddecl)))
    2016                 :             :                    /* Let constrained hidden friends coexist for now, we'll
    2017                 :             :                       check satisfaction later.  */
    2018                 :    37047112 :                    && !member_like_constrained_friend_p (newdecl)
    2019                 :    36652494 :                    && !member_like_constrained_friend_p (olddecl)
    2020                 :             :                    // The functions have the same parameter types.
    2021                 :    36619993 :                    && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2022                 :    36619993 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
    2023                 :             :                    // And the same constraints.
    2024                 :    37055248 :                    && equivalently_constrained (newdecl, olddecl))
    2025                 :             :             {
    2026                 :          63 :               auto_diagnostic_group d;
    2027                 :          63 :               error_at (newdecl_loc,
    2028                 :             :                         "ambiguating new declaration of %q#D", newdecl);
    2029                 :          63 :               inform (olddecl_loc,
    2030                 :             :                       "old declaration %q#D", olddecl);
    2031                 :          63 :               return error_mark_node;
    2032                 :          63 :             }
    2033                 :             :           else
    2034                 :    37055122 :             return NULL_TREE;
    2035                 :             :         }
    2036                 :             :       else
    2037                 :             :         {
    2038                 :         111 :           auto_diagnostic_group d;
    2039                 :         111 :           error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
    2040                 :         111 :           inform (olddecl_loc,
    2041                 :             :                   "previous declaration as %q#D", olddecl);
    2042                 :         111 :           return error_mark_node;
    2043                 :         111 :         }
    2044                 :             :     }
    2045                 :    14533332 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2046                 :    14533332 :            && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
    2047                 :             :     {
    2048                 :             :       /* OMP UDRs are never duplicates. */
    2049                 :          27 :       gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
    2050                 :          27 :       auto_diagnostic_group d;
    2051                 :          27 :       error_at (newdecl_loc,
    2052                 :             :                 "redeclaration of %<pragma omp declare reduction%>");
    2053                 :          27 :       inform (olddecl_loc,
    2054                 :             :               "previous %<pragma omp declare reduction%> declaration");
    2055                 :          27 :       return error_mark_node;
    2056                 :          27 :     }
    2057                 :    14533305 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2058                 :    14533305 :             && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
    2059                 :         220 :                  && (!DECL_TEMPLATE_INFO (newdecl)
    2060                 :         220 :                      || (DECL_TI_TEMPLATE (newdecl)
    2061                 :         220 :                          != DECL_TI_TEMPLATE (olddecl))))
    2062                 :    10459846 :                 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2063                 :      590609 :                     && (!DECL_TEMPLATE_INFO (olddecl)
    2064                 :      590609 :                         || (DECL_TI_TEMPLATE (olddecl)
    2065                 :      590609 :                             != DECL_TI_TEMPLATE (newdecl))))))
    2066                 :             :     /* It's OK to have a template specialization and a non-template
    2067                 :             :        with the same type, or to have specializations of two
    2068                 :             :        different templates with the same type.  Note that if one is a
    2069                 :             :        specialization, and the other is an instantiation of the same
    2070                 :             :        template, that we do not exit at this point.  That situation
    2071                 :             :        can occur if we instantiate a template class, and then
    2072                 :             :        specialize one of its methods.  This situation is valid, but
    2073                 :             :        the declarations must be merged in the usual way.  */
    2074                 :             :     return NULL_TREE;
    2075                 :    14533305 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2076                 :    14533305 :            && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
    2077                 :      590449 :                 && !DECL_USE_TEMPLATE (newdecl))
    2078                 :    10459846 :                || (DECL_TEMPLATE_INSTANTIATION (newdecl)
    2079                 :          60 :                    && !DECL_USE_TEMPLATE (olddecl))))
    2080                 :             :     /* One of the declarations is a template instantiation, and the
    2081                 :             :        other is not a template at all.  That's OK.  */
    2082                 :             :     return NULL_TREE;
    2083                 :    14533305 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    2084                 :             :     {
    2085                 :             :       /* In [namespace.alias] we have:
    2086                 :             : 
    2087                 :             :            In a declarative region, a namespace-alias-definition can be
    2088                 :             :            used to redefine a namespace-alias declared in that declarative
    2089                 :             :            region to refer only to the namespace to which it already
    2090                 :             :            refers.
    2091                 :             : 
    2092                 :             :          Therefore, if we encounter a second alias directive for the same
    2093                 :             :          alias, we can just ignore the second directive.  */
    2094                 :          21 :       if (DECL_NAMESPACE_ALIAS (newdecl)
    2095                 :          21 :           && (DECL_NAMESPACE_ALIAS (newdecl)
    2096                 :          18 :               == DECL_NAMESPACE_ALIAS (olddecl)))
    2097                 :             :         return olddecl;
    2098                 :             : 
    2099                 :             :       /* Leave it to update_binding to merge or report error.  */
    2100                 :             :       return NULL_TREE;
    2101                 :             :     }
    2102                 :             :   else
    2103                 :             :     {
    2104                 :    14533284 :       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
    2105                 :    14533284 :       if (errmsg)
    2106                 :             :         {
    2107                 :         553 :           auto_diagnostic_group d;
    2108                 :         553 :           error_at (newdecl_loc, errmsg, newdecl);
    2109                 :         553 :           if (DECL_NAME (olddecl) != NULL_TREE)
    2110                 :         553 :             inform (olddecl_loc,
    2111                 :         553 :                     (DECL_INITIAL (olddecl) && namespace_bindings_p ())
    2112                 :             :                     ? G_("%q#D previously defined here")
    2113                 :             :                     : G_("%q#D previously declared here"), olddecl);
    2114                 :         553 :           if (cxx_dialect >= cxx26
    2115                 :         148 :               && DECL_NAME (newdecl)
    2116                 :         148 :               && id_equal (DECL_NAME (newdecl), "_")
    2117                 :         566 :               && !name_independent_decl_p (newdecl))
    2118                 :             :             {
    2119                 :          13 :               if (TREE_CODE (newdecl) == PARM_DECL)
    2120                 :           2 :                 inform (newdecl_loc,
    2121                 :             :                         "parameter declaration is not name-independent");
    2122                 :          11 :               else if (DECL_DECOMPOSITION_P (newdecl))
    2123                 :             :                 {
    2124                 :           3 :                   if (at_namespace_scope_p ())
    2125                 :           2 :                     inform (newdecl_loc,
    2126                 :             :                             "structured binding at namespace scope is not "
    2127                 :             :                             "name-independent");
    2128                 :           1 :                   else if (TREE_STATIC (newdecl))
    2129                 :           1 :                     inform (newdecl_loc,
    2130                 :             :                             "static structured binding is not "
    2131                 :             :                             "name-independent");
    2132                 :           0 :                   else if (DECL_EXTERNAL (newdecl))
    2133                 :           0 :                     inform (newdecl_loc,
    2134                 :             :                             "extern structured binding is not "
    2135                 :             :                             "name-independent");
    2136                 :             :                 }
    2137                 :           8 :               else if (at_class_scope_p ()
    2138                 :           0 :                        && VAR_P (newdecl)
    2139                 :           8 :                        && TREE_STATIC (newdecl))
    2140                 :           0 :                 inform (newdecl_loc,
    2141                 :             :                         "static data member is not name-independent");
    2142                 :           8 :               else if (VAR_P (newdecl) && at_namespace_scope_p ())
    2143                 :           3 :                 inform (newdecl_loc,
    2144                 :             :                         "variable at namespace scope is not name-independent");
    2145                 :           5 :               else if (VAR_P (newdecl) && TREE_STATIC (newdecl))
    2146                 :           3 :                 inform (newdecl_loc,
    2147                 :             :                         "static variable is not name-independent");
    2148                 :           2 :               else if (VAR_P (newdecl) && DECL_EXTERNAL (newdecl))
    2149                 :           0 :                 inform (newdecl_loc,
    2150                 :             :                         "extern variable is not name-independent");
    2151                 :             :             }
    2152                 :         553 :           return error_mark_node;
    2153                 :         553 :         }
    2154                 :    14532731 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2155                 :    10459606 :                && DECL_INITIAL (olddecl) != NULL_TREE
    2156                 :       11805 :                && !prototype_p (TREE_TYPE (olddecl))
    2157                 :    14532731 :                && prototype_p (TREE_TYPE (newdecl)))
    2158                 :             :         {
    2159                 :             :           /* Prototype decl follows defn w/o prototype.  */
    2160                 :           0 :           auto_diagnostic_group d;
    2161                 :           0 :           if (warning_at (newdecl_loc, 0,
    2162                 :             :                           "prototype specified for %q#D", newdecl))
    2163                 :           0 :             inform (olddecl_loc,
    2164                 :             :                     "previous non-prototype definition here");
    2165                 :           0 :         }
    2166                 :    14132512 :       else if (VAR_OR_FUNCTION_DECL_P (olddecl)
    2167                 :    24992337 :                && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
    2168                 :             :         {
    2169                 :             :           /* [dcl.link]
    2170                 :             :              If two declarations of the same function or object
    2171                 :             :              specify different linkage-specifications ..., the program
    2172                 :             :              is ill-formed.... Except for functions with C++ linkage,
    2173                 :             :              a function declaration without a linkage specification
    2174                 :             :              shall not precede the first linkage specification for
    2175                 :             :              that function.  A function can be declared without a
    2176                 :             :              linkage specification after an explicit linkage
    2177                 :             :              specification has been seen; the linkage explicitly
    2178                 :             :              specified in the earlier declaration is not affected by
    2179                 :             :              such a function declaration.
    2180                 :             : 
    2181                 :             :              DR 563 raises the question why the restrictions on
    2182                 :             :              functions should not also apply to objects.  Older
    2183                 :             :              versions of G++ silently ignore the linkage-specification
    2184                 :             :              for this example:
    2185                 :             : 
    2186                 :             :                namespace N {
    2187                 :             :                  extern int i;
    2188                 :             :                  extern "C" int i;
    2189                 :             :                }
    2190                 :             : 
    2191                 :             :              which is clearly wrong.  Therefore, we now treat objects
    2192                 :             :              like functions.  */
    2193                 :        1871 :           if (current_lang_depth () == 0)
    2194                 :             :             {
    2195                 :             :               /* There is no explicit linkage-specification, so we use
    2196                 :             :                  the linkage from the previous declaration.  */
    2197                 :        1865 :               retrofit_lang_decl (newdecl);
    2198                 :        1865 :               SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    2199                 :             :             }
    2200                 :             :           else
    2201                 :             :             {
    2202                 :           6 :               auto_diagnostic_group d;
    2203                 :           6 :               error_at (newdecl_loc,
    2204                 :             :                         "conflicting declaration of %q#D with %qL linkage",
    2205                 :           6 :                         newdecl, DECL_LANGUAGE (newdecl));
    2206                 :           6 :               inform (olddecl_loc,
    2207                 :             :                       "previous declaration with %qL linkage",
    2208                 :           6 :                       DECL_LANGUAGE (olddecl));
    2209                 :           6 :             }
    2210                 :             :         }
    2211                 :             : 
    2212                 :    14532731 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
    2213                 :             :         ;
    2214                 :    13920440 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2215                 :             :         {
    2216                 :             :           /* Note: free functions, as TEMPLATE_DECLs, are handled below.  */
    2217                 :    11560674 :           if (DECL_FUNCTION_MEMBER_P (olddecl)
    2218                 :     9868946 :               && (/* grokfndecl passes member function templates too
    2219                 :             :                      as FUNCTION_DECLs.  */
    2220                 :     8340627 :                   DECL_TEMPLATE_INFO (olddecl)
    2221                 :             :                   /* C++11 8.3.6/6.
    2222                 :             :                      Default arguments for a member function of a class
    2223                 :             :                      template shall be specified on the initial declaration
    2224                 :             :                      of the member function within the class template.  */
    2225                 :      666907 :                   || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
    2226                 :             :             {
    2227                 :     7755546 :               check_redeclaration_no_default_args (newdecl);
    2228                 :             : 
    2229                 :     7755546 :               if (DECL_TEMPLATE_INFO (olddecl)
    2230                 :     7755546 :                   && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
    2231                 :             :                 {
    2232                 :     2164929 :                   tree new_parms = DECL_TEMPLATE_INFO (newdecl)
    2233                 :     2164929 :                     ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
    2234                 :     2164929 :                     : INNERMOST_TEMPLATE_PARMS (current_template_parms);
    2235                 :     2164929 :                   tree old_parms
    2236                 :     2164929 :                     = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
    2237                 :     2164929 :                   merge_default_template_args (new_parms, old_parms,
    2238                 :             :                                                /*class_p=*/false);
    2239                 :             :                 }
    2240                 :             :             }
    2241                 :             :           else
    2242                 :             :             {
    2243                 :     2113400 :               tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    2244                 :     2113400 :               tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    2245                 :     2113400 :               int i = 1;
    2246                 :             : 
    2247                 :     5711749 :               for (; t1 && t1 != void_list_node;
    2248                 :     3598349 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
    2249                 :     3600288 :                 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
    2250                 :             :                   {
    2251                 :          39 :                     if (simple_cst_equal (TREE_PURPOSE (t1),
    2252                 :          39 :                                           TREE_PURPOSE (t2)) == 1)
    2253                 :             :                       {
    2254                 :          12 :                         auto_diagnostic_group d;
    2255                 :          12 :                         if (permerror (newdecl_loc,
    2256                 :             :                                        "default argument given for parameter "
    2257                 :             :                                        "%d of %q#D", i, newdecl))
    2258                 :          12 :                           inform (olddecl_loc,
    2259                 :             :                                   "previous specification in %q#D here",
    2260                 :             :                                   olddecl);
    2261                 :          12 :                       }
    2262                 :             :                     else
    2263                 :             :                       {
    2264                 :          27 :                         auto_diagnostic_group d;
    2265                 :          27 :                         error_at (newdecl_loc,
    2266                 :             :                                   "default argument given for parameter %d "
    2267                 :             :                                   "of %q#D", i, newdecl);
    2268                 :          27 :                         inform (olddecl_loc,
    2269                 :             :                                 "previous specification in %q#D here",
    2270                 :             :                                 olddecl);
    2271                 :          27 :                       }
    2272                 :             :                   }
    2273                 :             : 
    2274                 :             :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2275                 :             :                  argument expression, that declaration... shall be the only
    2276                 :             :                  declaration of the function or function template in the
    2277                 :             :                  translation unit."  */
    2278                 :     2113400 :               check_no_redeclaration_friend_default_args (olddecl, newdecl);
    2279                 :             :             }
    2280                 :             :         }
    2281                 :             :     }
    2282                 :             : 
    2283                 :             :   /* Do not merge an implicit typedef with an explicit one.  In:
    2284                 :             : 
    2285                 :             :        class A;
    2286                 :             :        ...
    2287                 :             :        typedef class A A __attribute__ ((foo));
    2288                 :             : 
    2289                 :             :      the attribute should apply only to the typedef.  */
    2290                 :    18555699 :   if (TREE_CODE (olddecl) == TYPE_DECL
    2291                 :    18555699 :       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2292                 :       25316 :           || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
    2293                 :             :     return NULL_TREE;
    2294                 :             : 
    2295                 :    18524042 :   if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
    2296                 :             :     return NULL_TREE;
    2297                 :             : 
    2298                 :    18524030 :   if (!validate_constexpr_redeclaration (olddecl, newdecl))
    2299                 :          30 :     return error_mark_node;
    2300                 :             : 
    2301                 :    18524000 :   if (modules_p ()
    2302                 :       40083 :       && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
    2303                 :    18547395 :       && TREE_CODE (olddecl) != NAMESPACE_DECL)
    2304                 :             :     {
    2305                 :       23395 :       if (!module_may_redeclare (olddecl, newdecl))
    2306                 :          24 :         return error_mark_node;
    2307                 :             : 
    2308                 :       23371 :       if (!hiding)
    2309                 :             :         {
    2310                 :             :           /* The old declaration should match the exportingness of the new
    2311                 :             :              declaration.  But hidden friend declarations just keep the
    2312                 :             :              exportingness of the old declaration; see CWG2588.  */
    2313                 :       20939 :           tree not_tmpl = STRIP_TEMPLATE (olddecl);
    2314                 :       20939 :           if (DECL_LANG_SPECIFIC (not_tmpl)
    2315                 :       20897 :               && DECL_MODULE_ATTACH_P (not_tmpl)
    2316                 :             :               /* Typedefs are not entities and so are OK to be redeclared
    2317                 :             :                  as exported: see [module.interface]/p6.  */
    2318                 :       21152 :               && TREE_CODE (olddecl) != TYPE_DECL)
    2319                 :             :             {
    2320                 :         201 :               if (DECL_MODULE_EXPORT_P (newdecl)
    2321                 :         201 :                   && !DECL_MODULE_EXPORT_P (not_tmpl))
    2322                 :             :                 {
    2323                 :          15 :                   auto_diagnostic_group d;
    2324                 :          15 :                   error ("conflicting exporting for declaration %qD", newdecl);
    2325                 :          15 :                   inform (olddecl_loc,
    2326                 :             :                           "previously declared here without exporting");
    2327                 :          15 :                 }
    2328                 :             :             }
    2329                 :       20738 :           else if (DECL_MODULE_EXPORT_P (newdecl))
    2330                 :        8648 :             DECL_MODULE_EXPORT_P (not_tmpl) = true;
    2331                 :             :         }
    2332                 :             :     }
    2333                 :             : 
    2334                 :             :   /* We have committed to returning OLDDECL at this point.  */
    2335                 :             : 
    2336                 :             :   /* If new decl is `static' and an `extern' was seen previously,
    2337                 :             :      warn about it.  */
    2338                 :    18523976 :   warn_extern_redeclared_static (newdecl, olddecl);
    2339                 :             : 
    2340                 :             :   /* True to merge attributes between the declarations, false to
    2341                 :             :      set OLDDECL's attributes to those of NEWDECL (for template
    2342                 :             :      explicit specializations that specify their own attributes
    2343                 :             :      independent of those specified for the primary template).  */
    2344                 :    18523976 :   const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
    2345                 :    14482529 :                            || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2346                 :    19114570 :                            || DECL_TEMPLATE_SPECIALIZATION (olddecl));
    2347                 :             : 
    2348                 :    18523976 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2349                 :             :     {
    2350                 :    14482529 :       if (merge_attr)
    2351                 :             :         {
    2352                 :    13892140 :           {
    2353                 :    13892140 :             auto_diagnostic_group d;
    2354                 :    13892140 :             if (diagnose_mismatched_attributes (olddecl, newdecl))
    2355                 :          36 :               inform (olddecl_loc, DECL_INITIAL (olddecl)
    2356                 :             :                       ? G_("previous definition of %qD here")
    2357                 :             :                       : G_("previous declaration of %qD here"), olddecl);
    2358                 :    13892140 :           }
    2359                 :             : 
    2360                 :             :           /* [dcl.attr.noreturn]: The first declaration of a function shall
    2361                 :             :              specify the noreturn attribute if any declaration of that function
    2362                 :             :              specifies the noreturn attribute.  */
    2363                 :    13892140 :           tree a;
    2364                 :    13892140 :           if (TREE_THIS_VOLATILE (newdecl)
    2365                 :      113526 :               && !TREE_THIS_VOLATILE (olddecl)
    2366                 :             :               /* This applies to [[noreturn]] only, not its GNU variants.  */
    2367                 :          76 :               && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
    2368                 :          54 :               && cxx11_attribute_p (a)
    2369                 :    13892161 :               && get_attribute_namespace (a) == NULL_TREE)
    2370                 :             :             {
    2371                 :           9 :               auto_diagnostic_group d;
    2372                 :           9 :               error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
    2373                 :             :                         "but its first declaration was not", newdecl);
    2374                 :           9 :               inform (olddecl_loc, "previous declaration of %qD", olddecl);
    2375                 :           9 :             }
    2376                 :             :         }
    2377                 :             : 
    2378                 :             :       /* Now that functions must hold information normally held
    2379                 :             :          by field decls, there is extra work to do so that
    2380                 :             :          declaration information does not get destroyed during
    2381                 :             :          definition.  */
    2382                 :    14482529 :       if (DECL_VINDEX (olddecl))
    2383                 :      167049 :         DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
    2384                 :    14482529 :       if (DECL_CONTEXT (olddecl))
    2385                 :    14482529 :         DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    2386                 :    14482529 :       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
    2387                 :    14482529 :       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2388                 :    14482529 :       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
    2389                 :    14482529 :       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
    2390                 :    14482529 :       DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
    2391                 :    14482529 :       DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
    2392                 :    14482529 :       DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
    2393                 :    14482529 :       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
    2394                 :    14482529 :       DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
    2395                 :    14482529 :         |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
    2396                 :    14482529 :       if (DECL_OVERLOADED_OPERATOR_P (olddecl))
    2397                 :     2531198 :         DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
    2398                 :     5062396 :           = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
    2399                 :    14482529 :       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
    2400                 :             : 
    2401                 :    14482529 :       duplicate_contracts (newdecl, olddecl);
    2402                 :             : 
    2403                 :             :       /* Optionally warn about more than one declaration for the same
    2404                 :             :          name, but don't warn about a function declaration followed by a
    2405                 :             :          definition.  */
    2406                 :          27 :       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
    2407                 :          27 :           && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
    2408                 :             :           /* Don't warn about extern decl followed by definition.  */
    2409                 :          27 :           && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
    2410                 :             :           /* Don't warn if at least one is/was hidden.  */
    2411                 :          27 :           && !(hiding || was_hidden)
    2412                 :             :           /* Don't warn about declaration followed by specialization.  */
    2413                 :    14482541 :           && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2414                 :           9 :               || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
    2415                 :             :         {
    2416                 :           6 :           auto_diagnostic_group d;
    2417                 :           6 :           if (warning_at (newdecl_loc,
    2418                 :           6 :                           OPT_Wredundant_decls,
    2419                 :             :                           "redundant redeclaration of %qD in same scope",
    2420                 :             :                           newdecl))
    2421                 :           6 :             inform (olddecl_loc,
    2422                 :             :                     "previous declaration of %qD", olddecl);
    2423                 :           6 :         }
    2424                 :             : 
    2425                 :             :       /* [dcl.fct.def.delete] A deleted definition of a function shall be the
    2426                 :             :          first declaration of the function or, for an explicit specialization
    2427                 :             :          of a function template, the first declaration of that
    2428                 :             :          specialization.  */
    2429                 :    14482529 :       if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
    2430                 :      590449 :             && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
    2431                 :             :         {
    2432                 :    13892140 :           if (DECL_DELETED_FN (newdecl))
    2433                 :             :             {
    2434                 :          21 :               auto_diagnostic_group d;
    2435                 :          21 :               if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
    2436                 :             :                            "is not first declaration", newdecl))
    2437                 :          21 :                 inform (olddecl_loc,
    2438                 :             :                         "previous declaration of %qD", olddecl);
    2439                 :          21 :             }
    2440                 :    13892140 :           DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
    2441                 :    13892140 :           if (DECL_DELETED_FN (olddecl)
    2442                 :           6 :               && DECL_INITIAL (olddecl)
    2443                 :    13892146 :               && TREE_CODE (DECL_INITIAL (olddecl)) == STRING_CST)
    2444                 :           3 :             DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2445                 :             :         }
    2446                 :             :     }
    2447                 :             : 
    2448                 :             :   /* Deal with C++: must preserve virtual function table size.  */
    2449                 :    18523976 :   if (TREE_CODE (olddecl) == TYPE_DECL)
    2450                 :             :     {
    2451                 :       25313 :       tree newtype = TREE_TYPE (newdecl);
    2452                 :       25313 :       tree oldtype = TREE_TYPE (olddecl);
    2453                 :             : 
    2454                 :       25313 :       if (newtype != error_mark_node && oldtype != error_mark_node
    2455                 :       50626 :           && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
    2456                 :       64740 :         CLASSTYPE_FRIEND_CLASSES (newtype)
    2457                 :       21580 :           = CLASSTYPE_FRIEND_CLASSES (oldtype);
    2458                 :             : 
    2459                 :       25313 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2460                 :             :     }
    2461                 :             : 
    2462                 :             :   /* Copy all the DECL_... slots specified in the new decl except for
    2463                 :             :      any that we copy here from the old type.  */
    2464                 :    18523976 :   if (merge_attr)
    2465                 :    17933587 :     DECL_ATTRIBUTES (newdecl)
    2466                 :    35867174 :       = (*targetm.merge_decl_attributes) (olddecl, newdecl);
    2467                 :             :   else
    2468                 :      590389 :     DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    2469                 :             : 
    2470                 :    18523976 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2471                 :             :     {
    2472                 :     3615915 :       tree old_result = DECL_TEMPLATE_RESULT (olddecl);
    2473                 :     3615915 :       tree new_result = DECL_TEMPLATE_RESULT (newdecl);
    2474                 :     3615915 :       TREE_TYPE (olddecl) = TREE_TYPE (old_result);
    2475                 :             : 
    2476                 :             :       /* The new decl should not already have gathered any
    2477                 :             :          specializations.  */
    2478                 :     3615915 :       gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
    2479                 :             : 
    2480                 :             :       /* Make sure the contracts are equivalent.  */
    2481                 :     3615915 :       duplicate_contracts (newdecl, olddecl);
    2482                 :             : 
    2483                 :             :       /* Remove contracts from old_result so they aren't appended to
    2484                 :             :          old_result by the merge function.  */
    2485                 :     3615915 :       remove_contract_attributes (old_result);
    2486                 :             : 
    2487                 :     3615915 :       DECL_ATTRIBUTES (old_result)
    2488                 :     3615915 :         = (*targetm.merge_decl_attributes) (old_result, new_result);
    2489                 :             : 
    2490                 :     3615915 :       if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2491                 :             :         {
    2492                 :     3615885 :           if (DECL_SOURCE_LOCATION (newdecl)
    2493                 :     3615885 :               != DECL_SOURCE_LOCATION (olddecl))
    2494                 :             :             {
    2495                 :             :               /* Per C++11 8.3.6/4, default arguments cannot be added in
    2496                 :             :                  later declarations of a function template.  */
    2497                 :     3592296 :               check_redeclaration_no_default_args (newdecl);
    2498                 :             :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2499                 :             :                  argument expression, that declaration... shall be the only
    2500                 :             :                  declaration of the function or function template in the
    2501                 :             :                  translation unit."  */
    2502                 :     3592296 :               check_no_redeclaration_friend_default_args
    2503                 :     3592296 :                 (old_result, new_result);
    2504                 :             : 
    2505                 :     3592296 :               tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
    2506                 :     3592296 :               tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
    2507                 :     3592296 :               merge_default_template_args (new_parms, old_parms,
    2508                 :             :                                            /*class_p=*/false);
    2509                 :             :             }
    2510                 :     3615885 :           if (!DECL_UNIQUE_FRIEND_P (new_result))
    2511                 :     2957192 :             DECL_UNIQUE_FRIEND_P (old_result) = false;
    2512                 :             : 
    2513                 :     3615885 :           check_default_args (newdecl);
    2514                 :             : 
    2515                 :     7231758 :           if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
    2516                 :     3615885 :               && DECL_INITIAL (new_result))
    2517                 :             :             {
    2518                 :          24 :               if (DECL_INITIAL (old_result))
    2519                 :          12 :                 DECL_UNINLINABLE (old_result) = 1;
    2520                 :             :               else
    2521                 :          12 :                 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
    2522                 :          24 :               DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
    2523                 :          72 :               DECL_NOT_REALLY_EXTERN (old_result)
    2524                 :          24 :                 = DECL_NOT_REALLY_EXTERN (new_result);
    2525                 :          48 :               DECL_INTERFACE_KNOWN (old_result)
    2526                 :          24 :                 = DECL_INTERFACE_KNOWN (new_result);
    2527                 :          24 :               DECL_DECLARED_INLINE_P (old_result)
    2528                 :          24 :                 = DECL_DECLARED_INLINE_P (new_result);
    2529                 :          24 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2530                 :          24 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2531                 :             :             }
    2532                 :             :           else
    2533                 :             :             {
    2534                 :     3615861 :               DECL_DECLARED_INLINE_P (old_result)
    2535                 :     3615861 :                 |= DECL_DECLARED_INLINE_P (new_result);
    2536                 :     3615861 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2537                 :     3615861 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2538                 :     3615861 :               check_redeclaration_exception_specification (newdecl, olddecl);
    2539                 :             : 
    2540                 :     3615861 :               merge_attribute_bits (new_result, old_result);
    2541                 :             :             }
    2542                 :             :         }
    2543                 :             : 
    2544                 :             :       /* Propagate purviewness and importingness as with
    2545                 :             :          set_instantiating_module, unless newdecl is a friend injection.  */
    2546                 :     3615915 :       if (modules_p () && DECL_LANG_SPECIFIC (new_result)
    2547                 :     3627491 :           && !(TREE_CODE (new_result) == FUNCTION_DECL
    2548                 :       11570 :                && DECL_UNIQUE_FRIEND_P (new_result)))
    2549                 :             :         {
    2550                 :        9750 :           if (DECL_MODULE_PURVIEW_P (new_result))
    2551                 :        4755 :             DECL_MODULE_PURVIEW_P (old_result) = true;
    2552                 :        9750 :           if (!DECL_MODULE_IMPORT_P (new_result))
    2553                 :        9750 :             DECL_MODULE_IMPORT_P (old_result) = false;
    2554                 :             :         }
    2555                 :             : 
    2556                 :             :       /* If the new declaration is a definition, update the file and
    2557                 :             :          line information on the declaration, and also make
    2558                 :             :          the old declaration the same definition.  */
    2559                 :     3615915 :       if (DECL_INITIAL (new_result) != NULL_TREE)
    2560                 :             :         {
    2561                 :     5486132 :           DECL_SOURCE_LOCATION (olddecl)
    2562                 :     5486132 :             = DECL_SOURCE_LOCATION (old_result)
    2563                 :     2743066 :             = DECL_SOURCE_LOCATION (newdecl);
    2564                 :     2743066 :           DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
    2565                 :     2743066 :           if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2566                 :             :             {
    2567                 :     2743066 :               DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
    2568                 :     9803677 :               for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
    2569                 :     7060611 :                 DECL_CONTEXT (p) = old_result;
    2570                 :             : 
    2571                 :     5486132 :               if (tree fc = DECL_FRIEND_CONTEXT (new_result))
    2572                 :          14 :                 SET_DECL_FRIEND_CONTEXT (old_result, fc);
    2573                 :             :             }
    2574                 :             :         }
    2575                 :             : 
    2576                 :     3615915 :       return olddecl;
    2577                 :             :     }
    2578                 :             : 
    2579                 :    14908061 :   if (types_match)
    2580                 :             :     {
    2581                 :    14907860 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2582                 :    14482328 :         check_redeclaration_exception_specification (newdecl, olddecl);
    2583                 :             : 
    2584                 :             :       /* Automatically handles default parameters.  */
    2585                 :    14907860 :       tree oldtype = TREE_TYPE (olddecl);
    2586                 :    14907860 :       tree newtype;
    2587                 :             : 
    2588                 :             :       /* For typedefs use the old type, as the new type's DECL_NAME points
    2589                 :             :          at newdecl, which will be ggc_freed.  */
    2590                 :    14907860 :       if (TREE_CODE (newdecl) == TYPE_DECL)
    2591                 :             :         {
    2592                 :             :           /* But NEWTYPE might have an attribute, honor that.  */
    2593                 :       25313 :           tree tem = TREE_TYPE (newdecl);
    2594                 :       25313 :           newtype = oldtype;
    2595                 :             : 
    2596                 :       25313 :           if (TYPE_USER_ALIGN (tem))
    2597                 :             :             {
    2598                 :          21 :               if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2599                 :           6 :                 SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2600                 :          21 :               TYPE_USER_ALIGN (newtype) = true;
    2601                 :             :             }
    2602                 :             : 
    2603                 :             :           /* And remove the new type from the variants list.  */
    2604                 :       25313 :           if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2605                 :             :             {
    2606                 :          24 :               tree remove = TREE_TYPE (newdecl);
    2607                 :          24 :               if (TYPE_MAIN_VARIANT (remove) == remove)
    2608                 :             :                 {
    2609                 :           9 :                   gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2610                 :             :                   /* If remove is the main variant, no need to remove that
    2611                 :             :                      from the list.  One of the DECL_ORIGINAL_TYPE
    2612                 :             :                      variants, e.g. created for aligned attribute, might still
    2613                 :             :                      refer to the newdecl TYPE_DECL though, so remove that one
    2614                 :             :                      in that case.  */
    2615                 :           9 :                   if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
    2616                 :           6 :                     if (orig != remove)
    2617                 :           6 :                       for (tree t = TYPE_MAIN_VARIANT (orig); t;
    2618                 :           0 :                            t = TYPE_MAIN_VARIANT (t))
    2619                 :           6 :                         if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2620                 :             :                           {
    2621                 :          12 :                             TYPE_NEXT_VARIANT (t)
    2622                 :           6 :                               = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2623                 :           6 :                             break;
    2624                 :             :                           }
    2625                 :             :                 }
    2626                 :             :               else
    2627                 :          15 :                 for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2628                 :           0 :                      t = TYPE_NEXT_VARIANT (t))
    2629                 :          15 :                   if (TYPE_NEXT_VARIANT (t) == remove)
    2630                 :             :                     {
    2631                 :          15 :                       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2632                 :          15 :                       break;
    2633                 :             :                     }
    2634                 :             :             }
    2635                 :             :         }
    2636                 :    14882547 :       else if (merge_attr)
    2637                 :    14292158 :         newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
    2638                 :             :       else
    2639                 :      590389 :         newtype = TREE_TYPE (newdecl);
    2640                 :             : 
    2641                 :    14907860 :       if (VAR_P (newdecl))
    2642                 :             :         {
    2643                 :      400219 :           DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
    2644                 :             :           /* For already initialized vars, TREE_READONLY could have been
    2645                 :             :              cleared in cp_finish_decl, because the var needs runtime
    2646                 :             :              initialization or destruction.  Make sure not to set
    2647                 :             :              TREE_READONLY on it again.  */
    2648                 :      400219 :           if (DECL_INITIALIZED_P (olddecl)
    2649                 :        1213 :               && !DECL_EXTERNAL (olddecl)
    2650                 :      400304 :               && !TREE_READONLY (olddecl))
    2651                 :          30 :             TREE_READONLY (newdecl) = 0;
    2652                 :      400219 :           DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
    2653                 :      800438 :           DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
    2654                 :      400219 :             |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
    2655                 :      400219 :           if (DECL_DEPENDENT_INIT_P (olddecl))
    2656                 :      107168 :             SET_DECL_DEPENDENT_INIT_P (newdecl, true);
    2657                 :      800438 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
    2658                 :      400219 :             |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
    2659                 :      400219 :           DECL_DECLARED_CONSTEXPR_P (newdecl)
    2660                 :      400219 :             |= DECL_DECLARED_CONSTEXPR_P (olddecl);
    2661                 :      800438 :           DECL_DECLARED_CONSTINIT_P (newdecl)
    2662                 :      400219 :             |= DECL_DECLARED_CONSTINIT_P (olddecl);
    2663                 :             : 
    2664                 :             :           /* Merge the threadprivate attribute from OLDDECL into NEWDECL.  */
    2665                 :      400219 :           if (DECL_LANG_SPECIFIC (olddecl)
    2666                 :      796845 :               && CP_DECL_THREADPRIVATE_P (olddecl))
    2667                 :             :             {
    2668                 :             :               /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed.  */
    2669                 :          41 :               retrofit_lang_decl (newdecl);
    2670                 :          41 :               CP_DECL_THREADPRIVATE_P (newdecl) = 1;
    2671                 :             :             }
    2672                 :             :         }
    2673                 :             : 
    2674                 :             :       /* An explicit specialization of a function template or of a member
    2675                 :             :          function of a class template can be declared transaction_safe
    2676                 :             :          independently of whether the corresponding template entity is declared
    2677                 :             :          transaction_safe. */
    2678                 :        1124 :       if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
    2679                 :        1022 :           && DECL_TEMPLATE_INSTANTIATION (olddecl)
    2680                 :          51 :           && DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2681                 :          51 :           && tx_safe_fn_type_p (newtype)
    2682                 :    14907860 :           && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
    2683                 :           0 :         newtype = tx_unsafe_fn_variant (newtype);
    2684                 :             : 
    2685                 :    14907860 :       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
    2686                 :             : 
    2687                 :    14907860 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2688                 :    14482328 :         check_default_args (newdecl);
    2689                 :             : 
    2690                 :             :       /* Lay the type out, unless already done.  */
    2691                 :    14907860 :       if (! same_type_p (newtype, oldtype)
    2692                 :         366 :           && TREE_TYPE (newdecl) != error_mark_node
    2693                 :    14908226 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2694                 :         285 :         layout_type (TREE_TYPE (newdecl));
    2695                 :             : 
    2696                 :    14907860 :       if ((VAR_P (newdecl)
    2697                 :    14507641 :            || TREE_CODE (newdecl) == PARM_DECL
    2698                 :    14507641 :            || TREE_CODE (newdecl) == RESULT_DECL
    2699                 :    14507641 :            || TREE_CODE (newdecl) == FIELD_DECL
    2700                 :    14507641 :            || TREE_CODE (newdecl) == TYPE_DECL)
    2701                 :    14933173 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2702                 :      260782 :         layout_decl (newdecl, 0);
    2703                 :             : 
    2704                 :             :       /* Merge deprecatedness.  */
    2705                 :    14907860 :       if (TREE_DEPRECATED (newdecl))
    2706                 :       12199 :         TREE_DEPRECATED (olddecl) = 1;
    2707                 :             : 
    2708                 :             :       /* Merge unavailability.  */
    2709                 :    14907860 :       if (TREE_UNAVAILABLE (newdecl))
    2710                 :           3 :         TREE_UNAVAILABLE (olddecl) = 1;
    2711                 :             : 
    2712                 :             :       /* Preserve function specific target and optimization options */
    2713                 :    14907860 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2714                 :             :         {
    2715                 :    14482328 :           if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    2716                 :    14482328 :               && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    2717                 :           0 :             DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    2718                 :           0 :               = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    2719                 :             : 
    2720                 :    14482328 :           if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    2721                 :    14482328 :               && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    2722                 :          55 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    2723                 :          55 :               = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    2724                 :             : 
    2725                 :    14482328 :           if (!DECL_UNIQUE_FRIEND_P (olddecl))
    2726                 :    14310745 :             DECL_UNIQUE_FRIEND_P (newdecl) = false;
    2727                 :             :         }
    2728                 :             :       else
    2729                 :             :         {
    2730                 :             :           /* Merge the const type qualifier.  */
    2731                 :      425532 :           if (TREE_READONLY (newdecl))
    2732                 :       42420 :             TREE_READONLY (olddecl) = 1;
    2733                 :             :           /* Merge the volatile type qualifier.  */
    2734                 :      425532 :           if (TREE_THIS_VOLATILE (newdecl))
    2735                 :           5 :             TREE_THIS_VOLATILE (olddecl) = 1;
    2736                 :             :         }
    2737                 :             : 
    2738                 :             :       /* Merge the initialization information.  */
    2739                 :    14907860 :       if (DECL_INITIAL (newdecl) == NULL_TREE
    2740                 :    14907860 :           && DECL_INITIAL (olddecl) != NULL_TREE)
    2741                 :             :         {
    2742                 :      178899 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2743                 :      178899 :           DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2744                 :      178899 :           if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2745                 :             :             {
    2746                 :       11721 :               DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    2747                 :       11721 :               DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    2748                 :             :             }
    2749                 :             :         }
    2750                 :             : 
    2751                 :    14907860 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2752                 :             :         {
    2753                 :    14482328 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2754                 :    14482328 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2755                 :    14482328 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2756                 :    14482328 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2757                 :       54506 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2758                 :    14482328 :           DECL_LOOPING_CONST_OR_PURE_P (newdecl)
    2759                 :    14482328 :             |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
    2760                 :    14482328 :           DECL_IS_REPLACEABLE_OPERATOR (newdecl)
    2761                 :    14482328 :             |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
    2762                 :             : 
    2763                 :    14482328 :           if (merge_attr)
    2764                 :    13891939 :             merge_attribute_bits (newdecl, olddecl);
    2765                 :             :           else
    2766                 :             :             {
    2767                 :             :               /* Merge the noreturn bit.  */
    2768                 :      590389 :               TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    2769                 :      590389 :               TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    2770                 :      590389 :               TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    2771                 :      590389 :               DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
    2772                 :      590389 :               DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
    2773                 :             :             }
    2774                 :             :           /* Keep the old RTL.  */
    2775                 :    14482328 :           COPY_DECL_RTL (olddecl, newdecl);
    2776                 :             :         }
    2777                 :      425532 :       else if (VAR_P (newdecl)
    2778                 :      425532 :                && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
    2779                 :             :         {
    2780                 :             :           /* Keep the old RTL.  We cannot keep the old RTL if the old
    2781                 :             :              declaration was for an incomplete object and the new
    2782                 :             :              declaration is not since many attributes of the RTL will
    2783                 :             :              change.  */
    2784                 :      400145 :           COPY_DECL_RTL (olddecl, newdecl);
    2785                 :             :         }
    2786                 :             :     }
    2787                 :             :   /* If cannot merge, then use the new type and qualifiers,
    2788                 :             :      and don't preserve the old rtl.  */
    2789                 :             :   else
    2790                 :             :     {
    2791                 :             :       /* Clean out any memory we had of the old declaration.  */
    2792                 :         201 :       tree oldstatic = value_member (olddecl, static_aggregates);
    2793                 :         201 :       if (oldstatic)
    2794                 :           0 :         TREE_VALUE (oldstatic) = error_mark_node;
    2795                 :             : 
    2796                 :         201 :       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
    2797                 :         201 :       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    2798                 :         201 :       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    2799                 :         201 :       TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    2800                 :         201 :       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
    2801                 :             :     }
    2802                 :             : 
    2803                 :             :   /* Merge the storage class information.  */
    2804                 :    14908061 :   merge_weak (newdecl, olddecl);
    2805                 :             : 
    2806                 :    14908061 :   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
    2807                 :    14908061 :   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    2808                 :    14908061 :   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
    2809                 :    14908061 :   if (! DECL_EXTERNAL (olddecl))
    2810                 :       29930 :     DECL_EXTERNAL (newdecl) = 0;
    2811                 :    14908061 :   if (! DECL_COMDAT (olddecl))
    2812                 :     6103302 :     DECL_COMDAT (newdecl) = 0;
    2813                 :             : 
    2814                 :    14908061 :   if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
    2815                 :             :     {
    2816                 :          75 :       if (!DECL_LOCAL_DECL_P (olddecl))
    2817                 :             :         /* This can happen if olddecl was brought in from the
    2818                 :             :            enclosing namespace via a using-decl.  The new decl is
    2819                 :             :            then not a block-scope extern at all.  */
    2820                 :           3 :         DECL_LOCAL_DECL_P (newdecl) = false;
    2821                 :             :       else
    2822                 :             :         {
    2823                 :          72 :           retrofit_lang_decl (newdecl);
    2824                 :          72 :           tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
    2825                 :          72 :             = DECL_LOCAL_DECL_ALIAS (olddecl);
    2826                 :          72 :           if (alias != error_mark_node)
    2827                 :             :             {
    2828                 :          69 :               DECL_ATTRIBUTES (alias)
    2829                 :          69 :                 = (*targetm.merge_decl_attributes) (alias, newdecl);
    2830                 :          69 :               if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2831                 :          39 :                 merge_attribute_bits (newdecl, alias);
    2832                 :             :             }
    2833                 :             :         }
    2834                 :             :     }
    2835                 :             : 
    2836                 :    14908061 :   new_template_info = NULL_TREE;
    2837                 :    14908061 :   if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
    2838                 :             :     {
    2839                 :    14879164 :       bool new_redefines_gnu_inline = false;
    2840                 :             : 
    2841                 :    14879164 :       if (new_defines_function
    2842                 :    14879164 :           && ((DECL_INTERFACE_KNOWN (olddecl)
    2843                 :        1238 :                && TREE_CODE (olddecl) == FUNCTION_DECL)
    2844                 :     9114712 :               || (TREE_CODE (olddecl) == TEMPLATE_DECL
    2845                 :           0 :                   && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
    2846                 :             :                       == FUNCTION_DECL))))
    2847                 :        2476 :         new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
    2848                 :             : 
    2849                 :             :       if (!new_redefines_gnu_inline)
    2850                 :             :         {
    2851                 :    14879086 :           DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
    2852                 :    14879086 :           DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
    2853                 :    14879086 :           DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
    2854                 :             :         }
    2855                 :             : 
    2856                 :    14879164 :       if (TREE_CODE (newdecl) != TYPE_DECL)
    2857                 :             :         {
    2858                 :    14879112 :           DECL_TEMPLATE_INSTANTIATED (newdecl)
    2859                 :    14879112 :             |= DECL_TEMPLATE_INSTANTIATED (olddecl);
    2860                 :    14879112 :           DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
    2861                 :             : 
    2862                 :             :           /* If the OLDDECL is an instantiation and/or specialization,
    2863                 :             :              then the NEWDECL must be too.  But, it may not yet be marked
    2864                 :             :              as such if the caller has created NEWDECL, but has not yet
    2865                 :             :              figured out that it is a redeclaration.  */
    2866                 :    14879112 :           if (!DECL_USE_TEMPLATE (newdecl))
    2867                 :    14288449 :             DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
    2868                 :             : 
    2869                 :    14879112 :           if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
    2870                 :    14288499 :             DECL_INITIALIZED_IN_CLASS_P (newdecl)
    2871                 :    28576998 :               |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
    2872                 :             :         }
    2873                 :             : 
    2874                 :             :       /* Don't really know how much of the language-specific
    2875                 :             :          values we should copy from old to new.  */
    2876                 :    14879164 :       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
    2877                 :             : 
    2878                 :    14879164 :       if (LANG_DECL_HAS_MIN (newdecl))
    2879                 :             :         {
    2880                 :    14879164 :           DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
    2881                 :    14879164 :           if (DECL_TEMPLATE_INFO (newdecl))
    2882                 :             :             {
    2883                 :      602524 :               new_template_info = DECL_TEMPLATE_INFO (newdecl);
    2884                 :      602524 :               if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    2885                 :      602524 :                   && DECL_TEMPLATE_SPECIALIZATION (newdecl))
    2886                 :             :                 /* Remember the presence of explicit specialization args.  */
    2887                 :     1180784 :                 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
    2888                 :     1180784 :                   = TINFO_USED_TEMPLATE_ID (new_template_info);
    2889                 :             :             }
    2890                 :             : 
    2891                 :             :           /* We don't want to copy template info from a non-templated friend
    2892                 :             :              (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now.  */
    2893                 :    14879164 :           gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
    2894                 :             :                                || !non_templated_friend_p (olddecl));
    2895                 :    14879164 :           DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
    2896                 :             :         }
    2897                 :             : 
    2898                 :    14879164 :       if (DECL_DECLARES_FUNCTION_P (newdecl))
    2899                 :             :         {
    2900                 :             :           /* Only functions have these fields.  */
    2901                 :    14482529 :           DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
    2902                 :    14482529 :           DECL_BEFRIENDING_CLASSES (newdecl)
    2903                 :    14482529 :             = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
    2904                 :    14482529 :                        DECL_BEFRIENDING_CLASSES (olddecl));
    2905                 :             :           /* DECL_THUNKS is only valid for virtual functions,
    2906                 :             :              otherwise it is a DECL_FRIEND_CONTEXT.  */
    2907                 :    14482529 :           if (DECL_VIRTUAL_P (newdecl))
    2908                 :      664317 :             SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
    2909                 :    27636424 :           else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
    2910                 :      102739 :             SET_DECL_FRIEND_CONTEXT (olddecl, fc);
    2911                 :             :         }
    2912                 :      396635 :       else if (VAR_P (newdecl))
    2913                 :             :         {
    2914                 :             :           /* Only variables have this field.  */
    2915                 :      396583 :           if (VAR_HAD_UNKNOWN_BOUND (olddecl))
    2916                 :         194 :             SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
    2917                 :             :         }
    2918                 :             :     }
    2919                 :             : 
    2920                 :    14908061 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2921                 :             :     {
    2922                 :    14482529 :       tree parm;
    2923                 :             : 
    2924                 :             :       /* Merge parameter attributes. */
    2925                 :    14482529 :       tree oldarg, newarg;
    2926                 :    14482529 :       for (oldarg = DECL_ARGUMENTS(olddecl), newarg = DECL_ARGUMENTS(newdecl);
    2927                 :    41019619 :            oldarg && newarg;
    2928                 :    26537090 :            oldarg = DECL_CHAIN(oldarg), newarg = DECL_CHAIN(newarg))
    2929                 :             :         {
    2930                 :    26537090 :           DECL_ATTRIBUTES (newarg)
    2931                 :    26537090 :             = (*targetm.merge_decl_attributes) (oldarg, newarg);
    2932                 :    26537090 :           DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    2933                 :             :         }
    2934                 :             : 
    2935                 :    14482529 :       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    2936                 :    14482529 :           && !DECL_TEMPLATE_INSTANTIATION (newdecl))
    2937                 :             :         {
    2938                 :             :           /* If newdecl is not a specialization, then it is not a
    2939                 :             :              template-related function at all.  And that means that we
    2940                 :             :              should have exited above, returning 0.  */
    2941                 :      590389 :           gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
    2942                 :             : 
    2943                 :      590389 :           if (DECL_ODR_USED (olddecl))
    2944                 :             :             /* From [temp.expl.spec]:
    2945                 :             : 
    2946                 :             :                If a template, a member template or the member of a class
    2947                 :             :                template is explicitly specialized then that
    2948                 :             :                specialization shall be declared before the first use of
    2949                 :             :                that specialization that would cause an implicit
    2950                 :             :                instantiation to take place, in every translation unit in
    2951                 :             :                which such a use occurs.  */
    2952                 :           0 :             error ("explicit specialization of %qD after first use",
    2953                 :             :                       olddecl);
    2954                 :             : 
    2955                 :      590389 :           SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
    2956                 :      590389 :           DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
    2957                 :     1180625 :                                    && DECL_DECLARED_INLINE_P (newdecl));
    2958                 :             : 
    2959                 :             :           /* Don't propagate visibility from the template to the
    2960                 :             :              specialization here.  We'll do that in determine_visibility if
    2961                 :             :              appropriate.  */
    2962                 :      590389 :           DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
    2963                 :             : 
    2964                 :             :           /* [temp.expl.spec/14] We don't inline explicit specialization
    2965                 :             :              just because the primary template says so.  */
    2966                 :      590389 :           gcc_assert (!merge_attr);
    2967                 :             : 
    2968                 :      590389 :           DECL_DECLARED_INLINE_P (olddecl)
    2969                 :      590389 :             = DECL_DECLARED_INLINE_P (newdecl);
    2970                 :             : 
    2971                 :      590389 :           DECL_DISREGARD_INLINE_LIMITS (olddecl)
    2972                 :      590389 :             = DECL_DISREGARD_INLINE_LIMITS (newdecl);
    2973                 :             : 
    2974                 :      590389 :           DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
    2975                 :             :         }
    2976                 :    13892140 :       else if (new_defines_function && DECL_INITIAL (olddecl))
    2977                 :             :         {
    2978                 :             :           /* Never inline re-defined extern inline functions.
    2979                 :             :              FIXME: this could be better handled by keeping both
    2980                 :             :              function as separate declarations.  */
    2981                 :          78 :           DECL_UNINLINABLE (newdecl) = 1;
    2982                 :             :         }
    2983                 :             :       else
    2984                 :             :         {
    2985                 :    13892062 :           if (DECL_PENDING_INLINE_P (olddecl))
    2986                 :             :             {
    2987                 :           6 :               DECL_PENDING_INLINE_P (newdecl) = 1;
    2988                 :           6 :               DECL_PENDING_INLINE_INFO (newdecl)
    2989                 :          12 :                 = DECL_PENDING_INLINE_INFO (olddecl);
    2990                 :             :             }
    2991                 :    13892056 :           else if (DECL_PENDING_INLINE_P (newdecl))
    2992                 :             :             ;
    2993                 :    13892056 :           else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
    2994                 :    13892056 :             DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
    2995                 :    27784112 :               = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
    2996                 :             : 
    2997                 :    13892062 :           DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
    2998                 :             : 
    2999                 :    41676186 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    3000                 :    27784124 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    3001                 :             : 
    3002                 :    27784124 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3003                 :    13892062 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3004                 :    13892062 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3005                 :    27378998 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3006                 :             :         }
    3007                 :             : 
    3008                 :             :       /* Preserve abstractness on cloned [cd]tors.  */
    3009                 :    14482529 :       DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
    3010                 :             : 
    3011                 :             :       /* Update newdecl's parms to point at olddecl.  */
    3012                 :    46994799 :       for (parm = DECL_ARGUMENTS (newdecl); parm;
    3013                 :    32512270 :            parm = DECL_CHAIN (parm))
    3014                 :    32512270 :         DECL_CONTEXT (parm) = olddecl;
    3015                 :             : 
    3016                 :    14482529 :       if (! types_match)
    3017                 :             :         {
    3018                 :         201 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    3019                 :         201 :           COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
    3020                 :         201 :           COPY_DECL_RTL (newdecl, olddecl);
    3021                 :             :         }
    3022                 :    14482529 :       if (! types_match || new_defines_function)
    3023                 :             :         {
    3024                 :             :           /* These are the final DECL_ARGUMENTS that will be used within the
    3025                 :             :              body; update any references to old DECL_ARGUMENTS in the
    3026                 :             :              contracts, if present.  */
    3027                 :     9116151 :           if (tree contracts = DECL_CONTRACTS (newdecl))
    3028                 :         132 :             remap_contracts (olddecl, newdecl, contracts, true);
    3029                 :             : 
    3030                 :             :           /* These need to be copied so that the names are available.
    3031                 :             :              Note that if the types do match, we'll preserve inline
    3032                 :             :              info and other bits, but if not, we won't.  */
    3033                 :     9116151 :           DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
    3034                 :     9116151 :           DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
    3035                 :             : 
    3036                 :             :           /* In some cases, duplicate_contracts will remove contracts from
    3037                 :             :              OLDDECL, to avoid duplications. Sometimes, the contracts end up
    3038                 :             :              shared. If we removed them, re-add them.  */
    3039                 :     9116151 :           if (!DECL_CONTRACTS (olddecl))
    3040                 :     9116104 :             copy_contract_attributes (olddecl, newdecl);
    3041                 :             :         }
    3042                 :             :       /* If redeclaring a builtin function, it stays built in
    3043                 :             :          if newdecl is a gnu_inline definition, or if newdecl is just
    3044                 :             :          a declaration.  */
    3045                 :    14482529 :       if (fndecl_built_in_p (olddecl)
    3046                 :    14542320 :           && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
    3047                 :             :         {
    3048                 :     4001172 :           copy_decl_built_in_function (newdecl, olddecl);
    3049                 :             :           /* If we're keeping the built-in definition, keep the rtl,
    3050                 :             :              regardless of declaration matches.  */
    3051                 :     4001172 :           COPY_DECL_RTL (olddecl, newdecl);
    3052                 :     4001172 :           if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3053                 :             :             {
    3054                 :     4001166 :               enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3055                 :     4001166 :               if (builtin_decl_explicit_p (fncode))
    3056                 :             :                 {
    3057                 :             :                   /* A compatible prototype of these builtin functions
    3058                 :             :                      is seen, assume the runtime implements it with
    3059                 :             :                      the expected semantics.  */
    3060                 :     4001166 :                   switch (fncode)
    3061                 :             :                     {
    3062                 :       10511 :                     case BUILT_IN_STPCPY:
    3063                 :       10511 :                       set_builtin_decl_implicit_p (fncode, true);
    3064                 :       10511 :                       break;
    3065                 :     3990655 :                     default:
    3066                 :     3990655 :                       set_builtin_decl_declared_p (fncode, true);
    3067                 :     3990655 :                       break;
    3068                 :             :                     }
    3069                 :             :                 }
    3070                 :             : 
    3071                 :     4001166 :               copy_attributes_to_builtin (newdecl);
    3072                 :             :             }
    3073                 :             :         }
    3074                 :    14482529 :       if (new_defines_function)
    3075                 :             :         /* If defining a function declared with other language
    3076                 :             :            linkage, use the previously declared language linkage.  */
    3077                 :     9115950 :         SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    3078                 :     5366579 :       else if (types_match)
    3079                 :             :         {
    3080                 :     5366378 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3081                 :             :           /* Don't clear out the arguments if we're just redeclaring a
    3082                 :             :              function.  */
    3083                 :     5366378 :           if (DECL_ARGUMENTS (olddecl))
    3084                 :             :             {
    3085                 :             :               /* If we removed contracts from previous definition, re-attach
    3086                 :             :                  them. Otherwise, rewrite the contracts so they match the
    3087                 :             :                  parameters of the new declaration.  */
    3088                 :     1269716 :               if (DECL_INITIAL (olddecl)
    3089                 :       11614 :                   && DECL_CONTRACTS (newdecl)
    3090                 :     1269727 :                   && !DECL_CONTRACTS (olddecl))
    3091                 :          10 :                 copy_contract_attributes (olddecl, newdecl);
    3092                 :             :               else
    3093                 :             :                 {
    3094                 :             :                   /* Temporarily undo the re-contexting of parameters so we can
    3095                 :             :                      actually remap parameters.  The inliner won't replace
    3096                 :             :                      parameters if we don't do this.  */
    3097                 :     1269706 :                   tree args = DECL_ARGUMENTS (newdecl);
    3098                 :     4755963 :                   for (tree p = args; p; p = DECL_CHAIN (p))
    3099                 :     3486257 :                     DECL_CONTEXT (p) = newdecl;
    3100                 :             : 
    3101                 :             :                   /* Save new argument names for use in contracts parsing,
    3102                 :             :                      unless we've already started parsing the body of olddecl
    3103                 :             :                      (particular issues arise when newdecl is from a prior
    3104                 :             :                      friend decl with no argument names, see
    3105                 :             :                      modules/contracts-tpl-friend-1).  */
    3106                 :     1269706 :                   if (tree contracts = DECL_CONTRACTS (olddecl))
    3107                 :          29 :                     remap_contracts (newdecl, olddecl, contracts, true);
    3108                 :             : 
    3109                 :             :                   /* And reverse this operation again. */
    3110                 :     4755963 :                   for (tree p = args; p; p = DECL_CHAIN (p))
    3111                 :     3486257 :                     DECL_CONTEXT (p) = olddecl;
    3112                 :             :                 }
    3113                 :             : 
    3114                 :     1269716 :               DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
    3115                 :             :             }
    3116                 :             :         }
    3117                 :             :     }
    3118                 :      425532 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    3119                 :           0 :     NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
    3120                 :             : 
    3121                 :             :   /* Now preserve various other info from the definition.  */
    3122                 :    14908061 :   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
    3123                 :    14908061 :   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
    3124                 :    14908061 :   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3125                 :    14908061 :   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    3126                 :             : 
    3127                 :             :   /* Warn about conflicting visibility specifications.  */
    3128                 :    14908061 :   if (DECL_VISIBILITY_SPECIFIED (olddecl)
    3129                 :     5305721 :       && DECL_VISIBILITY_SPECIFIED (newdecl)
    3130                 :    14908641 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    3131                 :             :     {
    3132                 :          12 :       auto_diagnostic_group d;
    3133                 :          12 :       if (warning_at (newdecl_loc, OPT_Wattributes,
    3134                 :             :                       "%qD: visibility attribute ignored because it "
    3135                 :             :                       "conflicts with previous declaration", newdecl))
    3136                 :          12 :         inform (olddecl_loc,
    3137                 :             :                 "previous declaration of %qD", olddecl);
    3138                 :          12 :     }
    3139                 :             :   /* Choose the declaration which specified visibility.  */
    3140                 :    14908061 :   if (DECL_VISIBILITY_SPECIFIED (olddecl))
    3141                 :             :     {
    3142                 :     5305721 :       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    3143                 :     5305721 :       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    3144                 :             :     }
    3145                 :             :   /* Init priority used to be merged from newdecl to olddecl by the memcpy,
    3146                 :             :      so keep this behavior.  */
    3147                 :    14908061 :   if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
    3148                 :             :     {
    3149                 :          10 :       SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
    3150                 :          10 :       DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
    3151                 :             :     }
    3152                 :             :   /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED.  */
    3153                 :    14908061 :   if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    3154                 :             :     {
    3155                 :          54 :       SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    3156                 :          54 :       DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    3157                 :             :     }
    3158                 :    14908007 :   else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    3159                 :    14908007 :       && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    3160                 :           3 :     DECL_USER_ALIGN (newdecl) = 1;
    3161                 :             : 
    3162                 :    14908061 :   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3163                 :    29816122 :   if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    3164                 :    14908061 :       > DECL_WARN_IF_NOT_ALIGN (newdecl))
    3165                 :           0 :     SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    3166                 :             :                                 DECL_WARN_IF_NOT_ALIGN (olddecl));
    3167                 :    14908061 :   if (TREE_CODE (newdecl) == FIELD_DECL)
    3168                 :           0 :     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
    3169                 :             : 
    3170                 :             :   /* Merge module entity mapping information.  */
    3171                 :    14908061 :   if (DECL_LANG_SPECIFIC (olddecl)
    3172                 :    29787268 :       && (DECL_MODULE_ENTITY_P (olddecl)
    3173                 :    14878934 :           || DECL_MODULE_KEYED_DECLS_P (olddecl)))
    3174                 :             :     {
    3175                 :         273 :       retrofit_lang_decl (newdecl);
    3176                 :         273 :       DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
    3177                 :         273 :       DECL_MODULE_KEYED_DECLS_P (newdecl) = DECL_MODULE_KEYED_DECLS_P (olddecl);
    3178                 :             :     }
    3179                 :             : 
    3180                 :             :   /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
    3181                 :             :      with that from NEWDECL below.  */
    3182                 :    14908061 :   if (DECL_LANG_SPECIFIC (olddecl))
    3183                 :             :     {
    3184                 :    14879207 :       gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
    3185                 :             :                            != DECL_LANG_SPECIFIC (newdecl));
    3186                 :    14879207 :       ggc_free (DECL_LANG_SPECIFIC (olddecl));
    3187                 :             :     }
    3188                 :             : 
    3189                 :             :   /* Merge the USED information.  */
    3190                 :    14908061 :   if (TREE_USED (olddecl))
    3191                 :      493877 :     TREE_USED (newdecl) = 1;
    3192                 :    14414184 :   else if (TREE_USED (newdecl))
    3193                 :          54 :     TREE_USED (olddecl) = 1;
    3194                 :             : 
    3195                 :    14908061 :   if (VAR_P (newdecl))
    3196                 :             :     {
    3197                 :      400219 :       if (DECL_READ_P (olddecl))
    3198                 :       36417 :         DECL_READ_P (newdecl) = 1;
    3199                 :      363802 :       else if (DECL_READ_P (newdecl))
    3200                 :           3 :         DECL_READ_P (olddecl) = 1;
    3201                 :             :     }
    3202                 :             : 
    3203                 :    14908061 :   if (DECL_PRESERVE_P (olddecl))
    3204                 :          48 :     DECL_PRESERVE_P (newdecl) = 1;
    3205                 :    14908013 :   else if (DECL_PRESERVE_P (newdecl))
    3206                 :          63 :     DECL_PRESERVE_P (olddecl) = 1;
    3207                 :             : 
    3208                 :             :   /* Merge the DECL_FUNCTION_VERSIONED information.  newdecl will be copied
    3209                 :             :      to olddecl and deleted.  */
    3210                 :    14908061 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3211                 :    29390590 :       && DECL_FUNCTION_VERSIONED (olddecl))
    3212                 :             :     {
    3213                 :             :       /* Set the flag for newdecl so that it gets copied to olddecl.  */
    3214                 :         258 :       DECL_FUNCTION_VERSIONED (newdecl) = 1;
    3215                 :             :       /* newdecl will be purged after copying to olddecl and is no longer
    3216                 :             :          a version.  */
    3217                 :         258 :       cgraph_node::delete_function_version_by_decl (newdecl);
    3218                 :             :     }
    3219                 :             : 
    3220                 :    14908061 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3221                 :             :     {
    3222                 :    14482529 :       int function_size;
    3223                 :    14482529 :       struct symtab_node *snode = symtab_node::get (olddecl);
    3224                 :             : 
    3225                 :    14482529 :       function_size = sizeof (struct tree_decl_common);
    3226                 :             : 
    3227                 :    14482529 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3228                 :             :               (char *) newdecl + sizeof (struct tree_common),
    3229                 :             :               function_size - sizeof (struct tree_common));
    3230                 :             : 
    3231                 :    14482529 :       memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3232                 :             :               (char *) newdecl + sizeof (struct tree_decl_common),
    3233                 :             :               sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
    3234                 :             : 
    3235                 :             :       /* Preserve symtab node mapping.  */
    3236                 :    14482529 :       olddecl->decl_with_vis.symtab_node = snode;
    3237                 :             : 
    3238                 :    14482529 :       if (new_template_info)
    3239                 :             :         /* If newdecl is a template instantiation, it is possible that
    3240                 :             :            the following sequence of events has occurred:
    3241                 :             : 
    3242                 :             :            o A friend function was declared in a class template.  The
    3243                 :             :            class template was instantiated.
    3244                 :             : 
    3245                 :             :            o The instantiation of the friend declaration was
    3246                 :             :            recorded on the instantiation list, and is newdecl.
    3247                 :             : 
    3248                 :             :            o Later, however, instantiate_class_template called pushdecl
    3249                 :             :            on the newdecl to perform name injection.  But, pushdecl in
    3250                 :             :            turn called duplicate_decls when it discovered that another
    3251                 :             :            declaration of a global function with the same name already
    3252                 :             :            existed.
    3253                 :             : 
    3254                 :             :            o Here, in duplicate_decls, we decided to clobber newdecl.
    3255                 :             : 
    3256                 :             :            If we're going to do that, we'd better make sure that
    3257                 :             :            olddecl, and not newdecl, is on the list of
    3258                 :             :            instantiations so that if we try to do the instantiation
    3259                 :             :            again we won't get the clobbered declaration.  */
    3260                 :      602515 :         reregister_specialization (newdecl,
    3261                 :             :                                    new_template_info,
    3262                 :             :                                    olddecl);
    3263                 :             :     }
    3264                 :             :   else
    3265                 :             :     {
    3266                 :      425532 :       size_t size = tree_code_size (TREE_CODE (newdecl));
    3267                 :             : 
    3268                 :      425532 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3269                 :             :               (char *) newdecl + sizeof (struct tree_common),
    3270                 :             :               sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3271                 :             : 
    3272                 :      425532 :       switch (TREE_CODE (newdecl))
    3273                 :             :         {
    3274                 :      425532 :         case LABEL_DECL:
    3275                 :      425532 :         case VAR_DECL:
    3276                 :      425532 :         case RESULT_DECL:
    3277                 :      425532 :         case PARM_DECL:
    3278                 :      425532 :         case FIELD_DECL:
    3279                 :      425532 :         case TYPE_DECL:
    3280                 :      425532 :         case CONST_DECL:
    3281                 :      425532 :           {
    3282                 :      425532 :             struct symtab_node *snode = NULL;
    3283                 :             : 
    3284                 :      425532 :             if (VAR_P (newdecl)
    3285                 :      425532 :                 && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
    3286                 :           3 :                     || DECL_EXTERNAL (olddecl)))
    3287                 :      400219 :               snode = symtab_node::get (olddecl);
    3288                 :      425532 :             memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3289                 :             :                     (char *) newdecl + sizeof (struct tree_decl_common),
    3290                 :             :                     size - sizeof (struct tree_decl_common)
    3291                 :      425532 :                     + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3292                 :      425532 :             if (VAR_P (newdecl))
    3293                 :      400219 :               olddecl->decl_with_vis.symtab_node = snode;
    3294                 :             :           }
    3295                 :             :           break;
    3296                 :           0 :         default:
    3297                 :           0 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3298                 :             :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3299                 :             :                   sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
    3300                 :           0 :                   + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3301                 :           0 :           break;
    3302                 :             :         }
    3303                 :             :     }
    3304                 :             : 
    3305                 :    14908061 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3306                 :             :     {
    3307                 :    14882748 :       if (DECL_EXTERNAL (olddecl)
    3308                 :      401582 :           || TREE_PUBLIC (olddecl)
    3309                 :    14882817 :           || TREE_STATIC (olddecl))
    3310                 :             :         {
    3311                 :             :           /* Merge the section attribute.
    3312                 :             :              We want to issue an error if the sections conflict but that must be
    3313                 :             :              done later in decl_attributes since we are called before attributes
    3314                 :             :              are assigned.  */
    3315                 :    14882748 :           if (DECL_SECTION_NAME (newdecl) != NULL)
    3316                 :           7 :             set_decl_section_name (olddecl, newdecl);
    3317                 :             : 
    3318                 :    14882748 :           if (DECL_ONE_ONLY (newdecl))
    3319                 :             :             {
    3320                 :           0 :               struct symtab_node *oldsym, *newsym;
    3321                 :           0 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3322                 :           0 :                 oldsym = cgraph_node::get_create (olddecl);
    3323                 :             :               else
    3324                 :           0 :                 oldsym = varpool_node::get_create (olddecl);
    3325                 :           0 :               newsym = symtab_node::get (newdecl);
    3326                 :           0 :               oldsym->set_comdat_group (newsym->get_comdat_group ());
    3327                 :             :             }
    3328                 :             :         }
    3329                 :             : 
    3330                 :    14882748 :       if (VAR_P (newdecl)
    3331                 :    14882748 :           && CP_DECL_THREAD_LOCAL_P (newdecl))
    3332                 :             :         {
    3333                 :         398 :           CP_DECL_THREAD_LOCAL_P (olddecl) = true;
    3334                 :         398 :           if (!processing_template_decl)
    3335                 :         371 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3336                 :             :         }
    3337                 :             :     }
    3338                 :             : 
    3339                 :    14908061 :   DECL_UID (olddecl) = olddecl_uid;
    3340                 :             : 
    3341                 :             :   /* NEWDECL contains the merged attribute lists.
    3342                 :             :      Update OLDDECL to be the same.  */
    3343                 :    14908061 :   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    3344                 :             : 
    3345                 :             :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3346                 :             :     so that encode_section_info has a chance to look at the new decl
    3347                 :             :     flags and attributes.  */
    3348                 :    14908061 :   if (DECL_RTL_SET_P (olddecl)
    3349                 :    14908061 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3350                 :           0 :           || (VAR_P (olddecl)
    3351                 :           0 :               && TREE_STATIC (olddecl))))
    3352                 :           0 :     make_decl_rtl (olddecl);
    3353                 :             : 
    3354                 :             :   /* The NEWDECL will no longer be needed.  Because every out-of-class
    3355                 :             :      declaration of a member results in a call to duplicate_decls,
    3356                 :             :      freeing these nodes represents in a significant savings.
    3357                 :             : 
    3358                 :             :      Before releasing the node, be sore to remove function from symbol
    3359                 :             :      table that might have been inserted there to record comdat group.
    3360                 :             :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3361                 :             :      structure is shared in between newdecl and oldecl.  */
    3362                 :    14908061 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3363                 :    14482529 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3364                 :    14908061 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3365                 :             :     {
    3366                 :    14882748 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3367                 :    14882748 :       if (snode)
    3368                 :         399 :         snode->remove ();
    3369                 :             :     }
    3370                 :             : 
    3371                 :    14908061 :   if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3372                 :             :     {
    3373                 :    14482529 :       tree clone;
    3374                 :    15005831 :       FOR_EACH_CLONE (clone, olddecl)
    3375                 :             :         {
    3376                 :      523302 :           DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
    3377                 :      523302 :           DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
    3378                 :             :         }
    3379                 :             :     }
    3380                 :             : 
    3381                 :             :   /* Remove the associated constraints for newdecl, if any, before
    3382                 :             :      reclaiming memory. */
    3383                 :    14908061 :   if (flag_concepts)
    3384                 :     3610170 :     remove_constraints (newdecl);
    3385                 :             : 
    3386                 :             :   /* And similarly for any module tracking data.  */
    3387                 :    14908061 :   if (modules_p ())
    3388                 :       28483 :     remove_defining_module (newdecl);
    3389                 :             : 
    3390                 :    14908061 :   ggc_free (newdecl);
    3391                 :             : 
    3392                 :    14908061 :   return olddecl;
    3393                 :             : }
    3394                 :             : 
    3395                 :             : /* Return zero if the declaration NEWDECL is valid
    3396                 :             :    when the declaration OLDDECL (assumed to be for the same name)
    3397                 :             :    has already been seen.
    3398                 :             :    Otherwise return an error message format string with a %s
    3399                 :             :    where the identifier should go.  */
    3400                 :             : 
    3401                 :             : static const char *
    3402                 :    14533284 : redeclaration_error_message (tree newdecl, tree olddecl)
    3403                 :             : {
    3404                 :    14533320 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    3405                 :             :     {
    3406                 :             :       /* Because C++ can put things into name space for free,
    3407                 :             :          constructs like "typedef struct foo { ... } foo"
    3408                 :             :          would look like an erroneous redeclaration.  */
    3409                 :       57006 :       if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
    3410                 :             :         return NULL;
    3411                 :             :       else
    3412                 :             :         return G_("redefinition of %q#D");
    3413                 :             :     }
    3414                 :    14476314 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3415                 :             :     {
    3416                 :             :       /* If this is a pure function, its olddecl will actually be
    3417                 :             :          the original initialization to `0' (which we force to call
    3418                 :             :          abort()).  Don't complain about redefinition in this case.  */
    3419                 :    20919692 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
    3420                 :    10459864 :           && DECL_INITIAL (olddecl) == NULL_TREE)
    3421                 :             :         return NULL;
    3422                 :             : 
    3423                 :             :       /* If both functions come from different namespaces, this is not
    3424                 :             :          a redeclaration - this is a conflict with a used function.  */
    3425                 :    20919662 :       if (DECL_NAMESPACE_SCOPE_P (olddecl)
    3426                 :     1627648 :           && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
    3427                 :    10459834 :           && ! decls_match (olddecl, newdecl))
    3428                 :             :         return G_("%qD conflicts with used function");
    3429                 :             : 
    3430                 :             :       /* We'll complain about linkage mismatches in
    3431                 :             :          warn_extern_redeclared_static.  */
    3432                 :             : 
    3433                 :             :       /* Defining the same name twice is no good.  */
    3434                 :    10459831 :       if (decl_defined_p (olddecl)
    3435                 :    10459831 :           && decl_defined_p (newdecl))
    3436                 :             :         {
    3437                 :         306 :           if (DECL_NAME (olddecl) == NULL_TREE)
    3438                 :             :             return G_("%q#D not declared in class");
    3439                 :         447 :           else if (!GNU_INLINE_P (olddecl)
    3440                 :         393 :                    || GNU_INLINE_P (newdecl))
    3441                 :         222 :             return G_("redefinition of %q#D");
    3442                 :             :         }
    3443                 :             : 
    3444                 :    11172672 :       if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
    3445                 :             :         {
    3446                 :      665573 :           bool olda = GNU_INLINE_P (olddecl);
    3447                 :      665573 :           bool newa = GNU_INLINE_P (newdecl);
    3448                 :             : 
    3449                 :      665573 :           if (olda != newa)
    3450                 :             :             {
    3451                 :          15 :               if (newa)
    3452                 :             :                 return G_("%q+D redeclared inline with "
    3453                 :             :                           "%<gnu_inline%> attribute");
    3454                 :             :               else
    3455                 :             :                 return G_("%q+D redeclared inline without "
    3456                 :             :                           "%<gnu_inline%> attribute");
    3457                 :             :             }
    3458                 :             :         }
    3459                 :             : 
    3460                 :             :       /* [class.compare.default]: A definition of a comparison operator as
    3461                 :             :          defaulted that appears in a class shall be the first declaration of
    3462                 :             :          that function.  */
    3463                 :    10459594 :       special_function_kind sfk = special_function_p (olddecl);
    3464                 :    10459594 :       if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
    3465                 :             :         return G_("comparison operator %q+D defaulted after "
    3466                 :             :                   "its first declaration");
    3467                 :             : 
    3468                 :    10459591 :       check_abi_tag_redeclaration
    3469                 :    10459591 :         (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
    3470                 :    10459591 :          lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
    3471                 :             : 
    3472                 :    10459591 :       return NULL;
    3473                 :             :     }
    3474                 :     4016468 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    3475                 :             :     {
    3476                 :     3615954 :       tree nt, ot;
    3477                 :             : 
    3478                 :     3615954 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
    3479                 :             :         return G_("redefinition of %q#D");
    3480                 :             : 
    3481                 :     3615948 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
    3482                 :          36 :         return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
    3483                 :          36 :                                             DECL_TEMPLATE_RESULT (olddecl));
    3484                 :             : 
    3485                 :     3615912 :       if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
    3486                 :             :         return NULL;
    3487                 :             : 
    3488                 :     3615900 :       nt = DECL_TEMPLATE_RESULT (newdecl);
    3489                 :     3615900 :       if (DECL_TEMPLATE_INFO (nt))
    3490                 :      539256 :         nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
    3491                 :     3615900 :       ot = DECL_TEMPLATE_RESULT (olddecl);
    3492                 :     3615900 :       if (DECL_TEMPLATE_INFO (ot))
    3493                 :     3615900 :         ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
    3494                 :     6359017 :       if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
    3495                 :     3615939 :           && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
    3496                 :          15 :         return G_("redefinition of %q#D");
    3497                 :             : 
    3498                 :     4936231 :       if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
    3499                 :             :         {
    3500                 :      840615 :           bool olda = GNU_INLINE_P (ot);
    3501                 :      840615 :           bool newa = GNU_INLINE_P (nt);
    3502                 :             : 
    3503                 :      840615 :           if (olda != newa)
    3504                 :             :             {
    3505                 :           0 :               if (newa)
    3506                 :             :                 return G_("%q+D redeclared inline with "
    3507                 :             :                           "%<gnu_inline%> attribute");
    3508                 :             :               else
    3509                 :             :                 return G_("%q+D redeclared inline without "
    3510                 :             :                           "%<gnu_inline%> attribute");
    3511                 :             :             }
    3512                 :             :         }
    3513                 :             : 
    3514                 :             :       /* Core issue #226 (C++11):
    3515                 :             : 
    3516                 :             :            If a friend function template declaration specifies a
    3517                 :             :            default template-argument, that declaration shall be a
    3518                 :             :            definition and shall be the only declaration of the
    3519                 :             :            function template in the translation unit.  */
    3520                 :     3615885 :       if ((cxx_dialect != cxx98)
    3521                 :     3597515 :           && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
    3522                 :     3833743 :           && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
    3523                 :             :                                        /*is_primary=*/true,
    3524                 :             :                                        /*is_partial=*/false,
    3525                 :             :                                        /*is_friend_decl=*/2))
    3526                 :             :         return G_("redeclaration of friend %q#D "
    3527                 :             :                   "may not have default template arguments");
    3528                 :             : 
    3529                 :     3615882 :       return NULL;
    3530                 :             :     }
    3531                 :      400514 :   else if (VAR_P (newdecl)
    3532                 :      400430 :            && (CP_DECL_THREAD_LOCAL_P (newdecl)
    3533                 :      400430 :                != CP_DECL_THREAD_LOCAL_P (olddecl))
    3534                 :      400561 :            && (! DECL_LANG_SPECIFIC (olddecl)
    3535                 :          44 :                || ! CP_DECL_THREADPRIVATE_P (olddecl)
    3536                 :          41 :                || CP_DECL_THREAD_LOCAL_P (newdecl)))
    3537                 :             :     {
    3538                 :             :       /* Only variables can be thread-local, and all declarations must
    3539                 :             :          agree on this property.  */
    3540                 :           6 :       if (CP_DECL_THREAD_LOCAL_P (newdecl))
    3541                 :             :         return G_("thread-local declaration of %q#D follows "
    3542                 :             :                   "non-thread-local declaration");
    3543                 :             :       else
    3544                 :           3 :         return G_("non-thread-local declaration of %q#D follows "
    3545                 :             :                   "thread-local declaration");
    3546                 :             :     }
    3547                 :      400508 :   else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
    3548                 :             :     {
    3549                 :             :       /* The objects have been declared at namespace scope.  If either
    3550                 :             :          is a member of an anonymous union, then this is an invalid
    3551                 :             :          redeclaration.  For example:
    3552                 :             : 
    3553                 :             :            int i;
    3554                 :             :            union { int i; };
    3555                 :             : 
    3556                 :             :            is invalid.  */
    3557                 :      400346 :       if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
    3558                 :      800761 :           || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
    3559                 :             :         return G_("redeclaration of %q#D");
    3560                 :             :       /* If at least one declaration is a reference, there is no
    3561                 :             :          conflict.  For example:
    3562                 :             : 
    3563                 :             :            int i = 3;
    3564                 :             :            extern int i;
    3565                 :             : 
    3566                 :             :          is valid.  */
    3567                 :      400412 :       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
    3568                 :             :         return NULL;
    3569                 :             : 
    3570                 :             :       /* Static data member declared outside a class definition
    3571                 :             :          if the variable is defined within the class with constexpr
    3572                 :             :          specifier is declaration rather than definition (and
    3573                 :             :          deprecated).  */
    3574                 :        2824 :       if (cxx_dialect >= cxx17
    3575                 :        2749 :           && VAR_P (olddecl)
    3576                 :        2693 :           && DECL_CLASS_SCOPE_P (olddecl)
    3577                 :        2649 :           && DECL_DECLARED_CONSTEXPR_P (olddecl)
    3578                 :        5461 :           && !DECL_INITIAL (newdecl))
    3579                 :             :         {
    3580                 :        2637 :           DECL_EXTERNAL (newdecl) = 1;
    3581                 :             :           /* For now, only warn with explicit -Wdeprecated.  */
    3582                 :        2637 :           if (OPTION_SET_P (warn_deprecated))
    3583                 :             :             {
    3584                 :          40 :               auto_diagnostic_group d;
    3585                 :          40 :               if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
    3586                 :             :                                 "redundant redeclaration of %<constexpr%> "
    3587                 :             :                                 "static data member %qD", newdecl))
    3588                 :           4 :                 inform (DECL_SOURCE_LOCATION (olddecl),
    3589                 :             :                           "previous declaration of %qD", olddecl);
    3590                 :          40 :             }
    3591                 :        2637 :           return NULL;
    3592                 :             :         }
    3593                 :             : 
    3594                 :             :       /* Reject two definitions.  */
    3595                 :             :       return G_("redefinition of %q#D");
    3596                 :             :     }
    3597                 :             :   else
    3598                 :             :     {
    3599                 :             :       /* Objects declared with block scope:  */
    3600                 :             :       /* Reject two definitions, and reject a definition
    3601                 :             :          together with an external reference.  */
    3602                 :          81 :       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
    3603                 :             :         return G_("redeclaration of %q#D");
    3604                 :             :       return NULL;
    3605                 :             :     }
    3606                 :             : }
    3607                 :             : 
    3608                 :             : 
    3609                 :             : /* Hash and equality functions for the named_label table.  */
    3610                 :             : 
    3611                 :             : hashval_t
    3612                 :       68060 : named_label_hash::hash (const value_type entry)
    3613                 :             : {
    3614                 :       68060 :   return IDENTIFIER_HASH_VALUE (entry->name);
    3615                 :             : }
    3616                 :             : 
    3617                 :             : bool
    3618                 :       64531 : named_label_hash::equal (const value_type entry, compare_type name)
    3619                 :             : {
    3620                 :       64531 :   return name == entry->name;
    3621                 :             : }
    3622                 :             : 
    3623                 :             : /* Look for a label named ID in the current function.  If one cannot
    3624                 :             :    be found, create one.  Return the named_label_entry, or NULL on
    3625                 :             :    failure.  */
    3626                 :             : 
    3627                 :             : static named_label_entry *
    3628                 :       22564 : lookup_label_1 (tree id, bool making_local_p)
    3629                 :             : {
    3630                 :       22564 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    3631                 :             : 
    3632                 :             :   /* You can't use labels at global scope.  */
    3633                 :       22564 :   if (current_function_decl == NULL_TREE)
    3634                 :             :     {
    3635                 :           3 :       error ("label %qE referenced outside of any function", id);
    3636                 :           3 :       return NULL;
    3637                 :             :     }
    3638                 :             : 
    3639                 :       22561 :   if (!named_labels)
    3640                 :        4547 :     named_labels = hash_table<named_label_hash>::create_ggc (13);
    3641                 :             : 
    3642                 :       22561 :   hashval_t hash = IDENTIFIER_HASH_VALUE (id);
    3643                 :       22561 :   named_label_entry **slot
    3644                 :       22561 :     = named_labels->find_slot_with_hash (id, hash, INSERT);
    3645                 :       22561 :   named_label_entry *old = *slot;
    3646                 :             : 
    3647                 :       22561 :   if (old && old->label_decl)
    3648                 :             :     {
    3649                 :        2615 :       if (!making_local_p)
    3650                 :             :         return old;
    3651                 :             : 
    3652                 :           9 :       if (old->binding_level == current_binding_level)
    3653                 :             :         {
    3654                 :           0 :           auto_diagnostic_group d;
    3655                 :           0 :           error ("local label %qE conflicts with existing label", id);
    3656                 :           0 :           inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
    3657                 :           0 :           return NULL;
    3658                 :           0 :         }
    3659                 :             :     }
    3660                 :             : 
    3661                 :             :   /* We are making a new decl, create or reuse the named_label_entry  */
    3662                 :       19964 :   named_label_entry *ent = NULL;
    3663                 :          21 :   if (old && !old->label_decl)
    3664                 :             :     ent = old;
    3665                 :             :   else
    3666                 :             :     {
    3667                 :       19943 :       ent = ggc_cleared_alloc<named_label_entry> ();
    3668                 :       19943 :       ent->name = id;
    3669                 :       19943 :       ent->outer = old;
    3670                 :       19943 :       *slot = ent;
    3671                 :             :     }
    3672                 :             : 
    3673                 :             :   /* Now create the LABEL_DECL.  */
    3674                 :       19955 :   tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
    3675                 :             : 
    3676                 :       19955 :   DECL_CONTEXT (decl) = current_function_decl;
    3677                 :       19955 :   SET_DECL_MODE (decl, VOIDmode);
    3678                 :       19955 :   if (making_local_p)
    3679                 :             :     {
    3680                 :         207 :       C_DECLARED_LABEL_FLAG (decl) = true;
    3681                 :         207 :       DECL_CHAIN (decl) = current_binding_level->names;
    3682                 :         207 :       current_binding_level->names = decl;
    3683                 :             :     }
    3684                 :             : 
    3685                 :       19955 :   ent->label_decl = decl;
    3686                 :             : 
    3687                 :       19955 :   return ent;
    3688                 :       22564 : }
    3689                 :             : 
    3690                 :             : /* Wrapper for lookup_label_1.  */
    3691                 :             : 
    3692                 :             : tree
    3693                 :        2155 : lookup_label (tree id)
    3694                 :             : {
    3695                 :        2155 :   named_label_entry *ent = lookup_label_1 (id, false);
    3696                 :        2155 :   return ent ? ent->label_decl : NULL_TREE;
    3697                 :             : }
    3698                 :             : 
    3699                 :             : /* Remember that we've seen &&ID.  */
    3700                 :             : 
    3701                 :             : void
    3702                 :         250 : mark_label_addressed (tree id)
    3703                 :             : {
    3704                 :         250 :   named_label_entry *ent = lookup_label_1 (id, false);
    3705                 :         250 :   ent->addressed = true;
    3706                 :         250 : }
    3707                 :             : 
    3708                 :             : tree
    3709                 :         207 : declare_local_label (tree id)
    3710                 :             : {
    3711                 :         207 :   named_label_entry *ent = lookup_label_1 (id, true);
    3712                 :         207 :   return ent ? ent->label_decl : NULL_TREE;
    3713                 :             : }
    3714                 :             : 
    3715                 :             : /* Returns true if it is ill-formed to jump past the declaration of DECL.  */
    3716                 :             : 
    3717                 :             : static bool
    3718                 :      136033 : decl_jump_unsafe (tree decl)
    3719                 :             : {
    3720                 :             :   /* [stmt.dcl]/3: A program that jumps from a point where a local variable
    3721                 :             :      with automatic storage duration is not in scope to a point where it is
    3722                 :             :      in scope is ill-formed unless the variable has scalar type, class type
    3723                 :             :      with a trivial default constructor and a trivial destructor, a
    3724                 :             :      cv-qualified version of one of these types, or an array of one of the
    3725                 :             :      preceding types and is declared without an initializer (8.5).  */
    3726                 :      136033 :   tree type = TREE_TYPE (decl);
    3727                 :             : 
    3728                 :      136033 :   return (type != error_mark_node
    3729                 :      136015 :           && VAR_P (decl)
    3730                 :       12541 :           && !TREE_STATIC (decl)
    3731                 :      148438 :           && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    3732                 :       10909 :               || variably_modified_type_p (type, NULL_TREE)));
    3733                 :             : }
    3734                 :             : 
    3735                 :             : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
    3736                 :             :    to the user.  */
    3737                 :             : 
    3738                 :             : static bool
    3739                 :         286 : identify_goto (tree decl, location_t loc, const location_t *locus,
    3740                 :             :                enum diagnostics::kind diag_kind, bool computed)
    3741                 :             : {
    3742                 :         286 :   if (computed)
    3743                 :          43 :     diag_kind = diagnostics::kind::warning;
    3744                 :         286 :   bool complained
    3745                 :         373 :     = emit_diagnostic (diag_kind, loc, 0,
    3746                 :             :                        decl ? G_("jump to label %qD")
    3747                 :             :                        : G_("jump to case label"), decl);
    3748                 :         286 :   if (complained && locus)
    3749                 :             :     {
    3750                 :         199 :       if (computed)
    3751                 :          43 :         inform (*locus, "  as a possible target of computed goto");
    3752                 :             :       else
    3753                 :         156 :         inform (*locus, "  from here");
    3754                 :             :     }
    3755                 :         286 :   return complained;
    3756                 :             : }
    3757                 :             : 
    3758                 :             : /* Check that a single previously seen jump to a newly defined label
    3759                 :             :    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
    3760                 :             :    the jump context; NAMES are the names in scope in LEVEL at the jump
    3761                 :             :    context; LOCUS is the source position of the jump or 0.  COMPUTED
    3762                 :             :    is a vec of decls if the jump is a computed goto.  Returns
    3763                 :             :    true if all is well.  */
    3764                 :             : 
    3765                 :             : static bool
    3766                 :     1989065 : check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
    3767                 :             :                        bool exited_omp, const location_t *locus,
    3768                 :             :                        vec<tree,va_gc> *computed)
    3769                 :             : {
    3770                 :     1989065 :   auto_diagnostic_group d;
    3771                 :     1989065 :   cp_binding_level *b;
    3772                 :     1989065 :   bool complained = false;
    3773                 :     1989065 :   int identified = 0;
    3774                 :     1989065 :   bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
    3775                 :     1989065 :   bool saw_ceif = false, saw_se = false;
    3776                 :             : 
    3777                 :     1989065 :   if (exited_omp)
    3778                 :             :     {
    3779                 :          12 :       complained = identify_goto (decl, input_location, locus,
    3780                 :             :                                   diagnostics::kind::error,
    3781                 :             :                                   computed);
    3782                 :          12 :       if (complained)
    3783                 :          12 :         inform (input_location, "  exits OpenMP structured block");
    3784                 :             :       saw_omp = true;
    3785                 :             :       identified = 2;
    3786                 :             :     }
    3787                 :             : 
    3788                 :     5938990 :   for (b = current_binding_level; b ; b = b->level_chain)
    3789                 :             :     {
    3790                 :     3949925 :       tree new_decls, old_decls = (b == level ? names : NULL_TREE);
    3791                 :             : 
    3792                 :     4214501 :       for (new_decls = b->names; new_decls != old_decls;
    3793                 :      132288 :            new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
    3794                 :      122707 :                         : TREE_CHAIN (new_decls)))
    3795                 :             :         {
    3796                 :      132288 :           bool problem = decl_jump_unsafe (new_decls);
    3797                 :      132288 :           if (! problem)
    3798                 :      132243 :             continue;
    3799                 :             : 
    3800                 :          45 :           if (!identified)
    3801                 :             :             {
    3802                 :          45 :               complained = identify_goto (decl, input_location, locus,
    3803                 :             :                                           diagnostics::kind::error,
    3804                 :             :                                           computed);
    3805                 :          45 :               identified = 2;
    3806                 :             :             }
    3807                 :          45 :           if (complained)
    3808                 :          45 :             inform (DECL_SOURCE_LOCATION (new_decls),
    3809                 :             :                     "  crosses initialization of %q#D", new_decls);
    3810                 :             :         }
    3811                 :             : 
    3812                 :     3949925 :       if (b == level)
    3813                 :             :         break;
    3814                 :             : 
    3815                 :     1960860 :       const char *inf = NULL;
    3816                 :     1960860 :       location_t loc = input_location;
    3817                 :     1960860 :       switch (b->kind)
    3818                 :             :         {
    3819                 :           3 :         case sk_try:
    3820                 :           3 :           if (!saw_eh)
    3821                 :             :             inf = G_("  enters %<try%> block");
    3822                 :             :           saw_eh = true;
    3823                 :             :           break;
    3824                 :             : 
    3825                 :           9 :         case sk_catch:
    3826                 :           9 :           if (!saw_eh)
    3827                 :             :             inf = G_("  enters %<catch%> block");
    3828                 :             :           saw_eh = true;
    3829                 :             :           break;
    3830                 :             : 
    3831                 :         102 :         case sk_omp:
    3832                 :         102 :           if (!saw_omp)
    3833                 :             :             inf = G_("  enters OpenMP structured block");
    3834                 :             :           saw_omp = true;
    3835                 :             :           break;
    3836                 :             : 
    3837                 :           3 :         case sk_transaction:
    3838                 :           3 :           if (!saw_tm)
    3839                 :             :             inf = G_("  enters synchronized or atomic statement");
    3840                 :             :           saw_tm = true;
    3841                 :             :           break;
    3842                 :             : 
    3843                 :          18 :         case sk_stmt_expr:
    3844                 :          18 :           if (!saw_se)
    3845                 :             :             inf = G_("  enters statement expression");
    3846                 :             :           saw_se = true;
    3847                 :             :           break;
    3848                 :             : 
    3849                 :     1960621 :         case sk_block:
    3850                 :     1960621 :           if (!saw_cxif && level_for_constexpr_if (b->level_chain))
    3851                 :             :             {
    3852                 :           9 :               inf = G_("  enters %<constexpr if%> statement");
    3853                 :           9 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    3854                 :             :               saw_cxif = true;
    3855                 :             :             }
    3856                 :     1960612 :           else if (!saw_ceif && level_for_consteval_if (b->level_chain))
    3857                 :             :             {
    3858                 :          18 :               inf = G_("  enters %<consteval if%> statement");
    3859                 :          18 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    3860                 :             :               saw_ceif = true;
    3861                 :             :             }
    3862                 :             :           break;
    3863                 :             : 
    3864                 :             :         default:
    3865                 :             :           break;
    3866                 :             :         }
    3867                 :             : 
    3868                 :             :       if (inf)
    3869                 :             :         {
    3870                 :         141 :           if (identified < 2)
    3871                 :         141 :             complained = identify_goto (decl, input_location, locus,
    3872                 :             :                                         diagnostics::kind::error,
    3873                 :             :                                         computed);
    3874                 :         141 :           identified = 2;
    3875                 :         141 :           if (complained)
    3876                 :         141 :             inform (loc, inf);
    3877                 :             :         }
    3878                 :             :     }
    3879                 :             : 
    3880                 :     1989065 :   if (!vec_safe_is_empty (computed))
    3881                 :             :     {
    3882                 :           9 :       if (!identified)
    3883                 :           6 :         complained = identify_goto (decl, input_location, locus,
    3884                 :             :                                     diagnostics::kind::error,
    3885                 :             :                                     computed);
    3886                 :           9 :       identified = 2;
    3887                 :           9 :       if (complained)
    3888                 :          18 :         for (tree d : computed)
    3889                 :             :           {
    3890                 :           9 :             if (DECL_P (d))
    3891                 :           6 :               inform (DECL_SOURCE_LOCATION (d), "  does not destroy %qD", d);
    3892                 :           3 :             else if (d == get_identifier ("catch"))
    3893                 :           3 :               inform (*locus, "  does not clean up handled exception");
    3894                 :             :           }
    3895                 :             :     }
    3896                 :             : 
    3897                 :     3978130 :   return !identified;
    3898                 :     1989065 : }
    3899                 :             : 
    3900                 :             : static void
    3901                 :        1415 : check_previous_goto (tree decl, struct named_label_use_entry *use)
    3902                 :             : {
    3903                 :        1415 :   check_previous_goto_1 (decl, use->binding_level,
    3904                 :        1415 :                          use->names_in_scope, use->in_omp_scope,
    3905                 :        1415 :                          &use->o_goto_locus, use->computed_goto);
    3906                 :        1415 : }
    3907                 :             : 
    3908                 :             : static bool
    3909                 :     1987650 : check_switch_goto (cp_binding_level* level)
    3910                 :             : {
    3911                 :     1987650 :   return check_previous_goto_1 (NULL_TREE, level, level->names,
    3912                 :     1987650 :                                 false, NULL, nullptr);
    3913                 :             : }
    3914                 :             : 
    3915                 :             : /* Check that a new jump to a label ENT is OK.  COMPUTED is true
    3916                 :             :    if this is a possible target of a computed goto.  */
    3917                 :             : 
    3918                 :             : void
    3919                 :        2033 : check_goto_1 (named_label_entry *ent, bool computed)
    3920                 :             : {
    3921                 :        2033 :   auto_diagnostic_group d;
    3922                 :        2033 :   tree decl = ent->label_decl;
    3923                 :             : 
    3924                 :             :   /* If the label hasn't been defined yet, defer checking.  */
    3925                 :        2033 :   if (! DECL_INITIAL (decl))
    3926                 :             :     {
    3927                 :             :       /* Don't bother creating another use if the last goto had the
    3928                 :             :          same data, and will therefore create the same set of errors.  */
    3929                 :        1615 :       if (ent->uses
    3930                 :         493 :           && ent->uses->names_in_scope == current_binding_level->names)
    3931                 :             :         return;
    3932                 :             : 
    3933                 :        1424 :       named_label_use_entry *new_use
    3934                 :        1424 :         = ggc_alloc<named_label_use_entry> ();
    3935                 :        1424 :       new_use->binding_level = current_binding_level;
    3936                 :        1424 :       new_use->names_in_scope = current_binding_level->names;
    3937                 :        1424 :       new_use->o_goto_locus = input_location;
    3938                 :        1424 :       new_use->in_omp_scope = false;
    3939                 :        1424 :       new_use->computed_goto = computed ? make_tree_vector () : nullptr;
    3940                 :             : 
    3941                 :        1424 :       new_use->next = ent->uses;
    3942                 :        1424 :       ent->uses = new_use;
    3943                 :        1424 :       return;
    3944                 :             :     }
    3945                 :             : 
    3946                 :         418 :   bool saw_catch = false, complained = false;
    3947                 :         418 :   int identified = 0;
    3948                 :         418 :   tree bad;
    3949                 :         418 :   unsigned ix;
    3950                 :             : 
    3951                 :         409 :   if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
    3952                 :         403 :       || ent->in_constexpr_if || ent->in_consteval_if
    3953                 :         397 :       || ent->in_omp_scope || ent->in_stmt_expr
    3954                 :         797 :       || !vec_safe_is_empty (ent->bad_decls))
    3955                 :             :     {
    3956                 :          45 :       enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
    3957                 :          45 :       if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
    3958                 :          30 :           || ent->in_consteval_if || ent->in_transaction_scope
    3959                 :          24 :           || ent->in_omp_scope || ent->in_stmt_expr)
    3960                 :          39 :         diag_kind = diagnostics::kind::error;
    3961                 :          45 :       complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    3962                 :             :                                   &input_location, diag_kind, computed);
    3963                 :          45 :       identified = 1 + (diag_kind == diagnostics::kind::error);
    3964                 :             :     }
    3965                 :             : 
    3966                 :         424 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
    3967                 :             :     {
    3968                 :           6 :       bool problem = decl_jump_unsafe (bad);
    3969                 :             : 
    3970                 :           6 :       if (problem && DECL_ARTIFICIAL (bad))
    3971                 :             :         {
    3972                 :             :           /* Can't skip init of __exception_info.  */
    3973                 :           0 :           if (identified == 1)
    3974                 :             :             {
    3975                 :           0 :               complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    3976                 :             :                                           &input_location,
    3977                 :             :                                           diagnostics::kind::error,
    3978                 :             :                                           computed);
    3979                 :           0 :               identified = 2;
    3980                 :             :             }
    3981                 :           0 :           if (complained)
    3982                 :           0 :             inform (DECL_SOURCE_LOCATION (bad), "  enters %<catch%> block");
    3983                 :             :           saw_catch = true;
    3984                 :             :         }
    3985                 :           6 :       else if (complained)
    3986                 :           6 :         inform (DECL_SOURCE_LOCATION (bad),
    3987                 :             :                 "  skips initialization of %q#D", bad);
    3988                 :             :     }
    3989                 :             : 
    3990                 :         418 :   if (complained)
    3991                 :             :     {
    3992                 :          45 :       if (ent->in_try_scope)
    3993                 :           9 :         inform (input_location, "  enters %<try%> block");
    3994                 :          36 :       else if (ent->in_catch_scope && !saw_catch)
    3995                 :           3 :         inform (input_location, "  enters %<catch%> block");
    3996                 :          33 :       else if (ent->in_transaction_scope)
    3997                 :           3 :         inform (input_location, "  enters synchronized or atomic statement");
    3998                 :          30 :       else if (ent->in_constexpr_if)
    3999                 :           3 :         inform (input_location, "  enters %<constexpr if%> statement");
    4000                 :          27 :       else if (ent->in_consteval_if)
    4001                 :           3 :         inform (input_location, "  enters %<consteval if%> statement");
    4002                 :          24 :       else if (ent->in_stmt_expr)
    4003                 :          15 :         inform (input_location, "  enters statement expression");
    4004                 :             :     }
    4005                 :             : 
    4006                 :         418 :   if (ent->in_omp_scope)
    4007                 :             :     {
    4008                 :           3 :       if (complained)
    4009                 :           3 :         inform (input_location, "  enters OpenMP structured block");
    4010                 :             :     }
    4011                 :         415 :   else if (flag_openmp)
    4012                 :          69 :     for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4013                 :             :       {
    4014                 :          42 :         if (b == ent->binding_level)
    4015                 :             :           break;
    4016                 :          36 :         if (b->kind == sk_omp)
    4017                 :             :           {
    4018                 :          21 :             if (identified < 2)
    4019                 :             :               {
    4020                 :          42 :                 complained = identify_goto (decl,
    4021                 :          21 :                                             DECL_SOURCE_LOCATION (decl),
    4022                 :             :                                             &input_location,
    4023                 :             :                                             diagnostics::kind::error,
    4024                 :             :                                             computed);
    4025                 :          21 :                 identified = 2;
    4026                 :             :               }
    4027                 :          21 :             if (complained)
    4028                 :          21 :               inform (input_location, "  exits OpenMP structured block");
    4029                 :             :             break;
    4030                 :             :           }
    4031                 :             :       }
    4032                 :             : 
    4033                 :             :   /* Warn if a computed goto might involve a local variable going out of scope
    4034                 :             :      without being cleaned up.  */
    4035                 :         418 :   if (computed)
    4036                 :             :     {
    4037                 :          71 :       auto level = ent->binding_level;
    4038                 :          71 :       auto names = ent->names_in_scope;
    4039                 :          71 :       for (auto b = current_binding_level; ; b = b->level_chain)
    4040                 :             :         {
    4041                 :         111 :           if (b->kind == sk_catch)
    4042                 :             :             {
    4043                 :           6 :               if (!identified)
    4044                 :             :                 {
    4045                 :           6 :                   complained
    4046                 :           6 :                     = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4047                 :             :                                      &input_location, diagnostics::kind::error,
    4048                 :             :                                      computed);
    4049                 :           6 :                   identified = 2;
    4050                 :             :                 }
    4051                 :           6 :               if (complained)
    4052                 :           6 :                 inform (input_location,
    4053                 :             :                         "  does not clean up handled exception");
    4054                 :             :             }
    4055                 :         111 :           tree end = b == level ? names : NULL_TREE;
    4056                 :         127 :           for (tree d = b->names; d != end; d = DECL_CHAIN (d))
    4057                 :             :             {
    4058                 :          16 :               if (automatic_var_with_nontrivial_dtor_p (d))
    4059                 :             :                 {
    4060                 :          10 :                   if (!identified)
    4061                 :             :                     {
    4062                 :          10 :                       complained
    4063                 :          10 :                         = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4064                 :             :                                          &input_location, diagnostics::kind::error,
    4065                 :             :                                          computed);
    4066                 :          10 :                       identified = 2;
    4067                 :             :                     }
    4068                 :          10 :                   if (complained)
    4069                 :          10 :                     inform (DECL_SOURCE_LOCATION (d),
    4070                 :             :                             "  does not destroy %qD", d);
    4071                 :             :                 }
    4072                 :             :             }
    4073                 :         111 :           if (b == level)
    4074                 :             :             break;
    4075                 :          40 :         }
    4076                 :             :     }
    4077                 :        2033 : }
    4078                 :             : 
    4079                 :             : /* Check that a new jump to a label DECL is OK.  Called by
    4080                 :             :    finish_goto_stmt.  */
    4081                 :             : 
    4082                 :             : void
    4083                 :        1993 : check_goto (tree decl)
    4084                 :             : {
    4085                 :        1993 :   if (!named_labels)
    4086                 :             :     return;
    4087                 :        1978 :   if (TREE_CODE (decl) != LABEL_DECL)
    4088                 :             :     {
    4089                 :             :       /* We don't know where a computed goto is jumping,
    4090                 :             :          so check all addressable labels.  */
    4091                 :         306 :       for (auto iter = named_labels->begin ();
    4092                 :         416 :            iter != named_labels->end ();
    4093                 :         196 :            ++iter)
    4094                 :             :         {
    4095                 :         196 :           auto ent = *iter;
    4096                 :         196 :           if (ent->addressed)
    4097                 :         165 :             check_goto_1 (ent, true);
    4098                 :             :         }
    4099                 :             :     }
    4100                 :             :   else
    4101                 :             :     {
    4102                 :        1868 :       hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
    4103                 :        1868 :       named_label_entry **slot
    4104                 :        1868 :         = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
    4105                 :        1868 :       named_label_entry *ent = *slot;
    4106                 :        1868 :       check_goto_1 (ent, false);
    4107                 :             :     }
    4108                 :             : }
    4109                 :             : 
    4110                 :             : /* Check that a return is ok wrt OpenMP structured blocks.
    4111                 :             :    Called by finish_return_stmt.  Returns true if all is well.  */
    4112                 :             : 
    4113                 :             : bool
    4114                 :      232390 : check_omp_return (void)
    4115                 :             : {
    4116                 :      890300 :   for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4117                 :      657910 :     if (b->kind == sk_omp)
    4118                 :             :       {
    4119                 :          15 :         error ("invalid exit from OpenMP structured block");
    4120                 :          15 :         return false;
    4121                 :             :       }
    4122                 :      657895 :     else if (b->kind == sk_function_parms)
    4123                 :             :       break;
    4124                 :             :   return true;
    4125                 :             : }
    4126                 :             : 
    4127                 :             : /* Define a label, specifying the location in the source file.
    4128                 :             :    Return the LABEL_DECL node for the label.  */
    4129                 :             : 
    4130                 :             : tree
    4131                 :       19952 : define_label (location_t location, tree name)
    4132                 :             : {
    4133                 :       19952 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    4134                 :             : 
    4135                 :             :   /* After labels, make any new cleanups in the function go into their
    4136                 :             :      own new (temporary) binding contour.  */
    4137                 :       19952 :   for (cp_binding_level *p = current_binding_level;
    4138                 :       29094 :        p->kind != sk_function_parms;
    4139                 :        9142 :        p = p->level_chain)
    4140                 :        9142 :     p->more_cleanups_ok = 0;
    4141                 :             : 
    4142                 :       19952 :   named_label_entry *ent = lookup_label_1 (name, false);
    4143                 :       19952 :   tree decl = ent->label_decl;
    4144                 :             : 
    4145                 :       19952 :   if (DECL_INITIAL (decl) != NULL_TREE)
    4146                 :             :     {
    4147                 :           6 :       error ("duplicate label %qD", decl);
    4148                 :           6 :       return error_mark_node;
    4149                 :             :     }
    4150                 :             :   else
    4151                 :             :     {
    4152                 :             :       /* Mark label as having been defined.  */
    4153                 :       19946 :       DECL_INITIAL (decl) = error_mark_node;
    4154                 :             :       /* Say where in the source.  */
    4155                 :       19946 :       DECL_SOURCE_LOCATION (decl) = location;
    4156                 :             : 
    4157                 :       19946 :       ent->binding_level = current_binding_level;
    4158                 :       19946 :       ent->names_in_scope = current_binding_level->names;
    4159                 :             : 
    4160                 :       21361 :       for (named_label_use_entry *use = ent->uses; use; use = use->next)
    4161                 :        1415 :         check_previous_goto (decl, use);
    4162                 :       19946 :       ent->uses = NULL;
    4163                 :             :     }
    4164                 :             : 
    4165                 :       19946 :   return decl;
    4166                 :       19952 : }
    4167                 :             : 
    4168                 :             : struct cp_switch
    4169                 :             : {
    4170                 :             :   cp_binding_level *level;
    4171                 :             :   struct cp_switch *next;
    4172                 :             :   /* The SWITCH_STMT being built.  */
    4173                 :             :   tree switch_stmt;
    4174                 :             :   /* A splay-tree mapping the low element of a case range to the high
    4175                 :             :      element, or NULL_TREE if there is no high element.  Used to
    4176                 :             :      determine whether or not a new case label duplicates an old case
    4177                 :             :      label.  We need a tree, rather than simply a hash table, because
    4178                 :             :      of the GNU case range extension.  */
    4179                 :             :   splay_tree cases;
    4180                 :             :   /* Remember whether a default: case label has been seen.  */
    4181                 :             :   bool has_default_p;
    4182                 :             :   /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT.  */
    4183                 :             :   bool break_stmt_seen_p;
    4184                 :             :   /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
    4185                 :             :      where BREAK_STMT doesn't belong to the SWITCH_STMT.  */
    4186                 :             :   bool in_loop_body_p;
    4187                 :             : };
    4188                 :             : 
    4189                 :             : /* A stack of the currently active switch statements.  The innermost
    4190                 :             :    switch statement is on the top of the stack.  There is no need to
    4191                 :             :    mark the stack for garbage collection because it is only active
    4192                 :             :    during the processing of the body of a function, and we never
    4193                 :             :    collect at that point.  */
    4194                 :             : 
    4195                 :             : static struct cp_switch *switch_stack;
    4196                 :             : 
    4197                 :             : /* Called right after a switch-statement condition is parsed.
    4198                 :             :    SWITCH_STMT is the switch statement being parsed.  */
    4199                 :             : 
    4200                 :             : void
    4201                 :      498821 : push_switch (tree switch_stmt)
    4202                 :             : {
    4203                 :      498821 :   struct cp_switch *p = XNEW (struct cp_switch);
    4204                 :      498821 :   p->level = current_binding_level;
    4205                 :      498821 :   p->next = switch_stack;
    4206                 :      498821 :   p->switch_stmt = switch_stmt;
    4207                 :      498821 :   p->cases = splay_tree_new (case_compare, NULL, NULL);
    4208                 :      498821 :   p->has_default_p = false;
    4209                 :      498821 :   p->break_stmt_seen_p = false;
    4210                 :      498821 :   p->in_loop_body_p = false;
    4211                 :      498821 :   switch_stack = p;
    4212                 :      498821 : }
    4213                 :             : 
    4214                 :             : void
    4215                 :      498821 : pop_switch (void)
    4216                 :             : {
    4217                 :      498821 :   struct cp_switch *cs = switch_stack;
    4218                 :             : 
    4219                 :             :   /* Emit warnings as needed.  */
    4220                 :      498821 :   location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
    4221                 :      498821 :   tree cond = SWITCH_STMT_COND (cs->switch_stmt);
    4222                 :      498821 :   const bool bool_cond_p
    4223                 :      498821 :     = (SWITCH_STMT_TYPE (cs->switch_stmt)
    4224                 :      498821 :        && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
    4225                 :      498821 :   if (!processing_template_decl)
    4226                 :      314530 :     c_do_switch_warnings (cs->cases, switch_location,
    4227                 :      314530 :                           SWITCH_STMT_TYPE (cs->switch_stmt), cond,
    4228                 :             :                           bool_cond_p);
    4229                 :             : 
    4230                 :             :   /* For the benefit of block_may_fallthru remember if the switch body
    4231                 :             :      case labels cover all possible values and if there are break; stmts.  */
    4232                 :      498821 :   if (cs->has_default_p
    4233                 :      498821 :       || (!processing_template_decl
    4234                 :       43266 :           && c_switch_covers_all_cases_p (cs->cases,
    4235                 :       43266 :                                           SWITCH_STMT_TYPE (cs->switch_stmt))))
    4236                 :      385383 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
    4237                 :      498821 :   if (!cs->break_stmt_seen_p)
    4238                 :      256423 :     SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
    4239                 :             :   /* Now that we're done with the switch warnings, set the switch type
    4240                 :             :      to the type of the condition if the index type was of scoped enum type.
    4241                 :             :      (Such types don't participate in the integer promotions.)  We do this
    4242                 :             :      because of bit-fields whose declared type is a scoped enum type:
    4243                 :             :      gimplification will use the lowered index type, but convert the
    4244                 :             :      case values to SWITCH_STMT_TYPE, which would have been the declared type
    4245                 :             :      and verify_gimple_switch doesn't accept that.  */
    4246                 :      498821 :   if (is_bitfield_expr_with_lowered_type (cond))
    4247                 :       55314 :     SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
    4248                 :      498821 :   gcc_assert (!cs->in_loop_body_p);
    4249                 :      498821 :   splay_tree_delete (cs->cases);
    4250                 :      498821 :   switch_stack = switch_stack->next;
    4251                 :      498821 :   free (cs);
    4252                 :      498821 : }
    4253                 :             : 
    4254                 :             : /* Note that a BREAK_STMT is about to be added.  If it is inside of
    4255                 :             :    a SWITCH_STMT and not inside of a loop body inside of it, note
    4256                 :             :    in switch_stack we've seen a BREAK_STMT.  */
    4257                 :             : 
    4258                 :             : void
    4259                 :     3574882 : note_break_stmt (void)
    4260                 :             : {
    4261                 :     3574882 :   if (switch_stack && !switch_stack->in_loop_body_p)
    4262                 :     1554053 :     switch_stack->break_stmt_seen_p = true;
    4263                 :     3574882 : }
    4264                 :             : 
    4265                 :             : /* Note the start of processing of an iteration statement's body.
    4266                 :             :    The note_break_stmt function will do nothing while processing it.
    4267                 :             :    Return a flag that should be passed to note_iteration_stmt_body_end.  */
    4268                 :             : 
    4269                 :             : bool
    4270                 :    15609451 : note_iteration_stmt_body_start (void)
    4271                 :             : {
    4272                 :    15609451 :   if (!switch_stack)
    4273                 :             :     return false;
    4274                 :      118941 :   bool ret = switch_stack->in_loop_body_p;
    4275                 :      118941 :   switch_stack->in_loop_body_p = true;
    4276                 :      118941 :   return ret;
    4277                 :             : }
    4278                 :             : 
    4279                 :             : /* Note the end of processing of an iteration statement's body.  */
    4280                 :             : 
    4281                 :             : void
    4282                 :    15609451 : note_iteration_stmt_body_end (bool prev)
    4283                 :             : {
    4284                 :    15609451 :   if (switch_stack)
    4285                 :      118941 :     switch_stack->in_loop_body_p = prev;
    4286                 :    15609451 : }
    4287                 :             : 
    4288                 :             : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
    4289                 :             :    condition.  Note that if TYPE and VALUE are already integral we don't
    4290                 :             :    really do the conversion because the language-independent
    4291                 :             :    warning/optimization code will work better that way.  */
    4292                 :             : 
    4293                 :             : static tree
    4294                 :     3975054 : case_conversion (tree type, tree value)
    4295                 :             : {
    4296                 :     3975054 :   if (value == NULL_TREE)
    4297                 :             :     return value;
    4298                 :             : 
    4299                 :     1716425 :   value = mark_rvalue_use (value);
    4300                 :             : 
    4301                 :     1716425 :   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    4302                 :      973879 :     type = type_promotes_to (type);
    4303                 :             : 
    4304                 :     1716425 :   tree ovalue = value;
    4305                 :             :   /* The constant-expression VALUE shall be a converted constant expression
    4306                 :             :      of the adjusted type of the switch condition, which doesn't allow
    4307                 :             :      narrowing conversions.  */
    4308                 :     1716425 :   value = build_converted_constant_expr (type, value, tf_warning_or_error);
    4309                 :             : 
    4310                 :     1716425 :   if (cxx_dialect >= cxx11
    4311                 :     1716425 :       && (SCOPED_ENUM_P (type)
    4312                 :      971161 :           || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
    4313                 :             :     /* Use the converted value.  */;
    4314                 :             :   else
    4315                 :             :     /* The already integral case.  */
    4316                 :             :     value = ovalue;
    4317                 :             : 
    4318                 :     1716425 :   return cxx_constant_value (value);
    4319                 :             : }
    4320                 :             : 
    4321                 :             : /* Note that we've seen a definition of a case label, and complain if this
    4322                 :             :    is a bad place for one.  */
    4323                 :             : 
    4324                 :             : tree
    4325                 :     3686896 : finish_case_label (location_t loc, tree low_value, tree high_value)
    4326                 :             : {
    4327                 :     3686896 :   tree cond, r;
    4328                 :     3686896 :   cp_binding_level *p;
    4329                 :     3686896 :   tree type;
    4330                 :             : 
    4331                 :     3686896 :   if (low_value == NULL_TREE && high_value == NULL_TREE)
    4332                 :      385347 :     switch_stack->has_default_p = true;
    4333                 :             : 
    4334                 :     3686896 :   if (processing_template_decl)
    4335                 :             :     {
    4336                 :     1699246 :       tree label;
    4337                 :             : 
    4338                 :             :       /* For templates, just add the case label; we'll do semantic
    4339                 :             :          analysis at instantiation-time.  */
    4340                 :     1699246 :       label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
    4341                 :     1699246 :       return add_stmt (build_case_label (low_value, high_value, label));
    4342                 :             :     }
    4343                 :             : 
    4344                 :             :   /* Find the condition on which this switch statement depends.  */
    4345                 :     1987650 :   cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
    4346                 :     1987650 :   if (cond && TREE_CODE (cond) == TREE_LIST)
    4347                 :           0 :     cond = TREE_VALUE (cond);
    4348                 :             : 
    4349                 :     1987650 :   if (!check_switch_goto (switch_stack->level))
    4350                 :          87 :     return error_mark_node;
    4351                 :             : 
    4352                 :     1987563 :   type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
    4353                 :     1987563 :   if (type == error_mark_node)
    4354                 :             :     return error_mark_node;
    4355                 :             : 
    4356                 :     1987527 :   low_value = case_conversion (type, low_value);
    4357                 :     1987527 :   high_value = case_conversion (type, high_value);
    4358                 :             : 
    4359                 :     1987527 :   r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
    4360                 :             : 
    4361                 :             :   /* After labels, make any new cleanups in the function go into their
    4362                 :             :      own new (temporary) binding contour.  */
    4363                 :     1987527 :   for (p = current_binding_level;
    4364                 :     8365441 :        p->kind != sk_function_parms;
    4365                 :     6377914 :        p = p->level_chain)
    4366                 :     6377914 :     p->more_cleanups_ok = 0;
    4367                 :             : 
    4368                 :             :   return r;
    4369                 :             : }
    4370                 :             : 
    4371                 :             : struct typename_info {
    4372                 :             :   tree scope;
    4373                 :             :   tree name;
    4374                 :             :   tree template_id;
    4375                 :             :   bool enum_p;
    4376                 :             :   bool class_p;
    4377                 :             :   bool union_p;
    4378                 :             : };
    4379                 :             : 
    4380                 :             : struct typename_hasher : ggc_ptr_hash<tree_node>
    4381                 :             : {
    4382                 :             :   typedef typename_info *compare_type;
    4383                 :             : 
    4384                 :             :   /* Hash a TYPENAME_TYPE.  */
    4385                 :             : 
    4386                 :             :   static hashval_t
    4387                 :   391574448 :   hash (tree context, tree fullname)
    4388                 :             :   {
    4389                 :   391574448 :     hashval_t hash = 0;
    4390                 :   391574448 :     hash = iterative_hash_object (context, hash);
    4391                 :   391574448 :     hash = iterative_hash_object (fullname, hash);
    4392                 :   391574448 :     return hash;
    4393                 :             :   }
    4394                 :             : 
    4395                 :             :   static hashval_t
    4396                 :    57028812 :   hash (const typename_info *ti)
    4397                 :             :   {
    4398                 :    57028812 :     return typename_hasher::hash (ti->scope, ti->template_id);
    4399                 :             :   }
    4400                 :             : 
    4401                 :             :   static hashval_t
    4402                 :   334545636 :   hash (tree t)
    4403                 :             :   {
    4404                 :   334545636 :     return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
    4405                 :             :   }
    4406                 :             : 
    4407                 :             :   /* Compare two TYPENAME_TYPEs.  */
    4408                 :             : 
    4409                 :             :   static bool
    4410                 :   388708978 :   equal (tree t1, const typename_info *t2)
    4411                 :             :   {
    4412                 :   388708978 :     return (TYPE_IDENTIFIER (t1) == t2->name
    4413                 :   115129309 :             && TYPE_CONTEXT (t1) == t2->scope
    4414                 :    29018315 :             && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
    4415                 :    29006919 :             && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
    4416                 :    29006865 :             && TYPENAME_IS_CLASS_P (t1) == t2->class_p
    4417                 :   417715813 :             && TYPENAME_IS_UNION_P (t1) == t2->union_p);
    4418                 :             :   }
    4419                 :             : };
    4420                 :             : 
    4421                 :             : /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
    4422                 :             :    the type of `T', NAME is the IDENTIFIER_NODE for `t'.
    4423                 :             : 
    4424                 :             :    Returns the new TYPENAME_TYPE.  */
    4425                 :             : 
    4426                 :             : static GTY (()) hash_table<typename_hasher> *typename_htab;
    4427                 :             : 
    4428                 :             : tree
    4429                 :    57028812 : build_typename_type (tree context, tree name, tree fullname,
    4430                 :             :                      enum tag_types tag_type)
    4431                 :             : {
    4432                 :    57028812 :   typename_info ti;
    4433                 :             : 
    4434                 :    57028812 :   if (typename_htab == NULL)
    4435                 :       19461 :     typename_htab = hash_table<typename_hasher>::create_ggc (61);
    4436                 :             : 
    4437                 :    57028812 :   ti.scope = FROB_CONTEXT (context);
    4438                 :    57028812 :   ti.name = name;
    4439                 :    57028812 :   ti.template_id = fullname;
    4440                 :    57028812 :   ti.enum_p = tag_type == enum_type;
    4441                 :    57028812 :   ti.class_p = (tag_type == class_type || tag_type == record_type);
    4442                 :    57028812 :   ti.union_p = tag_type == union_type;
    4443                 :    57028812 :   hashval_t hash = typename_hasher::hash (&ti);
    4444                 :             : 
    4445                 :             :   /* See if we already have this type.  */
    4446                 :    57028812 :   tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
    4447                 :    57028812 :   tree t = *e;
    4448                 :    57028812 :   if (*e)
    4449                 :             :     t = *e;
    4450                 :             :   else
    4451                 :             :     {
    4452                 :             :       /* Build the TYPENAME_TYPE.  */
    4453                 :    28021977 :       t = cxx_make_type (TYPENAME_TYPE);
    4454                 :    28021977 :       TYPE_CONTEXT (t) = ti.scope;
    4455                 :    28021977 :       TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
    4456                 :    28021977 :       TYPENAME_IS_ENUM_P (t) = ti.enum_p;
    4457                 :    28021977 :       TYPENAME_IS_CLASS_P (t) = ti.class_p;
    4458                 :    28021977 :       TYPENAME_IS_UNION_P (t) = ti.union_p;
    4459                 :             : 
    4460                 :             :       /* Build the corresponding TYPE_DECL.  */
    4461                 :    28021977 :       tree d = build_decl (input_location, TYPE_DECL, name, t);
    4462                 :    28021977 :       TYPE_NAME (t) = d;
    4463                 :    28021977 :       TYPE_STUB_DECL (t) = d;
    4464                 :    28021977 :       DECL_CONTEXT (d) = ti.scope;
    4465                 :    28021977 :       DECL_ARTIFICIAL (d) = 1;
    4466                 :             : 
    4467                 :             :       /* Store it in the hash table.  */
    4468                 :    28021977 :       *e = t;
    4469                 :             : 
    4470                 :             :       /* TYPENAME_TYPEs must always be compared structurally, because
    4471                 :             :          they may or may not resolve down to another type depending on
    4472                 :             :          the currently open classes. */
    4473                 :    28021977 :       SET_TYPE_STRUCTURAL_EQUALITY (t);
    4474                 :             :     }
    4475                 :             : 
    4476                 :    57028812 :   return t;
    4477                 :             : }
    4478                 :             : 
    4479                 :             : /* Resolve `typename CONTEXT::NAME'.  TAG_TYPE indicates the tag
    4480                 :             :    provided to name the type.  Returns an appropriate type, unless an
    4481                 :             :    error occurs, in which case error_mark_node is returned.  If we
    4482                 :             :    locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
    4483                 :             :    return that, rather than the _TYPE it corresponds to, in other
    4484                 :             :    cases we look through the type decl.  If TF_ERROR is set, complain
    4485                 :             :    about errors, otherwise be quiet.  */
    4486                 :             : 
    4487                 :             : tree
    4488                 :   188628635 : make_typename_type (tree context, tree name, enum tag_types tag_type,
    4489                 :             :                     tsubst_flags_t complain)
    4490                 :             : {
    4491                 :   188628635 :   tree fullname;
    4492                 :   188628635 :   tree t;
    4493                 :   188628635 :   bool want_template;
    4494                 :             : 
    4495                 :   188628635 :   if (name == error_mark_node
    4496                 :   188628633 :       || context == NULL_TREE
    4497                 :   188628633 :       || context == error_mark_node)
    4498                 :             :     return error_mark_node;
    4499                 :             : 
    4500                 :   188628617 :   if (TYPE_P (name))
    4501                 :             :     {
    4502                 :           0 :       if (!(TYPE_LANG_SPECIFIC (name)
    4503                 :           0 :             && (CLASSTYPE_IS_TEMPLATE (name)
    4504                 :           0 :                 || CLASSTYPE_USE_TEMPLATE (name))))
    4505                 :           0 :         name = TYPE_IDENTIFIER (name);
    4506                 :             :       else
    4507                 :             :         /* Create a TEMPLATE_ID_EXPR for the type.  */
    4508                 :           0 :         name = build_nt (TEMPLATE_ID_EXPR,
    4509                 :           0 :                          CLASSTYPE_TI_TEMPLATE (name),
    4510                 :           0 :                          CLASSTYPE_TI_ARGS (name));
    4511                 :             :     }
    4512                 :   188628617 :   else if (TREE_CODE (name) == TYPE_DECL)
    4513                 :           0 :     name = DECL_NAME (name);
    4514                 :             : 
    4515                 :   188628617 :   fullname = name;
    4516                 :             : 
    4517                 :   188628617 :   if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    4518                 :             :     {
    4519                 :     6351590 :       name = TREE_OPERAND (name, 0);
    4520                 :     6351590 :       if (DECL_TYPE_TEMPLATE_P (name))
    4521                 :           0 :         name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
    4522                 :     6351590 :       if (TREE_CODE (name) != IDENTIFIER_NODE)
    4523                 :             :         {
    4524                 :           0 :           if (complain & tf_error)
    4525                 :           0 :             error ("%qD is not a type", name);
    4526                 :           0 :           return error_mark_node;
    4527                 :             :         }
    4528                 :             :     }
    4529                 :   188628617 :   if (TREE_CODE (name) == TEMPLATE_DECL)
    4530                 :             :     {
    4531                 :           0 :       if (complain & tf_error)
    4532                 :           0 :         error ("%qD used without template arguments", name);
    4533                 :           0 :       return error_mark_node;
    4534                 :             :     }
    4535                 :   188628617 :   else if (is_overloaded_fn (name))
    4536                 :             :     {
    4537                 :           3 :       if (complain & tf_error)
    4538                 :           3 :         error ("%qD is a function, not a type", name);
    4539                 :           3 :       return error_mark_node;
    4540                 :             :     }
    4541                 :   188628614 :   gcc_assert (identifier_p (name));
    4542                 :   188628614 :   gcc_assert (TYPE_P (context));
    4543                 :             : 
    4544                 :   188628614 :   if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
    4545                 :             :     /* This can happen for C++17 variadic using (c++/88986).  */;
    4546                 :   176845685 :   else if (!MAYBE_CLASS_TYPE_P (context))
    4547                 :             :     {
    4548                 :           6 :       if (complain & tf_error)
    4549                 :           6 :         error ("%q#T is not a class", context);
    4550                 :           6 :       return error_mark_node;
    4551                 :             :     }
    4552                 :             : 
    4553                 :             :   /* When the CONTEXT is a dependent type,  NAME could refer to a
    4554                 :             :      dependent base class of CONTEXT.  But look inside it anyway
    4555                 :             :      if CONTEXT is a currently open scope, in case it refers to a
    4556                 :             :      member of the current instantiation or a non-dependent base;
    4557                 :             :      lookup will stop when we hit a dependent base.  */
    4558                 :   188628608 :   if (!dependent_scope_p (context))
    4559                 :             :     {
    4560                 :             :       /* We generally don't ignore non-types during TYPENAME_TYPE lookup
    4561                 :             :          (as per [temp.res.general]/3), unless
    4562                 :             :            - the tag corresponds to a class-key or 'enum' so
    4563                 :             :              [basic.lookup.elab] applies, or
    4564                 :             :            - the tag corresponds to scope_type or tf_qualifying_scope is
    4565                 :             :              set so [basic.lookup.qual]/1 applies.
    4566                 :             :          TODO: If we'd set/track the scope_type tag thoroughly on all
    4567                 :             :          TYPENAME_TYPEs that are followed by :: then we wouldn't need the
    4568                 :             :          tf_qualifying_scope flag.  */
    4569                 :   271656468 :       bool want_type = (tag_type != none_type && tag_type != typename_type)
    4570                 :   135828234 :         || (complain & tf_qualifying_scope);
    4571                 :   135828234 :       t = lookup_member (context, name, /*protect=*/2, want_type, complain);
    4572                 :             :     }
    4573                 :             :   else
    4574                 :             :     t = NULL_TREE;
    4575                 :             : 
    4576                 :   206150836 :   if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
    4577                 :    52801292 :     return build_typename_type (context, name, fullname, tag_type);
    4578                 :             : 
    4579                 :   135827316 :   want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
    4580                 :             : 
    4581                 :   135827316 :   if (!t)
    4582                 :             :     {
    4583                 :    17521310 :       if (complain & tf_error)
    4584                 :             :         {
    4585                 :         233 :           if (!COMPLETE_TYPE_P (context))
    4586                 :          18 :             cxx_incomplete_type_error (NULL_TREE, context);
    4587                 :             :           else
    4588                 :         429 :             error (want_template ? G_("no class template named %q#T in %q#T")
    4589                 :             :                    : G_("no type named %q#T in %q#T"), name, context);
    4590                 :             :         }
    4591                 :    17521310 :       return error_mark_node;
    4592                 :             :     }
    4593                 :             : 
    4594                 :             :   /* Pull out the template from an injected-class-name (or multiple).  */
    4595                 :   118306006 :   if (want_template)
    4596                 :     4866285 :     t = maybe_get_template_decl_from_type_decl (t);
    4597                 :             : 
    4598                 :   118306006 :   if (TREE_CODE (t) == TREE_LIST)
    4599                 :             :     {
    4600                 :           3 :       if (complain & tf_error)
    4601                 :             :         {
    4602                 :           3 :           auto_diagnostic_group d;
    4603                 :           3 :           error ("lookup of %qT in %qT is ambiguous", name, context);
    4604                 :           3 :           print_candidates (t);
    4605                 :           3 :         }
    4606                 :           3 :       return error_mark_node;
    4607                 :             :     }
    4608                 :             : 
    4609                 :   118306003 :   if (want_template && !DECL_TYPE_TEMPLATE_P (t))
    4610                 :             :     {
    4611                 :           6 :       if (complain & tf_error)
    4612                 :           6 :         error ("%<typename %T::%D%> names %q#T, which is not a class template",
    4613                 :             :                context, name, t);
    4614                 :           6 :       return error_mark_node;
    4615                 :             :     }
    4616                 :   118305997 :   if (!want_template && TREE_CODE (t) != TYPE_DECL)
    4617                 :             :     {
    4618                 :         327 :       if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
    4619                 :         657 :           && DECL_TYPE_TEMPLATE_P (t))
    4620                 :             :         /* The caller permits this typename-specifier to name a template
    4621                 :             :            (because it appears in a CTAD-enabled context).  */;
    4622                 :             :       else
    4623                 :             :         {
    4624                 :          23 :           if (complain & tf_error)
    4625                 :          17 :             error ("%<typename %T::%D%> names %q#D, which is not a type",
    4626                 :             :                    context, name, t);
    4627                 :          23 :           return error_mark_node;
    4628                 :             :         }
    4629                 :             :     }
    4630                 :             : 
    4631                 :   118305974 :   if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
    4632                 :             :                                             context, complain))
    4633                 :          49 :     return error_mark_node;
    4634                 :             : 
    4635                 :   118305925 :   if (!want_template && DECL_TYPE_TEMPLATE_P (t))
    4636                 :         316 :     return make_template_placeholder (t);
    4637                 :             : 
    4638                 :   118305609 :   if (want_template)
    4639                 :             :     {
    4640                 :     4866279 :       t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
    4641                 :             :                                  NULL_TREE, context,
    4642                 :             :                                  complain | tf_user);
    4643                 :     4866279 :       if (t == error_mark_node)
    4644                 :             :         return error_mark_node;
    4645                 :     4866274 :       t = TYPE_NAME (t);
    4646                 :             :     }
    4647                 :             : 
    4648                 :   118305604 :   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
    4649                 :     3461784 :     t = TREE_TYPE (t);
    4650                 :             : 
    4651                 :   118305604 :   maybe_record_typedef_use (t);
    4652                 :             : 
    4653                 :   118305604 :   return t;
    4654                 :             : }
    4655                 :             : 
    4656                 :             : /* Resolve `CONTEXT::template NAME'.  Returns a TEMPLATE_DECL if the name
    4657                 :             :    can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
    4658                 :             :    in which case error_mark_node is returned.
    4659                 :             : 
    4660                 :             :    If PARM_LIST is non-NULL, also make sure that the template parameter
    4661                 :             :    list of TEMPLATE_DECL matches.
    4662                 :             : 
    4663                 :             :    If COMPLAIN zero, don't complain about any errors that occur.  */
    4664                 :             : 
    4665                 :             : tree
    4666                 :       82084 : make_unbound_class_template (tree context, tree name, tree parm_list,
    4667                 :             :                              tsubst_flags_t complain)
    4668                 :             : {
    4669                 :       82084 :   if (TYPE_P (name))
    4670                 :           0 :     name = TYPE_IDENTIFIER (name);
    4671                 :       82084 :   else if (DECL_P (name))
    4672                 :           0 :     name = DECL_NAME (name);
    4673                 :       82084 :   gcc_assert (identifier_p (name));
    4674                 :             : 
    4675                 :       82084 :   if (!dependent_type_p (context)
    4676                 :       82084 :       || currently_open_class (context))
    4677                 :             :     {
    4678                 :       27258 :       tree tmpl = NULL_TREE;
    4679                 :             : 
    4680                 :       27258 :       if (MAYBE_CLASS_TYPE_P (context))
    4681                 :       27252 :         tmpl = lookup_field (context, name, 0, false);
    4682                 :             : 
    4683                 :       27252 :       if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
    4684                 :           3 :         tmpl = maybe_get_template_decl_from_type_decl (tmpl);
    4685                 :             : 
    4686                 :       27246 :       if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
    4687                 :             :         {
    4688                 :          12 :           if (complain & tf_error)
    4689                 :           9 :             error ("no class template named %q#T in %q#T", name, context);
    4690                 :          12 :           return error_mark_node;
    4691                 :             :         }
    4692                 :             : 
    4693                 :       27246 :       if (parm_list
    4694                 :       27246 :           && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
    4695                 :             :         {
    4696                 :           0 :           if (complain & tf_error)
    4697                 :             :             {
    4698                 :           0 :               auto_diagnostic_group d;
    4699                 :           0 :               error ("template parameters do not match template %qD", tmpl);
    4700                 :           0 :               inform (DECL_SOURCE_LOCATION (tmpl),
    4701                 :             :                       "%qD declared here", tmpl);
    4702                 :           0 :             }
    4703                 :           0 :           return error_mark_node;
    4704                 :             :         }
    4705                 :             : 
    4706                 :       27246 :       if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
    4707                 :             :                                           complain))
    4708                 :           0 :         return error_mark_node;
    4709                 :             : 
    4710                 :             :       return tmpl;
    4711                 :             :     }
    4712                 :             : 
    4713                 :       54826 :   return make_unbound_class_template_raw (context, name, parm_list);
    4714                 :             : }
    4715                 :             : 
    4716                 :             : /* Build an UNBOUND_CLASS_TEMPLATE.  */
    4717                 :             : 
    4718                 :             : tree
    4719                 :       54870 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
    4720                 :             : {
    4721                 :             :   /* Build the UNBOUND_CLASS_TEMPLATE.  */
    4722                 :       54870 :   tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
    4723                 :       54870 :   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
    4724                 :       54870 :   TREE_TYPE (t) = NULL_TREE;
    4725                 :       54870 :   SET_TYPE_STRUCTURAL_EQUALITY (t);
    4726                 :             : 
    4727                 :             :   /* Build the corresponding TEMPLATE_DECL.  */
    4728                 :       54870 :   tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
    4729                 :       54870 :   TYPE_NAME (t) = d;
    4730                 :       54870 :   TYPE_STUB_DECL (t) = d;
    4731                 :       54870 :   DECL_CONTEXT (d) = TYPE_CONTEXT (t);
    4732                 :       54870 :   DECL_ARTIFICIAL (d) = 1;
    4733                 :       54870 :   DECL_TEMPLATE_PARMS (d) = parm_list;
    4734                 :             : 
    4735                 :       54870 :   return t;
    4736                 :             : }
    4737                 :             : 
    4738                 :             : 
    4739                 :             : 
    4740                 :             : /* Push the declarations of builtin types into the global namespace.
    4741                 :             :    RID_INDEX is the index of the builtin type in the array
    4742                 :             :    RID_POINTERS.  NAME is the name used when looking up the builtin
    4743                 :             :    type.  TYPE is the _TYPE node for the builtin type.
    4744                 :             : 
    4745                 :             :    The calls to set_global_binding below should be
    4746                 :             :    eliminated.  Built-in types should not be looked up name; their
    4747                 :             :    names are keywords that the parser can recognize.  However, there
    4748                 :             :    is code in c-common.cc that uses identifier_global_value to look up
    4749                 :             :    built-in types by name.  */
    4750                 :             : 
    4751                 :             : void
    4752                 :     3955439 : record_builtin_type (enum rid rid_index,
    4753                 :             :                      const char* name,
    4754                 :             :                      tree type)
    4755                 :             : {
    4756                 :     3955439 :   tree decl = NULL_TREE;
    4757                 :             : 
    4758                 :     3955439 :   if (name)
    4759                 :             :     {
    4760                 :     2316282 :       tree tname = get_identifier (name);
    4761                 :     2316282 :       tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
    4762                 :     2316282 :       DECL_ARTIFICIAL (tdecl) = 1;
    4763                 :     2316282 :       set_global_binding (tdecl);
    4764                 :     2316282 :       decl = tdecl;
    4765                 :             :     }
    4766                 :             : 
    4767                 :     3955439 :   if ((int) rid_index < (int) RID_MAX)
    4768                 :     2412703 :     if (tree rname = ridpointers[(int) rid_index])
    4769                 :     1834177 :       if (!decl || DECL_NAME (decl) != rname)
    4770                 :             :         {
    4771                 :     1349894 :           tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
    4772                 :     1349894 :           DECL_ARTIFICIAL (rdecl) = 1;
    4773                 :     1349894 :           set_global_binding (rdecl);
    4774                 :     1349894 :           if (!decl)
    4775                 :             :             decl = rdecl;
    4776                 :             :         }
    4777                 :             : 
    4778                 :     3666176 :   if (decl)
    4779                 :             :     {
    4780                 :     3376913 :       if (!TYPE_NAME (type))
    4781                 :     2798387 :         TYPE_NAME (type) = decl;
    4782                 :     3376913 :       debug_hooks->type_decl (decl, 0);
    4783                 :             :     }
    4784                 :     3955439 : }
    4785                 :             : 
    4786                 :             : /* Push a type into the namespace so that the back ends ignore it.  */
    4787                 :             : 
    4788                 :             : static void
    4789                 :      289263 : record_unknown_type (tree type, const char* name)
    4790                 :             : {
    4791                 :      289263 :   tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
    4792                 :             :                                     TYPE_DECL, get_identifier (name), type));
    4793                 :             :   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
    4794                 :      289263 :   DECL_IGNORED_P (decl) = 1;
    4795                 :      289263 :   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    4796                 :      289263 :   TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
    4797                 :      289263 :   SET_TYPE_ALIGN (type, 1);
    4798                 :      289263 :   TYPE_USER_ALIGN (type) = 0;
    4799                 :      289263 :   SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
    4800                 :      289263 : }
    4801                 :             : 
    4802                 :             : /* Create all the predefined identifiers.  */
    4803                 :             : 
    4804                 :             : static void
    4805                 :       96421 : initialize_predefined_identifiers (void)
    4806                 :             : {
    4807                 :       96421 :   struct predefined_identifier
    4808                 :             :   {
    4809                 :             :     const char *name; /* Name.  */
    4810                 :             :     tree *node;  /* Node to store it in.  */
    4811                 :             :     cp_identifier_kind kind;  /* Kind of identifier.  */
    4812                 :             :   };
    4813                 :             : 
    4814                 :             :   /* A table of identifiers to create at startup.  */
    4815                 :       96421 :   static const predefined_identifier predefined_identifiers[] = {
    4816                 :             :     {"C++", &lang_name_cplusplus, cik_normal},
    4817                 :             :     {"C", &lang_name_c, cik_normal},
    4818                 :             :     /* Some of these names have a trailing space so that it is
    4819                 :             :        impossible for them to conflict with names written by users.  */
    4820                 :             :     {"__ct ", &ctor_identifier, cik_ctor},
    4821                 :             :     {"__ct_base ", &base_ctor_identifier, cik_ctor},
    4822                 :             :     {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
    4823                 :             :     {"__dt ", &dtor_identifier, cik_dtor},
    4824                 :             :     {"__dt_base ", &base_dtor_identifier, cik_dtor},
    4825                 :             :     {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
    4826                 :             :     {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
    4827                 :             :     {"__conv_op ", &conv_op_identifier, cik_conv_op},
    4828                 :             :     {"__in_chrg", &in_charge_identifier, cik_normal},
    4829                 :             :     {"__as_base ", &as_base_identifier, cik_normal},
    4830                 :             :     {"this", &this_identifier, cik_normal},
    4831                 :             :     {"__delta", &delta_identifier, cik_normal},
    4832                 :             :     {"__pfn", &pfn_identifier, cik_normal},
    4833                 :             :     {"_vptr", &vptr_identifier, cik_normal},
    4834                 :             :     {"__vtt_parm", &vtt_parm_identifier, cik_normal},
    4835                 :             :     {"::", &global_identifier, cik_normal},
    4836                 :             :       /* The demangler expects anonymous namespaces to be called
    4837                 :             :          something starting with '_GLOBAL__N_'.  It no longer needs
    4838                 :             :          to be unique to the TU.  */
    4839                 :             :     {"_GLOBAL__N_1", &anon_identifier, cik_normal},
    4840                 :             :     {"auto", &auto_identifier, cik_normal},
    4841                 :             :     {"decltype(auto)", &decltype_auto_identifier, cik_normal},
    4842                 :             :     {"initializer_list", &init_list_identifier, cik_normal},
    4843                 :             :     {"__for_range ", &for_range__identifier, cik_normal},
    4844                 :             :     {"__for_begin ", &for_begin__identifier, cik_normal},
    4845                 :             :     {"__for_end ", &for_end__identifier, cik_normal},
    4846                 :             :     {"__for_range", &for_range_identifier, cik_normal},
    4847                 :             :     {"__for_begin", &for_begin_identifier, cik_normal},
    4848                 :             :     {"__for_end", &for_end_identifier, cik_normal},
    4849                 :             :     {"abi_tag", &abi_tag_identifier, cik_normal},
    4850                 :             :     {"aligned", &aligned_identifier, cik_normal},
    4851                 :             :     {"begin", &begin_identifier, cik_normal},
    4852                 :             :     {"end", &end_identifier, cik_normal},
    4853                 :             :     {"get", &get__identifier, cik_normal},
    4854                 :             :     {"gnu", &gnu_identifier, cik_normal},
    4855                 :             :     {"tuple_element", &tuple_element_identifier, cik_normal},
    4856                 :             :     {"tuple_size", &tuple_size_identifier, cik_normal},
    4857                 :             :     {"type", &type_identifier, cik_normal},
    4858                 :             :     {"value", &value_identifier, cik_normal},
    4859                 :             :     {"_FUN", &fun_identifier, cik_normal},
    4860                 :             :     {"__closure", &closure_identifier, cik_normal},
    4861                 :             :     {"heap uninit", &heap_uninit_identifier, cik_normal},
    4862                 :             :     {"heap ", &heap_identifier, cik_normal},
    4863                 :             :     {"heap deleted", &heap_deleted_identifier, cik_normal},
    4864                 :             :     {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
    4865                 :             :     {"heap []", &heap_vec_identifier, cik_normal},
    4866                 :             :     {"omp", &omp_identifier, cik_normal},
    4867                 :             :     {"internal ", &internal_identifier, cik_normal},
    4868                 :             :     {NULL, NULL, cik_normal}
    4869                 :             :   };
    4870                 :             : 
    4871                 :     4628208 :   for (const predefined_identifier *pid = predefined_identifiers;
    4872                 :     4628208 :        pid->name; ++pid)
    4873                 :             :     {
    4874                 :     4531787 :       *pid->node = get_identifier (pid->name);
    4875                 :             :       /* Some of these identifiers already have a special kind.  */
    4876                 :     4531787 :       if (pid->kind != cik_normal)
    4877                 :      771368 :         set_identifier_kind (*pid->node, pid->kind);
    4878                 :             :     }
    4879                 :       96421 : }
    4880                 :             : 
    4881                 :             : /* Build a specific variant of operator new.  */
    4882                 :             : 
    4883                 :             : static void
    4884                 :      172059 : cxx_build_operator_new (tree newtype)
    4885                 :             : {
    4886                 :      172059 :   tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    4887                 :      172059 :   DECL_IS_MALLOC (opnew) = 1;
    4888                 :      172059 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4889                 :      172059 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    4890                 :      172059 :   opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    4891                 :      172059 :   DECL_IS_MALLOC (opnew) = 1;
    4892                 :      172059 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4893                 :      172059 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    4894                 :      172059 : }
    4895                 :             : 
    4896                 :             : /* Build a specific variant of operator delete.  */
    4897                 :             : 
    4898                 :             : static void
    4899                 :      324569 : cxx_build_operator_delete (tree deltype)
    4900                 :             : {
    4901                 :      324569 :   tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4902                 :      324569 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4903                 :      324569 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4904                 :      324569 :   opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4905                 :      324569 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4906                 :      324569 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4907                 :      324569 : }
    4908                 :             : 
    4909                 :             : /* Declare all variants of operator new and delete.  */
    4910                 :             : 
    4911                 :             : static void
    4912                 :       96421 : cxx_init_operator_new_delete_decls (void)
    4913                 :             : {
    4914                 :       96421 :   tree newattrs, extvisattr;
    4915                 :       96421 :   tree newtype, deltype;
    4916                 :       96421 :   tree ptr_ftype_sizetype;
    4917                 :       96421 :   tree new_eh_spec;
    4918                 :       96421 :   tree void_ftype_ptr = build_function_type_list (void_type_node,
    4919                 :             :                                                   ptr_type_node, NULL_TREE);
    4920                 :       96421 :   void_ftype_ptr
    4921                 :       96421 :     = build_exception_variant (void_ftype_ptr, empty_except_spec);
    4922                 :             : 
    4923                 :       96421 :   ptr_ftype_sizetype
    4924                 :       96421 :     = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
    4925                 :       96421 :   if (cxx_dialect == cxx98)
    4926                 :             :     {
    4927                 :       14004 :       tree bad_alloc_id;
    4928                 :       14004 :       tree bad_alloc_type_node;
    4929                 :       14004 :       tree bad_alloc_decl;
    4930                 :             : 
    4931                 :       14004 :       push_nested_namespace (std_node);
    4932                 :       14004 :       bad_alloc_id = get_identifier ("bad_alloc");
    4933                 :       14004 :       bad_alloc_type_node = make_class_type (RECORD_TYPE);
    4934                 :       14004 :       TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
    4935                 :       14004 :       bad_alloc_decl
    4936                 :       14004 :         = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
    4937                 :       14004 :       DECL_CONTEXT (bad_alloc_decl) = current_namespace;
    4938                 :       14004 :       pop_nested_namespace (std_node);
    4939                 :             : 
    4940                 :       14004 :       new_eh_spec
    4941                 :       14004 :         = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
    4942                 :             :     }
    4943                 :             :   else
    4944                 :       82417 :     new_eh_spec = noexcept_false_spec;
    4945                 :             : 
    4946                 :       96421 :   extvisattr = build_tree_list (get_identifier ("externally_visible"),
    4947                 :             :                                 NULL_TREE);
    4948                 :       96421 :   newattrs = tree_cons (get_identifier ("alloc_size"),
    4949                 :             :                         build_tree_list (NULL_TREE, integer_one_node),
    4950                 :             :                         extvisattr);
    4951                 :       96421 :   newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
    4952                 :       96421 :   newtype = build_exception_variant (newtype, new_eh_spec);
    4953                 :       96421 :   deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
    4954                 :       96421 :   deltype = build_exception_variant (deltype, empty_except_spec);
    4955                 :       96421 :   cxx_build_operator_new (newtype);
    4956                 :       96421 :   cxx_build_operator_delete (deltype);
    4957                 :       96421 :   if (flag_sized_deallocation)
    4958                 :             :     {
    4959                 :             :       /* Also push the sized deallocation variants:
    4960                 :             :            void operator delete(void*, std::size_t) throw();
    4961                 :             :            void operator delete[](void*, std::size_t) throw();  */
    4962                 :       76877 :       tree void_ftype_ptr_size
    4963                 :       76877 :         = build_function_type_list (void_type_node, ptr_type_node,
    4964                 :             :                                     size_type_node, NULL_TREE);
    4965                 :       76877 :       deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
    4966                 :             :                                                  extvisattr);
    4967                 :       76877 :       deltype = build_exception_variant (deltype, empty_except_spec);
    4968                 :       76877 :       cxx_build_operator_delete (deltype);
    4969                 :             :     }
    4970                 :             : 
    4971                 :       96421 :   if (aligned_new_threshold)
    4972                 :             :     {
    4973                 :       75638 :       push_nested_namespace (std_node);
    4974                 :       75638 :       tree align_id = get_identifier ("align_val_t");
    4975                 :       75638 :       align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
    4976                 :             :                                     NULL_TREE, /*scoped*/true, NULL);
    4977                 :       75638 :       pop_nested_namespace (std_node);
    4978                 :             : 
    4979                 :             :       /* operator new (size_t, align_val_t); */
    4980                 :       75638 :       newtype = build_function_type_list (ptr_type_node, size_type_node,
    4981                 :             :                                           align_type_node, NULL_TREE);
    4982                 :       75638 :       newtype = cp_build_type_attribute_variant (newtype, newattrs);
    4983                 :       75638 :       newtype = build_exception_variant (newtype, new_eh_spec);
    4984                 :       75638 :       cxx_build_operator_new (newtype);
    4985                 :             : 
    4986                 :             :       /* operator delete (void *, align_val_t); */
    4987                 :       75638 :       deltype = build_function_type_list (void_type_node, ptr_type_node,
    4988                 :             :                                           align_type_node, NULL_TREE);
    4989                 :       75638 :       deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    4990                 :       75638 :       deltype = build_exception_variant (deltype, empty_except_spec);
    4991                 :       75638 :       cxx_build_operator_delete (deltype);
    4992                 :             : 
    4993                 :       75638 :       if (flag_sized_deallocation)
    4994                 :             :         {
    4995                 :             :           /* operator delete (void *, size_t, align_val_t); */
    4996                 :       75633 :           deltype = build_function_type_list (void_type_node, ptr_type_node,
    4997                 :             :                                               size_type_node, align_type_node,
    4998                 :             :                                               NULL_TREE);
    4999                 :       75633 :           deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    5000                 :       75633 :           deltype = build_exception_variant (deltype, empty_except_spec);
    5001                 :       75633 :           cxx_build_operator_delete (deltype);
    5002                 :             :         }
    5003                 :             :     }
    5004                 :       96421 : }
    5005                 :             : 
    5006                 :             : /* Create the predefined scalar types of C,
    5007                 :             :    and some nodes representing standard constants (0, 1, (void *)0).
    5008                 :             :    Initialize the global binding level.
    5009                 :             :    Make definitions for built-in primitive functions.  */
    5010                 :             : 
    5011                 :             : void
    5012                 :       96421 : cxx_init_decl_processing (void)
    5013                 :             : {
    5014                 :       96421 :   tree void_ftype;
    5015                 :             : 
    5016                 :             :   /* Create all the identifiers we need.  */
    5017                 :       96421 :   initialize_predefined_identifiers ();
    5018                 :             : 
    5019                 :             :   /* Create the global variables.  */
    5020                 :       96421 :   push_to_top_level ();
    5021                 :             : 
    5022                 :       96421 :   current_function_decl = NULL_TREE;
    5023                 :       96421 :   current_binding_level = NULL;
    5024                 :             :   /* Enter the global namespace.  */
    5025                 :       96421 :   gcc_assert (global_namespace == NULL_TREE);
    5026                 :       96421 :   global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
    5027                 :             :                                       void_type_node);
    5028                 :       96421 :   TREE_PUBLIC (global_namespace) = true;
    5029                 :       96421 :   DECL_MODULE_EXPORT_P (global_namespace) = true;
    5030                 :       96421 :   DECL_CONTEXT (global_namespace)
    5031                 :       96421 :     = build_translation_unit_decl (get_identifier (main_input_filename));
    5032                 :             :   /* Remember whether we want the empty class passing ABI change warning
    5033                 :             :      in this TU.  */
    5034                 :       96421 :   TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
    5035                 :      123880 :     = warn_abi && abi_version_crosses (12);
    5036                 :       96421 :   debug_hooks->register_main_translation_unit
    5037                 :       96421 :     (DECL_CONTEXT (global_namespace));
    5038                 :       96421 :   begin_scope (sk_namespace, global_namespace);
    5039                 :       96421 :   current_namespace = global_namespace;
    5040                 :             : 
    5041                 :       96421 :   if (flag_visibility_ms_compat)
    5042                 :           6 :     default_visibility = VISIBILITY_HIDDEN;
    5043                 :             : 
    5044                 :             :   /* Initially, C.  */
    5045                 :       96421 :   current_lang_name = lang_name_c;
    5046                 :             : 
    5047                 :             :   /* Create the `std' namespace.  */
    5048                 :       96421 :   push_namespace (get_identifier ("std"));
    5049                 :       96421 :   std_node = current_namespace;
    5050                 :       96421 :   pop_namespace ();
    5051                 :             : 
    5052                 :       96421 :   flag_noexcept_type = (cxx_dialect >= cxx17);
    5053                 :             : 
    5054                 :       96421 :   c_common_nodes_and_builtins ();
    5055                 :             : 
    5056                 :       96421 :   tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
    5057                 :       96421 :   tree decl
    5058                 :       96421 :     = add_builtin_function ("__builtin_is_constant_evaluated",
    5059                 :             :                             bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    5060                 :             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5061                 :       96421 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5062                 :             : 
    5063                 :             :   /* The concrete return type of __builtin_source_location is
    5064                 :             :      const std::source_location::__impl*, but we can't form the type
    5065                 :             :      at this point.  So we initially declare it with an auto return
    5066                 :             :      type which we then "deduce" from require_deduced_type upon first use.  */
    5067                 :       96421 :   tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
    5068                 :       96421 :   decl = add_builtin_function ("__builtin_source_location",
    5069                 :             :                                auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
    5070                 :             :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5071                 :       96421 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5072                 :             : 
    5073                 :       96421 :   tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
    5074                 :             :                                                         NULL_TREE);
    5075                 :       96421 :   decl
    5076                 :       96421 :     = add_builtin_function ("__builtin_is_corresponding_member",
    5077                 :             :                             bool_vaftype,
    5078                 :             :                             CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
    5079                 :             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5080                 :       96421 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5081                 :             : 
    5082                 :       96421 :   decl
    5083                 :       96421 :     = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
    5084                 :             :                             bool_vaftype,
    5085                 :             :                             CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
    5086                 :             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5087                 :       96421 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5088                 :             : 
    5089                 :       96421 :   if (cxx_dialect >= cxx26)
    5090                 :             :     {
    5091                 :       23359 :       tree void_ptrintftype
    5092                 :       23359 :         = build_function_type_list (void_type_node, ptr_type_node,
    5093                 :             :                                     integer_type_node, NULL_TREE);
    5094                 :       23359 :       decl = add_builtin_function ("__builtin_eh_ptr_adjust_ref",
    5095                 :             :                                    void_ptrintftype,
    5096                 :             :                                    CP_BUILT_IN_EH_PTR_ADJUST_REF,
    5097                 :             :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5098                 :       23359 :       set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5099                 :             :     }
    5100                 :             : 
    5101                 :       96421 :   integer_two_node = build_int_cst (NULL_TREE, 2);
    5102                 :             : 
    5103                 :             :   /* Guess at the initial static decls size.  */
    5104                 :       96421 :   vec_alloc (static_decls, 500);
    5105                 :             : 
    5106                 :             :   /* ... and keyed classes.  */
    5107                 :       96421 :   vec_alloc (keyed_classes, 100);
    5108                 :             : 
    5109                 :       96421 :   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
    5110                 :       96421 :   truthvalue_type_node = boolean_type_node;
    5111                 :       96421 :   truthvalue_false_node = boolean_false_node;
    5112                 :       96421 :   truthvalue_true_node = boolean_true_node;
    5113                 :             : 
    5114                 :       96421 :   empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
    5115                 :       96421 :   noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
    5116                 :       96421 :   noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
    5117                 :       96421 :   noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
    5118                 :             :                                             NULL_TREE);
    5119                 :             : 
    5120                 :             : #if 0
    5121                 :             :   record_builtin_type (RID_MAX, NULL, string_type_node);
    5122                 :             : #endif
    5123                 :             : 
    5124                 :       96421 :   delta_type_node = ptrdiff_type_node;
    5125                 :       96421 :   vtable_index_type = ptrdiff_type_node;
    5126                 :             : 
    5127                 :       96421 :   vtt_parm_type = build_pointer_type (const_ptr_type_node);
    5128                 :       96421 :   void_ftype = build_function_type_list (void_type_node, NULL_TREE);
    5129                 :             : 
    5130                 :             :   /* Create the conversion operator marker.  This operator's DECL_NAME
    5131                 :             :      is in the identifier table, so we can use identifier equality to
    5132                 :             :      find it.  */
    5133                 :       96421 :   conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
    5134                 :             :                                     void_ftype);
    5135                 :             : 
    5136                 :             :   /* C++ extensions */
    5137                 :             : 
    5138                 :       96421 :   unknown_type_node = make_node (LANG_TYPE);
    5139                 :       96421 :   record_unknown_type (unknown_type_node, "unknown type");
    5140                 :             : 
    5141                 :             :   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
    5142                 :       96421 :   TREE_TYPE (unknown_type_node) = unknown_type_node;
    5143                 :             : 
    5144                 :             :   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
    5145                 :             :      result.  */
    5146                 :       96421 :   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
    5147                 :       96421 :   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
    5148                 :             : 
    5149                 :       96421 :   init_list_type_node = make_node (LANG_TYPE);
    5150                 :       96421 :   record_unknown_type (init_list_type_node, "init list");
    5151                 :             : 
    5152                 :             :   /* Used when parsing to distinguish parameter-lists () and (void).  */
    5153                 :       96421 :   explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
    5154                 :             : 
    5155                 :       96421 :   {
    5156                 :             :     /* Make sure we get a unique function type, so we can give
    5157                 :             :        its pointer type a name.  (This wins for gdb.) */
    5158                 :       96421 :     tree vfunc_type = make_node (FUNCTION_TYPE);
    5159                 :       96421 :     TREE_TYPE (vfunc_type) = integer_type_node;
    5160                 :       96421 :     TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
    5161                 :       96421 :     layout_type (vfunc_type);
    5162                 :             : 
    5163                 :       96421 :     vtable_entry_type = build_pointer_type (vfunc_type);
    5164                 :             :   }
    5165                 :       96421 :   record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
    5166                 :             : 
    5167                 :       96421 :   vtbl_type_node
    5168                 :       96421 :     = build_cplus_array_type (vtable_entry_type, NULL_TREE);
    5169                 :       96421 :   layout_type (vtbl_type_node);
    5170                 :       96421 :   vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
    5171                 :       96421 :   record_builtin_type (RID_MAX, NULL, vtbl_type_node);
    5172                 :       96421 :   vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
    5173                 :       96421 :   layout_type (vtbl_ptr_type_node);
    5174                 :       96421 :   record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
    5175                 :             : 
    5176                 :       96421 :   push_namespace (get_identifier ("__cxxabiv1"));
    5177                 :       96421 :   abi_node = current_namespace;
    5178                 :       96421 :   pop_namespace ();
    5179                 :             : 
    5180                 :       96421 :   any_targ_node = make_node (LANG_TYPE);
    5181                 :       96421 :   record_unknown_type (any_targ_node, "any type");
    5182                 :             : 
    5183                 :             :   /* Now, C++.  */
    5184                 :       96421 :   current_lang_name = lang_name_cplusplus;
    5185                 :             : 
    5186                 :       96421 :   if (aligned_new_threshold > 1
    5187                 :       96421 :       && !pow2p_hwi (aligned_new_threshold))
    5188                 :             :     {
    5189                 :           0 :       error ("%<-faligned-new=%d%> is not a power of two",
    5190                 :             :              aligned_new_threshold);
    5191                 :           0 :       aligned_new_threshold = 1;
    5192                 :             :     }
    5193                 :       96421 :   if (aligned_new_threshold == -1)
    5194                 :      117190 :     aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
    5195                 :       96421 :   if (aligned_new_threshold == 1)
    5196                 :       75635 :     aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
    5197                 :             : 
    5198                 :             :   /* Ensure attribs.cc is initialized.  */
    5199                 :       96421 :   init_attributes ();
    5200                 :       96421 :   cxx_init_operator_new_delete_decls ();
    5201                 :             : 
    5202                 :             :   /* C++-specific nullptr initialization.  */
    5203                 :       96421 :   if (abi_version_at_least (9))
    5204                 :       96250 :     SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    5205                 :       96421 :   record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
    5206                 :             : 
    5207                 :       96421 :   if (! supports_one_only ())
    5208                 :           0 :     flag_weak = 0;
    5209                 :             : 
    5210                 :       96421 :   abort_fndecl
    5211                 :       96421 :     = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
    5212                 :             :                             ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
    5213                 :       96421 :   if (flag_weak)
    5214                 :             :     /* If no definition is available, resolve references to NULL.  */
    5215                 :       96391 :     declare_weak (abort_fndecl);
    5216                 :             : 
    5217                 :             :   /* Perform other language dependent initializations.  */
    5218                 :       96421 :   init_class_processing ();
    5219                 :       96421 :   init_rtti_processing ();
    5220                 :       96421 :   init_template_processing ();
    5221                 :             : 
    5222                 :       96421 :   if (flag_exceptions)
    5223                 :       95181 :     init_exception_processing ();
    5224                 :             : 
    5225                 :       96421 :   if (flag_contracts)
    5226                 :         153 :     init_terminate_fn ();
    5227                 :             : 
    5228                 :       96421 :   if (modules_p ())
    5229                 :        4321 :     init_modules (parse_in);
    5230                 :             : 
    5231                 :       96421 :   make_fname_decl = cp_make_fname_decl;
    5232                 :       96421 :   start_fname_decls ();
    5233                 :             : 
    5234                 :             :   /* Show we use EH for cleanups.  */
    5235                 :       96421 :   if (flag_exceptions)
    5236                 :       95181 :     using_eh_for_cleanups ();
    5237                 :             : 
    5238                 :             :   /* Check that the hardware interference sizes are at least
    5239                 :             :      alignof(max_align_t), as required by the standard.  */
    5240                 :       96421 :   const int max_align = max_align_t_align () / BITS_PER_UNIT;
    5241                 :       96421 :   if (OPTION_SET_P (param_destruct_interfere_size))
    5242                 :             :     {
    5243                 :           0 :       if (param_destruct_interfere_size < max_align)
    5244                 :           0 :         error ("%<--param destructive-interference-size=%d%> is less than "
    5245                 :             :                "%d", param_destruct_interfere_size, max_align);
    5246                 :           0 :       else if (param_destruct_interfere_size < param_l1_cache_line_size)
    5247                 :           0 :         warning (OPT_Winterference_size,
    5248                 :             :                  "%<--param destructive-interference-size=%d%> "
    5249                 :             :                  "is less than %<--param l1-cache-line-size=%d%>",
    5250                 :             :                  param_destruct_interfere_size, param_l1_cache_line_size);
    5251                 :             :     }
    5252                 :       96421 :   else if (param_destruct_interfere_size)
    5253                 :             :     /* Assume the internal value is OK.  */;
    5254                 :           0 :   else if (param_l1_cache_line_size >= max_align)
    5255                 :           0 :     param_destruct_interfere_size = param_l1_cache_line_size;
    5256                 :             :   /* else leave it unset.  */
    5257                 :             : 
    5258                 :       96421 :   if (OPTION_SET_P (param_construct_interfere_size))
    5259                 :             :     {
    5260                 :           0 :       if (param_construct_interfere_size < max_align)
    5261                 :           0 :         error ("%<--param constructive-interference-size=%d%> is less than "
    5262                 :             :                "%d", param_construct_interfere_size, max_align);
    5263                 :           0 :       else if (param_construct_interfere_size > param_l1_cache_line_size
    5264                 :           0 :                && param_l1_cache_line_size >= max_align)
    5265                 :           0 :         warning (OPT_Winterference_size,
    5266                 :             :                  "%<--param constructive-interference-size=%d%> "
    5267                 :             :                  "is greater than %<--param l1-cache-line-size=%d%>",
    5268                 :             :                  param_construct_interfere_size, param_l1_cache_line_size);
    5269                 :             :     }
    5270                 :       96421 :   else if (param_construct_interfere_size)
    5271                 :             :     /* Assume the internal value is OK.  */;
    5272                 :           0 :   else if (param_l1_cache_line_size >= max_align)
    5273                 :           0 :     param_construct_interfere_size = param_l1_cache_line_size;
    5274                 :       96421 : }
    5275                 :             : 
    5276                 :             : /* Enter an abi node in global-module context.  returns a cookie to
    5277                 :             :    give to pop_abi_namespace.  */
    5278                 :             : 
    5279                 :             : unsigned
    5280                 :       62033 : push_abi_namespace (tree node)
    5281                 :             : {
    5282                 :       62033 :   push_nested_namespace (node);
    5283                 :       62033 :   push_visibility ("default", 2);
    5284                 :       62033 :   unsigned flags = module_kind;
    5285                 :       62033 :   module_kind = 0;
    5286                 :       62033 :   return flags;
    5287                 :             : }
    5288                 :             : 
    5289                 :             : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
    5290                 :             :    you.  */
    5291                 :             : 
    5292                 :             : void
    5293                 :       62033 : pop_abi_namespace (unsigned flags, tree node)
    5294                 :             : {
    5295                 :       62033 :   module_kind = flags;
    5296                 :       62033 :   pop_visibility (2);
    5297                 :       62033 :   pop_nested_namespace (node);
    5298                 :       62033 : }
    5299                 :             : 
    5300                 :             : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
    5301                 :             :    the decl, LOC is the location to give the decl, NAME is the
    5302                 :             :    initialization string and TYPE_DEP indicates whether NAME depended
    5303                 :             :    on the type of the function. We make use of that to detect
    5304                 :             :    __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
    5305                 :             :    at the point of first use, so we mustn't push the decl now.  */
    5306                 :             : 
    5307                 :             : static tree
    5308                 :      114165 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
    5309                 :             : {
    5310                 :      114165 :   tree domain = NULL_TREE;
    5311                 :      114165 :   tree init = NULL_TREE;
    5312                 :             : 
    5313                 :      114165 :   if (!(type_dep && current_function_decl && in_template_context))
    5314                 :             :     {
    5315                 :       35764 :       const char *name = NULL;
    5316                 :       35764 :       bool release_name = false;
    5317                 :             : 
    5318                 :       35764 :       if (current_function_decl == NULL_TREE)
    5319                 :             :         name = "top level";
    5320                 :       35750 :       else if (type_dep == 0)
    5321                 :             :         {
    5322                 :             :           /* __FUNCTION__ */
    5323                 :         605 :           name = fname_as_string (type_dep);
    5324                 :         605 :           release_name = true;
    5325                 :             :         }
    5326                 :             :       else
    5327                 :             :         {
    5328                 :             :           /* __PRETTY_FUNCTION__ */
    5329                 :       35145 :           gcc_checking_assert (type_dep == 1);
    5330                 :       35145 :           name = cxx_printable_name (current_function_decl, 2);
    5331                 :             :         }
    5332                 :             : 
    5333                 :       35764 :       size_t length = strlen (name);
    5334                 :       35764 :       domain = build_index_type (size_int (length));
    5335                 :       35764 :       init = build_string (length + 1, name);
    5336                 :       35764 :       if (release_name)
    5337                 :         605 :         free (const_cast<char *> (name));
    5338                 :             :     }
    5339                 :             : 
    5340                 :      114165 :   tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
    5341                 :      114165 :   type = build_cplus_array_type (type, domain);
    5342                 :             : 
    5343                 :      114165 :   if (init)
    5344                 :       35764 :     TREE_TYPE (init) = type;
    5345                 :             :   else
    5346                 :       78401 :     init = error_mark_node;
    5347                 :             : 
    5348                 :      114165 :   tree decl = build_decl (loc, VAR_DECL, id, type);
    5349                 :             : 
    5350                 :      114165 :   TREE_READONLY (decl) = 1;
    5351                 :      114165 :   DECL_ARTIFICIAL (decl) = 1;
    5352                 :      114165 :   DECL_DECLARED_CONSTEXPR_P (decl) = 1;
    5353                 :      114165 :   TREE_STATIC (decl) = 1;
    5354                 :             : 
    5355                 :      114165 :   TREE_USED (decl) = 1;
    5356                 :             : 
    5357                 :      114165 :   SET_DECL_VALUE_EXPR (decl, init);
    5358                 :      114165 :   DECL_HAS_VALUE_EXPR_P (decl) = 1;
    5359                 :             :   /* For decl_constant_var_p.  */
    5360                 :      114165 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    5361                 :             : 
    5362                 :      114165 :   if (current_function_decl)
    5363                 :             :     {
    5364                 :      114151 :       DECL_CONTEXT (decl) = current_function_decl;
    5365                 :      114151 :       decl = pushdecl_outermost_localscope (decl);
    5366                 :      114151 :       if (decl != error_mark_node)
    5367                 :      114148 :         add_decl_expr (decl);
    5368                 :             :       else
    5369                 :           3 :         gcc_assert (seen_error ());
    5370                 :             :     }
    5371                 :             :   else
    5372                 :             :     {
    5373                 :          14 :       DECL_THIS_STATIC (decl) = true;
    5374                 :          14 :       decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
    5375                 :             :     }
    5376                 :             : 
    5377                 :      114165 :   return decl;
    5378                 :             : }
    5379                 :             : 
    5380                 :             : /* Install DECL as a builtin function at current global scope.  Return
    5381                 :             :    the new decl (if we found an existing version).  Also installs it
    5382                 :             :    into ::std, if it's not '_*'.  */
    5383                 :             : 
    5384                 :             : tree
    5385                 :   222739725 : cxx_builtin_function (tree decl)
    5386                 :             : {
    5387                 :   222739725 :   retrofit_lang_decl (decl);
    5388                 :             : 
    5389                 :   222739725 :   DECL_ARTIFICIAL (decl) = 1;
    5390                 :   222739725 :   SET_DECL_LANGUAGE (decl, lang_c);
    5391                 :             :   /* Runtime library routines are, by definition, available in an
    5392                 :             :      external shared object.  */
    5393                 :   222739725 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    5394                 :   222739725 :   DECL_VISIBILITY_SPECIFIED (decl) = 1;
    5395                 :             : 
    5396                 :   222739725 :   tree id = DECL_NAME (decl);
    5397                 :   222739725 :   const char *name = IDENTIFIER_POINTER (id);
    5398                 :   222739725 :   bool hiding = false;
    5399                 :   222739725 :   if (name[0] != '_' || name[1] != '_')
    5400                 :             :     /* In the user's namespace, it must be declared before use.  */
    5401                 :             :     hiding = true;
    5402                 :   186712727 :   else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
    5403                 :   186712727 :            && !startswith (name + 2, "builtin_")
    5404                 :   209160825 :            && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
    5405                 :             :                            "_chk", strlen ("_chk") + 1))
    5406                 :             :     /* Treat __*_chk fortification functions as anticipated as well,
    5407                 :             :        unless they are __builtin_*_chk.  */
    5408                 :             :     hiding = true;
    5409                 :             : 
    5410                 :             :   /* All builtins that don't begin with an '_' should additionally
    5411                 :             :      go in the 'std' namespace.  */
    5412                 :   222739725 :   if (name[0] != '_')
    5413                 :             :     {
    5414                 :    35894579 :       tree std_decl = copy_decl (decl);
    5415                 :             : 
    5416                 :    35894579 :       push_nested_namespace (std_node);
    5417                 :    35894579 :       DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
    5418                 :    35894579 :       pushdecl (std_decl, hiding);
    5419                 :    35894579 :       pop_nested_namespace (std_node);
    5420                 :             :     }
    5421                 :             : 
    5422                 :   222739725 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    5423                 :   222739725 :   decl = pushdecl (decl, hiding);
    5424                 :             : 
    5425                 :   222739725 :   return decl;
    5426                 :             : }
    5427                 :             : 
    5428                 :             : /* Like cxx_builtin_function, but guarantee the function is added to the global
    5429                 :             :    scope.  This is to allow function specific options to add new machine
    5430                 :             :    dependent builtins when the target ISA changes via attribute((target(...)))
    5431                 :             :    which saves space on program startup if the program does not use non-generic
    5432                 :             :    ISAs.  */
    5433                 :             : 
    5434                 :             : tree
    5435                 :      629402 : cxx_builtin_function_ext_scope (tree decl)
    5436                 :             : {
    5437                 :      629402 :   push_nested_namespace (global_namespace);
    5438                 :      629402 :   decl = cxx_builtin_function (decl);
    5439                 :      629402 :   pop_nested_namespace (global_namespace);
    5440                 :             : 
    5441                 :      629402 :   return decl;
    5442                 :             : }
    5443                 :             : 
    5444                 :             : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    5445                 :             : 
    5446                 :             : tree
    5447                 :           0 : cxx_simulate_builtin_function_decl (tree decl)
    5448                 :             : {
    5449                 :           0 :   retrofit_lang_decl (decl);
    5450                 :             : 
    5451                 :           0 :   DECL_ARTIFICIAL (decl) = 1;
    5452                 :           0 :   SET_DECL_LANGUAGE (decl, lang_cplusplus);
    5453                 :           0 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    5454                 :           0 :   return pushdecl (decl);
    5455                 :             : }
    5456                 :             : 
    5457                 :             : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
    5458                 :             :    function.  Not called directly.  */
    5459                 :             : 
    5460                 :             : static tree
    5461                 :     1557078 : build_library_fn (tree name, enum tree_code operator_code, tree type,
    5462                 :             :                   int ecf_flags)
    5463                 :             : {
    5464                 :     1557078 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    5465                 :     1557078 :   DECL_EXTERNAL (fn) = 1;
    5466                 :     1557078 :   TREE_PUBLIC (fn) = 1;
    5467                 :     1557078 :   DECL_ARTIFICIAL (fn) = 1;
    5468                 :     1557078 :   DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
    5469                 :     1557078 :     = OVL_OP_INFO (false, operator_code)->ovl_op_code;
    5470                 :     1557078 :   SET_DECL_LANGUAGE (fn, lang_c);
    5471                 :             :   /* Runtime library routines are, by definition, available in an
    5472                 :             :      external shared object.  */
    5473                 :     1557078 :   DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
    5474                 :     1557078 :   DECL_VISIBILITY_SPECIFIED (fn) = 1;
    5475                 :     1557078 :   set_call_expr_flags (fn, ecf_flags);
    5476                 :     1557078 :   return fn;
    5477                 :             : }
    5478                 :             : 
    5479                 :             : /* Returns the _DECL for a library function with C++ linkage.  */
    5480                 :             : 
    5481                 :             : static tree
    5482                 :     1088528 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
    5483                 :             :                      int ecf_flags)
    5484                 :             : {
    5485                 :     1088528 :   tree fn = build_library_fn (name, operator_code, type, ecf_flags);
    5486                 :     1088528 :   DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
    5487                 :     1088528 :   SET_DECL_LANGUAGE (fn, lang_cplusplus);
    5488                 :     1088528 :   return fn;
    5489                 :             : }
    5490                 :             : 
    5491                 :             : /* Like build_library_fn, but takes a C string instead of an
    5492                 :             :    IDENTIFIER_NODE.  */
    5493                 :             : 
    5494                 :             : tree
    5495                 :      102744 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
    5496                 :             : {
    5497                 :      102744 :   return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
    5498                 :             : }
    5499                 :             : 
    5500                 :             : /* Like build_cp_library_fn, but takes a C string instead of an
    5501                 :             :    IDENTIFIER_NODE.  */
    5502                 :             : 
    5503                 :             : tree
    5504                 :       95272 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
    5505                 :             : {
    5506                 :       95272 :   return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
    5507                 :       95272 :                               ecf_flags);
    5508                 :             : }
    5509                 :             : 
    5510                 :             : /* Like build_library_fn, but also pushes the function so that we will
    5511                 :             :    be able to find it via get_global_binding.  Also, the function
    5512                 :             :    may throw exceptions listed in RAISES.  */
    5513                 :             : 
    5514                 :             : tree
    5515                 :      365806 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
    5516                 :             : {
    5517                 :      365806 :   if (raises)
    5518                 :       41527 :     type = build_exception_variant (type, raises);
    5519                 :             : 
    5520                 :      365806 :   tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
    5521                 :      365806 :   return pushdecl_top_level (fn);
    5522                 :             : }
    5523                 :             : 
    5524                 :             : /* Like build_cp_library_fn, but also pushes the function so that it
    5525                 :             :    will be found by normal lookup.  */
    5526                 :             : 
    5527                 :             : static tree
    5528                 :      993256 : push_cp_library_fn (enum tree_code operator_code, tree type,
    5529                 :             :                     int ecf_flags)
    5530                 :             : {
    5531                 :      993256 :   tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
    5532                 :             :                                  operator_code, type, ecf_flags);
    5533                 :      993256 :   pushdecl (fn);
    5534                 :      993256 :   if (flag_tm)
    5535                 :        3088 :     apply_tm_attr (fn, get_identifier ("transaction_safe"));
    5536                 :      993256 :   return fn;
    5537                 :             : }
    5538                 :             : 
    5539                 :             : /* Like push_library_fn, but also note that this function throws
    5540                 :             :    and does not return.  Used for __throw_foo and the like.  */
    5541                 :             : 
    5542                 :             : tree
    5543                 :      106538 : push_throw_library_fn (tree name, tree type)
    5544                 :             : {
    5545                 :      106538 :   tree fn = push_library_fn (name, type, NULL_TREE,
    5546                 :             :                              ECF_NORETURN | ECF_XTHROW | ECF_COLD);
    5547                 :      106538 :   return fn;
    5548                 :             : }
    5549                 :             : 
    5550                 :             : /* When we call finish_struct for an anonymous union, we create
    5551                 :             :    default copy constructors and such.  But, an anonymous union
    5552                 :             :    shouldn't have such things; this function undoes the damage to the
    5553                 :             :    anonymous union type T.
    5554                 :             : 
    5555                 :             :    (The reason that we create the synthesized methods is that we don't
    5556                 :             :    distinguish `union { int i; }' from `typedef union { int i; } U'.
    5557                 :             :    The first is an anonymous union; the second is just an ordinary
    5558                 :             :    union type.)  */
    5559                 :             : 
    5560                 :             : void
    5561                 :       97116 : fixup_anonymous_aggr (tree t)
    5562                 :             : {
    5563                 :             :   /* Wipe out memory of synthesized methods.  */
    5564                 :       97116 :   TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
    5565                 :       97116 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
    5566                 :       97116 :   TYPE_HAS_COPY_CTOR (t) = 0;
    5567                 :       97116 :   TYPE_HAS_CONST_COPY_CTOR (t) = 0;
    5568                 :       97116 :   TYPE_HAS_COPY_ASSIGN (t) = 0;
    5569                 :       97116 :   TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
    5570                 :             : 
    5571                 :             :   /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
    5572                 :             :      invalid members.  */
    5573                 :      517192 :   for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
    5574                 :             :     {
    5575                 :      420076 :       if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
    5576                 :           0 :         *prev_p = DECL_CHAIN (probe);
    5577                 :             :       else
    5578                 :      420076 :         prev_p = &DECL_CHAIN (probe);
    5579                 :             : 
    5580                 :      420076 :       if (DECL_ARTIFICIAL (probe)
    5581                 :      420076 :           && (!DECL_IMPLICIT_TYPEDEF_P (probe)
    5582                 :       43230 :               || TYPE_ANON_P (TREE_TYPE (probe))))
    5583                 :      146099 :         continue;
    5584                 :             : 
    5585                 :      273977 :       if (TREE_CODE (probe) != FIELD_DECL
    5586                 :      273923 :           || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
    5587                 :             :         {
    5588                 :             :           /* We already complained about static data members in
    5589                 :             :              finish_static_data_member_decl.  */
    5590                 :          66 :           if (!VAR_P (probe))
    5591                 :             :             {
    5592                 :          51 :               auto_diagnostic_group d;
    5593                 :          51 :               if (permerror (DECL_SOURCE_LOCATION (probe),
    5594                 :          51 :                              TREE_CODE (t) == UNION_TYPE
    5595                 :             :                              ? "%q#D invalid; an anonymous union may "
    5596                 :             :                              "only have public non-static data members"
    5597                 :             :                              : "%q#D invalid; an anonymous struct may "
    5598                 :             :                              "only have public non-static data members", probe))
    5599                 :             :                 {
    5600                 :          51 :                   static bool hint;
    5601                 :          51 :                   if (flag_permissive && !hint)
    5602                 :             :                     {
    5603                 :           6 :                       hint = true;
    5604                 :           6 :                       inform (DECL_SOURCE_LOCATION (probe),
    5605                 :             :                               "this flexibility is deprecated and will be "
    5606                 :             :                               "removed");
    5607                 :             :                     }
    5608                 :             :                 }
    5609                 :          51 :             }
    5610                 :             :         }
    5611                 :             :       }
    5612                 :             : 
    5613                 :             :   /* Splice all functions out of CLASSTYPE_MEMBER_VEC.  */
    5614                 :       97116 :   vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
    5615                 :       97116 :   unsigned store = 0;
    5616                 :      224851 :   for (tree elt : vec)
    5617                 :      127735 :     if (!is_overloaded_fn (elt))
    5618                 :      127714 :       (*vec)[store++] = elt;
    5619                 :       97116 :   vec_safe_truncate (vec, store);
    5620                 :             : 
    5621                 :             :   /* Wipe RTTI info.  */
    5622                 :       97116 :   CLASSTYPE_TYPEINFO_VAR (t) = NULL_TREE;
    5623                 :             : 
    5624                 :             :   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
    5625                 :             :      assignment operators (because they cannot have these methods themselves).
    5626                 :             :      For anonymous unions this is already checked because they are not allowed
    5627                 :             :      in any union, otherwise we have to check it.  */
    5628                 :       97116 :   if (TREE_CODE (t) != UNION_TYPE)
    5629                 :             :     {
    5630                 :       20224 :       tree field, type;
    5631                 :             : 
    5632                 :       20224 :       if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
    5633                 :             :         {
    5634                 :           9 :           error_at (location_of (t), "anonymous struct with base classes");
    5635                 :             :           /* Avoid ICE after error on anon-struct9.C.  */
    5636                 :           9 :           TYPE_NEEDS_CONSTRUCTING (t) = false;
    5637                 :             :         }
    5638                 :             : 
    5639                 :       91448 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5640                 :       71224 :         if (TREE_CODE (field) == FIELD_DECL)
    5641                 :             :           {
    5642                 :       50899 :             type = TREE_TYPE (field);
    5643                 :       50899 :             if (CLASS_TYPE_P (type))
    5644                 :             :               {
    5645                 :          61 :                 if (TYPE_NEEDS_CONSTRUCTING (type))
    5646                 :           6 :                   error ("member %q+#D with constructor not allowed "
    5647                 :             :                          "in anonymous aggregate", field);
    5648                 :          61 :                 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    5649                 :           0 :                   error ("member %q+#D with destructor not allowed "
    5650                 :             :                          "in anonymous aggregate", field);
    5651                 :          61 :                 if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    5652                 :           0 :                   error ("member %q+#D with copy assignment operator "
    5653                 :             :                          "not allowed in anonymous aggregate", field);
    5654                 :             :               }
    5655                 :             :           }
    5656                 :             :     }
    5657                 :       97116 : }
    5658                 :             : 
    5659                 :             : /* Warn for an attribute located at LOCATION that appertains to the
    5660                 :             :    class type CLASS_TYPE that has not been properly placed after its
    5661                 :             :    class-key, in it class-specifier.  */
    5662                 :             : 
    5663                 :             : void
    5664                 :         102 : warn_misplaced_attr_for_class_type (location_t location,
    5665                 :             :                                     tree class_type)
    5666                 :             : {
    5667                 :         102 :   gcc_assert (OVERLOAD_TYPE_P (class_type));
    5668                 :             : 
    5669                 :         102 :   auto_diagnostic_group d;
    5670                 :         102 :   if (warning_at (location, OPT_Wattributes,
    5671                 :             :                   "attribute ignored in declaration "
    5672                 :             :                   "of %q#T", class_type))
    5673                 :         102 :     inform (location,
    5674                 :             :             "attribute for %q#T must follow the %qs keyword",
    5675                 :             :             class_type, class_key_or_enum_as_string (class_type));
    5676                 :         102 : }
    5677                 :             : 
    5678                 :             : /* Returns the cv-qualifiers that apply to the type specified
    5679                 :             :    by the DECLSPECS.  */
    5680                 :             : 
    5681                 :             : static int
    5682                 :   927223659 : get_type_quals (const cp_decl_specifier_seq *declspecs)
    5683                 :             : {
    5684                 :   927223659 :   int type_quals = TYPE_UNQUALIFIED;
    5685                 :             : 
    5686                 :   927223659 :   if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    5687                 :   102036367 :     type_quals |= TYPE_QUAL_CONST;
    5688                 :   927223659 :   if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    5689                 :     1609641 :     type_quals |= TYPE_QUAL_VOLATILE;
    5690                 :   927223659 :   if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    5691                 :          34 :     type_quals |= TYPE_QUAL_RESTRICT;
    5692                 :             : 
    5693                 :   927223659 :   return type_quals;
    5694                 :             : }
    5695                 :             : 
    5696                 :             : /* Make sure that a declaration with no declarator is well-formed, i.e.
    5697                 :             :    just declares a tagged type or anonymous union.
    5698                 :             : 
    5699                 :             :    Returns the type declared; or NULL_TREE if none.  */
    5700                 :             : 
    5701                 :             : tree
    5702                 :    32846621 : check_tag_decl (cp_decl_specifier_seq *declspecs,
    5703                 :             :                 bool explicit_type_instantiation_p)
    5704                 :             : {
    5705                 :    32846621 :   int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    5706                 :    32846621 :   int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
    5707                 :             :   /* If a class, struct, or enum type is declared by the DECLSPECS
    5708                 :             :      (i.e, if a class-specifier, enum-specifier, or non-typename
    5709                 :             :      elaborated-type-specifier appears in the DECLSPECS),
    5710                 :             :      DECLARED_TYPE is set to the corresponding type.  */
    5711                 :    32846621 :   tree declared_type = NULL_TREE;
    5712                 :    32846621 :   bool error_p = false;
    5713                 :             : 
    5714                 :    32846621 :   if (declspecs->multiple_types_p)
    5715                 :          26 :     error_at (smallest_type_location (declspecs),
    5716                 :             :               "multiple types in one declaration");
    5717                 :    32846595 :   else if (declspecs->redefined_builtin_type)
    5718                 :             :     {
    5719                 :          21 :       location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
    5720                 :          21 :       if (!in_system_header_at (loc))
    5721                 :           9 :         permerror (loc, "redeclaration of C++ built-in type %qT",
    5722                 :             :                    declspecs->redefined_builtin_type);
    5723                 :          21 :       return NULL_TREE;
    5724                 :             :     }
    5725                 :             : 
    5726                 :    32846600 :   if (declspecs->type
    5727                 :    32846585 :       && TYPE_P (declspecs->type)
    5728                 :    65501938 :       && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
    5729                 :    32653829 :            && MAYBE_CLASS_TYPE_P (declspecs->type))
    5730                 :     1693057 :           || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
    5731                 :             :     declared_type = declspecs->type;
    5732                 :      192813 :   else if (declspecs->type == error_mark_node)
    5733                 :        1465 :     error_p = true;
    5734                 :             : 
    5735                 :    32846600 :   if (type_uses_auto (declared_type))
    5736                 :             :     {
    5737                 :           8 :       error_at (declspecs->locations[ds_type_spec],
    5738                 :             :                 "%<auto%> can only be specified for variables "
    5739                 :             :                 "or function declarations");
    5740                 :           8 :       return error_mark_node;
    5741                 :             :     }
    5742                 :             : 
    5743                 :    32846592 :   if (declared_type && !OVERLOAD_TYPE_P (declared_type))
    5744                 :             :     declared_type = NULL_TREE;
    5745                 :             : 
    5746                 :    32846592 :   if (!declared_type && !saw_friend && !error_p)
    5747                 :          88 :     permerror (input_location, "declaration does not declare anything");
    5748                 :             :   /* Check for an anonymous union.  */
    5749                 :    32653752 :   else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
    5750                 :    94868118 :            && TYPE_UNNAMED_P (declared_type))
    5751                 :             :     {
    5752                 :             :       /* 7/3 In a simple-declaration, the optional init-declarator-list
    5753                 :             :          can be omitted only when declaring a class (clause 9) or
    5754                 :             :          enumeration (7.2), that is, when the decl-specifier-seq contains
    5755                 :             :          either a class-specifier, an elaborated-type-specifier with
    5756                 :             :          a class-key (9.1), or an enum-specifier.  In these cases and
    5757                 :             :          whenever a class-specifier or enum-specifier is present in the
    5758                 :             :          decl-specifier-seq, the identifiers in these specifiers are among
    5759                 :             :          the names being declared by the declaration (as class-name,
    5760                 :             :          enum-names, or enumerators, depending on the syntax).  In such
    5761                 :             :          cases, and except for the declaration of an unnamed bit-field (9.6),
    5762                 :             :          the decl-specifier-seq shall introduce one or more names into the
    5763                 :             :          program, or shall redeclare a name introduced by a previous
    5764                 :             :          declaration.  [Example:
    5765                 :             :              enum { };                  // ill-formed
    5766                 :             :              typedef class { };         // ill-formed
    5767                 :             :          --end example]  */
    5768                 :       97122 :       if (saw_typedef)
    5769                 :             :         {
    5770                 :           6 :           error_at (declspecs->locations[ds_typedef],
    5771                 :             :                     "missing type-name in typedef-declaration");
    5772                 :           6 :           return NULL_TREE;
    5773                 :             :         }
    5774                 :       97116 :       /* Anonymous unions are objects, so they can have specifiers.  */;
    5775                 :       97116 :       SET_ANON_AGGR_TYPE_P (declared_type);
    5776                 :             : 
    5777                 :       97116 :       if (TREE_CODE (declared_type) != UNION_TYPE)
    5778                 :       20224 :         pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
    5779                 :       20224 :                  OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
    5780                 :             :     }
    5781                 :             : 
    5782                 :             :   else
    5783                 :             :     {
    5784                 :    32749382 :       if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
    5785                 :           9 :         error_at (declspecs->locations[ds_inline],
    5786                 :             :                   "%<inline%> can only be specified for functions");
    5787                 :    32749373 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
    5788                 :           3 :         error_at (declspecs->locations[ds_virtual],
    5789                 :             :                   "%<virtual%> can only be specified for functions");
    5790                 :    32749370 :       else if (saw_friend
    5791                 :    32749370 :                && (!current_class_type
    5792                 :     1684826 :                    || current_scope () != current_class_type))
    5793                 :           0 :         error_at (declspecs->locations[ds_friend],
    5794                 :             :                   "%<friend%> can only be specified inside a class");
    5795                 :    32749370 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
    5796                 :           3 :         error_at (declspecs->locations[ds_explicit],
    5797                 :             :                   "%<explicit%> can only be specified for constructors");
    5798                 :    32749367 :       else if (declspecs->storage_class)
    5799                 :           3 :         error_at (declspecs->locations[ds_storage_class],
    5800                 :             :                   "a storage class can only be specified for objects "
    5801                 :             :                   "and functions");
    5802                 :    32749364 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    5803                 :           9 :         error_at (declspecs->locations[ds_const],
    5804                 :             :                   "%<const%> can only be specified for objects and "
    5805                 :             :                   "functions");
    5806                 :    32749355 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    5807                 :           3 :         error_at (declspecs->locations[ds_volatile],
    5808                 :             :                   "%<volatile%> can only be specified for objects and "
    5809                 :             :                   "functions");
    5810                 :    32749352 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    5811                 :           3 :         error_at (declspecs->locations[ds_restrict],
    5812                 :             :                   "%<__restrict%> can only be specified for objects and "
    5813                 :             :                   "functions");
    5814                 :    32749349 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
    5815                 :           3 :         error_at (declspecs->locations[ds_thread],
    5816                 :             :                   "%<__thread%> can only be specified for objects "
    5817                 :             :                   "and functions");
    5818                 :    32749346 :       else if (saw_typedef)
    5819                 :          24 :         warning_at (declspecs->locations[ds_typedef], 0,
    5820                 :             :                     "%<typedef%> was ignored in this declaration");
    5821                 :    32749322 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
    5822                 :           9 :         error_at (declspecs->locations[ds_constexpr],
    5823                 :             :                   "%qs cannot be used for type declarations", "constexpr");
    5824                 :    32749313 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
    5825                 :           3 :         error_at (declspecs->locations[ds_constinit],
    5826                 :             :                   "%qs cannot be used for type declarations", "constinit");
    5827                 :    32749310 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
    5828                 :           3 :         error_at (declspecs->locations[ds_consteval],
    5829                 :             :                   "%qs cannot be used for type declarations", "consteval");
    5830                 :             :     }
    5831                 :             : 
    5832                 :    32846586 :   if (declspecs->attributes && warn_attributes && declared_type)
    5833                 :             :     {
    5834                 :          31 :       location_t loc;
    5835                 :          25 :       if (!CLASS_TYPE_P (declared_type)
    5836                 :          56 :           || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
    5837                 :             :         /* For a non-template class, use the name location.  */
    5838                 :          22 :         loc = location_of (declared_type);
    5839                 :             :       else
    5840                 :             :         /* For a template class (an explicit instantiation), use the
    5841                 :             :            current location.  */
    5842                 :           9 :         loc = input_location;
    5843                 :             : 
    5844                 :          31 :       if (explicit_type_instantiation_p)
    5845                 :             :         /* [dcl.attr.grammar]/4:
    5846                 :             : 
    5847                 :             :                No attribute-specifier-seq shall appertain to an explicit
    5848                 :             :                instantiation.  */
    5849                 :             :         {
    5850                 :           6 :           auto_diagnostic_group d;
    5851                 :           6 :           if (warning_at (loc, OPT_Wattributes,
    5852                 :             :                           "attribute ignored in explicit instantiation %q#T",
    5853                 :             :                           declared_type))
    5854                 :           6 :             inform (loc,
    5855                 :             :                     "no attribute can be applied to "
    5856                 :             :                     "an explicit instantiation");
    5857                 :           6 :         }
    5858                 :             :       else
    5859                 :          25 :         warn_misplaced_attr_for_class_type (loc, declared_type);
    5860                 :             :     }
    5861                 :             : 
    5862                 :    32846586 :   if (declspecs->std_attributes
    5863                 :          77 :       && declared_type
    5864                 :    32846660 :       && any_nonignored_attribute_p (declspecs->std_attributes))
    5865                 :             :     {
    5866                 :          74 :       auto_diagnostic_group d;
    5867                 :          74 :       if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
    5868                 :             :                       "attribute ignored"))
    5869                 :          74 :         inform (declspecs->locations[ds_std_attribute],
    5870                 :             :                 "an attribute that appertains to a type-specifier is ignored");
    5871                 :          74 :     }
    5872                 :             : 
    5873                 :             :   /* Diagnose invalid application of contracts, if any.  */
    5874                 :    32846586 :   if (find_contract (declspecs->attributes))
    5875                 :           1 :     diagnose_misapplied_contracts (declspecs->attributes);
    5876                 :             :   else
    5877                 :    32846585 :     diagnose_misapplied_contracts (declspecs->std_attributes);
    5878                 :             : 
    5879                 :             :   return declared_type;
    5880                 :             : }
    5881                 :             : 
    5882                 :             : /* Called when a declaration is seen that contains no names to declare.
    5883                 :             :    If its type is a reference to a structure, union or enum inherited
    5884                 :             :    from a containing scope, shadow that tag name for the current scope
    5885                 :             :    with a forward reference.
    5886                 :             :    If its type defines a new named structure or union
    5887                 :             :    or defines an enum, it is valid but we need not do anything here.
    5888                 :             :    Otherwise, it is an error.
    5889                 :             : 
    5890                 :             :    C++: may have to grok the declspecs to learn about static,
    5891                 :             :    complain for anonymous unions.
    5892                 :             : 
    5893                 :             :    Returns the TYPE declared -- or NULL_TREE if none.  */
    5894                 :             : 
    5895                 :             : tree
    5896                 :    28780926 : shadow_tag (cp_decl_specifier_seq *declspecs)
    5897                 :             : {
    5898                 :    28780926 :   tree t = check_tag_decl (declspecs,
    5899                 :             :                            /*explicit_type_instantiation_p=*/false);
    5900                 :             : 
    5901                 :    28780926 :   if (!t)
    5902                 :             :     return NULL_TREE;
    5903                 :             : 
    5904                 :    28779451 :   t = maybe_process_partial_specialization (t);
    5905                 :    28779451 :   if (t == error_mark_node)
    5906                 :             :     return NULL_TREE;
    5907                 :             : 
    5908                 :             :   /* This is where the variables in an anonymous union are
    5909                 :             :      declared.  An anonymous union declaration looks like:
    5910                 :             :      union { ... } ;
    5911                 :             :      because there is no declarator after the union, the parser
    5912                 :             :      sends that declaration here.  */
    5913                 :    28778232 :   if (ANON_AGGR_TYPE_P (t))
    5914                 :             :     {
    5915                 :         246 :       fixup_anonymous_aggr (t);
    5916                 :             : 
    5917                 :         246 :       if (TYPE_FIELDS (t))
    5918                 :             :         {
    5919                 :         246 :           tree decl = grokdeclarator (/*declarator=*/NULL,
    5920                 :             :                                       declspecs, NORMAL, 0, NULL);
    5921                 :         246 :           finish_anon_union (decl);
    5922                 :             :         }
    5923                 :             :     }
    5924                 :             : 
    5925                 :             :   return t;
    5926                 :             : }
    5927                 :             : 
    5928                 :             : /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
    5929                 :             : 
    5930                 :             : tree
    5931                 :   343666972 : groktypename (cp_decl_specifier_seq *type_specifiers,
    5932                 :             :               const cp_declarator *declarator,
    5933                 :             :               bool is_template_arg)
    5934                 :             : {
    5935                 :   343666972 :   tree attrs;
    5936                 :   343666972 :   tree type;
    5937                 :    54114513 :   enum decl_context context
    5938                 :   343666972 :     = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
    5939                 :   343666972 :   attrs = type_specifiers->attributes;
    5940                 :   343666972 :   type_specifiers->attributes = NULL_TREE;
    5941                 :   343666972 :   type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
    5942                 :   343666972 :   if (attrs && type != error_mark_node)
    5943                 :             :     {
    5944                 :         585 :       if (CLASS_TYPE_P (type))
    5945                 :           6 :         warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
    5946                 :             :                  "outside of definition", type);
    5947                 :         579 :       else if (MAYBE_CLASS_TYPE_P (type))
    5948                 :             :         /* A template type parameter or other dependent type.  */
    5949                 :           9 :         warning (OPT_Wattributes, "ignoring attributes applied to dependent "
    5950                 :             :                  "type %qT without an associated declaration", type);
    5951                 :             :       else
    5952                 :         570 :         cplus_decl_attributes (&type, attrs, 0);
    5953                 :             :     }
    5954                 :   343666972 :   return type;
    5955                 :             : }
    5956                 :             : 
    5957                 :             : /* Process a DECLARATOR for a function-scope or namespace-scope
    5958                 :             :    variable or function declaration.
    5959                 :             :    (Function definitions go through start_function; class member
    5960                 :             :    declarations appearing in the body of the class go through
    5961                 :             :    grokfield.)  The DECL corresponding to the DECLARATOR is returned.
    5962                 :             :    If an error occurs, the error_mark_node is returned instead.
    5963                 :             : 
    5964                 :             :    DECLSPECS are the decl-specifiers for the declaration.  INITIALIZED is
    5965                 :             :    SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
    5966                 :             :    for an explicitly defaulted function, or SD_DELETED for an explicitly
    5967                 :             :    deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
    5968                 :             :    implicitly initialized via a default constructor.  It can also be
    5969                 :             :    SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
    5970                 :             :    mark the new decl as DECL_DECOMPOSITION_P.
    5971                 :             : 
    5972                 :             :    ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
    5973                 :             :    declaration.
    5974                 :             : 
    5975                 :             :    The scope represented by the context of the returned DECL is pushed
    5976                 :             :    (if it is not the global namespace) and is assigned to
    5977                 :             :    *PUSHED_SCOPE_P.  The caller is then responsible for calling
    5978                 :             :    pop_scope on *PUSHED_SCOPE_P if it is set.  */
    5979                 :             : 
    5980                 :             : tree
    5981                 :   113950118 : start_decl (const cp_declarator *declarator,
    5982                 :             :             cp_decl_specifier_seq *declspecs,
    5983                 :             :             int initialized,
    5984                 :             :             tree attributes,
    5985                 :             :             tree prefix_attributes,
    5986                 :             :             tree *pushed_scope_p)
    5987                 :             : {
    5988                 :   113950118 :   tree decl;
    5989                 :   113950118 :   tree context;
    5990                 :   113950118 :   bool was_public;
    5991                 :   113950118 :   int flags;
    5992                 :   113950118 :   bool alias;
    5993                 :   113950118 :   tree initial;
    5994                 :             : 
    5995                 :   113950118 :   *pushed_scope_p = NULL_TREE;
    5996                 :             : 
    5997                 :   113950118 :   if (prefix_attributes != error_mark_node)
    5998                 :   113950116 :     attributes = attr_chainon (attributes, prefix_attributes);
    5999                 :             : 
    6000                 :   113950118 :   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
    6001                 :             :                          &attributes);
    6002                 :             : 
    6003                 :   113950118 :   if (decl == NULL_TREE || VOID_TYPE_P (decl)
    6004                 :   113950118 :       || decl == error_mark_node
    6005                 :   113947995 :       || prefix_attributes == error_mark_node)
    6006                 :        2125 :     return error_mark_node;
    6007                 :             : 
    6008                 :   113947993 :   context = CP_DECL_CONTEXT (decl);
    6009                 :   113947993 :   if (context != global_namespace)
    6010                 :    17820966 :     *pushed_scope_p = push_scope (context);
    6011                 :             : 
    6012                 :   113947993 :   if (initialized && TREE_CODE (decl) == TYPE_DECL)
    6013                 :             :     {
    6014                 :          15 :       error_at (DECL_SOURCE_LOCATION (decl),
    6015                 :             :                 "typedef %qD is initialized (use %qs instead)",
    6016                 :             :                 decl, "decltype");
    6017                 :          15 :       return error_mark_node;
    6018                 :             :     }
    6019                 :             : 
    6020                 :             :   /* Save the DECL_INITIAL value in case it gets clobbered to assist
    6021                 :             :      with attribute validation.  */
    6022                 :   113947978 :   initial = DECL_INITIAL (decl);
    6023                 :             : 
    6024                 :   113947978 :   if (initialized)
    6025                 :             :     {
    6026                 :    50547782 :       if (! toplevel_bindings_p ()
    6027                 :    50547782 :           && DECL_EXTERNAL (decl))
    6028                 :           3 :         warning (0, "declaration of %q#D has %<extern%> and is initialized",
    6029                 :             :                  decl);
    6030                 :    50547782 :       DECL_EXTERNAL (decl) = 0;
    6031                 :    50547782 :       if (toplevel_bindings_p ())
    6032                 :     4359524 :         TREE_STATIC (decl) = 1;
    6033                 :             :       /* Tell 'cplus_decl_attributes' this is an initialized decl,
    6034                 :             :          even though we might not yet have the initializer expression.  */
    6035                 :    50547782 :       if (!DECL_INITIAL (decl))
    6036                 :    50191254 :         DECL_INITIAL (decl) = error_mark_node;
    6037                 :             :     }
    6038                 :   113947978 :   alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
    6039                 :             : 
    6040                 :   113947978 :   if (alias && TREE_CODE (decl) == FUNCTION_DECL)
    6041                 :        3863 :     record_key_method_defined (decl);
    6042                 :             : 
    6043                 :             :   /* If this is a typedef that names the class for linkage purposes
    6044                 :             :      (7.1.3p8), apply any attributes directly to the type.  */
    6045                 :   113947978 :   if (TREE_CODE (decl) == TYPE_DECL
    6046                 :    20235811 :       && OVERLOAD_TYPE_P (TREE_TYPE (decl))
    6047                 :   121853230 :       && decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl))))
    6048                 :             :     flags = ATTR_FLAG_TYPE_IN_PLACE;
    6049                 :             :   else
    6050                 :             :     flags = 0;
    6051                 :             : 
    6052                 :             :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    6053                 :   113947978 :   cplus_decl_attributes (&decl, attributes, flags);
    6054                 :             : 
    6055                 :             :   /* Restore the original DECL_INITIAL that we may have clobbered earlier to
    6056                 :             :      assist with attribute validation.  */
    6057                 :   113947978 :   DECL_INITIAL (decl) = initial;
    6058                 :             : 
    6059                 :             :   /* Dllimported symbols cannot be defined.  Static data members (which
    6060                 :             :      can be initialized in-class and dllimported) go through grokfield,
    6061                 :             :      not here, so we don't need to exclude those decls when checking for
    6062                 :             :      a definition.  */
    6063                 :   113947978 :   if (initialized && DECL_DLLIMPORT_P (decl))
    6064                 :             :     {
    6065                 :           0 :       error_at (DECL_SOURCE_LOCATION (decl),
    6066                 :             :                 "definition of %q#D is marked %<dllimport%>", decl);
    6067                 :           0 :       DECL_DLLIMPORT_P (decl) = 0;
    6068                 :             :     }
    6069                 :             : 
    6070                 :             :   /* If #pragma weak was used, mark the decl weak now.  */
    6071                 :   113947978 :   if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
    6072                 :    43062735 :     maybe_apply_pragma_weak (decl);
    6073                 :             : 
    6074                 :   113947978 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6075                 :    37232571 :       && DECL_DECLARED_INLINE_P (decl)
    6076                 :     1978980 :       && DECL_UNINLINABLE (decl)
    6077                 :   113947978 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    6078                 :             :     {
    6079                 :           0 :       auto_urlify_attributes sentinel;
    6080                 :           0 :       warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6081                 :             :                   "inline function %qD given attribute %qs", decl, "noinline");
    6082                 :           0 :     }
    6083                 :             : 
    6084                 :   113947978 :   if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
    6085                 :             :     {
    6086                 :      773856 :       bool this_tmpl = (current_template_depth
    6087                 :      773856 :                         > template_class_depth (context));
    6088                 :      773856 :       if (VAR_P (decl))
    6089                 :             :         {
    6090                 :      396571 :           tree field = lookup_field (context, DECL_NAME (decl), 0, false);
    6091                 :      396571 :           if (field == NULL_TREE
    6092                 :      396571 :               || !(VAR_P (field) || variable_template_p (field)))
    6093                 :           7 :             error ("%q+#D is not a static data member of %q#T", decl, context);
    6094                 :      396564 :           else if (variable_template_p (field)
    6095                 :      396564 :                    && (DECL_LANG_SPECIFIC (decl)
    6096                 :         111 :                        && DECL_TEMPLATE_SPECIALIZATION (decl)))
    6097                 :             :             /* OK, specialization was already checked.  */;
    6098                 :      396501 :           else if (variable_template_p (field) && !this_tmpl)
    6099                 :             :             {
    6100                 :           3 :               auto_diagnostic_group d;
    6101                 :           3 :               error_at (DECL_SOURCE_LOCATION (decl),
    6102                 :             :                         "non-member-template declaration of %qD", decl);
    6103                 :           3 :               inform (DECL_SOURCE_LOCATION (field), "does not match "
    6104                 :             :                       "member template declaration here");
    6105                 :           3 :               return error_mark_node;
    6106                 :           3 :             }
    6107                 :             :           else
    6108                 :             :             {
    6109                 :      396498 :               if (variable_template_p (field))
    6110                 :          45 :                 field = DECL_TEMPLATE_RESULT (field);
    6111                 :             : 
    6112                 :      396498 :               if (DECL_CONTEXT (field) != context)
    6113                 :             :                 {
    6114                 :           3 :                   if (!same_type_p (DECL_CONTEXT (field), context))
    6115                 :           3 :                     permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
    6116                 :             :                                "to be defined as %<%T::%D%>",
    6117                 :           3 :                                DECL_CONTEXT (field), DECL_NAME (decl),
    6118                 :           3 :                                context, DECL_NAME (decl));
    6119                 :           3 :                   DECL_CONTEXT (decl) = DECL_CONTEXT (field);
    6120                 :             :                 }
    6121                 :             :               /* Static data member are tricky; an in-class initialization
    6122                 :             :                  still doesn't provide a definition, so the in-class
    6123                 :             :                  declaration will have DECL_EXTERNAL set, but will have an
    6124                 :             :                  initialization.  Thus, duplicate_decls won't warn
    6125                 :             :                  about this situation, and so we check here.  */
    6126                 :      396498 :               if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
    6127                 :           9 :                 error ("duplicate initialization of %qD", decl);
    6128                 :      396498 :               field = duplicate_decls (decl, field);
    6129                 :      396498 :               if (field == error_mark_node)
    6130                 :             :                 return error_mark_node;
    6131                 :      396442 :               else if (field)
    6132                 :      396442 :                 decl = field;
    6133                 :             :             }
    6134                 :             :         }
    6135                 :             :       else
    6136                 :             :         {
    6137                 :      377298 :           tree field = check_classfn (context, decl,
    6138                 :             :                                       this_tmpl
    6139                 :          13 :                                       ? current_template_parms
    6140                 :             :                                       : NULL_TREE);
    6141                 :      377213 :           if (field && field != error_mark_node
    6142                 :      754498 :               && duplicate_decls (decl, field))
    6143                 :      377212 :             decl = field;
    6144                 :             :         }
    6145                 :             : 
    6146                 :             :       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
    6147                 :      773797 :       DECL_IN_AGGR_P (decl) = 0;
    6148                 :             :       /* Do not mark DECL as an explicit specialization if it was not
    6149                 :             :          already marked as an instantiation; a declaration should
    6150                 :             :          never be marked as a specialization unless we know what
    6151                 :             :          template is being specialized.  */
    6152                 :      773797 :       if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    6153                 :             :         {
    6154                 :      375475 :           SET_DECL_TEMPLATE_SPECIALIZATION (decl);
    6155                 :      375475 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6156                 :      353802 :             DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
    6157                 :      353802 :                                   && DECL_DECLARED_INLINE_P (decl));
    6158                 :             :           else
    6159                 :       21673 :             DECL_COMDAT (decl) = false;
    6160                 :             : 
    6161                 :             :           /* [temp.expl.spec] An explicit specialization of a static data
    6162                 :             :              member of a template is a definition if the declaration
    6163                 :             :              includes an initializer; otherwise, it is a declaration.
    6164                 :             : 
    6165                 :             :              We check for processing_specialization so this only applies
    6166                 :             :              to the new specialization syntax.  */
    6167                 :      375475 :           if (!initialized && processing_specialization)
    6168                 :      375282 :             DECL_EXTERNAL (decl) = 1;
    6169                 :             :         }
    6170                 :             : 
    6171                 :     1149148 :       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
    6172                 :             :           /* Aliases are definitions. */
    6173                 :      773854 :           && !alias)
    6174                 :             :         {
    6175                 :          30 :           if (DECL_VIRTUAL_P (decl) || !flag_contracts)
    6176                 :          11 :             permerror (declarator->id_loc,
    6177                 :             :                        "declaration of %q#D outside of class is not definition",
    6178                 :             :                        decl);
    6179                 :          19 :           else if (flag_contract_strict_declarations)
    6180                 :           4 :             warning_at (declarator->id_loc, OPT_fcontract_strict_declarations_,
    6181                 :             :                         "declaration of %q#D outside of class is not definition",
    6182                 :             :                         decl);
    6183                 :             :         }
    6184                 :             :     }
    6185                 :             : 
    6186                 :             :   /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works.  */
    6187                 :   113947919 :   if (initialized == SD_DECOMPOSITION)
    6188                 :      168617 :     fit_decomposition_lang_decl (decl, NULL_TREE);
    6189                 :             : 
    6190                 :   113947919 :   was_public = TREE_PUBLIC (decl);
    6191                 :             : 
    6192                 :   190428567 :   if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
    6193                 :   114304465 :       && current_function_decl)
    6194                 :             :     {
    6195                 :             :       /* A function-scope decl of some namespace-scope decl.  */
    6196                 :       38361 :       DECL_LOCAL_DECL_P (decl) = true;
    6197                 :       38361 :       if (named_module_attach_p ())
    6198                 :           3 :         error_at (declarator->id_loc,
    6199                 :             :                   "block-scope extern declaration %q#D must not be"
    6200                 :             :                   " attached to a named module", decl);
    6201                 :             :     }
    6202                 :             : 
    6203                 :             :   /* Enter this declaration into the symbol table.  Don't push the plain
    6204                 :             :      VAR_DECL for a variable template.  */
    6205                 :   113947919 :   if (!template_parm_scope_p ()
    6206                 :   113947919 :       || !VAR_P (decl))
    6207                 :   111152961 :     decl = maybe_push_decl (decl);
    6208                 :             : 
    6209                 :   113947919 :   if (processing_template_decl)
    6210                 :    70879016 :     decl = push_template_decl (decl);
    6211                 :             : 
    6212                 :   113947919 :   if (decl == error_mark_node)
    6213                 :             :     return error_mark_node;
    6214                 :             : 
    6215                 :   113947522 :   if (VAR_P (decl)
    6216                 :    56479322 :       && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
    6217                 :       65903 :       && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
    6218                 :             :       /* But not templated variables.  */
    6219                 :   113974786 :       && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
    6220                 :             :     {
    6221                 :             :       /* This is a const variable with implicit 'static'.  Set
    6222                 :             :          DECL_THIS_STATIC so we can tell it from variables that are
    6223                 :             :          !TREE_PUBLIC because of the anonymous namespace.  */
    6224                 :       27264 :       gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
    6225                 :       27264 :       DECL_THIS_STATIC (decl) = 1;
    6226                 :             :     }
    6227                 :             : 
    6228                 :    62896982 :   if (current_function_decl && VAR_P (decl)
    6229                 :    51159762 :       && maybe_constexpr_fn (current_function_decl)
    6230                 :   119851949 :       && cxx_dialect < cxx23)
    6231                 :             :     {
    6232                 :     2850315 :       bool ok = false;
    6233                 :     2850315 :       if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
    6234                 :             :         {
    6235                 :          10 :           if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    6236                 :          20 :             error_at (DECL_SOURCE_LOCATION (decl),
    6237                 :             :                       "%qD defined %<thread_local%> in %qs function only "
    6238                 :             :                       "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6239                 :          10 :                       DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6240                 :             :                       ? "consteval" : "constexpr");
    6241                 :             :         }
    6242                 :     2850305 :       else if (TREE_STATIC (decl))
    6243                 :             :         {
    6244                 :          52 :           if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    6245                 :          76 :             error_at (DECL_SOURCE_LOCATION (decl),
    6246                 :             :                       "%qD defined %<static%> in %qs function only available "
    6247                 :             :                       "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6248                 :          38 :                       DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6249                 :             :                       ? "consteval" : "constexpr");
    6250                 :             :         }
    6251                 :             :       else
    6252                 :             :         ok = true;
    6253                 :          48 :       if (!ok)
    6254                 :          62 :         cp_function_chain->invalid_constexpr = true;
    6255                 :             :     }
    6256                 :             : 
    6257                 :   113947522 :   if (!processing_template_decl && VAR_P (decl))
    6258                 :     5441615 :     start_decl_1 (decl, initialized);
    6259                 :             : 
    6260                 :   113947519 :   return decl;
    6261                 :             : }
    6262                 :             : 
    6263                 :             : /* Process the declaration of a variable DECL.  INITIALIZED is true
    6264                 :             :    iff DECL is explicitly initialized.  (INITIALIZED is false if the
    6265                 :             :    variable is initialized via an implicitly-called constructor.)
    6266                 :             :    This function must be called for ordinary variables (including, for
    6267                 :             :    example, implicit instantiations of templates), but must not be
    6268                 :             :    called for template declarations.  */
    6269                 :             : 
    6270                 :             : void
    6271                 :     5450385 : start_decl_1 (tree decl, bool initialized)
    6272                 :             : {
    6273                 :     5450385 :   gcc_checking_assert (!processing_template_decl);
    6274                 :             : 
    6275                 :     5450385 :   if (error_operand_p (decl))
    6276                 :             :     return;
    6277                 :             : 
    6278                 :     5450370 :   gcc_checking_assert (VAR_P (decl));
    6279                 :             : 
    6280                 :     5450370 :   tree type = TREE_TYPE (decl);
    6281                 :     5450370 :   bool complete_p = COMPLETE_TYPE_P (type);
    6282                 :     5450370 :   bool aggregate_definition_p
    6283                 :     5450370 :     = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
    6284                 :             : 
    6285                 :             :   /* If an explicit initializer is present, or if this is a definition
    6286                 :             :      of an aggregate, then we need a complete type at this point.
    6287                 :             :      (Scalars are always complete types, so there is nothing to
    6288                 :             :      check.)  This code just sets COMPLETE_P; errors (if necessary)
    6289                 :             :      are issued below.  */
    6290                 :     3413218 :   if ((initialized || aggregate_definition_p)
    6291                 :     4432629 :       && !complete_p
    6292                 :     4346591 :       && COMPLETE_TYPE_P (complete_type (type)))
    6293                 :             :     {
    6294                 :      339180 :       complete_p = true;
    6295                 :             :       /* We will not yet have set TREE_READONLY on DECL if the type
    6296                 :             :          was "const", but incomplete, before this point.  But, now, we
    6297                 :             :          have a complete type, so we can try again.  */
    6298                 :      339180 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    6299                 :             :     }
    6300                 :             : 
    6301                 :     5450367 :   if (initialized)
    6302                 :             :     /* Is it valid for this decl to have an initializer at all?  */
    6303                 :             :     {
    6304                 :             :       /* Don't allow initializations for incomplete types except for
    6305                 :             :          arrays which might be completed by the initialization.  */
    6306                 :     3795292 :       if (complete_p)
    6307                 :             :         ;                       /* A complete type is ok.  */
    6308                 :      593966 :       else if (type_uses_auto (type))
    6309                 :             :         ;                       /* An auto type is ok.  */
    6310                 :       64257 :       else if (TREE_CODE (type) != ARRAY_TYPE)
    6311                 :             :         {
    6312                 :          33 :           auto_diagnostic_group d;
    6313                 :          33 :           error ("variable %q#D has initializer but incomplete type", decl);
    6314                 :          60 :           maybe_suggest_missing_header (input_location,
    6315                 :          33 :                                         TYPE_IDENTIFIER (type),
    6316                 :          33 :                                         CP_TYPE_CONTEXT (type));
    6317                 :          33 :           type = TREE_TYPE (decl) = error_mark_node;
    6318                 :          33 :         }
    6319                 :       64224 :       else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
    6320                 :             :         {
    6321                 :           0 :           if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    6322                 :           0 :             error ("elements of array %q#D have incomplete type", decl);
    6323                 :             :           /* else we already gave an error in start_decl.  */
    6324                 :             :         }
    6325                 :             :     }
    6326                 :     1655075 :   else if (aggregate_definition_p && !complete_p)
    6327                 :             :     {
    6328                 :         224 :       if (type_uses_auto (type))
    6329                 :          64 :         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
    6330                 :             :       else
    6331                 :             :         {
    6332                 :         160 :           auto_diagnostic_group d;
    6333                 :         160 :           error ("aggregate %q#D has incomplete type and cannot be defined",
    6334                 :             :                  decl);
    6335                 :         275 :           maybe_suggest_missing_header (input_location,
    6336                 :         160 :                                         TYPE_IDENTIFIER (type),
    6337                 :         160 :                                         CP_TYPE_CONTEXT (type));
    6338                 :             :           /* Change the type so that assemble_variable will give
    6339                 :             :              DECL an rtl we can live with: (mem (const_int 0)).  */
    6340                 :         160 :           type = TREE_TYPE (decl) = error_mark_node;
    6341                 :         160 :         }
    6342                 :             :     }
    6343                 :             : 
    6344                 :             :   /* Create a new scope to hold this declaration if necessary.
    6345                 :             :      Whether or not a new scope is necessary cannot be determined
    6346                 :             :      until after the type has been completed; if the type is a
    6347                 :             :      specialization of a class template it is not until after
    6348                 :             :      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    6349                 :             :      will be set correctly.  */
    6350                 :     5450367 :   maybe_push_cleanup_level (type);
    6351                 :             : }
    6352                 :             : 
    6353                 :             : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
    6354                 :             :    C++20 P0960.  TYPE is the type of the object we're initializing.  */
    6355                 :             : 
    6356                 :             : tree
    6357                 :         239 : do_aggregate_paren_init (tree init, tree type)
    6358                 :             : {
    6359                 :         239 :   tree val = TREE_VALUE (init);
    6360                 :             : 
    6361                 :         239 :   if (TREE_CHAIN (init) == NULL_TREE)
    6362                 :             :     {
    6363                 :             :       /* If the list has a single element and it's a string literal,
    6364                 :             :          then it's the initializer for the array as a whole.  */
    6365                 :         124 :       if (TREE_CODE (type) == ARRAY_TYPE
    6366                 :         124 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    6367                 :         155 :           && TREE_CODE (tree_strip_any_location_wrapper (val))
    6368                 :             :              == STRING_CST)
    6369                 :             :         return val;
    6370                 :             :       /* Handle non-standard extensions like compound literals.  This also
    6371                 :             :          prevents triggering aggregate parenthesized-initialization in
    6372                 :             :          compiler-generated code for =default.  */
    6373                 :          97 :       else if (same_type_ignoring_top_level_qualifiers_p (type,
    6374                 :          97 :                                                           TREE_TYPE (val)))
    6375                 :             :         return val;
    6376                 :             :     }
    6377                 :             : 
    6378                 :         187 :   init = build_constructor_from_list (init_list_type_node, init);
    6379                 :         187 :   CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    6380                 :         187 :   CONSTRUCTOR_IS_PAREN_INIT (init) = true;
    6381                 :         187 :   return init;
    6382                 :             : }
    6383                 :             : 
    6384                 :             : /* Handle initialization of references.  DECL, TYPE, and INIT have the
    6385                 :             :    same meaning as in cp_finish_decl.  *CLEANUP must be NULL on entry,
    6386                 :             :    but will be set to a new CLEANUP_STMT if a temporary is created
    6387                 :             :    that must be destroyed subsequently.
    6388                 :             : 
    6389                 :             :    Returns an initializer expression to use to initialize DECL, or
    6390                 :             :    NULL if the initialization can be performed statically.
    6391                 :             : 
    6392                 :             :    Quotes on semantics can be found in ARM 8.4.3.  */
    6393                 :             : 
    6394                 :             : static tree
    6395                 :      315054 : grok_reference_init (tree decl, tree type, tree init, int flags)
    6396                 :             : {
    6397                 :      315054 :   if (init == NULL_TREE)
    6398                 :             :     {
    6399                 :          15 :       if ((DECL_LANG_SPECIFIC (decl) == 0
    6400                 :           3 :            || DECL_IN_AGGR_P (decl) == 0)
    6401                 :          18 :           && ! DECL_THIS_EXTERN (decl))
    6402                 :          15 :         error_at (DECL_SOURCE_LOCATION (decl),
    6403                 :             :                   "%qD declared as reference but not initialized", decl);
    6404                 :          15 :       return NULL_TREE;
    6405                 :             :     }
    6406                 :             : 
    6407                 :      315039 :   tree ttype = TREE_TYPE (type);
    6408                 :      315039 :   if (TREE_CODE (init) == TREE_LIST)
    6409                 :             :     {
    6410                 :             :       /* This handles (C++20 only) code like
    6411                 :             : 
    6412                 :             :            const A& r(1, 2, 3);
    6413                 :             : 
    6414                 :             :          where we treat the parenthesized list as a CONSTRUCTOR.  */
    6415                 :        1212 :       if (TREE_TYPE (init) == NULL_TREE
    6416                 :        1212 :           && CP_AGGREGATE_TYPE_P (ttype)
    6417                 :          54 :           && !DECL_DECOMPOSITION_P (decl)
    6418                 :        1263 :           && (cxx_dialect >= cxx20))
    6419                 :             :         {
    6420                 :             :           /* We don't know yet if we should treat const A& r(1) as
    6421                 :             :              const A& r{1}.  */
    6422                 :          33 :           if (list_length (init) == 1)
    6423                 :             :             {
    6424                 :          12 :               flags |= LOOKUP_AGGREGATE_PAREN_INIT;
    6425                 :          12 :               init = build_x_compound_expr_from_list (init, ELK_INIT,
    6426                 :             :                                                       tf_warning_or_error);
    6427                 :             :             }
    6428                 :             :           /* If the list had more than one element, the code is ill-formed
    6429                 :             :              pre-C++20, so we can build a constructor right away.  */
    6430                 :             :           else
    6431                 :          21 :             init = do_aggregate_paren_init (init, ttype);
    6432                 :             :         }
    6433                 :             :       else
    6434                 :        1179 :         init = build_x_compound_expr_from_list (init, ELK_INIT,
    6435                 :             :                                                 tf_warning_or_error);
    6436                 :             :     }
    6437                 :             : 
    6438                 :      315039 :   if (TREE_CODE (ttype) != ARRAY_TYPE
    6439                 :      315039 :       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
    6440                 :             :     /* Note: default conversion is only called in very special cases.  */
    6441                 :          12 :     init = decay_conversion (init, tf_warning_or_error);
    6442                 :             : 
    6443                 :             :   /* check_initializer handles this for non-reference variables, but for
    6444                 :             :      references we need to do it here or the initializer will get the
    6445                 :             :      incomplete array type and confuse later calls to
    6446                 :             :      cp_complete_array_type.  */
    6447                 :      315039 :   if (TREE_CODE (ttype) == ARRAY_TYPE
    6448                 :        8118 :       && TYPE_DOMAIN (ttype) == NULL_TREE
    6449                 :      315122 :       && (BRACE_ENCLOSED_INITIALIZER_P (init)
    6450                 :          50 :           || TREE_CODE (init) == STRING_CST))
    6451                 :             :     {
    6452                 :          33 :       cp_complete_array_type (&ttype, init, false);
    6453                 :          33 :       if (ttype != TREE_TYPE (type))
    6454                 :          33 :         type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
    6455                 :             :     }
    6456                 :             : 
    6457                 :             :   /* Convert INIT to the reference type TYPE.  This may involve the
    6458                 :             :      creation of a temporary, whose lifetime must be the same as that
    6459                 :             :      of the reference.  If so, a DECL_EXPR for the temporary will be
    6460                 :             :      added just after the DECL_EXPR for DECL.  That's why we don't set
    6461                 :             :      DECL_INITIAL for local references (instead assigning to them
    6462                 :             :      explicitly); we need to allow the temporary to be initialized
    6463                 :             :      first.  */
    6464                 :      315039 :   return initialize_reference (type, init, flags,
    6465                 :      315039 :                                tf_warning_or_error);
    6466                 :             : }
    6467                 :             : 
    6468                 :             : /* Designated initializers in arrays are not supported in GNU C++.
    6469                 :             :    The parser cannot detect this error since it does not know whether
    6470                 :             :    a given brace-enclosed initializer is for a class type or for an
    6471                 :             :    array.  This function checks that CE does not use a designated
    6472                 :             :    initializer.  If it does, an error is issued.  Returns true if CE
    6473                 :             :    is valid, i.e., does not have a designated initializer.  */
    6474                 :             : 
    6475                 :             : bool
    6476                 :    47682455 : check_array_designated_initializer (constructor_elt *ce,
    6477                 :             :                                     unsigned HOST_WIDE_INT index)
    6478                 :             : {
    6479                 :             :   /* Designated initializers for array elements are not supported.  */
    6480                 :    47682455 :   if (ce->index)
    6481                 :             :     {
    6482                 :             :       /* The parser only allows identifiers as designated
    6483                 :             :          initializers.  */
    6484                 :    30847385 :       if (ce->index == error_mark_node)
    6485                 :             :         {
    6486                 :           0 :           error ("name used in a GNU-style designated "
    6487                 :             :                  "initializer for an array");
    6488                 :           0 :           return false;
    6489                 :             :         }
    6490                 :    30847385 :       else if (identifier_p (ce->index))
    6491                 :             :         {
    6492                 :          17 :           error ("name %qD used in a GNU-style designated "
    6493                 :             :                  "initializer for an array", ce->index);
    6494                 :          17 :           return false;
    6495                 :             :         }
    6496                 :             : 
    6497                 :    30847368 :       tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
    6498                 :             :                                                   ce->index, true);
    6499                 :    30847368 :       if (ce_index
    6500                 :    30847365 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
    6501                 :    61694730 :           && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
    6502                 :             :               == INTEGER_CST))
    6503                 :             :         {
    6504                 :             :           /* A C99 designator is OK if it matches the current index.  */
    6505                 :    30847362 :           if (wi::to_wide (ce_index) == index)
    6506                 :             :             {
    6507                 :    30847356 :               ce->index = ce_index;
    6508                 :    30847356 :               return true;
    6509                 :             :             }
    6510                 :             :           else
    6511                 :           6 :             sorry ("non-trivial designated initializers not supported");
    6512                 :             :         }
    6513                 :             :       else
    6514                 :           6 :         error_at (cp_expr_loc_or_input_loc (ce->index),
    6515                 :             :                   "C99 designator %qE is not an integral constant-expression",
    6516                 :             :                   ce->index);
    6517                 :             : 
    6518                 :          12 :       return false;
    6519                 :             :     }
    6520                 :             : 
    6521                 :             :   return true;
    6522                 :             : }
    6523                 :             : 
    6524                 :             : /* When parsing `int a[] = {1, 2};' we don't know the size of the
    6525                 :             :    array until we finish parsing the initializer.  If that's the
    6526                 :             :    situation we're in, update DECL accordingly.  */
    6527                 :             : 
    6528                 :             : static void
    6529                 :    56336298 : maybe_deduce_size_from_array_init (tree decl, tree init)
    6530                 :             : {
    6531                 :    56336298 :   tree type = TREE_TYPE (decl);
    6532                 :             : 
    6533                 :    56336298 :   if (TREE_CODE (type) == ARRAY_TYPE
    6534                 :      812204 :       && TYPE_DOMAIN (type) == NULL_TREE
    6535                 :    56861925 :       && TREE_CODE (decl) != TYPE_DECL)
    6536                 :             :     {
    6537                 :             :       /* do_default is really a C-ism to deal with tentative definitions.
    6538                 :             :          But let's leave it here to ease the eventual merge.  */
    6539                 :      525627 :       int do_default = !DECL_EXTERNAL (decl);
    6540                 :      525627 :       tree initializer = init ? init : DECL_INITIAL (decl);
    6541                 :      525627 :       int failure = 0;
    6542                 :             : 
    6543                 :             :       /* Check that there are no designated initializers in INIT, as
    6544                 :             :          those are not supported in GNU C++, and as the middle-end
    6545                 :             :          will crash if presented with a non-numeric designated
    6546                 :             :          initializer.  */
    6547                 :      525627 :       if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
    6548                 :             :         {
    6549                 :       94145 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
    6550                 :       94145 :           constructor_elt *ce;
    6551                 :       94145 :           HOST_WIDE_INT i, j = 0;
    6552                 :    15159793 :           FOR_EACH_VEC_SAFE_ELT (v, i, ce)
    6553                 :             :             {
    6554                 :    15067142 :               if (instantiation_dependent_expression_p (ce->index))
    6555                 :    56336298 :                 return;
    6556                 :    15067136 :               if (!check_array_designated_initializer (ce, j))
    6557                 :           2 :                 failure = 1;
    6558                 :             :               /* If an un-designated initializer is type-dependent, we can't
    6559                 :             :                  check brace elision yet.  */
    6560                 :    15067136 :               if (ce->index == NULL_TREE
    6561                 :    15067136 :                   && type_dependent_expression_p (ce->value))
    6562                 :             :                 return;
    6563                 :    15065648 :               if (TREE_CODE (ce->value) == RAW_DATA_CST)
    6564                 :         193 :                 j += RAW_DATA_LENGTH (ce->value);
    6565                 :             :               else
    6566                 :    15065455 :                 ++j;
    6567                 :             :             }
    6568                 :             :         }
    6569                 :             : 
    6570                 :       92651 :       if (failure)
    6571                 :           2 :         TREE_TYPE (decl) = error_mark_node;
    6572                 :             :       else
    6573                 :             :         {
    6574                 :      524131 :           failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
    6575                 :             :                                             do_default);
    6576                 :      524131 :           if (failure == 1)
    6577                 :             :             {
    6578                 :          33 :               error_at (cp_expr_loc_or_loc (initializer,
    6579                 :          30 :                                          DECL_SOURCE_LOCATION (decl)),
    6580                 :             :                         "initializer fails to determine size of %qD", decl);
    6581                 :             :             }
    6582                 :      524101 :           else if (failure == 2)
    6583                 :             :             {
    6584                 :          30 :               if (do_default)
    6585                 :             :                 {
    6586                 :           6 :                   error_at (DECL_SOURCE_LOCATION (decl),
    6587                 :             :                             "array size missing in %qD", decl);
    6588                 :             :                 }
    6589                 :             :               /* If a `static' var's size isn't known, make it extern as
    6590                 :             :                  well as static, so it does not get allocated.  If it's not
    6591                 :             :                  `static', then don't mark it extern; finish_incomplete_decl
    6592                 :             :                  will give it a default size and it will get allocated.  */
    6593                 :          24 :               else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
    6594                 :           0 :                 DECL_EXTERNAL (decl) = 1;
    6595                 :             :             }
    6596                 :      524071 :           else if (failure == 3)
    6597                 :             :             {
    6598                 :           6 :               error_at (DECL_SOURCE_LOCATION (decl),
    6599                 :             :                         "zero-size array %qD", decl);
    6600                 :             :             }
    6601                 :             :         }
    6602                 :             : 
    6603                 :      524133 :       cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
    6604                 :             : 
    6605                 :      524133 :       relayout_decl (decl);
    6606                 :             :     }
    6607                 :             : }
    6608                 :             : 
    6609                 :             : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
    6610                 :             :    any appropriate error messages regarding the layout.  */
    6611                 :             : 
    6612                 :             : static void
    6613                 :    47778072 : layout_var_decl (tree decl)
    6614                 :             : {
    6615                 :    47778072 :   tree type;
    6616                 :             : 
    6617                 :    47778072 :   type = TREE_TYPE (decl);
    6618                 :    47778072 :   if (type == error_mark_node)
    6619                 :             :     return;
    6620                 :             : 
    6621                 :             :   /* If we haven't already laid out this declaration, do so now.
    6622                 :             :      Note that we must not call complete type for an external object
    6623                 :             :      because it's type might involve templates that we are not
    6624                 :             :      supposed to instantiate yet.  (And it's perfectly valid to say
    6625                 :             :      `extern X x' for some incomplete type `X'.)  */
    6626                 :    47778024 :   if (!DECL_EXTERNAL (decl))
    6627                 :    39096757 :     complete_type (type);
    6628                 :    47778024 :   if (!DECL_SIZE (decl)
    6629                 :      519976 :       && TREE_TYPE (decl) != error_mark_node
    6630                 :    48298000 :       && complete_or_array_type_p (type))
    6631                 :      476947 :     layout_decl (decl, 0);
    6632                 :             : 
    6633                 :    47778024 :   if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
    6634                 :             :     {
    6635                 :             :       /* An automatic variable with an incomplete type: that is an error.
    6636                 :             :          Don't talk about array types here, since we took care of that
    6637                 :             :          message in grokdeclarator.  */
    6638                 :          17 :       error_at (DECL_SOURCE_LOCATION (decl),
    6639                 :             :                 "storage size of %qD isn%'t known", decl);
    6640                 :          17 :       TREE_TYPE (decl) = error_mark_node;
    6641                 :             :     }
    6642                 :             : #if 0
    6643                 :             :   /* Keep this code around in case we later want to control debug info
    6644                 :             :      based on whether a type is "used".  (jason 1999-11-11) */
    6645                 :             : 
    6646                 :             :   else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
    6647                 :             :     /* Let debugger know it should output info for this type.  */
    6648                 :             :     note_debug_info_needed (ttype);
    6649                 :             : 
    6650                 :             :   if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
    6651                 :             :     note_debug_info_needed (DECL_CONTEXT (decl));
    6652                 :             : #endif
    6653                 :             : 
    6654                 :    86874781 :   if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
    6655                 :    24589460 :       && DECL_SIZE (decl) != NULL_TREE
    6656                 :    72187101 :       && ! TREE_CONSTANT (DECL_SIZE (decl)))
    6657                 :             :     {
    6658                 :           6 :       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    6659                 :           6 :           && !DECL_LOCAL_DECL_P (decl))
    6660                 :           0 :         constant_expression_warning (DECL_SIZE (decl));
    6661                 :             :       else
    6662                 :             :         {
    6663                 :           6 :           error_at (DECL_SOURCE_LOCATION (decl),
    6664                 :             :                     "storage size of %qD isn%'t constant", decl);
    6665                 :           6 :           TREE_TYPE (decl) = error_mark_node;
    6666                 :           6 :           type = error_mark_node;
    6667                 :             :         }
    6668                 :             :     }
    6669                 :             : 
    6670                 :             :   /* If the final element initializes a flexible array field, adjust
    6671                 :             :      the size of the DECL with the initializer based on whether the
    6672                 :             :      DECL is a union or a structure.  */
    6673                 :    47778024 :   if (type != error_mark_node
    6674                 :    47778018 :       && DECL_INITIAL (decl)
    6675                 :    24406152 :       && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    6676                 :     3812696 :       && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
    6677                 :     3171181 :       && DECL_SIZE (decl) != NULL_TREE
    6678                 :     3171181 :       && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    6679                 :     3171181 :       && COMPLETE_TYPE_P (type)
    6680                 :     3171181 :       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
    6681                 :    50949205 :       && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
    6682                 :             :     {
    6683                 :     3171181 :       constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
    6684                 :     3171181 :       if (elt.index)
    6685                 :             :         {
    6686                 :      996474 :           tree itype = TREE_TYPE (elt.index);
    6687                 :      996474 :           tree vtype = TREE_TYPE (elt.value);
    6688                 :      996474 :           if (TREE_CODE (itype) == ARRAY_TYPE
    6689                 :       51572 :               && TYPE_DOMAIN (itype) == NULL
    6690                 :         272 :               && TREE_CODE (vtype) == ARRAY_TYPE
    6691                 :      996746 :               && COMPLETE_TYPE_P (vtype))
    6692                 :             :             {
    6693                 :             :               /* For a structure, add the size of the initializer to the DECL's
    6694                 :             :                  size.  */
    6695                 :         272 :               if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    6696                 :             :                 {
    6697                 :         257 :                   DECL_SIZE (decl)
    6698                 :         257 :                     = size_binop (PLUS_EXPR, DECL_SIZE (decl),
    6699                 :             :                                   TYPE_SIZE (vtype));
    6700                 :         257 :                   DECL_SIZE_UNIT (decl)
    6701                 :         514 :                     = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    6702                 :             :                                   TYPE_SIZE_UNIT (vtype));
    6703                 :             :                 }
    6704                 :             :               /* For a union, the DECL's size is the maximum of the current size
    6705                 :             :                  and the size of the initializer.  */
    6706                 :             :               else
    6707                 :             :                 {
    6708                 :          15 :                   DECL_SIZE (decl)
    6709                 :          15 :                     = size_binop (MAX_EXPR, DECL_SIZE (decl),
    6710                 :             :                                   TYPE_SIZE (vtype));
    6711                 :          15 :                   DECL_SIZE_UNIT (decl)
    6712                 :          30 :                     = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    6713                 :             :                                   TYPE_SIZE_UNIT (vtype));
    6714                 :             :                 }
    6715                 :             :             }
    6716                 :             :         }
    6717                 :             :     }
    6718                 :             : }
    6719                 :             : 
    6720                 :             : /* If a local static variable is declared in an inline function, or if
    6721                 :             :    we have a weak definition, we must endeavor to create only one
    6722                 :             :    instance of the variable at link-time.  */
    6723                 :             : 
    6724                 :             : void
    6725                 :    53778725 : maybe_commonize_var (tree decl)
    6726                 :             : {
    6727                 :             :   /* Don't mess with __FUNCTION__ and similar.  But do handle structured
    6728                 :             :      bindings.  */
    6729                 :    53778725 :   if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
    6730                 :             :     return;
    6731                 :             : 
    6732                 :             :   /* Static data in a function with comdat linkage also has comdat
    6733                 :             :      linkage.  */
    6734                 :    48732480 :   if ((TREE_STATIC (decl)
    6735                 :    25176515 :        && DECL_FUNCTION_SCOPE_P (decl)
    6736                 :      141758 :        && vague_linkage_p (DECL_CONTEXT (decl)))
    6737                 :    99273419 :       || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
    6738                 :             :     {
    6739                 :    20779125 :       if (flag_weak)
    6740                 :             :         {
    6741                 :             :           /* With weak symbols, we simply make the variable COMDAT;
    6742                 :             :              that will cause copies in multiple translations units to
    6743                 :             :              be merged.  */
    6744                 :    20779098 :           comdat_linkage (decl);
    6745                 :             :         }
    6746                 :             :       else
    6747                 :             :         {
    6748                 :          27 :           if (DECL_INITIAL (decl) == NULL_TREE
    6749                 :          27 :               || DECL_INITIAL (decl) == error_mark_node)
    6750                 :             :             {
    6751                 :             :               /* Without weak symbols, we can use COMMON to merge
    6752                 :             :                  uninitialized variables.  */
    6753                 :          24 :               TREE_PUBLIC (decl) = 1;
    6754                 :          24 :               DECL_COMMON (decl) = 1;
    6755                 :             :             }
    6756                 :             :           else
    6757                 :             :             {
    6758                 :             :               /* While for initialized variables, we must use internal
    6759                 :             :                  linkage -- which means that multiple copies will not
    6760                 :             :                  be merged.  */
    6761                 :           3 :               TREE_PUBLIC (decl) = 0;
    6762                 :           3 :               DECL_COMMON (decl) = 0;
    6763                 :           3 :               DECL_INTERFACE_KNOWN (decl) = 1;
    6764                 :           3 :               const char *msg;
    6765                 :           3 :               if (DECL_INLINE_VAR_P (decl))
    6766                 :             :                 msg = G_("sorry: semantics of inline variable "
    6767                 :             :                          "%q#D are wrong (you%'ll wind up with "
    6768                 :             :                          "multiple copies)");
    6769                 :             :               else
    6770                 :             :                 msg = G_("sorry: semantics of inline function "
    6771                 :             :                          "static data %q#D are wrong (you%'ll wind "
    6772                 :             :                          "up with multiple copies)");
    6773                 :           3 :               auto_diagnostic_group d;
    6774                 :           3 :               if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6775                 :             :                               msg, decl))
    6776                 :           3 :                 inform (DECL_SOURCE_LOCATION (decl),
    6777                 :             :                         "you can work around this by removing the initializer");
    6778                 :           3 :             }
    6779                 :             :         }
    6780                 :             :     }
    6781                 :             : }
    6782                 :             : 
    6783                 :             : /* Issue an error message if DECL is an uninitialized const variable.
    6784                 :             :    CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
    6785                 :             :    context from potential_constant_expression.  Returns true if all is well,
    6786                 :             :    false otherwise.  */
    6787                 :             : 
    6788                 :             : bool
    6789                 :     6455066 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
    6790                 :             :                                    tsubst_flags_t complain)
    6791                 :             : {
    6792                 :     6455066 :   tree type = strip_array_types (TREE_TYPE (decl));
    6793                 :             : 
    6794                 :             :   /* ``Unless explicitly declared extern, a const object does not have
    6795                 :             :      external linkage and must be initialized. ($8.4; $12.1)'' ARM
    6796                 :             :      7.1.6 */
    6797                 :     6455066 :   if (VAR_P (decl)
    6798                 :     6455066 :       && !TYPE_REF_P (type)
    6799                 :     6438192 :       && (CP_TYPE_CONST_P (type)
    6800                 :             :           /* C++20 permits trivial default initialization in constexpr
    6801                 :             :              context (P1331R2).  */
    6802                 :     5387973 :           || (cxx_dialect < cxx20
    6803                 :     2819544 :               && (constexpr_context_p
    6804                 :     2513735 :                   || var_in_constexpr_fn (decl))))
    6805                 :     7924239 :       && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    6806                 :             :     {
    6807                 :      661378 :       tree field = default_init_uninitialized_part (type);
    6808                 :      661378 :       if (!field)
    6809                 :             :         return true;
    6810                 :             : 
    6811                 :      114859 :       auto_diagnostic_group d;
    6812                 :      114859 :       bool show_notes = true;
    6813                 :             : 
    6814                 :      114859 :       if (!constexpr_context_p || cxx_dialect >= cxx20)
    6815                 :             :         {
    6816                 :      111101 :           if (CP_TYPE_CONST_P (type))
    6817                 :             :             {
    6818                 :          90 :               if (complain & tf_error)
    6819                 :          84 :                 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
    6820                 :             :                                         "uninitialized %<const %D%>", decl);
    6821                 :             :             }
    6822                 :             :           else
    6823                 :             :             {
    6824                 :      111011 :               if (!is_instantiation_of_constexpr (current_function_decl)
    6825                 :      111011 :                   && (complain & tf_error))
    6826                 :          21 :                 error_at (DECL_SOURCE_LOCATION (decl),
    6827                 :             :                           "uninitialized variable %qD in %<constexpr%> "
    6828                 :             :                           "function", decl);
    6829                 :             :               else
    6830                 :             :                 show_notes = false;
    6831                 :      111011 :               cp_function_chain->invalid_constexpr = true;
    6832                 :             :             }
    6833                 :             :         }
    6834                 :        3758 :       else if (complain & tf_error)
    6835                 :           2 :         error_at (DECL_SOURCE_LOCATION (decl),
    6836                 :             :                   "uninitialized variable %qD in %<constexpr%> context",
    6837                 :             :                   decl);
    6838                 :             : 
    6839                 :      114859 :       if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
    6840                 :             :         {
    6841                 :          62 :           tree defaulted_ctor;
    6842                 :             : 
    6843                 :          62 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    6844                 :             :                   "%q#T has no user-provided default constructor", type);
    6845                 :          62 :           defaulted_ctor = in_class_defaulted_default_constructor (type);
    6846                 :          62 :           if (defaulted_ctor)
    6847                 :          33 :             inform (DECL_SOURCE_LOCATION (defaulted_ctor),
    6848                 :             :                     "constructor is not user-provided because it is "
    6849                 :             :                     "explicitly defaulted in the class body");
    6850                 :          62 :           inform (DECL_SOURCE_LOCATION (field),
    6851                 :             :                   "and the implicitly-defined constructor does not "
    6852                 :             :                   "initialize %q#D", field);
    6853                 :             :         }
    6854                 :             : 
    6855                 :      114859 :       return false;
    6856                 :      114859 :     }
    6857                 :             : 
    6858                 :             :   return true;
    6859                 :             : }
    6860                 :             : 
    6861                 :             : /* Structure holding the current initializer being processed by reshape_init.
    6862                 :             :    CUR is a pointer to the current element being processed, END is a pointer
    6863                 :             :    after the last element present in the initializer and RAW_IDX is index into
    6864                 :             :    RAW_DATA_CST if that is CUR elt.  */
    6865                 :             : struct reshape_iter
    6866                 :             : {
    6867                 :             :   constructor_elt *cur;
    6868                 :             :   constructor_elt *end;
    6869                 :             :   unsigned raw_idx;
    6870                 :             : };
    6871                 :             : 
    6872                 :             : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
    6873                 :             : 
    6874                 :             : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    6875                 :             :    returned is the next FIELD_DECL (possibly FIELD itself) that can be
    6876                 :             :    initialized as if for an aggregate class.  If there are no more such fields,
    6877                 :             :    the return value will be NULL.  */
    6878                 :             : 
    6879                 :             : tree
    6880                 :    14281003 : next_aggregate_field (tree field)
    6881                 :             : {
    6882                 :    14281003 :   while (field
    6883                 :    49931858 :          && (TREE_CODE (field) != FIELD_DECL
    6884                 :     9150161 :              || DECL_UNNAMED_BIT_FIELD (field)
    6885                 :     9150039 :              || (DECL_ARTIFICIAL (field)
    6886                 :             :                  /* In C++17, aggregates can have bases.  */
    6887                 :       73946 :                  && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
    6888                 :    35650855 :     field = DECL_CHAIN (field);
    6889                 :             : 
    6890                 :    14281003 :   return field;
    6891                 :             : }
    6892                 :             : 
    6893                 :             : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    6894                 :             :    returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
    6895                 :             :    to a subobject.  If there are no more such fields, the return value will be
    6896                 :             :    NULL.  */
    6897                 :             : 
    6898                 :             : tree
    6899                 :    54904561 : next_subobject_field (tree field)
    6900                 :             : {
    6901                 :    54904561 :   while (field
    6902                 :   667977139 :          && (TREE_CODE (field) != FIELD_DECL
    6903                 :    25435607 :              || DECL_UNNAMED_BIT_FIELD (field)
    6904                 :    25435527 :              || (DECL_ARTIFICIAL (field)
    6905                 :     7034638 :                  && !DECL_FIELD_IS_BASE (field)
    6906                 :     1757356 :                  && !DECL_VIRTUAL_P (field))))
    6907                 :   613072578 :     field = DECL_CHAIN (field);
    6908                 :             : 
    6909                 :    54904561 :   return field;
    6910                 :             : }
    6911                 :             : 
    6912                 :             : /* Return true for [dcl.init.list] direct-list-initialization from
    6913                 :             :    single element of enumeration with a fixed underlying type.  */
    6914                 :             : 
    6915                 :             : bool
    6916                 :   125236201 : is_direct_enum_init (tree type, tree init)
    6917                 :             : {
    6918                 :   125236201 :   if (cxx_dialect >= cxx17
    6919                 :   123270099 :       && TREE_CODE (type) == ENUMERAL_TYPE
    6920                 :     6240398 :       && ENUM_FIXED_UNDERLYING_TYPE_P (type)
    6921                 :     3953155 :       && TREE_CODE (init) == CONSTRUCTOR
    6922                 :      410221 :       && CONSTRUCTOR_IS_DIRECT_INIT (init)
    6923                 :      206968 :       && CONSTRUCTOR_NELTS (init) == 1
    6924                 :         218 :       && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
    6925                 :             :       /* DR 2374: The single element needs to be implicitly
    6926                 :             :          convertible to the underlying type of the enum.  */
    6927                 :         218 :       && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
    6928                 :   125236417 :       && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
    6929                 :         216 :                           TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
    6930                 :         216 :                           CONSTRUCTOR_ELT (init, 0)->value,
    6931                 :             :                           LOOKUP_IMPLICIT, tf_none))
    6932                 :             :     return true;
    6933                 :             :   return false;
    6934                 :             : }
    6935                 :             : 
    6936                 :             : /* Helper function for reshape_init*.  Split first element of
    6937                 :             :    RAW_DATA_CST or return NULL for other elements.  Set *INC_CUR
    6938                 :             :    to true if the whole d->cur has been consumed.  */
    6939                 :             : 
    6940                 :             : static tree
    6941                 :    22557364 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
    6942                 :             : {
    6943                 :    22557364 :   *inc_cur = true;
    6944                 :    22557364 :   if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
    6945                 :             :     return NULL_TREE;
    6946                 :       30720 :   tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
    6947                 :       30720 :   if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
    6948                 :       30588 :     *inc_cur = false;
    6949                 :             :   else
    6950                 :         132 :     d->raw_idx = 0;
    6951                 :             :   return ret;
    6952                 :             : }
    6953                 :             : 
    6954                 :             : /* Wrapper around that which for RAW_DATA_CST in INIT
    6955                 :             :    (as well as in D->cur->value) peels off the first element
    6956                 :             :    of the raw data and returns it, otherwise increments
    6957                 :             :    D->cur and returns INIT.  */
    6958                 :             : 
    6959                 :             : static tree
    6960                 :    22557348 : consume_init (tree init, reshape_iter *d)
    6961                 :             : {
    6962                 :    22557348 :   bool inc_cur;
    6963                 :    22557348 :   if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    6964                 :       30720 :     init = raw_init;
    6965                 :    22557348 :   if (inc_cur)
    6966                 :    22526760 :     d->cur++;
    6967                 :    22557348 :   return init;
    6968                 :             : }
    6969                 :             : 
    6970                 :             : /* Subroutine of reshape_init_array and reshape_init_vector, which does
    6971                 :             :    the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
    6972                 :             :    INTEGER_CST representing the size of the array minus one (the maximum index),
    6973                 :             :    or NULL_TREE if the array was declared without specifying the size. D is
    6974                 :             :    the iterator within the constructor.  */
    6975                 :             : 
    6976                 :             : static tree
    6977                 :      361942 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
    6978                 :             :                       tree first_initializer_p, bool vector_p,
    6979                 :             :                       tsubst_flags_t complain)
    6980                 :             : {
    6981                 :      361942 :   tree new_init;
    6982                 :      361942 :   bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
    6983                 :      361942 :   unsigned HOST_WIDE_INT max_index_cst = 0;
    6984                 :      361942 :   unsigned HOST_WIDE_INT index;
    6985                 :             : 
    6986                 :             :   /* The initializer for an array is always a CONSTRUCTOR.  If this is the
    6987                 :             :      outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
    6988                 :             :      to build a new one.  But don't reuse if not complaining; if this is
    6989                 :             :      tentative, we might also reshape to another type (95319).  */
    6990                 :      361942 :   bool reuse = (first_initializer_p
    6991                 :      314321 :                 && (complain & tf_error)
    6992                 :      313068 :                 && !CP_AGGREGATE_TYPE_P (elt_type)
    6993                 :      625333 :                 && !TREE_SIDE_EFFECTS (first_initializer_p));
    6994                 :      106137 :   if (reuse)
    6995                 :             :     new_init = first_initializer_p;
    6996                 :             :   else
    6997                 :      106137 :     new_init = build_constructor (init_list_type_node, NULL);
    6998                 :             : 
    6999                 :      361942 :   if (sized_array_p)
    7000                 :             :     {
    7001                 :      251182 :       poly_uint64 midx;
    7002                 :             :       /* Minus 1 is used for zero sized arrays.  */
    7003                 :      251182 :       if (integer_all_onesp (max_index))
    7004                 :          24 :         return new_init;
    7005                 :             : 
    7006                 :      251158 :       if (tree_fits_poly_uint64_p (max_index))
    7007                 :      251158 :         midx = tree_to_poly_uint64 (max_index);
    7008                 :             :       /* sizetype is sign extended, not zero extended.  */
    7009                 :             :       else
    7010                 :           0 :         midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
    7011                 :             : 
    7012                 :             :       /* For VLA vectors, we restict the number of elements in the constructor
    7013                 :             :          to lower bound of the VLA elements.  */
    7014                 :      251158 :       max_index_cst = constant_lower_bound (midx);
    7015                 :             :     }
    7016                 :             : 
    7017                 :      361918 :   constructor_elt *first_cur = d->cur;
    7018                 :             :   /* Loop until there are no more initializers.  */
    7019                 :    17433822 :   for (index = 0;
    7020                 :    17433822 :        d->cur != d->end && (!sized_array_p || index <= max_index_cst);
    7021                 :             :        ++index)
    7022                 :             :     {
    7023                 :    17072086 :       tree elt_init;
    7024                 :    17072086 :       constructor_elt *old_cur = d->cur;
    7025                 :    17072086 :       unsigned int old_raw_idx = d->raw_idx;
    7026                 :    17072086 :       bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
    7027                 :             : 
    7028                 :    17072086 :       if (d->cur->index)
    7029                 :     1489220 :         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7030                 :    17072086 :       check_array_designated_initializer (d->cur, index);
    7031                 :    17072086 :       if (TREE_CODE (d->cur->value) == RAW_DATA_CST
    7032                 :       32693 :           && (TREE_CODE (elt_type) == INTEGER_TYPE
    7033                 :       10233 :               || is_byte_access_type (elt_type))
    7034                 :       22460 :           && TYPE_PRECISION (elt_type) == CHAR_BIT
    7035                 :        1799 :           && (!sized_array_p || index < max_index_cst)
    7036                 :    17073873 :           && !vector_p)
    7037                 :             :         {
    7038                 :         467 :           elt_init = d->cur->value;
    7039                 :         467 :           unsigned int off = d->raw_idx;
    7040                 :         467 :           unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
    7041                 :         467 :           if (!sized_array_p || len <= max_index_cst - index + 1)
    7042                 :             :             {
    7043                 :         458 :               d->cur++;
    7044                 :         458 :               d->raw_idx = 0;
    7045                 :             :             }
    7046                 :             :           else
    7047                 :             :             {
    7048                 :           9 :               len = max_index_cst - index + 1;
    7049                 :           9 :               d->raw_idx += len;
    7050                 :             :             }
    7051                 :         467 :           if (!reuse || off || d->cur == old_cur)
    7052                 :             :             {
    7053                 :          25 :               elt_init = copy_node (elt_init);
    7054                 :          25 :               RAW_DATA_LENGTH (elt_init) = len;
    7055                 :          25 :               RAW_DATA_POINTER (elt_init) += off;
    7056                 :             :             }
    7057                 :         467 :           TREE_TYPE (elt_init) = elt_type;
    7058                 :             :         }
    7059                 :             :       else
    7060                 :    17071619 :         elt_init = reshape_init_r (elt_type, d,
    7061                 :             :                                    /*first_initializer_p=*/NULL_TREE,
    7062                 :             :                                    complain);
    7063                 :    17072086 :       if (elt_init == error_mark_node)
    7064                 :             :         return error_mark_node;
    7065                 :    17071907 :       tree idx = size_int (index);
    7066                 :    17071907 :       if (reuse && old_raw_data_cst && d->cur == old_cur)
    7067                 :             :         {
    7068                 :             :           /* We need to stop reusing as some RAW_DATA_CST in the original
    7069                 :             :              ctor had to be split.  */
    7070                 :          72 :           new_init = build_constructor (init_list_type_node, NULL);
    7071                 :          72 :           if (index)
    7072                 :             :             {
    7073                 :          72 :               vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
    7074                 :          72 :               memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
    7075                 :          72 :                       (d->cur - first_cur)
    7076                 :             :                       * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
    7077                 :          72 :               if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
    7078                 :             :                 {
    7079                 :             :                   unsigned int j;
    7080                 :             :                   tree nidx, nval;
    7081                 :           4 :                   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
    7082                 :             :                                             j, nidx, nval)
    7083                 :           4 :                     if (nidx)
    7084                 :             :                       {
    7085                 :           4 :                         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
    7086                 :           4 :                         (void) nval;
    7087                 :           4 :                         break;
    7088                 :             :                       }
    7089                 :             :                 }
    7090                 :             :             }
    7091                 :             :           reuse = false;
    7092                 :             :         }
    7093                 :    17071835 :       if (reuse)
    7094                 :             :         {
    7095                 :    15302767 :           old_cur->index = idx;
    7096                 :    15302767 :           old_cur->value = elt_init;
    7097                 :             :         }
    7098                 :             :       else
    7099                 :     1769140 :         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    7100                 :             :                                 idx, elt_init);
    7101                 :    17071907 :       if (!TREE_CONSTANT (elt_init))
    7102                 :      167778 :         TREE_CONSTANT (new_init) = false;
    7103                 :             : 
    7104                 :             :       /* This can happen with an invalid initializer (c++/54501).  */
    7105                 :    17071907 :       if (d->cur == old_cur
    7106                 :       32082 :           && !sized_array_p
    7107                 :       14085 :           && d->raw_idx == old_raw_idx)
    7108                 :             :         break;
    7109                 :             : 
    7110                 :    17071904 :       if (TREE_CODE (elt_init) == RAW_DATA_CST)
    7111                 :         467 :         index += RAW_DATA_LENGTH (elt_init) - 1;
    7112                 :             :     }
    7113                 :             : 
    7114                 :             :   return new_init;
    7115                 :             : }
    7116                 :             : 
    7117                 :             : /* Subroutine of reshape_init_r, processes the initializers for arrays.
    7118                 :             :    Parameters are the same of reshape_init_r.  */
    7119                 :             : 
    7120                 :             : static tree
    7121                 :      320761 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
    7122                 :             :                     tsubst_flags_t complain)
    7123                 :             : {
    7124                 :      320761 :   tree max_index = NULL_TREE;
    7125                 :             : 
    7126                 :      320761 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    7127                 :             : 
    7128                 :      320761 :   if (TYPE_DOMAIN (type))
    7129                 :      210046 :     max_index = array_type_nelts_minus_one (type);
    7130                 :             : 
    7131                 :      320761 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7132                 :      320761 :                                first_initializer_p, false, complain);
    7133                 :             : }
    7134                 :             : 
    7135                 :             : /* Subroutine of reshape_init_r, processes the initializers for vectors.
    7136                 :             :    Parameters are the same of reshape_init_r.  */
    7137                 :             : 
    7138                 :             : static tree
    7139                 :       41181 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
    7140                 :             : {
    7141                 :       41181 :   tree max_index = NULL_TREE;
    7142                 :             : 
    7143                 :       41181 :   gcc_assert (VECTOR_TYPE_P (type));
    7144                 :             : 
    7145                 :       41181 :   if (COMPOUND_LITERAL_P (d->cur->value))
    7146                 :             :     {
    7147                 :           0 :       tree value = d->cur->value;
    7148                 :           0 :       if (!same_type_p (TREE_TYPE (value), type))
    7149                 :             :         {
    7150                 :           0 :           if (complain & tf_error)
    7151                 :           0 :             error ("invalid type %qT as initializer for a vector of type %qT",
    7152                 :           0 :                    TREE_TYPE (d->cur->value), type);
    7153                 :           0 :           value = error_mark_node;
    7154                 :             :         }
    7155                 :           0 :       ++d->cur;
    7156                 :           0 :       return value;
    7157                 :             :     }
    7158                 :             : 
    7159                 :             :   /* For a vector, we initialize it as an array of the appropriate size.  */
    7160                 :       41181 :   if (VECTOR_TYPE_P (type))
    7161                 :       41181 :     max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
    7162                 :             : 
    7163                 :       41181 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7164                 :       41181 :                                NULL_TREE, true, complain);
    7165                 :             : }
    7166                 :             : 
    7167                 :             : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
    7168                 :             :    INIT, in isolation from any designator or other initializers.  */
    7169                 :             : 
    7170                 :             : static tree
    7171                 :      577917 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
    7172                 :             : {
    7173                 :             :   /* We could also implement this by wrapping init in a new CONSTRUCTOR and
    7174                 :             :      calling reshape_init, but this way can just live on the stack.  */
    7175                 :      577917 :   constructor_elt elt = { /*index=*/NULL_TREE, init };
    7176                 :      577917 :   reshape_iter iter = { &elt, &elt + 1, 0 };
    7177                 :      577917 :   return reshape_init_r (type, &iter,
    7178                 :             :                          /*first_initializer_p=*/NULL_TREE,
    7179                 :      577917 :                          complain);
    7180                 :             : }
    7181                 :             : 
    7182                 :             : /* Subroutine of reshape_init_r, processes the initializers for classes
    7183                 :             :    or union. Parameters are the same of reshape_init_r.  */
    7184                 :             : 
    7185                 :             : static tree
    7186                 :     3617215 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
    7187                 :             :                     tsubst_flags_t complain)
    7188                 :             : {
    7189                 :     3617215 :   tree field;
    7190                 :     3617215 :   tree new_init;
    7191                 :             : 
    7192                 :     3617215 :   gcc_assert (CLASS_TYPE_P (type));
    7193                 :             : 
    7194                 :             :   /* The initializer for a class is always a CONSTRUCTOR.  */
    7195                 :     3617215 :   new_init = build_constructor (init_list_type_node, NULL);
    7196                 :             : 
    7197                 :     3617215 :   int binfo_idx = -1;
    7198                 :     3617215 :   tree binfo = TYPE_BINFO (type);
    7199                 :     3617215 :   tree base_binfo = NULL_TREE;
    7200                 :     3617215 :   if (cxx_dialect >= cxx17 && uses_template_parms (type))
    7201                 :             :     {
    7202                 :             :       /* We get here from maybe_aggr_guide for C++20 class template argument
    7203                 :             :          deduction.  In this case we need to look through the binfo because a
    7204                 :             :          template doesn't have base fields.  */
    7205                 :         338 :       binfo_idx = 0;
    7206                 :         338 :       BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
    7207                 :             :     }
    7208                 :          67 :   if (base_binfo)
    7209                 :             :     field = base_binfo;
    7210                 :             :   else
    7211                 :     3617148 :     field = next_aggregate_field (TYPE_FIELDS (type));
    7212                 :             : 
    7213                 :     3617215 :   if (!field)
    7214                 :             :     {
    7215                 :             :       /* [dcl.init.aggr]
    7216                 :             : 
    7217                 :             :         An initializer for an aggregate member that is an
    7218                 :             :         empty class shall have the form of an empty
    7219                 :             :         initializer-list {}.  */
    7220                 :         324 :       if (!first_initializer_p)
    7221                 :             :         {
    7222                 :         270 :           if (complain & tf_error)
    7223                 :          13 :             error ("initializer for %qT must be brace-enclosed", type);
    7224                 :         270 :           return error_mark_node;
    7225                 :             :         }
    7226                 :             :       return new_init;
    7227                 :             :     }
    7228                 :             : 
    7229                 :             :   /* For C++20 CTAD, handle pack expansions in the base list.  */
    7230                 :             :   tree last_was_pack_expansion = NULL_TREE;
    7231                 :             : 
    7232                 :             :   /* Loop through the initializable fields, gathering initializers.  */
    7233                 :    11005549 :   while (d->cur != d->end)
    7234                 :             :     {
    7235                 :     7500758 :       tree field_init;
    7236                 :     7500758 :       constructor_elt *old_cur = d->cur;
    7237                 :     7500758 :       unsigned old_raw_idx = d->raw_idx;
    7238                 :     7500758 :       bool direct_desig = false;
    7239                 :             : 
    7240                 :             :       /* Handle C++20 designated initializers.  */
    7241                 :     7500758 :       if (d->cur->index)
    7242                 :             :         {
    7243                 :      578077 :           if (d->cur->index == error_mark_node)
    7244                 :             :             return error_mark_node;
    7245                 :             : 
    7246                 :      578071 :           if (TREE_CODE (d->cur->index) == FIELD_DECL)
    7247                 :             :             {
    7248                 :             :               /* We already reshaped this; we should have returned early from
    7249                 :             :                  reshape_init.  */
    7250                 :           0 :               gcc_checking_assert (false);
    7251                 :             :               if (field != d->cur->index)
    7252                 :             :                 {
    7253                 :             :                   if (tree id = DECL_NAME (d->cur->index))
    7254                 :             :                     gcc_checking_assert (d->cur->index
    7255                 :             :                                          == get_class_binding (type, id));
    7256                 :             :                   field = d->cur->index;
    7257                 :             :                 }
    7258                 :             :             }
    7259                 :      578071 :           else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    7260                 :             :             {
    7261                 :      578065 :               CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7262                 :      578065 :               field = get_class_binding (type, d->cur->index);
    7263                 :      578065 :               direct_desig = true;
    7264                 :             :             }
    7265                 :             :           else
    7266                 :             :             {
    7267                 :           6 :               if (complain & tf_error)
    7268                 :           6 :                 error ("%<[%E] =%> used in a GNU-style designated initializer"
    7269                 :             :                        " for class %qT", d->cur->index, type);
    7270                 :           6 :               return error_mark_node;
    7271                 :             :             }
    7272                 :             : 
    7273                 :      578065 :           if (!field && ANON_AGGR_TYPE_P (type))
    7274                 :             :             /* Apparently the designator isn't for a member of this anonymous
    7275                 :             :                struct, so head back to the enclosing class.  */
    7276                 :             :             break;
    7277                 :             : 
    7278                 :      578062 :           if (!field || TREE_CODE (field) != FIELD_DECL)
    7279                 :             :             {
    7280                 :          18 :               if (complain & tf_error)
    7281                 :             :                 {
    7282                 :           6 :                   if (field && TREE_CODE (field) == TREE_LIST)
    7283                 :             :                     {
    7284                 :           3 :                       auto_diagnostic_group g;
    7285                 :           3 :                       error ("request for member %qD is ambiguous",
    7286                 :           3 :                              d->cur->index);
    7287                 :           3 :                       print_candidates (field);
    7288                 :           3 :                     }
    7289                 :             :                   else
    7290                 :           3 :                     error ("%qT has no non-static data member named %qD", type,
    7291                 :           3 :                            d->cur->index);
    7292                 :             :                 }
    7293                 :          18 :               return error_mark_node;
    7294                 :             :             }
    7295                 :             : 
    7296                 :             :           /* If the element is an anonymous union object and the initializer
    7297                 :             :              list is a designated-initializer-list, the anonymous union object
    7298                 :             :              is initialized by the designated-initializer-list { D }, where D
    7299                 :             :              is the designated-initializer-clause naming a member of the
    7300                 :             :              anonymous union object.  */
    7301                 :      578044 :           tree ictx = DECL_CONTEXT (field);
    7302                 :      578044 :           if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
    7303                 :             :             {
    7304                 :             :               /* Find the anon aggr that is a direct member of TYPE.  */
    7305                 :         139 :               while (ANON_AGGR_TYPE_P (ictx))
    7306                 :             :                 {
    7307                 :         136 :                   tree cctx = TYPE_CONTEXT (ictx);
    7308                 :         136 :                   if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
    7309                 :         124 :                     goto found;
    7310                 :             :                   ictx = cctx;
    7311                 :             :                 }
    7312                 :             : 
    7313                 :             :               /* Not found, e.g. FIELD is a member of a base class.  */
    7314                 :           3 :               if (complain & tf_error)
    7315                 :           3 :                 error ("%qD is not a direct member of %qT", field, type);
    7316                 :           3 :               return error_mark_node;
    7317                 :             : 
    7318                 :         124 :             found:
    7319                 :             :               /* Now find the TYPE member with that anon aggr type.  */
    7320                 :         124 :               tree aafield = TYPE_FIELDS (type);
    7321                 :        1067 :               for (; aafield; aafield = TREE_CHAIN (aafield))
    7322                 :        1067 :                 if (TREE_TYPE (aafield) == ictx)
    7323                 :             :                   break;
    7324                 :           0 :               gcc_assert (aafield);
    7325                 :             :               field = aafield;
    7326                 :             :               direct_desig = false;
    7327                 :             :             }
    7328                 :             :         }
    7329                 :             : 
    7330                 :             :       /* If we processed all the member of the class, we are done.  */
    7331                 :     7500598 :       if (!field)
    7332                 :             :         break;
    7333                 :             : 
    7334                 :    15000595 :       last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
    7335                 :     7500307 :                                  ? field : NULL_TREE);
    7336                 :     7500307 :       if (last_was_pack_expansion)
    7337                 :             :         /* Each non-trailing aggregate element that is a pack expansion is
    7338                 :             :            assumed to correspond to no elements of the initializer list.  */
    7339                 :          19 :         goto continue_;
    7340                 :             : 
    7341                 :     7500288 :       if (direct_desig)
    7342                 :             :         {
    7343                 :             :           /* The designated field F is initialized from this one element.
    7344                 :             : 
    7345                 :             :              Note that we don't want to do this if we found the designator
    7346                 :             :              inside an anon aggr above; we use the normal code to implement:
    7347                 :             : 
    7348                 :             :              "If the element is an anonymous union member and the initializer
    7349                 :             :              list is a brace-enclosed designated- initializer-list, the element
    7350                 :             :              is initialized by the designated-initializer-list { D }, where D
    7351                 :             :              is the designated- initializer-clause naming a member of the
    7352                 :             :              anonymous union member."  */
    7353                 :      577917 :           gcc_checking_assert (TREE_CODE (d->cur->value) != RAW_DATA_CST);
    7354                 :      577917 :           field_init = reshape_single_init (TREE_TYPE (field),
    7355                 :             :                                             d->cur->value, complain);
    7356                 :      577917 :           d->cur++;
    7357                 :             :         }
    7358                 :             :       else
    7359                 :     6922371 :         field_init = reshape_init_r (TREE_TYPE (field), d,
    7360                 :             :                                      /*first_initializer_p=*/NULL_TREE,
    7361                 :             :                                      complain);
    7362                 :             : 
    7363                 :     7500288 :       if (field_init == error_mark_node)
    7364                 :             :         return error_mark_node;
    7365                 :             : 
    7366                 :     7499999 :       if (d->cur == old_cur && d->cur->index && d->raw_idx == old_raw_idx)
    7367                 :             :         {
    7368                 :             :           /* This can happen with an invalid initializer for a flexible
    7369                 :             :              array member (c++/54441).  */
    7370                 :           0 :           if (complain & tf_error)
    7371                 :           0 :             error ("invalid initializer for %q#D", field);
    7372                 :           0 :           return error_mark_node;
    7373                 :             :         }
    7374                 :             : 
    7375                 :     7499999 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
    7376                 :             : 
    7377                 :             :       /* [dcl.init.aggr]
    7378                 :             : 
    7379                 :             :         When a union  is  initialized with a brace-enclosed
    7380                 :             :         initializer, the braces shall only contain an
    7381                 :             :         initializer for the first member of the union.  */
    7382                 :     7499999 :       if (TREE_CODE (type) == UNION_TYPE)
    7383                 :             :         break;
    7384                 :             : 
    7385                 :     7388639 :     continue_:
    7386                 :     7388658 :       if (base_binfo)
    7387                 :             :         {
    7388                 :          82 :           if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
    7389                 :             :             field = base_binfo;
    7390                 :             :           else
    7391                 :          35 :             field = next_aggregate_field (TYPE_FIELDS (type));
    7392                 :             :         }
    7393                 :             :       else
    7394                 :     7388576 :         field = next_aggregate_field (DECL_CHAIN (field));
    7395                 :             :     }
    7396                 :             : 
    7397                 :             :   /* A trailing aggregate element that is a pack expansion is assumed to
    7398                 :             :      correspond to all remaining elements of the initializer list (if any).  */
    7399                 :     3616569 :   if (last_was_pack_expansion)
    7400                 :             :     {
    7401                 :          16 :       tree init = d->cur->value;
    7402                 :          16 :       bool inc_cur;
    7403                 :          16 :       if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    7404                 :           0 :         init = raw_init;
    7405                 :          16 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    7406                 :             :                               last_was_pack_expansion, init);
    7407                 :          46 :       while (d->cur != d->end)
    7408                 :          30 :         d->cur++;
    7409                 :             :     }
    7410                 :             : 
    7411                 :             :   return new_init;
    7412                 :             : }
    7413                 :             : 
    7414                 :             : /* Subroutine of reshape_init_r.  We're in a context where C99 initializer
    7415                 :             :    designators are not valid; either complain or return true to indicate
    7416                 :             :    that reshape_init_r should return error_mark_node.  */
    7417                 :             : 
    7418                 :             : static bool
    7419                 :       63485 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
    7420                 :             : {
    7421                 :       63485 :   if (d->cur->index)
    7422                 :             :     {
    7423                 :          30 :       if (complain & tf_error)
    7424                 :          45 :         error_at (cp_expr_loc_or_input_loc (d->cur->index),
    7425                 :             :                   "C99 designator %qE outside aggregate initializer",
    7426                 :             :                   d->cur->index);
    7427                 :             :       else
    7428                 :             :         return true;
    7429                 :             :     }
    7430                 :             :   return false;
    7431                 :             : }
    7432                 :             : 
    7433                 :             : /* Subroutine of reshape_init, which processes a single initializer (part of
    7434                 :             :    a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
    7435                 :             :    iterator within the CONSTRUCTOR which points to the initializer to process.
    7436                 :             :    If this is the first initializer of the outermost CONSTRUCTOR node,
    7437                 :             :    FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE.  */
    7438                 :             : 
    7439                 :             : static tree
    7440                 :    28607178 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
    7441                 :             :                 tsubst_flags_t complain)
    7442                 :             : {
    7443                 :    28607178 :   tree init = d->cur->value;
    7444                 :             : 
    7445                 :    28607178 :   if (error_operand_p (init))
    7446                 :         129 :     return error_mark_node;
    7447                 :             : 
    7448                 :     4035145 :   if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
    7449                 :    28670368 :       && has_designator_problem (d, complain))
    7450                 :           0 :     return error_mark_node;
    7451                 :             : 
    7452                 :    28607049 :   tree stripped_init = tree_strip_any_location_wrapper (init);
    7453                 :             : 
    7454                 :    28607049 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    7455                 :             :     {
    7456                 :             :       /* A complex type can be initialized from one or two initializers,
    7457                 :             :          but braces are not elided.  */
    7458                 :         564 :       init = consume_init (init, d);
    7459                 :         564 :       if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
    7460                 :             :         {
    7461                 :           9 :           if (CONSTRUCTOR_NELTS (stripped_init) > 2)
    7462                 :             :             {
    7463                 :           0 :               if (complain & tf_error)
    7464                 :           0 :                 error ("too many initializers for %qT", type);
    7465                 :             :               else
    7466                 :           0 :                 return error_mark_node;
    7467                 :             :             }
    7468                 :             :         }
    7469                 :         555 :       else if (first_initializer_p && d->cur != d->end)
    7470                 :             :         {
    7471                 :          36 :           if (error_operand_p (d->cur->value)
    7472                 :          36 :               || has_designator_problem (d, complain))
    7473                 :           0 :             return error_mark_node;
    7474                 :          36 :           vec<constructor_elt, va_gc> *v = 0;
    7475                 :          36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    7476                 :          36 :           init = consume_init (d->cur->value, d);
    7477                 :          36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    7478                 :          36 :           init = build_constructor (init_list_type_node, v);
    7479                 :             :         }
    7480                 :         564 :       return init;
    7481                 :             :     }
    7482                 :             : 
    7483                 :             :   /* A non-aggregate type is always initialized with a single
    7484                 :             :      initializer.  */
    7485                 :    57163105 :   if (!CP_AGGREGATE_TYPE_P (type)
    7486                 :             :       /* As is an array with dependent bound, which we can see
    7487                 :             :          during C++20 aggregate CTAD.  */
    7488                 :    34609718 :       || (cxx_dialect >= cxx20
    7489                 :     3835676 :           && TREE_CODE (type) == ARRAY_TYPE
    7490                 :      154632 :           && uses_template_parms (TYPE_DOMAIN (type))))
    7491                 :             :     {
    7492                 :             :       /* It is invalid to initialize a non-aggregate type with a
    7493                 :             :          brace-enclosed initializer before C++0x.
    7494                 :             :          We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
    7495                 :             :          of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
    7496                 :             :          a CONSTRUCTOR (with a record type).  */
    7497                 :    22553398 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR
    7498                 :             :           /* Don't complain about a capture-init.  */
    7499                 :      308414 :           && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
    7500                 :    22851727 :           && BRACE_ENCLOSED_INITIALIZER_P (stripped_init))  /* p7626.C */
    7501                 :             :         {
    7502                 :      298290 :           if (SCALAR_TYPE_P (type))
    7503                 :             :             {
    7504                 :         726 :               if (cxx_dialect < cxx11)
    7505                 :             :                 {
    7506                 :          16 :                   if (complain & tf_error)
    7507                 :          16 :                     error ("braces around scalar initializer for type %qT",
    7508                 :             :                            type);
    7509                 :          16 :                   init = error_mark_node;
    7510                 :             :                 }
    7511                 :         710 :               else if (first_initializer_p
    7512                 :         710 :                        || (CONSTRUCTOR_NELTS (stripped_init) > 0
    7513                 :         546 :                            && (BRACE_ENCLOSED_INITIALIZER_P
    7514                 :             :                                (CONSTRUCTOR_ELT (stripped_init,0)->value))))
    7515                 :             :                 {
    7516                 :          13 :                   if (complain & tf_error)
    7517                 :          13 :                     error ("too many braces around scalar initializer "
    7518                 :             :                            "for type %qT", type);
    7519                 :          13 :                   init = error_mark_node;
    7520                 :             :                 }
    7521                 :             :             }
    7522                 :             :           else
    7523                 :      297564 :             maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    7524                 :             :         }
    7525                 :    22553398 :       return consume_init (init, d);
    7526                 :             :     }
    7527                 :             : 
    7528                 :             :   /* "If T is a class type and the initializer list has a single element of
    7529                 :             :      type cv U, where U is T or a class derived from T, the object is
    7530                 :             :      initialized from that element."  Even if T is an aggregate.  */
    7531                 :     6030860 :   if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
    7532                 :     5602434 :       && first_initializer_p
    7533                 :             :       /* But not if it's a designated init.  */
    7534                 :     3644630 :       && !d->cur->index
    7535                 :     3399219 :       && d->end - d->cur == 1
    7536                 :      433746 :       && TREE_CODE (init) != RAW_DATA_CST
    7537                 :     6486833 :       && reference_related_p (type, TREE_TYPE (init)))
    7538                 :             :     {
    7539                 :         416 :       d->cur++;
    7540                 :         416 :       return init;
    7541                 :             :     }
    7542                 :             : 
    7543                 :             :   /* [dcl.init.aggr]
    7544                 :             : 
    7545                 :             :      All implicit type conversions (clause _conv_) are considered when
    7546                 :             :      initializing the aggregate member with an initializer from an
    7547                 :             :      initializer-list.  If the initializer can initialize a member,
    7548                 :             :      the member is initialized.  Otherwise, if the member is itself a
    7549                 :             :      non-empty subaggregate, brace elision is assumed and the
    7550                 :             :      initializer is considered for the initialization of the first
    7551                 :             :      member of the subaggregate.  */
    7552                 :     2645676 :   if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
    7553                 :             :       /* But don't try this for the first initializer, since that would be
    7554                 :             :          looking through the outermost braces; A a2 = { a1 }; is not a
    7555                 :             :          valid aggregate initialization.  */
    7556                 :     3407055 :       && !first_initializer_p
    7557                 :     6064639 :       && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
    7558                 :        8656 :           || can_convert_arg (type, TREE_TYPE (init),
    7559                 :        8656 :                               TREE_CODE (init) == RAW_DATA_CST
    7560                 :     6054277 :                               ? build_int_cst (integer_type_node,
    7561                 :        1606 :                                                *(const unsigned char *)
    7562                 :        1606 :                                                RAW_DATA_POINTER (init))
    7563                 :             :                               : init,
    7564                 :             :                               LOOKUP_NORMAL, complain)))
    7565                 :        3350 :     return consume_init (init, d);
    7566                 :             : 
    7567                 :             :   /* [dcl.init.string]
    7568                 :             : 
    7569                 :             :       A char array (whether plain char, signed char, or unsigned char)
    7570                 :             :       can be initialized by a string-literal (optionally enclosed in
    7571                 :             :       braces); a wchar_t array can be initialized by a wide
    7572                 :             :       string-literal (optionally enclosed in braces).  */
    7573                 :     6049321 :   if (TREE_CODE (type) == ARRAY_TYPE
    7574                 :     6049321 :       && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
    7575                 :             :     {
    7576                 :       88762 :       tree str_init = init;
    7577                 :       88762 :       tree stripped_str_init = stripped_init;
    7578                 :       88762 :       reshape_iter stripd = {};
    7579                 :             : 
    7580                 :             :       /* Strip one level of braces if and only if they enclose a single
    7581                 :             :          element (as allowed by [dcl.init.string]).  */
    7582                 :       88762 :       if (!first_initializer_p
    7583                 :       12483 :           && TREE_CODE (stripped_str_init) == CONSTRUCTOR
    7584                 :      100145 :           && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
    7585                 :             :         {
    7586                 :         375 :           stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
    7587                 :         375 :           str_init = stripd.cur->value;
    7588                 :         375 :           stripped_str_init = tree_strip_any_location_wrapper (str_init);
    7589                 :             :         }
    7590                 :             : 
    7591                 :             :       /* If it's a string literal, then it's the initializer for the array
    7592                 :             :          as a whole. Otherwise, continue with normal initialization for
    7593                 :             :          array types (one value per array element).  */
    7594                 :       88762 :       if (TREE_CODE (stripped_str_init) == STRING_CST)
    7595                 :             :         {
    7596                 :          72 :           if ((first_initializer_p && has_designator_problem (d, complain))
    7597                 :        1025 :               || (stripd.cur && has_designator_problem (&stripd, complain)))
    7598                 :         953 :             return error_mark_node;
    7599                 :         953 :           d->cur++;
    7600                 :         953 :           return str_init;
    7601                 :             :         }
    7602                 :             :     }
    7603                 :             : 
    7604                 :             :   /* The following cases are about aggregates. If we are not within a full
    7605                 :             :      initializer already, and there is not a CONSTRUCTOR, it means that there
    7606                 :             :      is a missing set of braces (that is, we are processing the case for
    7607                 :             :      which reshape_init exists).  */
    7608                 :     6048368 :   bool braces_elided_p = false;
    7609                 :     6048368 :   if (!first_initializer_p)
    7610                 :             :     {
    7611                 :     2077030 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR)
    7612                 :             :         {
    7613                 :     2069241 :           tree init_type = TREE_TYPE (init);
    7614                 :     2069241 :           if (init_type && TYPE_PTRMEMFUNC_P (init_type))
    7615                 :             :             /* There is no need to call reshape_init for pointer-to-member
    7616                 :             :                function initializers, as they are always constructed correctly
    7617                 :             :                by the front end.  Here we have e.g. {.__pfn=0B, .__delta=0},
    7618                 :             :                which is missing outermost braces.  We should warn below, and
    7619                 :             :                one of the routines below will wrap it in additional { }.  */;
    7620                 :             :           /* For a nested compound literal, proceed to specialized routines,
    7621                 :             :              to handle initialization of arrays and similar.  */
    7622                 :     2069232 :           else if (COMPOUND_LITERAL_P (stripped_init))
    7623                 :           6 :             gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    7624                 :             :           /* If we have an unresolved designator, we need to find the member it
    7625                 :             :              designates within TYPE, so proceed to the routines below.  For
    7626                 :             :              FIELD_DECL or INTEGER_CST designators, we're already initializing
    7627                 :             :              the designated element.  */
    7628                 :     2069226 :           else if (d->cur->index
    7629                 :          27 :                    && TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    7630                 :             :             /* Brace elision with designators is only permitted for anonymous
    7631                 :             :                aggregates.  */
    7632                 :          15 :             gcc_checking_assert (ANON_AGGR_TYPE_P (type));
    7633                 :             :           /* A CONSTRUCTOR of the target's type is a previously
    7634                 :             :              digested initializer.  */
    7635                 :     2069211 :           else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
    7636                 :             :             {
    7637                 :           0 :               ++d->cur;
    7638                 :           0 :               return init;
    7639                 :             :             }
    7640                 :             :           else
    7641                 :             :             {
    7642                 :             :               /* Something that hasn't been reshaped yet.  */
    7643                 :     2069211 :               ++d->cur;
    7644                 :     2069211 :               gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    7645                 :     2069211 :               return reshape_init (type, init, complain);
    7646                 :             :             }
    7647                 :             :         }
    7648                 :             : 
    7649                 :        7819 :       if (complain & tf_warning)
    7650                 :        6670 :         warning (OPT_Wmissing_braces,
    7651                 :             :                  "missing braces around initializer for %qT",
    7652                 :             :                  type);
    7653                 :             :       braces_elided_p = true;
    7654                 :             :     }
    7655                 :             : 
    7656                 :             :   /* Dispatch to specialized routines.  */
    7657                 :     3979157 :   tree new_init;
    7658                 :     3979157 :   if (CLASS_TYPE_P (type))
    7659                 :     3617215 :     new_init = reshape_init_class (type, d, first_initializer_p, complain);
    7660                 :      361942 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    7661                 :      320761 :     new_init = reshape_init_array (type, d, first_initializer_p, complain);
    7662                 :       41181 :   else if (VECTOR_TYPE_P (type))
    7663                 :       41181 :     new_init = reshape_init_vector (type, d, complain);
    7664                 :             :   else
    7665                 :           0 :     gcc_unreachable ();
    7666                 :             : 
    7667                 :     3979157 :   if (braces_elided_p
    7668                 :        7819 :       && TREE_CODE (new_init) == CONSTRUCTOR)
    7669                 :        7543 :     CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
    7670                 :             : 
    7671                 :             :   return new_init;
    7672                 :             : }
    7673                 :             : 
    7674                 :             : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
    7675                 :             :    brace-enclosed aggregate initializer.
    7676                 :             : 
    7677                 :             :    INIT is the CONSTRUCTOR containing the list of initializers describing
    7678                 :             :    a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
    7679                 :             :    It may not presently match the shape of the TYPE; for example:
    7680                 :             : 
    7681                 :             :      struct S { int a; int b; };
    7682                 :             :      struct S a[] = { 1, 2, 3, 4 };
    7683                 :             : 
    7684                 :             :    Here INIT will hold a vector of four elements, rather than a
    7685                 :             :    vector of two elements, each itself a vector of two elements.  This
    7686                 :             :    routine transforms INIT from the former form into the latter.  The
    7687                 :             :    revised CONSTRUCTOR node is returned.  */
    7688                 :             : 
    7689                 :             : tree
    7690                 :     9611616 : reshape_init (tree type, tree init, tsubst_flags_t complain)
    7691                 :             : {
    7692                 :     9611616 :   vec<constructor_elt, va_gc> *v;
    7693                 :     9611616 :   reshape_iter d;
    7694                 :     9611616 :   tree new_init;
    7695                 :             : 
    7696                 :     9611616 :   gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
    7697                 :             : 
    7698                 :     9611616 :   v = CONSTRUCTOR_ELTS (init);
    7699                 :             : 
    7700                 :             :   /* An empty constructor does not need reshaping, and it is always a valid
    7701                 :             :      initializer.  */
    7702                 :     9612187 :   if (vec_safe_is_empty (v))
    7703                 :             :     return init;
    7704                 :             : 
    7705                 :     4036047 :   if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
    7706                 :             :     /* Already reshaped.  */
    7707                 :             :     return init;
    7708                 :             : 
    7709                 :             :   /* Brace elision is not performed for a CONSTRUCTOR representing
    7710                 :             :      parenthesized aggregate initialization.  */
    7711                 :     4035910 :   if (CONSTRUCTOR_IS_PAREN_INIT (init))
    7712                 :             :     {
    7713                 :         463 :       tree elt = (*v)[0].value;
    7714                 :             :       /* If we're initializing a char array from a string-literal that is
    7715                 :             :          enclosed in braces, unwrap it here.  */
    7716                 :         463 :       if (TREE_CODE (type) == ARRAY_TYPE
    7717                 :         221 :           && vec_safe_length (v) == 1
    7718                 :         121 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    7719                 :         496 :           && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
    7720                 :             :         return elt;
    7721                 :         434 :       return init;
    7722                 :             :     }
    7723                 :             : 
    7724                 :             :   /* Handle [dcl.init.list] direct-list-initialization from
    7725                 :             :      single element of enumeration with a fixed underlying type.  */
    7726                 :     4035447 :   if (is_direct_enum_init (type, init))
    7727                 :             :     {
    7728                 :         176 :       tree elt = CONSTRUCTOR_ELT (init, 0)->value;
    7729                 :         176 :       type = cv_unqualified (type);
    7730                 :         176 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
    7731                 :             :         {
    7732                 :         161 :           warning_sentinel w (warn_useless_cast);
    7733                 :         161 :           warning_sentinel w2 (warn_ignored_qualifiers);
    7734                 :         161 :           return cp_build_c_cast (input_location, type, elt,
    7735                 :             :                                   tf_warning_or_error);
    7736                 :         161 :         }
    7737                 :             :       else
    7738                 :          15 :         return error_mark_node;
    7739                 :             :     }
    7740                 :             : 
    7741                 :             :   /* Recurse on this CONSTRUCTOR.  */
    7742                 :     4035271 :   d.cur = &(*v)[0];
    7743                 :     4035271 :   d.end = d.cur + v->length ();
    7744                 :     4035271 :   d.raw_idx = 0;
    7745                 :             : 
    7746                 :     4035271 :   new_init = reshape_init_r (type, &d, init, complain);
    7747                 :     4035271 :   if (new_init == error_mark_node)
    7748                 :             :     return error_mark_node;
    7749                 :             : 
    7750                 :             :   /* Make sure all the element of the constructor were used. Otherwise,
    7751                 :             :      issue an error about exceeding initializers.  */
    7752                 :     4034644 :   if (d.cur != d.end)
    7753                 :             :     {
    7754                 :         159 :       if (complain & tf_error)
    7755                 :          63 :         error ("too many initializers for %qT", type);
    7756                 :         159 :       return error_mark_node;
    7757                 :             :     }
    7758                 :             : 
    7759                 :     4034485 :   if (CONSTRUCTOR_IS_DIRECT_INIT (init)
    7760                 :     4034485 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    7761                 :      463323 :     CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
    7762                 :     4034485 :   if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
    7763                 :     4034485 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    7764                 :       30699 :     gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
    7765                 :             :                          || seen_error ());
    7766                 :             : 
    7767                 :             :   return new_init;
    7768                 :             : }
    7769                 :             : 
    7770                 :             : /* Verify array initializer.  Returns true if errors have been reported.  */
    7771                 :             : 
    7772                 :             : bool
    7773                 :      878878 : check_array_initializer (tree decl, tree type, tree init)
    7774                 :             : {
    7775                 :      878878 :   tree element_type = TREE_TYPE (type);
    7776                 :             : 
    7777                 :             :   /* Structured binding when initialized with an array type needs
    7778                 :             :      to have complete type.  */
    7779                 :      878878 :   if (decl
    7780                 :      873602 :       && DECL_DECOMPOSITION_P (decl)
    7781                 :         273 :       && DECL_DECOMP_IS_BASE (decl)
    7782                 :      879151 :       && !COMPLETE_TYPE_P (type))
    7783                 :             :     {
    7784                 :           0 :       error_at (DECL_SOURCE_LOCATION (decl),
    7785                 :             :                 "structured binding has incomplete type %qT", type);
    7786                 :           0 :       TREE_TYPE (decl) = error_mark_node;
    7787                 :           0 :       return true;
    7788                 :             :     }
    7789                 :             : 
    7790                 :             :   /* The array type itself need not be complete, because the
    7791                 :             :      initializer may tell us how many elements are in the array.
    7792                 :             :      But, the elements of the array must be complete.  */
    7793                 :      878878 :   if (!COMPLETE_TYPE_P (complete_type (element_type)))
    7794                 :             :     {
    7795                 :          15 :       if (decl)
    7796                 :           9 :         error_at (DECL_SOURCE_LOCATION (decl),
    7797                 :             :                   "elements of array %q#D have incomplete type", decl);
    7798                 :             :       else
    7799                 :           6 :         error ("elements of array %q#T have incomplete type", type);
    7800                 :          15 :       return true;
    7801                 :             :     }
    7802                 :             : 
    7803                 :      878863 :   location_t loc = (decl ? location_of (decl) : input_location);
    7804                 :      878863 :   if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
    7805                 :             :     return true;
    7806                 :             : 
    7807                 :             :   /* A compound literal can't have variable size.  */
    7808                 :      878863 :   if (init && !decl
    7809                 :      878863 :       && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
    7810                 :        5267 :           || !TREE_CONSTANT (TYPE_SIZE (element_type))))
    7811                 :             :     {
    7812                 :           3 :       error ("variable-sized compound literal");
    7813                 :           3 :       return true;
    7814                 :             :     }
    7815                 :             :   return false;
    7816                 :             : }
    7817                 :             : 
    7818                 :             : /* Subroutine of check_initializer; args are passed down from that function.
    7819                 :             :    Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init.  */
    7820                 :             : 
    7821                 :             : static tree
    7822                 :     2360368 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
    7823                 :             : {
    7824                 :     2360368 :   gcc_assert (stmts_are_full_exprs_p ());
    7825                 :     2360368 :   if (init)
    7826                 :     1722995 :     maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
    7827                 :     2360368 :   return build_aggr_init (decl, init, flags, tf_warning_or_error);
    7828                 :             : }
    7829                 :             : 
    7830                 :             : /* Verify INIT (the initializer for DECL), and record the
    7831                 :             :    initialization in DECL_INITIAL, if appropriate.  CLEANUP is as for
    7832                 :             :    grok_reference_init.
    7833                 :             : 
    7834                 :             :    If the return value is non-NULL, it is an expression that must be
    7835                 :             :    evaluated dynamically to initialize DECL.  */
    7836                 :             : 
    7837                 :             : static tree
    7838                 :    41853718 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
    7839                 :             : {
    7840                 :    41853718 :   tree type;
    7841                 :    41853718 :   tree init_code = NULL;
    7842                 :    41853718 :   tree core_type;
    7843                 :             : 
    7844                 :             :   /* Things that are going to be initialized need to have complete
    7845                 :             :      type.  */
    7846                 :    41853718 :   TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
    7847                 :             : 
    7848                 :    41853718 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    7849                 :             :     {
    7850                 :             :       /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
    7851                 :             :          it doesn't have storage to be initialized.  */
    7852                 :         138 :       gcc_assert (init == NULL_TREE);
    7853                 :             :       return NULL_TREE;
    7854                 :             :     }
    7855                 :             : 
    7856                 :    41853580 :   if (type == error_mark_node)
    7857                 :             :     /* We will have already complained.  */
    7858                 :             :     return NULL_TREE;
    7859                 :             : 
    7860                 :    41853580 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7861                 :             :     {
    7862                 :      873602 :       if (check_array_initializer (decl, type, init))
    7863                 :             :         return NULL_TREE;
    7864                 :             :     }
    7865                 :    40979978 :   else if (!COMPLETE_TYPE_P (type))
    7866                 :             :     {
    7867                 :          37 :       error_at (DECL_SOURCE_LOCATION (decl),
    7868                 :             :                 "%q#D has incomplete type", decl);
    7869                 :          37 :       TREE_TYPE (decl) = error_mark_node;
    7870                 :          37 :       return NULL_TREE;
    7871                 :             :     }
    7872                 :             :   else
    7873                 :             :     /* There is no way to make a variable-sized class type in GNU C++.  */
    7874                 :    40979941 :     gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
    7875                 :             : 
    7876                 :    41853534 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
    7877                 :             :     {
    7878                 :     1495566 :       int init_len = CONSTRUCTOR_NELTS (init);
    7879                 :     1495566 :       if (SCALAR_TYPE_P (type))
    7880                 :             :         {
    7881                 :       52579 :           if (init_len == 0)
    7882                 :             :             {
    7883                 :       43533 :               maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    7884                 :       43533 :               init = build_zero_init (type, NULL_TREE, false);
    7885                 :             :             }
    7886                 :        9046 :           else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
    7887                 :             :             {
    7888                 :          12 :               error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    7889                 :             :                         "scalar object %qD requires one element in "
    7890                 :             :                         "initializer", decl);
    7891                 :           6 :               TREE_TYPE (decl) = error_mark_node;
    7892                 :           6 :               return NULL_TREE;
    7893                 :             :             }
    7894                 :             :         }
    7895                 :             :     }
    7896                 :             : 
    7897                 :    41853528 :   if (TREE_CODE (decl) == CONST_DECL)
    7898                 :             :     {
    7899                 :           0 :       gcc_assert (!TYPE_REF_P (type));
    7900                 :             : 
    7901                 :           0 :       DECL_INITIAL (decl) = init;
    7902                 :             : 
    7903                 :           0 :       gcc_assert (init != NULL_TREE);
    7904                 :             :       init = NULL_TREE;
    7905                 :             :     }
    7906                 :    41853528 :   else if (!init && DECL_REALLY_EXTERN (decl))
    7907                 :             :     ;
    7908                 :    41853528 :   else if (flag_openmp
    7909                 :      129108 :            && VAR_P (decl)
    7910                 :      129108 :            && DECL_LANG_SPECIFIC (decl)
    7911                 :       54329 :            && DECL_OMP_DECLARE_MAPPER_P (decl)
    7912                 :    41853528 :            && TREE_CODE (init) == OMP_DECLARE_MAPPER)
    7913                 :             :     return NULL_TREE;
    7914                 :     4291413 :   else if (init || type_build_ctor_call (type)
    7915                 :    45507565 :            || TYPE_REF_P (type))
    7916                 :             :     {
    7917                 :    38199506 :       if (TYPE_REF_P (type))
    7918                 :             :         {
    7919                 :      315054 :           init = grok_reference_init (decl, type, init, flags);
    7920                 :      315054 :           flags |= LOOKUP_ALREADY_DIGESTED;
    7921                 :             :         }
    7922                 :    37884452 :       else if (!init)
    7923                 :      637376 :         check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    7924                 :             :                                            tf_warning_or_error);
    7925                 :             :       /* Do not reshape constructors of vectors (they don't need to be
    7926                 :             :          reshaped.  */
    7927                 :    37247076 :       else if (BRACE_ENCLOSED_INITIALIZER_P (init))
    7928                 :             :         {
    7929                 :     1451717 :           if (is_std_init_list (type))
    7930                 :             :             {
    7931                 :         328 :               init = perform_implicit_conversion (type, init,
    7932                 :             :                                                   tf_warning_or_error);
    7933                 :         328 :               flags |= LOOKUP_ALREADY_DIGESTED;
    7934                 :             :             }
    7935                 :     1451389 :           else if (TYPE_NON_AGGREGATE_CLASS (type))
    7936                 :             :             {
    7937                 :             :               /* Don't reshape if the class has constructors.  */
    7938                 :      213931 :               if (cxx_dialect == cxx98)
    7939                 :           6 :                 error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    7940                 :             :                           "in C++98 %qD must be initialized by "
    7941                 :             :                           "constructor, not by %<{...}%>",
    7942                 :             :                           decl);
    7943                 :             :             }
    7944                 :     1237458 :           else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
    7945                 :             :             {
    7946                 :           0 :               error ("opaque vector types cannot be initialized");
    7947                 :           0 :               init = error_mark_node;
    7948                 :             :             }
    7949                 :             :           else
    7950                 :             :             {
    7951                 :     1237458 :               init = reshape_init (type, init, tf_warning_or_error);
    7952                 :     1237458 :               flags |= LOOKUP_NO_NARROWING;
    7953                 :             :             }
    7954                 :             :         }
    7955                 :             :       /* [dcl.init] "Otherwise, if the destination type is an array, the object
    7956                 :             :          is initialized as follows..."  So handle things like
    7957                 :             : 
    7958                 :             :           int a[](1, 2, 3);
    7959                 :             : 
    7960                 :             :          which is permitted in C++20 by P0960.  */
    7961                 :    35795359 :       else if (TREE_CODE (init) == TREE_LIST
    7962                 :      621503 :                && TREE_TYPE (init) == NULL_TREE
    7963                 :      621503 :                && TREE_CODE (type) == ARRAY_TYPE
    7964                 :         165 :                && !DECL_DECOMPOSITION_P (decl)
    7965                 :    35795503 :                && (cxx_dialect >= cxx20))
    7966                 :         124 :         init = do_aggregate_paren_init (init, type);
    7967                 :    35795235 :       else if (TREE_CODE (init) == TREE_LIST
    7968                 :      621379 :                && TREE_TYPE (init) != unknown_type_node
    7969                 :    36416614 :                && !MAYBE_CLASS_TYPE_P (type))
    7970                 :             :         {
    7971                 :      135666 :           gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    7972                 :             : 
    7973                 :             :           /* We get here with code like `int a (2);' */
    7974                 :      135666 :           init = build_x_compound_expr_from_list (init, ELK_INIT,
    7975                 :             :                                                   tf_warning_or_error);
    7976                 :             :         }
    7977                 :             : 
    7978                 :             :       /* If DECL has an array type without a specific bound, deduce the
    7979                 :             :          array size from the initializer.  */
    7980                 :    38199506 :       maybe_deduce_size_from_array_init (decl, init);
    7981                 :    38199506 :       type = TREE_TYPE (decl);
    7982                 :    38199506 :       if (type == error_mark_node)
    7983                 :             :         return NULL_TREE;
    7984                 :             : 
    7985                 :    73609184 :       if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
    7986                 :     3437348 :            && !(flags & LOOKUP_ALREADY_DIGESTED)
    7987                 :     3437020 :            && !(init && BRACE_ENCLOSED_INITIALIZER_P (init)
    7988                 :     1292242 :                 && CP_AGGREGATE_TYPE_P (type)
    7989                 :     1078311 :                 && (CLASS_TYPE_P (type)
    7990                 :             :                     /* The call to build_aggr_init below could end up
    7991                 :             :                        calling build_vec_init, which may break when we
    7992                 :             :                        are processing a template.  */
    7993                 :        1583 :                     || processing_template_decl
    7994                 :        1517 :                     || !TYPE_NEEDS_CONSTRUCTING (type)
    7995                 :        1485 :                     || type_has_extended_temps (type))))
    7996                 :    74038868 :           || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
    7997                 :             :         {
    7998                 :     2360368 :           init_code = build_aggr_init_full_exprs (decl, init, flags);
    7999                 :             : 
    8000                 :             :           /* A constructor call is a non-trivial initializer even if
    8001                 :             :              it isn't explicitly written.  */
    8002                 :     2360368 :           if (TREE_SIDE_EFFECTS (init_code))
    8003                 :     2352053 :             DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
    8004                 :             : 
    8005                 :             :           /* If this is a constexpr initializer, expand_default_init will
    8006                 :             :              have returned an INIT_EXPR rather than a CALL_EXPR.  In that
    8007                 :             :              case, pull the initializer back out and pass it down into
    8008                 :             :              store_init_value.  */
    8009                 :     6116235 :           while (true)
    8010                 :             :             {
    8011                 :     6116235 :               if (TREE_CODE (init_code) == EXPR_STMT
    8012                 :     3766712 :                   || TREE_CODE (init_code) == STMT_EXPR
    8013                 :     3757313 :                   || TREE_CODE (init_code) == CONVERT_EXPR)
    8014                 :     3746514 :                 init_code = TREE_OPERAND (init_code, 0);
    8015                 :     2369721 :               else if (TREE_CODE (init_code) == BIND_EXPR)
    8016                 :        9353 :                 init_code = BIND_EXPR_BODY (init_code);
    8017                 :             :               else
    8018                 :             :                 break;
    8019                 :             :             }
    8020                 :     2360368 :           if (TREE_CODE (init_code) == INIT_EXPR)
    8021                 :             :             {
    8022                 :             :               /* In C++20, the call to build_aggr_init could have created
    8023                 :             :                  an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
    8024                 :             :                  A(1, 2).  */
    8025                 :     1393371 :               tree rhs = TREE_OPERAND (init_code, 1);
    8026                 :     1393371 :               if (processing_template_decl && TREE_CODE (rhs) == TARGET_EXPR)
    8027                 :             :                 /* Avoid leaking TARGET_EXPR into template trees.  */
    8028                 :        4691 :                 rhs = build_implicit_conv_flags (type, init, flags);
    8029                 :     1393371 :               init = rhs;
    8030                 :             : 
    8031                 :     1393371 :               init_code = NULL_TREE;
    8032                 :             :               /* Don't call digest_init; it's unnecessary and will complain
    8033                 :             :                  about aggregate initialization of non-aggregate classes.  */
    8034                 :     1393368 :               flags |= LOOKUP_ALREADY_DIGESTED;
    8035                 :             :             }
    8036                 :      966997 :           else if (DECL_DECLARED_CONSTEXPR_P (decl)
    8037                 :     1928923 :                    || DECL_DECLARED_CONSTINIT_P (decl))
    8038                 :             :             {
    8039                 :             :               /* Declared constexpr or constinit, but no suitable initializer;
    8040                 :             :                  massage init appropriately so we can pass it into
    8041                 :             :                  store_init_value for the error.  */
    8042                 :        5089 :               tree new_init = NULL_TREE;
    8043                 :        5089 :               if (!processing_template_decl
    8044                 :         384 :                   && TREE_CODE (init_code) == CALL_EXPR)
    8045                 :         328 :                 new_init = build_cplus_new (type, init_code, tf_none);
    8046                 :        4737 :               else if (CLASS_TYPE_P (type)
    8047                 :        9498 :                        && (!init || TREE_CODE (init) == TREE_LIST))
    8048                 :        4677 :                 new_init = build_functional_cast (input_location, type,
    8049                 :             :                                                   init, tf_none);
    8050                 :        5005 :               if (new_init)
    8051                 :             :                 {
    8052                 :        5005 :                   init = new_init;
    8053                 :        5005 :                   if (TREE_CODE (init) == TARGET_EXPR
    8054                 :         349 :                       && !(flags & LOOKUP_ONLYCONVERTING))
    8055                 :         349 :                     TARGET_EXPR_DIRECT_INIT_P (init) = true;
    8056                 :             :                 }
    8057                 :             :               init_code = NULL_TREE;
    8058                 :             :             }
    8059                 :             :           else
    8060                 :             :             init = NULL_TREE;
    8061                 :             :         }
    8062                 :             : 
    8063                 :    37237593 :       if (init && TREE_CODE (init) != TREE_VEC)
    8064                 :             :         {
    8065                 :    37237578 :           init_code = store_init_value (decl, init, cleanups, flags);
    8066                 :             : 
    8067                 :    37234881 :           if (DECL_INITIAL (decl)
    8068                 :    23970325 :               && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    8069                 :    38882306 :               && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
    8070                 :             :             {
    8071                 :     1005856 :               tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
    8072                 :     1005856 :               if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
    8073                 :     1005856 :                   && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
    8074                 :          36 :                 cp_complete_array_type (&TREE_TYPE (elt), elt, false);
    8075                 :             :             }
    8076                 :             : 
    8077                 :      878472 :           if (pedantic && TREE_CODE (type) == ARRAY_TYPE
    8078                 :       49184 :               && DECL_INITIAL (decl)
    8079                 :       48760 :               && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
    8080                 :    37280800 :               && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
    8081                 :           6 :             warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
    8082                 :           3 :                                          DECL_SOURCE_LOCATION (decl)),
    8083                 :           3 :                         0, "array %qD initialized by parenthesized "
    8084                 :             :                         "string literal %qE",
    8085                 :           3 :                         decl, DECL_INITIAL (decl));
    8086                 :             :           init = NULL_TREE;
    8087                 :             :         }
    8088                 :             :     }
    8089                 :             :   else
    8090                 :             :     {
    8091                 :     7308044 :       if (CLASS_TYPE_P (core_type = strip_array_types (type))
    8092                 :     4310093 :           && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
    8093                 :      656058 :               || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
    8094                 :          19 :         diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
    8095                 :             :                                                   /*complain=*/true);
    8096                 :             : 
    8097                 :     3654022 :       check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    8098                 :             :                                          tf_warning_or_error);
    8099                 :             :     }
    8100                 :             : 
    8101                 :           0 :   if (init && init != error_mark_node)
    8102                 :           0 :     init_code = cp_build_init_expr (decl, init);
    8103                 :             : 
    8104                 :    14345059 :   if (init_code && !TREE_SIDE_EFFECTS (init_code)
    8105                 :    41869275 :       && init_code != error_mark_node)
    8106                 :             :     init_code = NULL_TREE;
    8107                 :             : 
    8108                 :    41834582 :   if (init_code)
    8109                 :             :     {
    8110                 :             :       /* We might have set these in cp_finish_decl.  */
    8111                 :    14328815 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
    8112                 :    14328815 :       TREE_CONSTANT (decl) = false;
    8113                 :             :     }
    8114                 :             : 
    8115                 :    14328815 :   if (init_code
    8116                 :    14328815 :       && DECL_IN_AGGR_P (decl)
    8117                 :           6 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    8118                 :             :     {
    8119                 :           0 :       static int explained = 0;
    8120                 :             : 
    8121                 :           0 :       auto_diagnostic_group d;
    8122                 :           0 :       if (cxx_dialect < cxx11)
    8123                 :           0 :         error ("initializer invalid for static member with constructor");
    8124                 :           0 :       else if (cxx_dialect < cxx17)
    8125                 :           0 :         error ("non-constant in-class initialization invalid for static "
    8126                 :             :                "member %qD", decl);
    8127                 :             :       else
    8128                 :           0 :         error ("non-constant in-class initialization invalid for non-inline "
    8129                 :             :                "static member %qD", decl);
    8130                 :           0 :       if (!explained)
    8131                 :             :         {
    8132                 :           0 :           inform (input_location,
    8133                 :             :                   "(an out of class initialization is required)");
    8134                 :           0 :           explained = 1;
    8135                 :             :         }
    8136                 :           0 :       return NULL_TREE;
    8137                 :           0 :     }
    8138                 :             : 
    8139                 :             :   return init_code;
    8140                 :             : }
    8141                 :             : 
    8142                 :             : /* If DECL is not a local variable, give it RTL.  */
    8143                 :             : 
    8144                 :             : static void
    8145                 :   100398895 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
    8146                 :             : {
    8147                 :   100398895 :   int toplev = toplevel_bindings_p ();
    8148                 :   100398895 :   int defer_p;
    8149                 :             : 
    8150                 :             :   /* Set the DECL_ASSEMBLER_NAME for the object.  */
    8151                 :   100398895 :   if (asmspec)
    8152                 :             :     {
    8153                 :             :       /* The `register' keyword, when used together with an
    8154                 :             :          asm-specification, indicates that the variable should be
    8155                 :             :          placed in a particular register.  */
    8156                 :      998841 :       if (VAR_P (decl) && DECL_REGISTER (decl))
    8157                 :             :         {
    8158                 :          81 :           set_user_assembler_name (decl, asmspec);
    8159                 :          81 :           DECL_HARD_REGISTER (decl) = 1;
    8160                 :             :         }
    8161                 :             :       else
    8162                 :             :         {
    8163                 :      998760 :           if (TREE_CODE (decl) == FUNCTION_DECL
    8164                 :      998760 :               && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
    8165                 :       79410 :             set_builtin_user_assembler_name (decl, asmspec);
    8166                 :      998760 :           set_user_assembler_name (decl, asmspec);
    8167                 :      998760 :           if (DECL_LOCAL_DECL_P (decl))
    8168                 :           6 :             if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
    8169                 :             :               /* We have to propagate the name to the ns-alias.
    8170                 :             :                  This is horrible, as we're affecting a
    8171                 :             :                  possibly-shared decl.  Again, a one-true-decl
    8172                 :             :                  model breaks down.  */
    8173                 :           6 :               if (ns_decl != error_mark_node)
    8174                 :           6 :                 set_user_assembler_name (ns_decl, asmspec);
    8175                 :             :         }
    8176                 :             :     }
    8177                 :             : 
    8178                 :             :   /* Handle non-variables up front.  */
    8179                 :   100398895 :   if (!VAR_P (decl))
    8180                 :             :     {
    8181                 :    52662299 :       rest_of_decl_compilation (decl, toplev, at_eof);
    8182                 :    52662299 :       return;
    8183                 :             :     }
    8184                 :             : 
    8185                 :             :   /* If we see a class member here, it should be a static data
    8186                 :             :      member.  */
    8187                 :    47736596 :   if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
    8188                 :             :     {
    8189                 :     4010961 :       gcc_assert (TREE_STATIC (decl));
    8190                 :             :       /* An in-class declaration of a static data member should be
    8191                 :             :          external; it is only a declaration, and not a definition.  */
    8192                 :     4010961 :       if (init == NULL_TREE)
    8193                 :     4010951 :         gcc_assert (DECL_EXTERNAL (decl)
    8194                 :             :                     || !TREE_PUBLIC (decl));
    8195                 :             :     }
    8196                 :             : 
    8197                 :             :   /* We don't create any RTL for local variables.  */
    8198                 :    47736596 :   if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    8199                 :             :     return;
    8200                 :             : 
    8201                 :             :   /* We defer emission of local statics until the corresponding
    8202                 :             :      DECL_EXPR is expanded.  But with constexpr its function might never
    8203                 :             :      be expanded, so go ahead and tell cgraph about the variable now.  */
    8204                 :    49096318 :   defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
    8205                 :      141877 :               && !var_in_maybe_constexpr_fn (decl))
    8206                 :    48954553 :              || DECL_VIRTUAL_P (decl));
    8207                 :             : 
    8208                 :             :   /* Defer template instantiations.  */
    8209                 :    24548159 :   if (DECL_LANG_SPECIFIC (decl)
    8210                 :    24548159 :       && DECL_IMPLICIT_INSTANTIATION (decl))
    8211                 :             :     defer_p = 1;
    8212                 :             : 
    8213                 :             :   /* If we're not deferring, go ahead and assemble the variable.  */
    8214                 :    15671429 :   if (!defer_p)
    8215                 :    13312980 :     rest_of_decl_compilation (decl, toplev, at_eof);
    8216                 :             : }
    8217                 :             : 
    8218                 :             : /* walk_tree helper for wrap_temporary_cleanups, below.  */
    8219                 :             : 
    8220                 :             : static tree
    8221                 :    10483536 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
    8222                 :             : {
    8223                 :             :   /* Stop at types or full-expression boundaries.  */
    8224                 :    10483536 :   if (TYPE_P (*stmt_p)
    8225                 :    10483325 :       || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
    8226                 :             :     {
    8227                 :         439 :       *walk_subtrees = 0;
    8228                 :         439 :       return NULL_TREE;
    8229                 :             :     }
    8230                 :             : 
    8231                 :    10483097 :   if (TREE_CODE (*stmt_p) == TARGET_EXPR)
    8232                 :             :     {
    8233                 :      178553 :       tree guard = (tree)data;
    8234                 :      178553 :       tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
    8235                 :             : 
    8236                 :       99078 :       if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
    8237                 :      271059 :           && !expr_noexcept_p (tcleanup, tf_none))
    8238                 :             :         {
    8239                 :         145 :           tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
    8240                 :             :           /* Tell honor_protect_cleanup_actions to handle this as a separate
    8241                 :             :              cleanup.  */
    8242                 :         145 :           TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
    8243                 :         145 :           TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
    8244                 :             :         }
    8245                 :             :     }
    8246                 :             : 
    8247                 :             :   return NULL_TREE;
    8248                 :             : }
    8249                 :             : 
    8250                 :             : /* We're initializing a local variable which has a cleanup GUARD.  If there
    8251                 :             :    are any temporaries used in the initializer INIT of this variable, we
    8252                 :             :    need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
    8253                 :             :    variable will be cleaned up properly if one of them throws.
    8254                 :             : 
    8255                 :             :    Unfortunately, there's no way to express this properly in terms of
    8256                 :             :    nesting, as the regions for the temporaries overlap the region for the
    8257                 :             :    variable itself; if there are two temporaries, the variable needs to be
    8258                 :             :    the first thing destroyed if either of the temporary destructors throws.
    8259                 :             :    However, we only want to run the variable's cleanup if it actually got
    8260                 :             :    constructed.  So we need to guard the temporary cleanups with the
    8261                 :             :    variable's cleanup if they are run on the normal path, but not if they
    8262                 :             :    are run on the exceptional path.  We implement this by telling
    8263                 :             :    honor_protect_cleanup_actions to strip the variable cleanup from the
    8264                 :             :    exceptional path.
    8265                 :             : 
    8266                 :             :    Another approach could be to make the variable cleanup region enclose
    8267                 :             :    initialization, but depend on a flag to indicate that the variable is
    8268                 :             :    initialized; that's effectively what we do for arrays.  But the current
    8269                 :             :    approach works fine for non-arrays, and has no code overhead in the usual
    8270                 :             :    case where the temporary destructors are noexcept.  */
    8271                 :             : 
    8272                 :             : static void
    8273                 :      975283 : wrap_temporary_cleanups (tree init, tree guard)
    8274                 :             : {
    8275                 :      975283 :   if (TREE_CODE (guard) == BIND_EXPR)
    8276                 :             :     {
    8277                 :             :       /* An array cleanup region already encloses any temporary cleanups,
    8278                 :             :          don't wrap it around them again.  */
    8279                 :         422 :       gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
    8280                 :             :       return;
    8281                 :             :     }
    8282                 :      974861 :   cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
    8283                 :             : }
    8284                 :             : 
    8285                 :             : /* Generate code to initialize DECL (a local variable).  */
    8286                 :             : 
    8287                 :             : static void
    8288                 :    23188419 : initialize_local_var (tree decl, tree init, bool decomp)
    8289                 :             : {
    8290                 :    23188419 :   tree type = TREE_TYPE (decl);
    8291                 :    23188419 :   tree cleanup;
    8292                 :    23188419 :   int already_used;
    8293                 :             : 
    8294                 :    23188419 :   gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL);
    8295                 :    23188419 :   gcc_assert (!TREE_STATIC (decl));
    8296                 :             : 
    8297                 :    23188419 :   if (DECL_SIZE (decl) == NULL_TREE)
    8298                 :             :     {
    8299                 :             :       /* If we used it already as memory, it must stay in memory.  */
    8300                 :           0 :       DECL_INITIAL (decl) = NULL_TREE;
    8301                 :           0 :       TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    8302                 :           0 :       return;
    8303                 :             :     }
    8304                 :             : 
    8305                 :    23188419 :   if (type == error_mark_node)
    8306                 :             :     return;
    8307                 :             : 
    8308                 :             :   /* Compute and store the initial value.  */
    8309                 :    23188419 :   already_used = TREE_USED (decl) || TREE_USED (type);
    8310                 :    23188419 :   if (TREE_USED (type))
    8311                 :          32 :     DECL_READ_P (decl) = 1;
    8312                 :             : 
    8313                 :             :   /* Generate a cleanup, if necessary.  */
    8314                 :    23188419 :   cleanup = (decomp ? NULL_TREE
    8315                 :    23170098 :              : cxx_maybe_build_cleanup (decl, tf_warning_or_error));
    8316                 :             : 
    8317                 :             :   /* Perform the initialization.  */
    8318                 :    23188419 :   if (init)
    8319                 :             :     {
    8320                 :    14314444 :       tree rinit = (TREE_CODE (init) == INIT_EXPR
    8321                 :    14314444 :                     ? TREE_OPERAND (init, 1) : NULL_TREE);
    8322                 :    13098736 :       if (rinit && !TREE_SIDE_EFFECTS (rinit)
    8323                 :    20406764 :           && TREE_OPERAND (init, 0) == decl)
    8324                 :             :         {
    8325                 :             :           /* Stick simple initializers in DECL_INITIAL so that
    8326                 :             :              -Wno-init-self works (c++/34772).  */
    8327                 :     7308028 :           DECL_INITIAL (decl) = rinit;
    8328                 :             : 
    8329                 :     7308028 :           if (warn_init_self && TYPE_REF_P (type))
    8330                 :             :             {
    8331                 :        2470 :               STRIP_NOPS (rinit);
    8332                 :        2470 :               if (rinit == decl)
    8333                 :           3 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    8334                 :           3 :                             OPT_Winit_self,
    8335                 :             :                             "reference %qD is initialized with itself", decl);
    8336                 :             :             }
    8337                 :             :         }
    8338                 :             :       else
    8339                 :             :         {
    8340                 :     7006416 :           int saved_stmts_are_full_exprs_p;
    8341                 :             : 
    8342                 :             :           /* If we're only initializing a single object, guard the
    8343                 :             :              destructors of any temporaries used in its initializer with
    8344                 :             :              its destructor.  */
    8345                 :     7006416 :           if (cleanup)
    8346                 :      969281 :             wrap_temporary_cleanups (init, cleanup);
    8347                 :             : 
    8348                 :     7006416 :           gcc_assert (building_stmt_list_p ());
    8349                 :     7006416 :           saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    8350                 :             :           /* Avoid CLEANUP_POINT_EXPR for the structured binding
    8351                 :             :              bases, those will have CLEANUP_POINT_EXPR at the end of
    8352                 :             :              code emitted by cp_finish_decomp.  */
    8353                 :     7006416 :           if (decomp)
    8354                 :       18089 :             current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    8355                 :             :           else
    8356                 :     6988327 :             current_stmt_tree ()->stmts_are_full_exprs_p = 1;
    8357                 :     7006416 :           finish_expr_stmt (init);
    8358                 :     7006416 :           current_stmt_tree ()->stmts_are_full_exprs_p
    8359                 :     7006416 :             = saved_stmts_are_full_exprs_p;
    8360                 :             :         }
    8361                 :             :     }
    8362                 :             : 
    8363                 :             :   /* Set this to 0 so we can tell whether an aggregate which was
    8364                 :             :      initialized was ever used.  Don't do this if it has a
    8365                 :             :      destructor, so we don't complain about the 'resource
    8366                 :             :      allocation is initialization' idiom.  Now set
    8367                 :             :      attribute((unused)) on types so decls of that type will be
    8368                 :             :      marked used. (see TREE_USED, above.)  */
    8369                 :    23188419 :   if (TYPE_NEEDS_CONSTRUCTING (type)
    8370                 :     1906416 :       && ! already_used
    8371                 :        4562 :       && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    8372                 :    23192555 :       && DECL_NAME (decl))
    8373                 :        4110 :     TREE_USED (decl) = 0;
    8374                 :    23184309 :   else if (already_used)
    8375                 :    20976462 :     TREE_USED (decl) = 1;
    8376                 :             : 
    8377                 :    23188419 :   if (cleanup)
    8378                 :      981814 :     finish_decl_cleanup (decl, cleanup);
    8379                 :             : }
    8380                 :             : 
    8381                 :             : /* DECL is a VAR_DECL for a compiler-generated variable with static
    8382                 :             :    storage duration (like a virtual table) whose initializer is a
    8383                 :             :    compile-time constant.  Initialize the variable and provide it to the
    8384                 :             :    back end.  */
    8385                 :             : 
    8386                 :             : void
    8387                 :     2174707 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
    8388                 :             : {
    8389                 :     2174707 :   tree init;
    8390                 :     2174707 :   gcc_assert (DECL_ARTIFICIAL (decl));
    8391                 :     2174707 :   init = build_constructor (TREE_TYPE (decl), v);
    8392                 :     2174707 :   gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
    8393                 :     2174707 :   DECL_INITIAL (decl) = init;
    8394                 :     2174707 :   DECL_INITIALIZED_P (decl) = 1;
    8395                 :             :   /* Mark the decl as constexpr so that we can access its content
    8396                 :             :      at compile time.  */
    8397                 :     2174707 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    8398                 :     2174707 :   DECL_DECLARED_CONSTEXPR_P (decl) = true;
    8399                 :     2174707 :   determine_visibility (decl);
    8400                 :     2174707 :   layout_var_decl (decl);
    8401                 :     2174707 :   maybe_commonize_var (decl);
    8402                 :     2174707 :   make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
    8403                 :     2174707 : }
    8404                 :             : 
    8405                 :             : /* INIT is the initializer for a variable, as represented by the
    8406                 :             :    parser.  Returns true iff INIT is value-dependent.  */
    8407                 :             : 
    8408                 :             : static bool
    8409                 :     8066742 : value_dependent_init_p (tree init)
    8410                 :             : {
    8411                 :     8066742 :   if (TREE_CODE (init) == TREE_LIST)
    8412                 :             :     /* A parenthesized initializer, e.g.: int i (3, 2); ? */
    8413                 :       10537 :     return any_value_dependent_elements_p (init);
    8414                 :     8056205 :   else if (TREE_CODE (init) == CONSTRUCTOR)
    8415                 :             :   /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
    8416                 :             :     {
    8417                 :       40636 :       if (dependent_type_p (TREE_TYPE (init)))
    8418                 :             :         return true;
    8419                 :             : 
    8420                 :       40630 :       vec<constructor_elt, va_gc> *elts;
    8421                 :       40630 :       size_t nelts;
    8422                 :       40630 :       size_t i;
    8423                 :             : 
    8424                 :       40630 :       elts = CONSTRUCTOR_ELTS (init);
    8425                 :       40630 :       nelts = vec_safe_length (elts);
    8426                 :      568902 :       for (i = 0; i < nelts; ++i)
    8427                 :      543050 :         if (value_dependent_init_p ((*elts)[i].value))
    8428                 :             :           return true;
    8429                 :             :     }
    8430                 :             :   else
    8431                 :             :     /* It must be a simple expression, e.g., int i = 3;  */
    8432                 :     8015569 :     return value_dependent_expression_p (init);
    8433                 :             : 
    8434                 :             :   return false;
    8435                 :             : }
    8436                 :             : 
    8437                 :             : /* A helper function to be called via walk_tree.  If any label exists
    8438                 :             :    under *TP, it is (going to be) forced.  Set has_forced_label_in_static.  */
    8439                 :             : 
    8440                 :             : static tree
    8441                 :         337 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
    8442                 :             : {
    8443                 :         337 :   if (TYPE_P (*tp))
    8444                 :           0 :     *walk_subtrees = 0;
    8445                 :         337 :   if (TREE_CODE (*tp) == LABEL_DECL)
    8446                 :           6 :     cfun->has_forced_label_in_static = 1;
    8447                 :         337 :   return NULL_TREE;
    8448                 :             : }
    8449                 :             : 
    8450                 :             : /* Return true if DECL has either a trivial destructor, or for C++20
    8451                 :             :    is constexpr and has a constexpr destructor.  */
    8452                 :             : 
    8453                 :             : static bool
    8454                 :    35767323 : decl_maybe_constant_destruction (tree decl, tree type)
    8455                 :             : {
    8456                 :    35767323 :   return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    8457                 :    35767323 :           || (cxx_dialect >= cxx20
    8458                 :     1300797 :               && VAR_P (decl)
    8459                 :     1300542 :               && DECL_DECLARED_CONSTEXPR_P (decl)
    8460                 :         339 :               && type_has_constexpr_destructor (strip_array_types (type))));
    8461                 :             : }
    8462                 :             : 
    8463                 :             : static tree declare_simd_adjust_this (tree *, int *, void *);
    8464                 :             : 
    8465                 :             : /* Helper function of omp_declare_variant_finalize.  Finalize one
    8466                 :             :    "omp declare variant base" attribute.  Return true if it should be
    8467                 :             :    removed.  */
    8468                 :             : 
    8469                 :             : static bool
    8470                 :        1487 : omp_declare_variant_finalize_one (tree decl, tree attr)
    8471                 :             : {
    8472                 :        1487 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    8473                 :             :     {
    8474                 :         116 :       walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
    8475                 :             :                  DECL_ARGUMENTS (decl), NULL);
    8476                 :         116 :       walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
    8477                 :             :                  DECL_ARGUMENTS (decl), NULL);
    8478                 :             :     }
    8479                 :             : 
    8480                 :        1487 :   tree ctx = TREE_VALUE (TREE_VALUE (attr));
    8481                 :        1487 :   tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
    8482                 :             :                                         OMP_TRAIT_CONSTRUCT_SIMD);
    8483                 :        1487 :   if (simd)
    8484                 :             :     {
    8485                 :          51 :       TREE_VALUE (simd)
    8486                 :          51 :         = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
    8487                 :          51 :                                                  OMP_TS_PROPERTIES (simd));
    8488                 :             :       /* FIXME, adjusting simd args unimplemented.  */
    8489                 :          51 :       return true;
    8490                 :             :     }
    8491                 :             : 
    8492                 :        1436 :   tree chain = TREE_CHAIN (TREE_VALUE (attr));
    8493                 :        1436 :   location_t varid_loc
    8494                 :        1436 :     = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
    8495                 :        1436 :   location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
    8496                 :        1436 :   cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
    8497                 :        1436 :   tree variant = TREE_PURPOSE (TREE_VALUE (attr));
    8498                 :             : 
    8499                 :        1436 :   location_t save_loc = input_location;
    8500                 :        1436 :   input_location = varid_loc;
    8501                 :             : 
    8502                 :        1436 :   releasing_vec args;
    8503                 :        1436 :   tree parm = DECL_ARGUMENTS (decl);
    8504                 :        1436 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    8505                 :         116 :     parm = DECL_CHAIN (parm);
    8506                 :        2644 :   for (; parm; parm = DECL_CHAIN (parm))
    8507                 :        1208 :     vec_safe_push (args, forward_parm (parm));
    8508                 :             : 
    8509                 :        1436 :   unsigned nappend_args = 0;
    8510                 :        1436 :   tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    8511                 :        1436 :   if (append_args_list)
    8512                 :             :     {
    8513                 :         357 :       append_args_list = TREE_VALUE (append_args_list);
    8514                 :         357 :       append_args_list = (append_args_list && TREE_CHAIN (append_args_list)
    8515                 :         594 :                           ? TREE_VALUE (TREE_CHAIN (append_args_list))
    8516                 :             :                           : NULL_TREE);
    8517                 :         744 :       for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    8518                 :         387 :         nappend_args++;
    8519                 :         357 :       if (nappend_args)
    8520                 :             :         {
    8521                 :         237 :           tree type;
    8522                 :         237 :           if ((type = lookup_qualified_name (global_namespace,
    8523                 :             :                                              "omp_interop_t",
    8524                 :             :                                              LOOK_want::NORMAL,
    8525                 :             :                                              /*complain*/false)) == NULL_TREE
    8526                 :         237 :               || !c_omp_interop_t_p (TREE_TYPE (type)))
    8527                 :             :             {
    8528                 :          24 :               location_t loc = input_location;
    8529                 :          24 :               variant = tree_strip_any_location_wrapper (variant);
    8530                 :          24 :               if (!identifier_p (variant))
    8531                 :             :                 {
    8532                 :          21 :                   if (TREE_CODE (variant) == OVERLOAD && OVL_SINGLE_P (variant))
    8533                 :          21 :                     variant = OVL_FIRST (variant);
    8534                 :          21 :                   loc = EXPR_LOC_OR_LOC (variant,
    8535                 :             :                                          DECL_SOURCE_LOCATION (variant));
    8536                 :             :                 }
    8537                 :          24 :               error_at (loc, "argument %d of %qE must be of %<omp_interop_t%>",
    8538                 :          24 :                         args->length () + 1, variant);
    8539                 :          24 :               inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    8540                 :             :                       "%<append_args%> specified here");
    8541                 :          24 :               return true;
    8542                 :             :             }
    8543                 :         564 :           for (unsigned i = 0; i < nappend_args; i++)
    8544                 :         351 :             vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
    8545                 :             :         }
    8546                 :             :     }
    8547                 :             : 
    8548                 :        1412 :   bool koenig_p = false;
    8549                 :        1412 :   if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
    8550                 :             :     {
    8551                 :        1406 :       if (identifier_p (variant)
    8552                 :             :           /* In C++20, we may need to perform ADL for a template
    8553                 :             :              name.  */
    8554                 :        1382 :           || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
    8555                 :          18 :               && identifier_p (TREE_OPERAND (variant, 0))))
    8556                 :             :         {
    8557                 :          24 :           if (!args->is_empty ())
    8558                 :             :             {
    8559                 :          24 :               koenig_p = true;
    8560                 :          24 :               if (!any_type_dependent_arguments_p (args))
    8561                 :          21 :                 variant = perform_koenig_lookup (variant, args,
    8562                 :             :                                                  tf_warning_or_error);
    8563                 :             :             }
    8564                 :             :           else
    8565                 :           0 :             variant = unqualified_fn_lookup_error (variant);
    8566                 :             :         }
    8567                 :        1382 :       else if (!args->is_empty () && is_overloaded_fn (variant))
    8568                 :             :         {
    8569                 :         716 :           tree fn = get_first_fn (variant);
    8570                 :         716 :           fn = STRIP_TEMPLATE (fn);
    8571                 :         716 :           if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
    8572                 :         716 :                  || DECL_FUNCTION_MEMBER_P (fn)
    8573                 :         603 :                  || DECL_LOCAL_DECL_P (fn)))
    8574                 :             :             {
    8575                 :         603 :               koenig_p = true;
    8576                 :         603 :               if (!any_type_dependent_arguments_p (args))
    8577                 :         552 :                 variant = perform_koenig_lookup (variant, args,
    8578                 :             :                                                  tf_warning_or_error);
    8579                 :             :             }
    8580                 :             :         }
    8581                 :             :     }
    8582                 :             : 
    8583                 :        1412 :   if (idk == CP_ID_KIND_QUALIFIED)
    8584                 :           6 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
    8585                 :             :                                 koenig_p, tf_warning_or_error);
    8586                 :             :   else
    8587                 :        1406 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    8588                 :             :                                 koenig_p, tf_warning_or_error);
    8589                 :        1412 :   if (variant == error_mark_node && !processing_template_decl)
    8590                 :             :     return true;
    8591                 :             : 
    8592                 :        1367 :   if (TREE_CODE (variant) == TARGET_EXPR)
    8593                 :           9 :     variant = TARGET_EXPR_INITIAL (variant);
    8594                 :             : 
    8595                 :        2725 :   variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
    8596                 :        1367 :   input_location = save_loc;
    8597                 :             : 
    8598                 :        1367 :   if (variant)
    8599                 :             :     {
    8600                 :        1283 :       bool fail;
    8601                 :        1283 :       const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
    8602                 :        1283 :       if (!nappend_args)
    8603                 :        1124 :         fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    8604                 :             :                            COMPARE_STRICT);
    8605                 :             :       else
    8606                 :             :         {
    8607                 :         159 :           unsigned nbase_args = 0;
    8608                 :         159 :           for (tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
    8609                 :         756 :                t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
    8610                 :         240 :             nbase_args++;
    8611                 :         159 :           tree vargs, varg;
    8612                 :         159 :           vargs = varg = TYPE_ARG_TYPES (TREE_TYPE (variant));
    8613                 :         399 :           for (unsigned i = 0; i < nbase_args && varg;
    8614                 :         240 :                i++, varg = TREE_CHAIN (varg))
    8615                 :         240 :             vargs = varg;
    8616                 :         417 :           for (unsigned i = 0; i < nappend_args && varg; i++)
    8617                 :         258 :             varg = TREE_CHAIN (varg);
    8618                 :         159 :           tree saved_vargs;
    8619                 :         159 :           if (nbase_args)
    8620                 :             :             {
    8621                 :         111 :               saved_vargs = TREE_CHAIN (vargs);
    8622                 :         111 :               TREE_CHAIN (vargs) = varg;
    8623                 :             :             }
    8624                 :             :           else
    8625                 :             :             {
    8626                 :          48 :               saved_vargs = vargs;
    8627                 :          48 :               TYPE_ARG_TYPES (TREE_TYPE (variant)) = varg;
    8628                 :             :             }
    8629                 :             :           /* Skip assert check that TYPE_CANONICAL is the same.  */
    8630                 :         159 :           fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    8631                 :             :                              COMPARE_STRUCTURAL);
    8632                 :         159 :           if (nbase_args)
    8633                 :         111 :             TREE_CHAIN (vargs) = saved_vargs;
    8634                 :             :           else
    8635                 :          48 :             TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_vargs;
    8636                 :         159 :           varg = saved_vargs;
    8637                 :         159 :           if (!fail && !processing_template_decl)
    8638                 :         402 :             for (unsigned i = 0; i < nappend_args;
    8639                 :         246 :                  i++, varg = TREE_CHAIN (varg))
    8640                 :         507 :               if (!varg || !c_omp_interop_t_p (TREE_VALUE (varg)))
    8641                 :             :                 {
    8642                 :           9 :                   error_at (DECL_SOURCE_LOCATION (variant),
    8643                 :             :                             "argument %d of %qD must be of %<omp_interop_t%>",
    8644                 :           9 :                             nbase_args + i + 1, variant);
    8645                 :           9 :                   inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    8646                 :             :                           "%<append_args%> specified here");
    8647                 :           9 :                   break;
    8648                 :             :                 }
    8649                 :             :         }
    8650                 :        1283 :       if (fail)
    8651                 :             :         {
    8652                 :          69 :           error_at (varid_loc, "variant %qD and base %qD have incompatible "
    8653                 :             :                                "types", variant, decl);
    8654                 :          69 :           return true;
    8655                 :             :         }
    8656                 :        1214 :       if (fndecl_built_in_p (variant)
    8657                 :        1214 :           && (startswith (varname, "__builtin_")
    8658                 :           0 :               || startswith (varname, "__sync_")
    8659                 :           0 :               || startswith (varname, "__atomic_")))
    8660                 :             :         {
    8661                 :           6 :           error_at (varid_loc, "variant %qD is a built-in", variant);
    8662                 :           6 :           return true;
    8663                 :             :         }
    8664                 :             :       else
    8665                 :             :         {
    8666                 :        1208 :           tree construct
    8667                 :        1208 :             = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
    8668                 :        1208 :           omp_mark_declare_variant (match_loc, variant, construct);
    8669                 :        1208 :           if (!omp_context_selector_matches (ctx, NULL_TREE, false))
    8670                 :             :             return true;
    8671                 :         860 :           TREE_PURPOSE (TREE_VALUE (attr)) = variant;
    8672                 :             : 
    8673                 :             :           // Prepend adjust_args list to variant attributes
    8674                 :         860 :           tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    8675                 :         860 :           if (adjust_args_list != NULL_TREE)
    8676                 :             :             {
    8677                 :         513 :               if (DECL_NONSTATIC_MEMBER_P (variant)
    8678                 :         288 :                   && TREE_VALUE (adjust_args_list))
    8679                 :             :                 {
    8680                 :             :                   /* Shift arg position for the added 'this' pointer.  */
    8681                 :             :                   /* Handle need_device_ptr  */
    8682                 :          21 :                   for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
    8683                 :          51 :                        t; t = TREE_CHAIN (t))
    8684                 :          30 :                     TREE_VALUE (t)
    8685                 :          30 :                       = build_int_cst (TREE_TYPE (t),
    8686                 :          30 :                                        tree_to_uhwi (TREE_VALUE (t)) + 1);
    8687                 :             :                 }
    8688                 :         267 :               if (DECL_NONSTATIC_MEMBER_P (variant) && append_args_list)
    8689                 :             :                 {
    8690                 :             :                   /* Shift likewise the number of args after which the
    8691                 :             :                      interop object should be added.  */
    8692                 :           6 :                   tree nargs = TREE_CHAIN (TREE_VALUE (adjust_args_list));
    8693                 :           6 :                   TREE_PURPOSE (nargs)
    8694                 :           6 :                     = build_int_cst (TREE_TYPE (nargs),
    8695                 :           6 :                                      tree_to_uhwi (TREE_PURPOSE (nargs)) + 1);
    8696                 :             :                 }
    8697                 :         531 :               for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    8698                 :         264 :                 TREE_VALUE (t)
    8699                 :         264 :                   = cp_finish_omp_init_prefer_type (TREE_VALUE (t));
    8700                 :         534 :               DECL_ATTRIBUTES (variant) = tree_cons (
    8701                 :             :                 get_identifier ("omp declare variant variant args"),
    8702                 :         534 :                 TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
    8703                 :             :             }
    8704                 :             :         }
    8705                 :             :     }
    8706                 :          84 :   else if (!processing_template_decl)
    8707                 :             :     {
    8708                 :           0 :       error_at (varid_loc, "could not find variant declaration");
    8709                 :           0 :       return true;
    8710                 :             :     }
    8711                 :             : 
    8712                 :             :   return false;
    8713                 :        1436 : }
    8714                 :             : 
    8715                 :             : /* Helper function, finish up "omp declare variant base" attribute
    8716                 :             :    now that there is a DECL.  ATTR is the first "omp declare variant base"
    8717                 :             :    attribute.  */
    8718                 :             : 
    8719                 :             : void
    8720                 :        1350 : omp_declare_variant_finalize (tree decl, tree attr)
    8721                 :             : {
    8722                 :        1350 :   size_t attr_len = strlen ("omp declare variant base");
    8723                 :        1350 :   tree *list = &DECL_ATTRIBUTES (decl);
    8724                 :        1350 :   bool remove_all = false;
    8725                 :        1350 :   location_t match_loc = DECL_SOURCE_LOCATION (decl);
    8726                 :        1350 :   if (TREE_CHAIN (TREE_VALUE (attr))
    8727                 :        1350 :       && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
    8728                 :        2700 :       && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
    8729                 :        1350 :     match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
    8730                 :        2700 :   if (DECL_CONSTRUCTOR_P (decl))
    8731                 :             :     {
    8732                 :          27 :       error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
    8733                 :          27 :       remove_all = true;
    8734                 :             :     }
    8735                 :        1323 :   else if (DECL_DESTRUCTOR_P (decl))
    8736                 :             :     {
    8737                 :           9 :       error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
    8738                 :           9 :       remove_all = true;
    8739                 :             :     }
    8740                 :        1314 :   else if (DECL_DEFAULTED_FN (decl))
    8741                 :             :     {
    8742                 :           2 :       error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
    8743                 :           2 :       remove_all = true;
    8744                 :             :     }
    8745                 :        1312 :   else if (DECL_DELETED_FN (decl))
    8746                 :             :     {
    8747                 :           2 :       error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
    8748                 :           2 :       remove_all = true;
    8749                 :             :     }
    8750                 :        1310 :   else if (DECL_VIRTUAL_P (decl))
    8751                 :             :     {
    8752                 :           0 :       error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
    8753                 :           0 :       remove_all = true;
    8754                 :             :     }
    8755                 :             :   /* This loop is like private_lookup_attribute, except that it works
    8756                 :             :      with tree * rather than tree, as we might want to remove the
    8757                 :             :      attributes that are diagnosed as errorneous.  */
    8758                 :        2889 :   while (*list)
    8759                 :             :     {
    8760                 :        1539 :       tree attr = get_attribute_name (*list);
    8761                 :        1539 :       size_t ident_len = IDENTIFIER_LENGTH (attr);
    8762                 :        4022 :       if (cmp_attribs ("omp declare variant base", attr_len,
    8763                 :        1539 :                        IDENTIFIER_POINTER (attr), ident_len))
    8764                 :             :         {
    8765                 :        1527 :           if (remove_all || omp_declare_variant_finalize_one (decl, *list))
    8766                 :             :             {
    8767                 :         583 :               *list = TREE_CHAIN (*list);
    8768                 :         583 :               continue;
    8769                 :             :             }
    8770                 :             :         }
    8771                 :         956 :       list = &TREE_CHAIN (*list);
    8772                 :             :     }
    8773                 :        1350 : }
    8774                 :             : 
    8775                 :             : static void cp_maybe_mangle_decomp (tree, cp_decomp *);
    8776                 :             : 
    8777                 :             : /* Finish processing of a declaration;
    8778                 :             :    install its line number and initial value.
    8779                 :             :    If the length of an array type is not known before,
    8780                 :             :    it must be determined now, from the initial value, or it is an error.
    8781                 :             : 
    8782                 :             :    INIT is the initializer (if any) for DECL.  If INIT_CONST_EXPR_P is
    8783                 :             :    true, then INIT is an integral constant expression.
    8784                 :             : 
    8785                 :             :    FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
    8786                 :             :    if the (init) syntax was used.
    8787                 :             : 
    8788                 :             :    DECOMP is first identifier's DECL and identifier count in a structured
    8789                 :             :    bindings, nullptr if not a structured binding.  */
    8790                 :             : 
    8791                 :             : void
    8792                 :   280310041 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
    8793                 :             :                 tree asmspec_tree, int flags, cp_decomp *decomp)
    8794                 :             : {
    8795                 :   280310041 :   vec<tree, va_gc> *cleanups = NULL;
    8796                 :   280310041 :   const char *asmspec = NULL;
    8797                 :   280310041 :   int was_readonly = 0;
    8798                 :   280310041 :   bool var_definition_p = false;
    8799                 :   280310041 :   tree auto_node;
    8800                 :   280310041 :   auto_vec<tree> extra_cleanups;
    8801                 :   280310041 :   tree aggregates1 = NULL_TREE;
    8802                 :   280310041 :   struct decomp_cleanup {
    8803                 :             :     tree decl;
    8804                 :             :     cp_decomp *&decomp;
    8805                 :   280307344 :     ~decomp_cleanup ()
    8806                 :             :     {
    8807                 :   280307344 :       if (decomp && DECL_DECOMPOSITION_P (decl))
    8808                 :       77732 :         cp_finish_decomp (decl, decomp);
    8809                 :   280307344 :     }
    8810                 :   280310041 :   } decomp_cl = { decl, decomp };
    8811                 :             : 
    8812                 :   280310041 :   if (decl == error_mark_node)
    8813                 :             :     return;
    8814                 :   280310004 :   else if (! decl)
    8815                 :             :     {
    8816                 :           0 :       if (init)
    8817                 :           0 :         error ("assignment (not initialization) in declaration");
    8818                 :           0 :       return;
    8819                 :             :     }
    8820                 :             : 
    8821                 :   280310004 :   gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    8822                 :             :   /* Parameters are handled by store_parm_decls, not cp_finish_decl.  */
    8823                 :   280310004 :   gcc_assert (TREE_CODE (decl) != PARM_DECL);
    8824                 :             : 
    8825                 :   280310004 :   tree type = TREE_TYPE (decl);
    8826                 :   280310004 :   if (type == error_mark_node)
    8827                 :             :     return;
    8828                 :             : 
    8829                 :   280309476 :   if (VAR_P (decl) && is_copy_initialization (init))
    8830                 :    77054886 :     flags |= LOOKUP_ONLYCONVERTING;
    8831                 :             : 
    8832                 :             :   /* Warn about register storage specifiers except when in GNU global
    8833                 :             :      or local register variable extension.  */
    8834                 :   280309476 :   if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
    8835                 :             :     {
    8836                 :        1928 :       if (cxx_dialect >= cxx17)
    8837                 :        1280 :         pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    8838                 :             :                  "ISO C++17 does not allow %<register%> storage "
    8839                 :             :                  "class specifier");
    8840                 :             :       else
    8841                 :         648 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    8842                 :             :                     "%<register%> storage class specifier used");
    8843                 :             :     }
    8844                 :             : 
    8845                 :             :   /* If a name was specified, get the string.  */
    8846                 :   280309476 :   if (at_namespace_scope_p ())
    8847                 :    57780816 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    8848                 :   280309476 :   if (asmspec_tree && asmspec_tree != error_mark_node)
    8849                 :      998844 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    8850                 :             : 
    8851                 :   280309476 :   bool in_class_decl
    8852                 :   280309476 :     = (current_class_type
    8853                 :   174505566 :        && CP_DECL_CONTEXT (decl) == current_class_type
    8854                 :   117137008 :        && TYPE_BEING_DEFINED (current_class_type)
    8855                 :   395885610 :        && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
    8856                 :             : 
    8857                 :   112310506 :   if (in_class_decl
    8858                 :   112310506 :       && (DECL_INITIAL (decl) || init))
    8859                 :    80747396 :     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
    8860                 :             : 
    8861                 :   280309476 :   if (VAR_P (decl)
    8862                 :   280309476 :       && (auto_node = type_uses_auto (type)))
    8863                 :             :     {
    8864                 :     8559410 :       tree d_init;
    8865                 :     8559410 :       if (init == NULL_TREE)
    8866                 :             :         {
    8867                 :        1383 :           if (DECL_LANG_SPECIFIC (decl)
    8868                 :        1305 :               && DECL_TEMPLATE_INSTANTIATION (decl)
    8869                 :        2685 :               && !DECL_TEMPLATE_INSTANTIATED (decl))
    8870                 :             :             {
    8871                 :             :               /* init is null because we're deferring instantiating the
    8872                 :             :                  initializer until we need it.  Well, we need it now.  */
    8873                 :        1296 :               instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
    8874                 :        1296 :               return;
    8875                 :             :             }
    8876                 :             : 
    8877                 :          87 :           if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    8878                 :             :             /* Class deduction with no initializer is OK.  */;
    8879                 :             :           else
    8880                 :             :             {
    8881                 :             :               /* Ordinary auto deduction without an initializer, a situation
    8882                 :             :                  which grokdeclarator already detects and rejects for the most
    8883                 :             :                  part.  But we can still get here if we're instantiating a
    8884                 :             :                  variable template before we've fully parsed (and attached) its
    8885                 :             :                  initializer, e.g. template<class> auto x = x<int>;  */
    8886                 :           3 :               error_at (DECL_SOURCE_LOCATION (decl),
    8887                 :             :                         "declaration of %q#D has no initializer", decl);
    8888                 :           3 :               TREE_TYPE (decl) = error_mark_node;
    8889                 :           3 :               return;
    8890                 :             :             }
    8891                 :             :         }
    8892                 :     8558111 :       d_init = init;
    8893                 :     8558111 :       if (d_init)
    8894                 :             :         {
    8895                 :     8558027 :           if (TREE_CODE (d_init) == TREE_LIST
    8896                 :     8598263 :               && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    8897                 :       22314 :             d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
    8898                 :             :                                                       tf_warning_or_error);
    8899                 :     8558027 :           d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
    8900                 :             :           /* Force auto deduction now.  Use tf_none to avoid redundant warnings
    8901                 :             :              on deprecated-14.C.  */
    8902                 :     8558027 :           mark_single_function (d_init, tf_none);
    8903                 :             :         }
    8904                 :     8558111 :       enum auto_deduction_context adc = adc_variable_type;
    8905                 :     8558111 :       if (DECL_DECOMPOSITION_P (decl))
    8906                 :             :         adc = adc_decomp_type;
    8907                 :     8558111 :       tree outer_targs = NULL_TREE;
    8908                 :     8558111 :       if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
    8909                 :         323 :           && DECL_LANG_SPECIFIC (decl)
    8910                 :         126 :           && DECL_TEMPLATE_INFO (decl)
    8911                 :     8558168 :           && !DECL_FUNCTION_SCOPE_P (decl))
    8912                 :             :         /* The outer template arguments might be needed for satisfaction.
    8913                 :             :            (For function scope variables, do_auto_deduction will obtain the
    8914                 :             :            outer template arguments from current_function_decl.)  */
    8915                 :          57 :         outer_targs = DECL_TI_ARGS (decl);
    8916                 :     8558111 :       type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
    8917                 :             :                                                    tf_warning_or_error, adc,
    8918                 :             :                                                    outer_targs, flags);
    8919                 :     8558111 :       if (type == error_mark_node)
    8920                 :             :         return;
    8921                 :     8557270 :       if (TREE_CODE (type) == FUNCTION_TYPE)
    8922                 :             :         {
    8923                 :           3 :           error ("initializer for %<decltype(auto) %D%> has function type; "
    8924                 :             :                  "did you forget the %<()%>?", decl);
    8925                 :           3 :           TREE_TYPE (decl) = error_mark_node;
    8926                 :           3 :           return;
    8927                 :             :         }
    8928                 :             :       /* As in start_decl_1, complete so TREE_READONLY is set properly.  */
    8929                 :     8557267 :       if (!processing_template_decl
    8930                 :     1945786 :           && !type_uses_auto (type)
    8931                 :    10503046 :           && !COMPLETE_TYPE_P (complete_type (type)))
    8932                 :             :         {
    8933                 :          15 :           auto_diagnostic_group d;
    8934                 :          15 :           error_at (location_of (decl),
    8935                 :             :                     "deduced type %qT for %qD is incomplete", type, decl);
    8936                 :          15 :           cxx_incomplete_type_inform (type);
    8937                 :          15 :           TREE_TYPE (decl) = error_mark_node;
    8938                 :          15 :           return;
    8939                 :          15 :         }
    8940                 :             : 
    8941                 :             :       /* Now that we have a type, try these again.  */
    8942                 :     8557252 :       layout_decl (decl, 0);
    8943                 :     8557252 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    8944                 :             : 
    8945                 :             :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    8946                 :     8557252 :       if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    8947                 :             :         {
    8948                 :        8811 :           tree tmpl = template_for_substitution (decl);
    8949                 :        8811 :           if (DECL_TEMPLATE_RESULT (tmpl) == decl)
    8950                 :        7373 :             TREE_TYPE (tmpl) = type;
    8951                 :             :         }
    8952                 :             :     }
    8953                 :             : 
    8954                 :   280307318 :   if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
    8955                 :             :     {
    8956                 :          54 :       DECL_DECLARED_CONSTEXPR_P (decl) = 0;
    8957                 :          54 :       if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
    8958                 :             :         {
    8959                 :           6 :           init = NULL_TREE;
    8960                 :           6 :           DECL_EXTERNAL (decl) = 1;
    8961                 :             :         }
    8962                 :             :     }
    8963                 :             : 
    8964                 :   280307318 :   if (VAR_P (decl)
    8965                 :    98718066 :       && DECL_CLASS_SCOPE_P (decl)
    8966                 :    15109151 :       && verify_type_context (DECL_SOURCE_LOCATION (decl),
    8967                 :             :                               TCTX_STATIC_STORAGE, type)
    8968                 :   295416469 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    8969                 :    13949925 :     check_static_variable_definition (decl, type);
    8970                 :             : 
    8971                 :   280307318 :   if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
    8972                 :             :     {
    8973                 :    22376007 :       type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    8974                 :    22376007 :                                    ? TCTX_THREAD_STORAGE
    8975                 :             :                                    : TCTX_STATIC_STORAGE);
    8976                 :    22376007 :       verify_type_context (input_location, context, TREE_TYPE (decl));
    8977                 :             :     }
    8978                 :             : 
    8979                 :   280307318 :   if (init && TREE_CODE (decl) == FUNCTION_DECL)
    8980                 :             :     {
    8981                 :      356537 :       tree clone;
    8982                 :      356537 :       if (init == ridpointers[(int)RID_DELETE]
    8983                 :      356537 :           || (TREE_CODE (init) == STRING_CST
    8984                 :          24 :               && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
    8985                 :             :         {
    8986                 :             :           /* FIXME check this is 1st decl.  */
    8987                 :      333063 :           if (UNLIKELY (DECL_MAIN_P (decl)))
    8988                 :             :             {
    8989                 :             :               /* [basic.start.main]/3: A program that defines main as deleted
    8990                 :             :                  is ill-formed.  */
    8991                 :           3 :               error ("%<::main%> cannot be deleted");
    8992                 :           3 :               DECL_INITIAL (decl) = NULL_TREE;
    8993                 :             :             }
    8994                 :             :           else
    8995                 :             :             {
    8996                 :      333060 :               DECL_DELETED_FN (decl) = 1;
    8997                 :      333060 :               DECL_DECLARED_INLINE_P (decl) = 1;
    8998                 :      333060 :               DECL_INITIAL (decl)
    8999                 :      333060 :                 = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
    9000                 :      333078 :               FOR_EACH_CLONE (clone, decl)
    9001                 :             :                 {
    9002                 :          18 :                   DECL_DELETED_FN (clone) = 1;
    9003                 :          18 :                   DECL_DECLARED_INLINE_P (clone) = 1;
    9004                 :          18 :                   DECL_INITIAL (clone) = DECL_INITIAL (decl);
    9005                 :             :                 }
    9006                 :             :             }
    9007                 :      333063 :           init = NULL_TREE;
    9008                 :             :         }
    9009                 :       23474 :       else if (init == ridpointers[(int)RID_DEFAULT])
    9010                 :             :         {
    9011                 :       23462 :           if (defaultable_fn_check (decl))
    9012                 :       23438 :             DECL_DEFAULTED_FN (decl) = 1;
    9013                 :             :           else
    9014                 :          24 :             DECL_INITIAL (decl) = NULL_TREE;
    9015                 :             :         }
    9016                 :             :     }
    9017                 :             : 
    9018                 :   280307318 :   if (init && VAR_P (decl))
    9019                 :             :     {
    9020                 :    84172218 :       DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
    9021                 :             :       /* If DECL is a reference, then we want to know whether init is a
    9022                 :             :          reference constant; init_const_expr_p as passed tells us whether
    9023                 :             :          it's an rvalue constant.  */
    9024                 :    84172218 :       if (TYPE_REF_P (type))
    9025                 :     2238180 :         init_const_expr_p = potential_constant_expression (init);
    9026                 :    84172218 :       if (init_const_expr_p)
    9027                 :             :         {
    9028                 :             :           /* Set these flags now for templates.  We'll update the flags in
    9029                 :             :              store_init_value for instantiations.  */
    9030                 :    72054412 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    9031                 :    72054412 :           if (decl_maybe_constant_var_p (decl)
    9032                 :             :               /* FIXME setting TREE_CONSTANT on refs breaks the back end.  */
    9033                 :    72054412 :               && !TYPE_REF_P (type))
    9034                 :    25634907 :             TREE_CONSTANT (decl) = true;
    9035                 :             :         }
    9036                 :             :       /* This is handled mostly by gimplify.cc, but we have to deal with
    9037                 :             :          not warning about int x = x; as it is a GCC extension to turn off
    9038                 :             :          this warning but only if warn_init_self is zero.  */
    9039                 :    84172218 :       if (!DECL_EXTERNAL (decl)
    9040                 :    82707451 :           && !TREE_STATIC (decl)
    9041                 :    62752542 :           && decl == tree_strip_any_location_wrapper (init)
    9042                 :    84175477 :           && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
    9043                 :        3235 :         suppress_warning (decl, OPT_Winit_self);
    9044                 :             :     }
    9045                 :   196135100 :   else if (VAR_P (decl)
    9046                 :    14545848 :            && COMPLETE_TYPE_P (type)
    9047                 :    11422998 :            && !TYPE_REF_P (type)
    9048                 :    11422634 :            && !dependent_type_p (type)
    9049                 :   207264748 :            && is_really_empty_class (type, /*ignore_vptr*/false))
    9050                 :             :     /* We have no initializer but there's nothing to initialize anyway.
    9051                 :             :        Treat DECL as constant due to c++/109876.  */
    9052                 :      490048 :     TREE_CONSTANT (decl) = true;
    9053                 :             : 
    9054                 :   280307318 :   if (flag_openmp
    9055                 :      735073 :       && TREE_CODE (decl) == FUNCTION_DECL
    9056                 :             :       /* #pragma omp declare variant on methods handled in finish_struct
    9057                 :             :          instead.  */
    9058                 :   280641297 :       && (!DECL_OBJECT_MEMBER_FUNCTION_P (decl)
    9059                 :      129277 :           || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
    9060                 :      205155 :     if (tree attr = lookup_attribute ("omp declare variant base",
    9061                 :      205155 :                                       DECL_ATTRIBUTES (decl)))
    9062                 :         967 :       omp_declare_variant_finalize (decl, attr);
    9063                 :             : 
    9064                 :   280307318 :   if (processing_template_decl)
    9065                 :             :     {
    9066                 :   163679550 :       bool type_dependent_p;
    9067                 :             : 
    9068                 :             :       /* Add this declaration to the statement-tree.  */
    9069                 :   163679550 :       if (at_function_scope_p ())
    9070                 :    59427622 :         add_decl_expr (decl);
    9071                 :             : 
    9072                 :   163679550 :       type_dependent_p = dependent_type_p (type);
    9073                 :             : 
    9074                 :   163679550 :       if (check_for_bare_parameter_packs (init))
    9075                 :             :         {
    9076                 :           3 :           init = NULL_TREE;
    9077                 :           3 :           DECL_INITIAL (decl) = NULL_TREE;
    9078                 :             :         }
    9079                 :             : 
    9080                 :             :       /* Generally, initializers in templates are expanded when the
    9081                 :             :          template is instantiated.  But, if DECL is a variable constant
    9082                 :             :          then it can be used in future constant expressions, so its value
    9083                 :             :          must be available. */
    9084                 :             : 
    9085                 :   163679550 :       bool dep_init = false;
    9086                 :             : 
    9087                 :   163679550 :       if (!VAR_P (decl) || type_dependent_p)
    9088                 :             :         /* We can't do anything if the decl has dependent type.  */;
    9089                 :    19877093 :       else if (init
    9090                 :    18284600 :                && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
    9091                 :    14443561 :                && !TYPE_REF_P (type)
    9092                 :    14417090 :                && decl_maybe_constant_var_p (decl)
    9093                 :    27400785 :                && !(dep_init = value_dependent_init_p (init)))
    9094                 :             :         {
    9095                 :             :           /* This variable seems to be a non-dependent constant, so process
    9096                 :             :              its initializer.  If check_initializer returns non-null the
    9097                 :             :              initialization wasn't constant after all.  */
    9098                 :     1740301 :           tree init_code;
    9099                 :     1740301 :           cleanups = make_tree_vector ();
    9100                 :     1740301 :           init_code = check_initializer (decl, init, flags, &cleanups);
    9101                 :     1740301 :           if (init_code == NULL_TREE)
    9102                 :     1740301 :             init = NULL_TREE;
    9103                 :     1740301 :           release_tree_vector (cleanups);
    9104                 :             :         }
    9105                 :             :       else
    9106                 :             :         {
    9107                 :    18136792 :           gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
    9108                 :             :           /* Try to deduce array size.  */
    9109                 :    18136792 :           maybe_deduce_size_from_array_init (decl, init);
    9110                 :             :           /* And complain about multiple initializers.  */
    9111                 :    16544299 :           if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
    9112                 :    18196830 :               && !MAYBE_CLASS_TYPE_P (type))
    9113                 :           7 :             init = build_x_compound_expr_from_list (init, ELK_INIT,
    9114                 :             :                                                     tf_warning_or_error);
    9115                 :             :         }
    9116                 :             : 
    9117                 :   163679550 :       if (init)
    9118                 :    47472036 :         DECL_INITIAL (decl) = init;
    9119                 :             : 
    9120                 :   163679550 :       if (dep_init)
    9121                 :             :         {
    9122                 :     5783391 :           retrofit_lang_decl (decl);
    9123                 :     5783391 :           SET_DECL_DEPENDENT_INIT_P (decl, true);
    9124                 :             :         }
    9125                 :             : 
    9126                 :   163679550 :       if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
    9127                 :             :         {
    9128                 :           3 :           set_user_assembler_name (decl, asmspec);
    9129                 :           3 :           DECL_HARD_REGISTER (decl) = 1;
    9130                 :             :         }
    9131                 :   163679550 :       return;
    9132                 :             :     }
    9133                 :             : 
    9134                 :             :   /* Just store non-static data member initializers for later.  */
    9135                 :   116627768 :   if (init && TREE_CODE (decl) == FIELD_DECL)
    9136                 :      386143 :     DECL_INITIAL (decl) = init;
    9137                 :             : 
    9138                 :             :   /* Take care of TYPE_DECLs up front.  */
    9139                 :   116627768 :   if (TREE_CODE (decl) == TYPE_DECL)
    9140                 :             :     {
    9141                 :     9778933 :       if (type != error_mark_node
    9142                 :     9778933 :           && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
    9143                 :             :         {
    9144                 :     4430140 :           if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
    9145                 :           0 :             warning (0, "shadowing previous type declaration of %q#D", decl);
    9146                 :     4430140 :           set_identifier_type_value (DECL_NAME (decl), decl);
    9147                 :             :         }
    9148                 :             : 
    9149                 :             :       /* If we have installed this as the canonical typedef for this
    9150                 :             :          type, and that type has not been defined yet, delay emitting
    9151                 :             :          the debug information for it, as we will emit it later.  */
    9152                 :     9778933 :       if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
    9153                 :     9778933 :           && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
    9154                 :      571777 :         TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    9155                 :             : 
    9156                 :     9778933 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
    9157                 :             :                                 at_eof);
    9158                 :     9778933 :       return;
    9159                 :             :     }
    9160                 :             : 
    9161                 :             :   /* A reference will be modified here, as it is initialized.  */
    9162                 :   106848835 :   if (! DECL_EXTERNAL (decl)
    9163                 :    47786082 :       && TREE_READONLY (decl)
    9164                 :   130778178 :       && TYPE_REF_P (type))
    9165                 :             :     {
    9166                 :      230443 :       was_readonly = 1;
    9167                 :      230443 :       TREE_READONLY (decl) = 0;
    9168                 :             :     }
    9169                 :             : 
    9170                 :             :   /* This needs to happen before extend_ref_init_temps.  */
    9171                 :   106848835 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    9172                 :             :     {
    9173                 :    98226909 :       if (VAR_P (decl))
    9174                 :    45564610 :         maybe_commonize_var (decl);
    9175                 :    98226909 :       determine_visibility (decl);
    9176                 :             :     }
    9177                 :             : 
    9178                 :   106848835 :   if (VAR_P (decl))
    9179                 :             :     {
    9180                 :    45564610 :       duration_kind dk = decl_storage_duration (decl);
    9181                 :             :       /* [dcl.constinit]/1 "The constinit specifier shall be applied
    9182                 :             :          only to a declaration of a variable with static or thread storage
    9183                 :             :          duration."  */
    9184                 :    45564610 :       if (DECL_DECLARED_CONSTINIT_P (decl)
    9185                 :    45564610 :           && !(dk == dk_thread || dk == dk_static))
    9186                 :             :         {
    9187                 :          24 :           error_at (DECL_SOURCE_LOCATION (decl),
    9188                 :             :                     "%<constinit%> can only be applied to a variable with "
    9189                 :             :                     "static or thread storage duration");
    9190                 :          24 :           return;
    9191                 :             :         }
    9192                 :             : 
    9193                 :    45564586 :       if (decomp)
    9194                 :             :         {
    9195                 :       35237 :           if (DECL_DECLARED_CONSTINIT_P (decl) && cxx_dialect < cxx26)
    9196                 :          40 :             pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
    9197                 :             :                      "%<constinit%> can be applied to structured binding "
    9198                 :             :                      "only with %<-std=c++2c%> or %<-std=gnu++2c%>");
    9199                 :       35237 :           cp_maybe_mangle_decomp (decl, decomp);
    9200                 :       35237 :           if (TREE_STATIC (decl) && !DECL_FUNCTION_SCOPE_P (decl))
    9201                 :             :             {
    9202                 :         343 :               if (CP_DECL_THREAD_LOCAL_P (decl))
    9203                 :          37 :                 aggregates1 = tls_aggregates;
    9204                 :             :               else
    9205                 :         306 :                 aggregates1 = static_aggregates;
    9206                 :             :             }
    9207                 :             :         }
    9208                 :             : 
    9209                 :             :       /* If this is a local variable that will need a mangled name,
    9210                 :             :          register it now.  We must do this before processing the
    9211                 :             :          initializer for the variable, since the initialization might
    9212                 :             :          require a guard variable, and since the mangled name of the
    9213                 :             :          guard variable will depend on the mangled name of this
    9214                 :             :          variable.  */
    9215                 :    91129172 :       if (DECL_FUNCTION_SCOPE_P (decl)
    9216                 :    23330314 :           && TREE_STATIC (decl)
    9217                 :    45706463 :           && !DECL_ARTIFICIAL (decl))
    9218                 :             :         {
    9219                 :             :           /* The variable holding an anonymous union will have had its
    9220                 :             :              discriminator set in finish_anon_union, after which it's
    9221                 :             :              NAME will have been cleared.  */
    9222                 :      141511 :           if (DECL_NAME (decl))
    9223                 :      141468 :             determine_local_discriminator (decl);
    9224                 :             :           /* Normally has_forced_label_in_static is set during GIMPLE
    9225                 :             :              lowering, but [cd]tors are never actually compiled directly.
    9226                 :             :              We need to set this early so we can deal with the label
    9227                 :             :              address extension.  */
    9228                 :      141511 :           if ((DECL_CONSTRUCTOR_P (current_function_decl)
    9229                 :      141482 :                || DECL_DESTRUCTOR_P (current_function_decl))
    9230                 :      141521 :               && init)
    9231                 :             :             {
    9232                 :          29 :               walk_tree (&init, notice_forced_label_r, NULL, NULL);
    9233                 :          29 :               add_local_decl (cfun, decl);
    9234                 :             :             }
    9235                 :             :           /* And make sure it's in the symbol table for
    9236                 :             :              c_parse_final_cleanups to find.  */
    9237                 :      141511 :           varpool_node::get_create (decl);
    9238                 :             :         }
    9239                 :             : 
    9240                 :    45564586 :       if (flag_openmp
    9241                 :      133118 :           && VAR_P (decl)
    9242                 :      133118 :           && DECL_LANG_SPECIFIC (decl)
    9243                 :       58516 :           && DECL_OMP_DECLARE_MAPPER_P (decl)
    9244                 :    45564590 :           && init)
    9245                 :             :         {
    9246                 :           3 :           gcc_assert (TREE_CODE (init) == OMP_DECLARE_MAPPER);
    9247                 :           3 :           DECL_INITIAL (decl) = init;
    9248                 :             :         }
    9249                 :             :       /* Convert the initializer to the type of DECL, if we have not
    9250                 :             :          already initialized DECL.  */
    9251                 :    45564583 :       else if (!DECL_INITIALIZED_P (decl)
    9252                 :             :                /* If !DECL_EXTERNAL then DECL is being defined.  In the
    9253                 :             :                   case of a static data member initialized inside the
    9254                 :             :                   class-specifier, there can be an initializer even if DECL
    9255                 :             :                   is *not* defined.  */
    9256                 :    45564583 :                && (!DECL_EXTERNAL (decl) || init))
    9257                 :             :         {
    9258                 :    40113417 :           cleanups = make_tree_vector ();
    9259                 :    40113417 :           init = check_initializer (decl, init, flags, &cleanups);
    9260                 :             : 
    9261                 :             :           /* Handle:
    9262                 :             : 
    9263                 :             :              [dcl.init]
    9264                 :             : 
    9265                 :             :              The memory occupied by any object of static storage
    9266                 :             :              duration is zero-initialized at program startup before
    9267                 :             :              any other initialization takes place.
    9268                 :             : 
    9269                 :             :              We cannot create an appropriate initializer until after
    9270                 :             :              the type of DECL is finalized.  If DECL_INITIAL is set,
    9271                 :             :              then the DECL is statically initialized, and any
    9272                 :             :              necessary zero-initialization has already been performed.  */
    9273                 :    40110720 :           if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
    9274                 :      417770 :             DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
    9275                 :             :                                                    /*nelts=*/NULL_TREE,
    9276                 :             :                                                    /*static_storage_p=*/true);
    9277                 :             :           /* Remember that the initialization for this variable has
    9278                 :             :              taken place.  */
    9279                 :    40110720 :           DECL_INITIALIZED_P (decl) = 1;
    9280                 :             :           /* This declaration is the definition of this variable,
    9281                 :             :              unless we are initializing a static data member within
    9282                 :             :              the class specifier.  */
    9283                 :    40110720 :           if (!DECL_EXTERNAL (decl))
    9284                 :    45561889 :             var_definition_p = true;
    9285                 :             :         }
    9286                 :             :       /* If the variable has an array type, lay out the type, even if
    9287                 :             :          there is no initializer.  It is valid to index through the
    9288                 :             :          array, and we must get TYPE_ALIGN set correctly on the array
    9289                 :             :          type.  */
    9290                 :     5451166 :       else if (TREE_CODE (type) == ARRAY_TYPE)
    9291                 :      224863 :         layout_type (type);
    9292                 :             : 
    9293                 :    45561889 :       if (TREE_STATIC (decl)
    9294                 :    21801510 :           && !at_function_scope_p ()
    9295                 :    67221522 :           && current_function_decl == NULL)
    9296                 :             :         /* So decl is a global variable or a static member of a
    9297                 :             :            non local class. Record the types it uses
    9298                 :             :            so that we can decide later to emit debug info for them.  */
    9299                 :    21659621 :         record_types_used_by_current_var_decl (decl);
    9300                 :             :     }
    9301                 :             : 
    9302                 :             :   /* Add this declaration to the statement-tree.  This needs to happen
    9303                 :             :      after the call to check_initializer so that the DECL_EXPR for a
    9304                 :             :      reference temp is added before the DECL_EXPR for the reference itself.  */
    9305                 :   106846114 :   if (DECL_FUNCTION_SCOPE_P (decl))
    9306                 :             :     {
    9307                 :             :       /* If we're building a variable sized type, and we might be
    9308                 :             :          reachable other than via the top of the current binding
    9309                 :             :          level, then create a new BIND_EXPR so that we deallocate
    9310                 :             :          the object at the right time.  */
    9311                 :    23330314 :       if (VAR_P (decl)
    9312                 :    23330314 :           && DECL_SIZE (decl)
    9313                 :    23280486 :           && !TREE_CONSTANT (DECL_SIZE (decl))
    9314                 :    23331298 :           && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
    9315                 :             :         {
    9316                 :           3 :           tree bind;
    9317                 :           3 :           bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
    9318                 :           3 :           TREE_SIDE_EFFECTS (bind) = 1;
    9319                 :           3 :           add_stmt (bind);
    9320                 :           3 :           BIND_EXPR_BODY (bind) = push_stmt_list ();
    9321                 :             :         }
    9322                 :    23330314 :       add_decl_expr (decl);
    9323                 :             :     }
    9324                 :             : 
    9325                 :   106846114 :   tree decomp_init = NULL_TREE;
    9326                 :             :   /* Let the middle end know about variables and functions -- but not
    9327                 :             :      static data members in uninstantiated class templates.  */
    9328                 :   106846114 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    9329                 :             :     {
    9330                 :    98224188 :       if (VAR_P (decl))
    9331                 :             :         {
    9332                 :    45561889 :           layout_var_decl (decl);
    9333                 :    45561889 :           if (!flag_weak)
    9334                 :             :             /* Check again now that we have an initializer.  */
    9335                 :          57 :             maybe_commonize_var (decl);
    9336                 :             :           /* A class-scope constexpr variable with an out-of-class declaration.
    9337                 :             :              C++17 makes them implicitly inline, but still force it out.  */
    9338                 :    61846585 :           if (DECL_INLINE_VAR_P (decl)
    9339                 :    15362509 :               && !DECL_VAR_DECLARED_INLINE_P (decl)
    9340                 :     9094506 :               && !DECL_TEMPLATE_INSTANTIATION (decl)
    9341                 :    29531104 :               && !in_class_decl)
    9342                 :         103 :             mark_needed (decl);
    9343                 :             :         }
    9344                 :             : 
    9345                 :    98224188 :       if (var_definition_p
    9346                 :             :           /* With -fmerge-all-constants, gimplify_init_constructor
    9347                 :             :              might add TREE_STATIC to aggregate variables.  */
    9348                 :    39095515 :           && (TREE_STATIC (decl)
    9349                 :    23188579 :               || (flag_merge_constants >= 2
    9350                 :          38 :                   && AGGREGATE_TYPE_P (type))))
    9351                 :             :         {
    9352                 :             :           /* If a TREE_READONLY variable needs initialization
    9353                 :             :              at runtime, it is no longer readonly and we need to
    9354                 :             :              avoid MEM_READONLY_P being set on RTL created for it.  */
    9355                 :    15906939 :           if (init)
    9356                 :             :             {
    9357                 :       14363 :               if (TREE_READONLY (decl))
    9358                 :         521 :                 TREE_READONLY (decl) = 0;
    9359                 :             :               was_readonly = 0;
    9360                 :             :             }
    9361                 :    15892576 :           else if (was_readonly)
    9362                 :        1698 :             TREE_READONLY (decl) = 1;
    9363                 :             : 
    9364                 :             :           /* Likewise if it needs destruction.  */
    9365                 :    15906939 :           if (!decl_maybe_constant_destruction (decl, type))
    9366                 :        3505 :             TREE_READONLY (decl) = 0;
    9367                 :             :         }
    9368                 :    82317249 :       else if (VAR_P (decl)
    9369                 :    29654950 :                && CP_DECL_THREAD_LOCAL_P (decl)
    9370                 :       20056 :                && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
    9371                 :       20056 :                && (was_readonly || TREE_READONLY (decl))
    9372                 :    82317264 :                && var_needs_tls_wrapper (decl))
    9373                 :             :         {
    9374                 :             :           /* TLS variables need dynamic initialization by the TLS wrapper
    9375                 :             :              function, we don't want to hoist accesses to it before the
    9376                 :             :              wrapper.  */
    9377                 :           6 :           was_readonly = 0;
    9378                 :           6 :           TREE_READONLY (decl) = 0;
    9379                 :             :         }
    9380                 :             : 
    9381                 :    98224188 :       make_rtl_for_nonlocal_decl (decl, init, asmspec);
    9382                 :             : 
    9383                 :             :       /* Check for abstractness of the type.  */
    9384                 :    98224188 :       if (var_definition_p)
    9385                 :    39095515 :         abstract_virtuals_error (decl, type);
    9386                 :             : 
    9387                 :    98224188 :       if (decomp && !cp_finish_decomp (decl, decomp, true))
    9388                 :       16707 :         decomp = NULL;
    9389                 :             : 
    9390                 :    98224188 :       if (TREE_TYPE (decl) == error_mark_node)
    9391                 :             :         /* No initialization required.  */
    9392                 :             :         ;
    9393                 :    98224117 :       else if (TREE_CODE (decl) == FUNCTION_DECL)
    9394                 :             :         {
    9395                 :    52662299 :           if (init)
    9396                 :             :             {
    9397                 :         582 :               if (init == ridpointers[(int)RID_DEFAULT])
    9398                 :             :                 {
    9399                 :             :                   /* An out-of-class default definition is defined at
    9400                 :             :                      the point where it is explicitly defaulted.  */
    9401                 :         570 :                   if (DECL_DELETED_FN (decl))
    9402                 :           6 :                     maybe_explain_implicit_delete (decl);
    9403                 :         564 :                   else if (DECL_INITIAL (decl) == error_mark_node)
    9404                 :         540 :                     synthesize_method (decl);
    9405                 :             :                 }
    9406                 :             :               else
    9407                 :          24 :                 error_at (cp_expr_loc_or_loc (init,
    9408                 :          12 :                                               DECL_SOURCE_LOCATION (decl)),
    9409                 :             :                           "function %q#D is initialized like a variable",
    9410                 :             :                           decl);
    9411                 :             :             }
    9412                 :             :           /* else no initialization required.  */
    9413                 :             :         }
    9414                 :    45561818 :       else if (DECL_EXTERNAL (decl)
    9415                 :    45561818 :                && ! (DECL_LANG_SPECIFIC (decl)
    9416                 :     6156591 :                      && DECL_NOT_REALLY_EXTERN (decl)))
    9417                 :             :         {
    9418                 :             :           /* check_initializer will have done any constant initialization.  */
    9419                 :             :         }
    9420                 :             :       /* A variable definition.  */
    9421                 :    40960135 :       else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    9422                 :             :         {
    9423                 :             :           /* Initialize the local variable.  */
    9424                 :    23188419 :           if (!decomp)
    9425                 :    23170098 :             initialize_local_var (decl, init, false);
    9426                 :             :           else
    9427                 :             :             {
    9428                 :       18321 :               tree cleanup = NULL_TREE;
    9429                 :       18321 :               if (DECL_SIZE (decl))
    9430                 :       18321 :                 cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
    9431                 :             :               /* If cp_finish_decomp needs to emit any code, we need to emit that
    9432                 :             :                  code after code emitted by initialize_local_var in a single
    9433                 :             :                  CLEANUP_POINT_EXPR, so that temporaries are destructed only
    9434                 :             :                  after the cp_finish_decomp emitted code.
    9435                 :             :                  If there are any cleanups, either extend_ref_init_temps
    9436                 :             :                  created ones or e.g. array destruction, push those first
    9437                 :             :                  with the cleanups guarded on a bool temporary, initially
    9438                 :             :                  set to false and set to true after initialize_local_var
    9439                 :             :                  emitted code.  */
    9440                 :       18321 :               tree guard = NULL_TREE;
    9441                 :       18321 :               if (cleanups || cleanup)
    9442                 :             :                 {
    9443                 :       18321 :                   guard = get_internal_target_expr (boolean_false_node);
    9444                 :       18321 :                   add_stmt (guard);
    9445                 :       18321 :                   guard = TARGET_EXPR_SLOT (guard);
    9446                 :             :                 }
    9447                 :       18321 :               tree sl = push_stmt_list ();
    9448                 :       18321 :               initialize_local_var (decl, init, true);
    9449                 :       18321 :               if (guard)
    9450                 :             :                 {
    9451                 :       18321 :                   add_stmt (build2 (MODIFY_EXPR, boolean_type_node,
    9452                 :             :                                     guard, boolean_true_node));
    9453                 :       18339 :                   for (tree &t : *cleanups)
    9454                 :          18 :                     t = build3 (COND_EXPR, void_type_node,
    9455                 :             :                                 guard, t, void_node);
    9456                 :       18321 :                   if (cleanup)
    9457                 :          25 :                     cleanup = build3 (COND_EXPR, void_type_node,
    9458                 :             :                                       guard, cleanup, void_node);
    9459                 :             :                 }
    9460                 :       18321 :               unsigned before = stmt_list_stack->length ();
    9461                 :       18321 :               cp_finish_decomp (decl, decomp);
    9462                 :       18321 :               decomp = NULL;
    9463                 :       18321 :               unsigned n_extra_cleanups = stmt_list_stack->length () - before;
    9464                 :       18321 :               sl = pop_stmt_list (sl);
    9465                 :       18321 :               if (n_extra_cleanups)
    9466                 :             :                 {
    9467                 :             :                   /* If cp_finish_decomp needs any cleanups, such as for
    9468                 :             :                      extend_ref_init_temps created vars, pop_stmt_list
    9469                 :             :                      popped that all, so push those extra cleanups around
    9470                 :             :                      the whole sequence with a guard variable.  */
    9471                 :          15 :                   gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
    9472                 :          15 :                   guard = get_internal_target_expr (integer_zero_node);
    9473                 :          15 :                   add_stmt (guard);
    9474                 :          15 :                   guard = TARGET_EXPR_SLOT (guard);
    9475                 :          63 :                   for (unsigned i = 0; i < n_extra_cleanups; ++i)
    9476                 :             :                     {
    9477                 :          48 :                       tree_stmt_iterator tsi = tsi_last (sl);
    9478                 :          48 :                       gcc_assert (!tsi_end_p (tsi));
    9479                 :          48 :                       tree last = tsi_stmt (tsi);
    9480                 :          48 :                       gcc_assert (TREE_CODE (last) == CLEANUP_STMT
    9481                 :             :                                   && !CLEANUP_EH_ONLY (last));
    9482                 :          48 :                       tree cst = build_int_cst (integer_type_node, i + 1);
    9483                 :          96 :                       tree cl = build3 (COND_EXPR, void_type_node,
    9484                 :             :                                         build2 (GE_EXPR, boolean_type_node,
    9485                 :             :                                                 guard, cst),
    9486                 :          48 :                                         CLEANUP_EXPR (last), void_node);
    9487                 :          48 :                       extra_cleanups.safe_push (cl);
    9488                 :          48 :                       tsi_link_before (&tsi, build2 (MODIFY_EXPR,
    9489                 :             :                                                      integer_type_node,
    9490                 :             :                                                      guard, cst),
    9491                 :             :                                        TSI_SAME_STMT);
    9492                 :          48 :                       tree sl2 = CLEANUP_BODY (last);
    9493                 :          48 :                       gcc_assert (TREE_CODE (sl2) == STATEMENT_LIST);
    9494                 :          48 :                       tsi_link_before (&tsi, sl2, TSI_SAME_STMT);
    9495                 :          48 :                       tsi_delink (&tsi);
    9496                 :             :                     }
    9497                 :             :                 }
    9498                 :       18321 :               decomp_init = maybe_cleanup_point_expr_void (sl);
    9499                 :       18321 :               if (cleanup)
    9500                 :          25 :                 finish_decl_cleanup (decl, cleanup);
    9501                 :             :             }
    9502                 :             :         }
    9503                 :             : 
    9504                 :             :       /* If a variable is defined, and then a subsequent
    9505                 :             :          definition with external linkage is encountered, we will
    9506                 :             :          get here twice for the same variable.  We want to avoid
    9507                 :             :          calling expand_static_init more than once.  For variables
    9508                 :             :          that are not static data members, we can call
    9509                 :             :          expand_static_init only when we actually process the
    9510                 :             :          initializer.  It is not legal to redeclare a static data
    9511                 :             :          member, so this issue does not arise in that case.  */
    9512                 :    17771716 :       else if (var_definition_p && TREE_STATIC (decl))
    9513                 :             :         {
    9514                 :    15906893 :           if (decomp && DECL_FUNCTION_SCOPE_P (decl))
    9515                 :             :             {
    9516                 :          68 :               tree sl = push_stmt_list ();
    9517                 :          68 :               auto saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    9518                 :          68 :               current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    9519                 :          68 :               expand_static_init (decl, init);
    9520                 :          68 :               current_stmt_tree ()->stmts_are_full_exprs_p
    9521                 :          68 :                 = saved_stmts_are_full_exprs_p;
    9522                 :          68 :               cp_finish_decomp (decl, decomp);
    9523                 :          68 :               decomp = NULL;
    9524                 :          68 :               sl = pop_stmt_list (sl);
    9525                 :          68 :               sl = maybe_cleanup_point_expr_void (sl);
    9526                 :          68 :               add_stmt (sl);
    9527                 :             :             }
    9528                 :             :           else
    9529                 :    15906825 :             expand_static_init (decl, init);
    9530                 :             :         }
    9531                 :             :     }
    9532                 :             : 
    9533                 :             :   /* If a CLEANUP_STMT was created to destroy a temporary bound to a
    9534                 :             :      reference, insert it in the statement-tree now.  */
    9535                 :   106846114 :   if (cleanups)
    9536                 :             :     {
    9537                 :    40116722 :       for (tree t : *cleanups)
    9538                 :             :         {
    9539                 :        6002 :           push_cleanup (NULL_TREE, t, false);
    9540                 :             :           /* As in initialize_local_var.  */
    9541                 :        6002 :           wrap_temporary_cleanups (init, t);
    9542                 :             :         }
    9543                 :    40110720 :       release_tree_vector (cleanups);
    9544                 :             :     }
    9545                 :             : 
    9546                 :   106846192 :   for (tree t : &extra_cleanups)
    9547                 :          48 :     push_cleanup (NULL_TREE, t, false);
    9548                 :             : 
    9549                 :   106846114 :   if (decomp_init)
    9550                 :       18321 :     add_stmt (decomp_init);
    9551                 :             : 
    9552                 :   106846114 :   if (decomp
    9553                 :         141 :       && var_definition_p
    9554                 :         141 :       && TREE_STATIC (decl)
    9555                 :   106846255 :       && !DECL_FUNCTION_SCOPE_P (decl))
    9556                 :             :     {
    9557                 :         141 :       tree &aggregates3 = (CP_DECL_THREAD_LOCAL_P (decl)
    9558                 :         141 :                            ? tls_aggregates : static_aggregates);
    9559                 :         141 :       tree aggregates2 = aggregates3;
    9560                 :         141 :       if (aggregates2 != aggregates1)
    9561                 :             :         {
    9562                 :          66 :           cp_finish_decomp (decl, decomp);
    9563                 :          66 :           decomp = NULL;
    9564                 :          66 :           if (aggregates3 != aggregates2)
    9565                 :             :             {
    9566                 :             :               /* If there are dynamic initializers for the structured
    9567                 :             :                  binding base or associated extended ref temps and also
    9568                 :             :                  dynamic initializers for the structured binding non-base
    9569                 :             :                  vars, mark them.  */
    9570                 :         315 :               for (tree t = aggregates3; t != aggregates2; t = TREE_CHAIN (t))
    9571                 :         252 :                 STATIC_INIT_DECOMP_NONBASE_P (t) = 1;
    9572                 :         150 :               for (tree t = aggregates2; t != aggregates1; t = TREE_CHAIN (t))
    9573                 :          87 :                 STATIC_INIT_DECOMP_BASE_P (t) = 1;
    9574                 :             :             }
    9575                 :             :         }
    9576                 :             :     }
    9577                 :             : 
    9578                 :   106846114 :   if (was_readonly)
    9579                 :      229915 :     TREE_READONLY (decl) = 1;
    9580                 :             : 
    9581                 :   106846114 :   if (flag_openmp
    9582                 :      352642 :       && VAR_P (decl)
    9583                 :   106979232 :       && lookup_attribute ("omp declare target implicit",
    9584                 :      133118 :                            DECL_ATTRIBUTES (decl)))
    9585                 :             :     {
    9586                 :          52 :       DECL_ATTRIBUTES (decl)
    9587                 :          52 :         = remove_attribute ("omp declare target implicit",
    9588                 :          52 :                             DECL_ATTRIBUTES (decl));
    9589                 :          52 :       complete_type (TREE_TYPE (decl));
    9590                 :          52 :       if (!omp_mappable_type (TREE_TYPE (decl)))
    9591                 :             :         {
    9592                 :          30 :           auto_diagnostic_group d;
    9593                 :          30 :           error ("%q+D in declare target directive does not have mappable"
    9594                 :             :                  " type", decl);
    9595                 :          30 :           if (TREE_TYPE (decl) != error_mark_node
    9596                 :          30 :               && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
    9597                 :          30 :             cxx_incomplete_type_inform (TREE_TYPE (decl));
    9598                 :          30 :         }
    9599                 :          22 :       else if (!lookup_attribute ("omp declare target",
    9600                 :          22 :                                   DECL_ATTRIBUTES (decl))
    9601                 :          44 :                && !lookup_attribute ("omp declare target link",
    9602                 :          22 :                                      DECL_ATTRIBUTES (decl)))
    9603                 :             :         {
    9604                 :          22 :           DECL_ATTRIBUTES (decl)
    9605                 :          22 :             = tree_cons (get_identifier ("omp declare target"),
    9606                 :          22 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
    9607                 :          22 :           symtab_node *node = symtab_node::get (decl);
    9608                 :          22 :           if (node != NULL)
    9609                 :             :             {
    9610                 :          19 :               node->offloadable = 1;
    9611                 :          19 :               if (ENABLE_OFFLOADING)
    9612                 :             :                 {
    9613                 :             :                   g->have_offload = true;
    9614                 :             :                   if (is_a <varpool_node *> (node))
    9615                 :             :                     vec_safe_push (offload_vars, decl);
    9616                 :             :                 }
    9617                 :             :             }
    9618                 :             :         }
    9619                 :             :     }
    9620                 :             : 
    9621                 :             :   /* This is the last point we can lower alignment so give the target the
    9622                 :             :      chance to do so.  */
    9623                 :   106846114 :   if (VAR_P (decl)
    9624                 :    45561889 :       && !is_global_var (decl)
    9625                 :   130034693 :       && !DECL_HARD_REGISTER (decl))
    9626                 :    23188529 :     targetm.lower_local_decl_alignment (decl);
    9627                 :             : 
    9628                 :   106846114 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
    9629                 :   280307344 : }
    9630                 :             : 
    9631                 :             : /* For class TYPE return itself or some its bases that contain
    9632                 :             :    any direct non-static data members.  Return error_mark_node if an
    9633                 :             :    error has been diagnosed.  */
    9634                 :             : 
    9635                 :             : static tree
    9636                 :       21300 : find_decomp_class_base (location_t loc, tree type, tree ret)
    9637                 :             : {
    9638                 :       42600 :   if (LAMBDA_TYPE_P (type))
    9639                 :             :     {
    9640                 :           9 :       auto_diagnostic_group d;
    9641                 :           9 :       error_at (loc, "cannot decompose lambda closure type %qT", type);
    9642                 :           9 :       inform (location_of (type), "lambda declared here");
    9643                 :           9 :       return error_mark_node;
    9644                 :           9 :     }
    9645                 :             : 
    9646                 :       21291 :   bool member_seen = false;
    9647                 :      300330 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    9648                 :      515245 :     if (TREE_CODE (field) != FIELD_DECL
    9649                 :       42981 :         || DECL_ARTIFICIAL (field)
    9650                 :      321959 :         || DECL_UNNAMED_BIT_FIELD (field))
    9651                 :      236185 :       continue;
    9652                 :       42875 :     else if (ret)
    9653                 :             :       return type;
    9654                 :       42858 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    9655                 :             :       {
    9656                 :           2 :         auto_diagnostic_group d;
    9657                 :           2 :         if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
    9658                 :           1 :           error_at (loc, "cannot decompose class type %qT because it has an "
    9659                 :             :                          "anonymous struct member", type);
    9660                 :             :         else
    9661                 :           1 :           error_at (loc, "cannot decompose class type %qT because it has an "
    9662                 :             :                          "anonymous union member", type);
    9663                 :           2 :         inform (DECL_SOURCE_LOCATION (field), "declared here");
    9664                 :           2 :         return error_mark_node;
    9665                 :           2 :       }
    9666                 :       42856 :     else if (!accessible_p (type, field, true))
    9667                 :             :       {
    9668                 :           2 :         auto_diagnostic_group d;
    9669                 :           2 :         error_at (loc, "cannot decompose inaccessible member %qD of %qT",
    9670                 :             :                   field, type);
    9671                 :           2 :         inform (DECL_SOURCE_LOCATION (field),
    9672                 :           2 :                 TREE_PRIVATE (field)
    9673                 :             :                 ? G_("declared private here")
    9674                 :             :                 : G_("declared protected here"));
    9675                 :           2 :         return error_mark_node;
    9676                 :           2 :       }
    9677                 :             :     else
    9678                 :             :       member_seen = true;
    9679                 :             : 
    9680                 :       21270 :   tree base_binfo, binfo;
    9681                 :       21270 :   tree orig_ret = ret;
    9682                 :       21270 :   int i;
    9683                 :       21270 :   if (member_seen)
    9684                 :       21221 :     ret = type;
    9685                 :       21325 :   for (binfo = TYPE_BINFO (type), i = 0;
    9686                 :       21325 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    9687                 :             :     {
    9688                 :          66 :       auto_diagnostic_group d;
    9689                 :          66 :       tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret);
    9690                 :          66 :       if (t == error_mark_node)
    9691                 :             :         {
    9692                 :           3 :           inform (location_of (type), "in base class of %qT", type);
    9693                 :           3 :           return error_mark_node;
    9694                 :             :         }
    9695                 :          63 :       if (t != NULL_TREE && t != ret)
    9696                 :             :         {
    9697                 :          36 :           if (ret == type)
    9698                 :             :             {
    9699                 :           4 :               error_at (loc, "cannot decompose class type %qT: both it and "
    9700                 :             :                              "its base class %qT have non-static data members",
    9701                 :             :                         type, t);
    9702                 :           4 :               return error_mark_node;
    9703                 :             :             }
    9704                 :          32 :           else if (orig_ret != NULL_TREE)
    9705                 :             :             return t;
    9706                 :          32 :           else if (ret != NULL_TREE)
    9707                 :             :             {
    9708                 :           4 :               error_at (loc, "cannot decompose class type %qT: its base "
    9709                 :             :                              "classes %qT and %qT have non-static data "
    9710                 :             :                              "members", type, ret, t);
    9711                 :           4 :               return error_mark_node;
    9712                 :             :             }
    9713                 :             :           else
    9714                 :             :             ret = t;
    9715                 :             :         }
    9716                 :          66 :     }
    9717                 :             :   return ret;
    9718                 :             : }
    9719                 :             : 
    9720                 :             : /* Return std::tuple_size<TYPE>::value.  */
    9721                 :             : 
    9722                 :             : static tree
    9723                 :       60948 : get_tuple_size (tree type)
    9724                 :             : {
    9725                 :       60948 :   tree args = make_tree_vec (1);
    9726                 :       60948 :   TREE_VEC_ELT (args, 0) = type;
    9727                 :       60948 :   tree inst = lookup_template_class (tuple_size_identifier, args,
    9728                 :             :                                      /*in_decl*/NULL_TREE,
    9729                 :             :                                      /*context*/std_node,
    9730                 :             :                                      tf_none);
    9731                 :       60948 :   inst = complete_type (inst);
    9732                 :       60948 :   if (inst == error_mark_node
    9733                 :       60251 :       || !COMPLETE_TYPE_P (inst)
    9734                 :      100647 :       || !CLASS_TYPE_P (type))
    9735                 :             :     return NULL_TREE;
    9736                 :       39699 :   tree val = lookup_qualified_name (inst, value_identifier,
    9737                 :             :                                     LOOK_want::NORMAL, /*complain*/false);
    9738                 :       39699 :   if (val == error_mark_node)
    9739                 :             :     return NULL_TREE;
    9740                 :       39693 :   if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
    9741                 :       39693 :     val = maybe_constant_value (val);
    9742                 :       39693 :   if (TREE_CODE (val) == INTEGER_CST)
    9743                 :             :     return val;
    9744                 :             :   else
    9745                 :           0 :     return error_mark_node;
    9746                 :             : }
    9747                 :             : 
    9748                 :             : /* Return std::tuple_element<I,TYPE>::type.  */
    9749                 :             : 
    9750                 :             : static tree
    9751                 :       42660 : get_tuple_element_type (tree type, unsigned i)
    9752                 :             : {
    9753                 :       42660 :   tree args = make_tree_vec (2);
    9754                 :       42660 :   TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
    9755                 :       42660 :   TREE_VEC_ELT (args, 1) = type;
    9756                 :       42660 :   tree inst = lookup_template_class (tuple_element_identifier, args,
    9757                 :             :                                      /*in_decl*/NULL_TREE,
    9758                 :             :                                      /*context*/std_node,
    9759                 :             :                                      tf_warning_or_error);
    9760                 :       42660 :   return make_typename_type (inst, type_identifier,
    9761                 :       42660 :                              none_type, tf_warning_or_error);
    9762                 :             : }
    9763                 :             : 
    9764                 :             : /* Return e.get<i>() or get<i>(e).  */
    9765                 :             : 
    9766                 :             : static tree
    9767                 :       42669 : get_tuple_decomp_init (tree decl, unsigned i)
    9768                 :             : {
    9769                 :       42669 :   tree targs = make_tree_vec (1);
    9770                 :       42669 :   TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
    9771                 :             : 
    9772                 :       42669 :   tree etype = TREE_TYPE (decl);
    9773                 :       42669 :   tree e = convert_from_reference (decl);
    9774                 :             : 
    9775                 :             :   /* [The id-expression] e is an lvalue if the type of the entity e is an
    9776                 :             :      lvalue reference and an xvalue otherwise.  */
    9777                 :       42669 :   if (!TYPE_REF_P (etype)
    9778                 :       42669 :       || TYPE_REF_IS_RVALUE (etype))
    9779                 :       41451 :     e = move (e);
    9780                 :             : 
    9781                 :       42669 :   tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
    9782                 :             :                                     LOOK_want::NORMAL, /*complain*/false);
    9783                 :       42669 :   bool use_member_get = false;
    9784                 :             : 
    9785                 :             :   /* To use a member get, member lookup must find at least one
    9786                 :             :      declaration that is a function template
    9787                 :             :      whose first template parameter is a non-type parameter.  */
    9788                 :      126639 :   for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
    9789                 :             :     {
    9790                 :       42669 :       tree fn = *iter;
    9791                 :       42669 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    9792                 :             :         {
    9793                 :        1371 :           tree tparms = DECL_TEMPLATE_PARMS (fn);
    9794                 :        1371 :           tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
    9795                 :        1371 :           if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
    9796                 :             :             {
    9797                 :             :               use_member_get = true;
    9798                 :             :               break;
    9799                 :             :             }
    9800                 :             :         }
    9801                 :             :     }
    9802                 :             : 
    9803                 :       42669 :   if (use_member_get)
    9804                 :             :     {
    9805                 :        1368 :       fns = lookup_template_function (fns, targs);
    9806                 :        1368 :       return build_new_method_call (e, fns, /*args*/NULL,
    9807                 :             :                                     /*path*/NULL_TREE, LOOKUP_NORMAL,
    9808                 :        1368 :                                     /*fn_p*/NULL, tf_warning_or_error);
    9809                 :             :     }
    9810                 :             :   else
    9811                 :             :     {
    9812                 :       41301 :       releasing_vec args (make_tree_vector_single (e));
    9813                 :       41301 :       fns = lookup_template_function (get__identifier, targs);
    9814                 :       41301 :       fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
    9815                 :       41301 :       return finish_call_expr (fns, &args, /*novirt*/false,
    9816                 :             :                                /*koenig*/true, tf_warning_or_error);
    9817                 :       41301 :     }
    9818                 :             : }
    9819                 :             : 
    9820                 :             : /* It's impossible to recover the decltype of a tuple decomposition variable
    9821                 :             :    based on the actual type of the variable, so store it in a hash table.  */
    9822                 :             : 
    9823                 :             : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
    9824                 :             : 
    9825                 :             : tree
    9826                 :          54 : lookup_decomp_type (tree v)
    9827                 :             : {
    9828                 :          54 :   if (decomp_type_table)
    9829                 :          51 :     if (tree *slot = decomp_type_table->get (v))
    9830                 :          51 :       return *slot;
    9831                 :             :   return NULL_TREE;
    9832                 :             : }
    9833                 :             : 
    9834                 :             : /* Mangle a decomposition declaration if needed.  Arguments like
    9835                 :             :    in cp_finish_decomp.  */
    9836                 :             : 
    9837                 :             : static void
    9838                 :       35237 : cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp)
    9839                 :             : {
    9840                 :       35237 :   if (!processing_template_decl
    9841                 :       35237 :       && !error_operand_p (decl)
    9842                 :       70474 :       && TREE_STATIC (decl))
    9843                 :             :     {
    9844                 :         532 :       auto_vec<tree, 16> v;
    9845                 :         532 :       v.safe_grow (decomp->count, true);
    9846                 :         532 :       tree d = decomp->decl;
    9847                 :        1961 :       for (unsigned int i = 0; i < decomp->count; i++, d = DECL_CHAIN (d))
    9848                 :        1429 :         v[decomp->count - i - 1] = d;
    9849                 :         532 :       if (DECL_FUNCTION_SCOPE_P (decl))
    9850                 :             :         {
    9851                 :             :           size_t sz = 3;
    9852                 :         683 :           for (unsigned int i = 0; i < decomp->count; ++i)
    9853                 :         494 :             sz += IDENTIFIER_LENGTH (DECL_NAME (v[i])) + 1;
    9854                 :         189 :           char *name = XALLOCAVEC (char, sz);
    9855                 :         189 :           name[0] = 'D';
    9856                 :         189 :           name[1] = 'C';
    9857                 :         189 :           char *p = name + 2;
    9858                 :         683 :           for (unsigned int i = 0; i < decomp->count; ++i)
    9859                 :             :             {
    9860                 :         494 :               size_t len = IDENTIFIER_LENGTH (DECL_NAME (v[i]));
    9861                 :         494 :               *p++ = ' ';
    9862                 :         494 :               memcpy (p, IDENTIFIER_POINTER (DECL_NAME (v[i])), len);
    9863                 :         494 :               p += len;
    9864                 :             :             }
    9865                 :         189 :           *p = '\0';
    9866                 :         189 :           determine_local_discriminator (decl, get_identifier (name));
    9867                 :             :         }
    9868                 :         532 :       SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
    9869                 :         532 :       maybe_apply_pragma_weak (decl);
    9870                 :         532 :     }
    9871                 :       35237 : }
    9872                 :             : 
    9873                 :             : /* Finish a decomposition declaration.  DECL is the underlying declaration
    9874                 :             :    "e", FIRST is the head of a chain of decls for the individual identifiers
    9875                 :             :    chained through DECL_CHAIN in reverse order and COUNT is the number of
    9876                 :             :    those decls.  If TEST_P is true, return true if any code would need to be
    9877                 :             :    actually emitted but don't emit it.  Return false otherwise.  */
    9878                 :             : 
    9879                 :             : bool
    9880                 :      131855 : cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p)
    9881                 :             : {
    9882                 :      131855 :   tree first = decomp->decl;
    9883                 :      131855 :   unsigned count = decomp->count;
    9884                 :      131855 :   if (error_operand_p (decl))
    9885                 :             :     {
    9886                 :          54 :      error_out:
    9887                 :         436 :       while (count--)
    9888                 :             :         {
    9889                 :         274 :           TREE_TYPE (first) = error_mark_node;
    9890                 :         274 :           if (DECL_HAS_VALUE_EXPR_P (first))
    9891                 :             :             {
    9892                 :           9 :               SET_DECL_VALUE_EXPR (first, NULL_TREE);
    9893                 :           9 :               DECL_HAS_VALUE_EXPR_P (first) = 0;
    9894                 :             :             }
    9895                 :         274 :           first = DECL_CHAIN (first);
    9896                 :             :         }
    9897                 :         162 :       if (DECL_P (decl) && DECL_NAMESPACE_SCOPE_P (decl))
    9898                 :          51 :         SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
    9899                 :         162 :       return false;
    9900                 :             :     }
    9901                 :             : 
    9902                 :      131801 :   location_t loc = DECL_SOURCE_LOCATION (decl);
    9903                 :      131801 :   if (type_dependent_expression_p (decl)
    9904                 :             :       /* This happens for range for when not in templates.
    9905                 :             :          Still add the DECL_VALUE_EXPRs for later processing.  */
    9906                 :      131801 :       || (!processing_template_decl
    9907                 :       54021 :           && type_uses_auto (TREE_TYPE (decl))))
    9908                 :             :     {
    9909                 :      211407 :       for (unsigned int i = 0; i < count; i++)
    9910                 :             :         {
    9911                 :      140992 :           if (!DECL_HAS_VALUE_EXPR_P (first))
    9912                 :             :             {
    9913                 :      140992 :               tree v = build_nt (ARRAY_REF, decl,
    9914                 :      140992 :                                  size_int (count - i - 1),
    9915                 :             :                                  NULL_TREE, NULL_TREE);
    9916                 :      140992 :               SET_DECL_VALUE_EXPR (first, v);
    9917                 :      140992 :               DECL_HAS_VALUE_EXPR_P (first) = 1;
    9918                 :             :             }
    9919                 :      140992 :           if (processing_template_decl)
    9920                 :      140420 :             fit_decomposition_lang_decl (first, decl);
    9921                 :      140992 :           first = DECL_CHAIN (first);
    9922                 :             :         }
    9923                 :             :       return false;
    9924                 :             :     }
    9925                 :             : 
    9926                 :       61386 :   auto_vec<tree, 16> v;
    9927                 :       61386 :   v.safe_grow (count, true);
    9928                 :       61386 :   tree d = first;
    9929                 :      185461 :   for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
    9930                 :             :     {
    9931                 :      124075 :       v[count - i - 1] = d;
    9932                 :      124075 :       fit_decomposition_lang_decl (d, decl);
    9933                 :             :     }
    9934                 :             : 
    9935                 :       61386 :   tree type = TREE_TYPE (decl);
    9936                 :       61386 :   tree dexp = decl;
    9937                 :             : 
    9938                 :       61386 :   if (TYPE_REF_P (type))
    9939                 :             :     {
    9940                 :        1288 :       dexp = convert_from_reference (dexp);
    9941                 :        1288 :       type = complete_type (TREE_TYPE (type));
    9942                 :        1288 :       if (type == error_mark_node)
    9943                 :         108 :         goto error_out;
    9944                 :        1288 :       if (!COMPLETE_TYPE_P (type))
    9945                 :             :         {
    9946                 :           3 :           error_at (loc, "structured binding refers to incomplete type %qT",
    9947                 :             :                     type);
    9948                 :           3 :           goto error_out;
    9949                 :             :         }
    9950                 :             :     }
    9951                 :             : 
    9952                 :       61383 :   tree eltype = NULL_TREE;
    9953                 :       61383 :   unsigned HOST_WIDE_INT eltscnt = 0;
    9954                 :       61383 :   if (TREE_CODE (type) == ARRAY_TYPE)
    9955                 :             :     {
    9956                 :         411 :       tree nelts;
    9957                 :         411 :       nelts = array_type_nelts_top (type);
    9958                 :         411 :       if (nelts == error_mark_node)
    9959                 :           0 :         goto error_out;
    9960                 :         411 :       if (DECL_DECOMP_BASE (decl))
    9961                 :             :         {
    9962                 :           9 :           error_at (loc, "array initializer for structured binding "
    9963                 :             :                     "declaration in condition");
    9964                 :           9 :           goto error_out;
    9965                 :             :         }
    9966                 :         402 :       if (!tree_fits_uhwi_p (nelts))
    9967                 :             :         {
    9968                 :           0 :           error_at (loc, "cannot decompose variable length array %qT", type);
    9969                 :           0 :           goto error_out;
    9970                 :             :         }
    9971                 :         402 :       eltscnt = tree_to_uhwi (nelts);
    9972                 :         402 :       if (count != eltscnt)
    9973                 :             :         {
    9974                 :           8 :        cnt_mismatch:
    9975                 :          23 :           auto_diagnostic_group d;
    9976                 :          23 :           if (count > eltscnt)
    9977                 :          12 :             error_n (loc, count,
    9978                 :             :                      "%u name provided for structured binding",
    9979                 :             :                      "%u names provided for structured binding", count);
    9980                 :             :           else
    9981                 :          11 :             error_n (loc, count,
    9982                 :             :                      "only %u name provided for structured binding",
    9983                 :             :                      "only %u names provided for structured binding", count);
    9984                 :          23 :           inform_n (loc, eltscnt,
    9985                 :             :                     "while %qT decomposes into %wu element",
    9986                 :             :                     "while %qT decomposes into %wu elements",
    9987                 :             :                     type, eltscnt);
    9988                 :          23 :           goto error_out;
    9989                 :             :         }
    9990                 :         394 :       eltype = TREE_TYPE (type);
    9991                 :        1368 :       for (unsigned int i = 0; i < count; i++)
    9992                 :             :         {
    9993                 :         974 :           TREE_TYPE (v[i]) = eltype;
    9994                 :         974 :           layout_decl (v[i], 0);
    9995                 :         974 :           if (processing_template_decl)
    9996                 :          60 :             continue;
    9997                 :         914 :           tree t = unshare_expr (dexp);
    9998                 :         914 :           t = build4 (ARRAY_REF, eltype, t, size_int (i), NULL_TREE, NULL_TREE);
    9999                 :         914 :           SET_DECL_VALUE_EXPR (v[i], t);
   10000                 :         914 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10001                 :             :         }
   10002                 :             :     }
   10003                 :             :   /* 2 GNU extensions.  */
   10004                 :       60972 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
   10005                 :             :     {
   10006                 :          15 :       eltscnt = 2;
   10007                 :          15 :       if (count != eltscnt)
   10008                 :           0 :         goto cnt_mismatch;
   10009                 :          15 :       eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
   10010                 :          45 :       for (unsigned int i = 0; i < count; i++)
   10011                 :             :         {
   10012                 :          30 :           TREE_TYPE (v[i]) = eltype;
   10013                 :          30 :           layout_decl (v[i], 0);
   10014                 :          30 :           if (processing_template_decl)
   10015                 :           0 :             continue;
   10016                 :          30 :           tree t = unshare_expr (dexp);
   10017                 :          45 :           t = build1 (i ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
   10018                 :          30 :           SET_DECL_VALUE_EXPR (v[i], t);
   10019                 :          30 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10020                 :             :         }
   10021                 :             :     }
   10022                 :       60957 :   else if (TREE_CODE (type) == VECTOR_TYPE)
   10023                 :             :     {
   10024                 :           9 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
   10025                 :             :         {
   10026                 :             :           error_at (loc, "cannot decompose variable length vector %qT", type);
   10027                 :             :           goto error_out;
   10028                 :             :         }
   10029                 :           9 :       if (count != eltscnt)
   10030                 :           0 :         goto cnt_mismatch;
   10031                 :           9 :       eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
   10032                 :          45 :       for (unsigned int i = 0; i < count; i++)
   10033                 :             :         {
   10034                 :          36 :           TREE_TYPE (v[i]) = eltype;
   10035                 :          36 :           layout_decl (v[i], 0);
   10036                 :          36 :           if (processing_template_decl)
   10037                 :           0 :             continue;
   10038                 :          36 :           tree t = unshare_expr (dexp);
   10039                 :          36 :           convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
   10040                 :          36 :                                                  &t, size_int (i));
   10041                 :          36 :           t = build4 (ARRAY_REF, eltype, t, size_int (i), NULL_TREE, NULL_TREE);
   10042                 :          36 :           SET_DECL_VALUE_EXPR (v[i], t);
   10043                 :          36 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10044                 :             :         }
   10045                 :             :     }
   10046                 :       60948 :   else if (tree tsize = get_tuple_size (type))
   10047                 :             :     {
   10048                 :       39693 :       if (tsize == error_mark_node)
   10049                 :             :         {
   10050                 :           0 :           error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
   10051                 :             :                          "constant expression", type);
   10052                 :           0 :           goto error_out;
   10053                 :             :         }
   10054                 :       39693 :       if (!tree_fits_uhwi_p (tsize))
   10055                 :             :         {
   10056                 :          12 :           auto_diagnostic_group d;
   10057                 :          12 :           error_n (loc, count,
   10058                 :             :                    "%u name provided for structured binding",
   10059                 :             :                    "%u names provided for structured binding", count);
   10060                 :          12 :           inform (loc, "while %qT decomposes into %E elements",
   10061                 :             :                   type, tsize);
   10062                 :          12 :           goto error_out;
   10063                 :          12 :         }
   10064                 :       39681 :       eltscnt = tree_to_uhwi (tsize);
   10065                 :       39681 :       if (count != eltscnt)
   10066                 :           3 :         goto cnt_mismatch;
   10067                 :       39678 :       if (test_p)
   10068                 :       61278 :         return true;
   10069                 :       21148 :       if (!processing_template_decl && DECL_DECOMP_BASE (decl))
   10070                 :             :         {
   10071                 :             :           /* For structured bindings used in conditions we need to evaluate
   10072                 :             :              the conversion of decl (aka e in the standard) to bool or
   10073                 :             :              integral/enumeral type (the latter for switch conditions)
   10074                 :             :              before the get methods.  */
   10075                 :          78 :           tree cond = convert_from_reference (decl);
   10076                 :          78 :           if (integer_onep (DECL_DECOMP_BASE (decl)))
   10077                 :             :             /* switch condition.  */
   10078                 :          18 :             cond = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   10079                 :             :                                                cond, true);
   10080                 :             :           else
   10081                 :             :             /* if/while/for condition.  */
   10082                 :          60 :             cond = contextual_conv_bool (cond, tf_warning_or_error);
   10083                 :          78 :           if (cond && !error_operand_p (cond))
   10084                 :             :             {
   10085                 :             :               /* Wrap that value into a TARGET_EXPR, emit it right
   10086                 :             :                  away and save for later uses in the cp_parse_condition
   10087                 :             :                  or its instantiation.  */
   10088                 :          78 :               cond = get_internal_target_expr (cond);
   10089                 :          78 :               add_stmt (cond);
   10090                 :          78 :               DECL_DECOMP_BASE (decl) = cond;
   10091                 :             :             }
   10092                 :             :         }
   10093                 :       21148 :       int save_read = DECL_READ_P (decl);
   10094                 :       63796 :       for (unsigned i = 0; i < count; ++i)
   10095                 :             :         {
   10096                 :       42669 :           location_t sloc = input_location;
   10097                 :       42669 :           location_t dloc = DECL_SOURCE_LOCATION (v[i]);
   10098                 :             : 
   10099                 :       42669 :           input_location = dloc;
   10100                 :       42669 :           tree init = get_tuple_decomp_init (decl, i);
   10101                 :       42669 :           tree eltype = (init == error_mark_node ? error_mark_node
   10102                 :       42660 :                          : get_tuple_element_type (type, i));
   10103                 :       42669 :           input_location = sloc;
   10104                 :             : 
   10105                 :       42669 :           if (VOID_TYPE_P (eltype))
   10106                 :             :             {
   10107                 :           3 :               error ("%<std::tuple_element<%u, %T>::type%> is %<void%>",
   10108                 :             :                      i, type);
   10109                 :           3 :               eltype = error_mark_node;
   10110                 :             :             }
   10111                 :       42669 :           if (init == error_mark_node || eltype == error_mark_node)
   10112                 :             :             {
   10113                 :          21 :               inform (dloc, "in initialization of structured binding "
   10114                 :          21 :                       "variable %qD", v[i]);
   10115                 :          21 :               goto error_out;
   10116                 :             :             }
   10117                 :             :           /* Save the decltype away before reference collapse.  */
   10118                 :       42648 :           hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
   10119                 :       42648 :           eltype = cp_build_reference_type (eltype, !lvalue_p (init));
   10120                 :       42648 :           TREE_TYPE (v[i]) = eltype;
   10121                 :       42648 :           layout_decl (v[i], 0);
   10122                 :       42648 :           if (DECL_HAS_VALUE_EXPR_P (v[i]))
   10123                 :             :             {
   10124                 :             :               /* In this case the names are variables, not just proxies.  */
   10125                 :         204 :               SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
   10126                 :         204 :               DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
   10127                 :             :             }
   10128                 :       42648 :           if (!processing_template_decl)
   10129                 :             :             {
   10130                 :       37338 :               copy_linkage (v[i], decl);
   10131                 :       37338 :               cp_finish_decl (v[i], init, /*constexpr*/false,
   10132                 :             :                               /*asm*/NULL_TREE, LOOKUP_NORMAL);
   10133                 :             :             }
   10134                 :             :         }
   10135                 :             :       /* Ignore reads from the underlying decl performed during initialization
   10136                 :             :          of the individual variables.  If those will be read, we'll mark
   10137                 :             :          the underlying decl as read at that point.  */
   10138                 :       21127 :       DECL_READ_P (decl) = save_read;
   10139                 :             :     }
   10140                 :       21255 :   else if (TREE_CODE (type) == UNION_TYPE)
   10141                 :             :     {
   10142                 :           3 :       error_at (loc, "cannot decompose union type %qT", type);
   10143                 :           3 :       goto error_out;
   10144                 :             :     }
   10145                 :       21252 :   else if (!CLASS_TYPE_P (type))
   10146                 :             :     {
   10147                 :          16 :       error_at (loc, "cannot decompose non-array non-class type %qT", type);
   10148                 :          16 :       goto error_out;
   10149                 :             :     }
   10150                 :       21236 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
   10151                 :           0 :     goto error_out;
   10152                 :       21236 :   else if (processing_template_decl && !COMPLETE_TYPE_P (type))
   10153                 :           2 :     pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
   10154                 :             :              type);
   10155                 :             :   else
   10156                 :             :     {
   10157                 :       21234 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE);
   10158                 :       21234 :       if (btype == error_mark_node)
   10159                 :          21 :         goto error_out;
   10160                 :       21213 :       else if (btype == NULL_TREE)
   10161                 :             :         {
   10162                 :           0 :           error_at (loc, "cannot decompose class type %qT without non-static "
   10163                 :             :                          "data members", type);
   10164                 :           0 :           goto error_out;
   10165                 :             :         }
   10166                 :      299209 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   10167                 :      513149 :         if (TREE_CODE (field) != FIELD_DECL
   10168                 :       42859 :             || DECL_ARTIFICIAL (field)
   10169                 :      320851 :             || DECL_UNNAMED_BIT_FIELD (field))
   10170                 :      235153 :           continue;
   10171                 :             :         else
   10172                 :       42843 :           eltscnt++;
   10173                 :       21213 :       if (count != eltscnt)
   10174                 :          12 :         goto cnt_mismatch;
   10175                 :       21201 :       tree t = dexp;
   10176                 :       21201 :       if (type != btype)
   10177                 :             :         {
   10178                 :          18 :           t = convert_to_base (t, btype, /*check_access*/true,
   10179                 :             :                                /*nonnull*/false, tf_warning_or_error);
   10180                 :          18 :           type = btype;
   10181                 :             :         }
   10182                 :       21201 :       unsigned int i = 0;
   10183                 :      299016 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   10184                 :      512812 :         if (TREE_CODE (field) != FIELD_DECL
   10185                 :       42834 :             || DECL_ARTIFICIAL (field)
   10186                 :      320645 :             || DECL_UNNAMED_BIT_FIELD (field))
   10187                 :      234997 :           continue;
   10188                 :             :         else
   10189                 :             :           {
   10190                 :       42818 :             tree tt = finish_non_static_data_member (field, unshare_expr (t),
   10191                 :             :                                                      NULL_TREE);
   10192                 :       42818 :             if (REFERENCE_REF_P (tt))
   10193                 :          30 :               tt = TREE_OPERAND (tt, 0);
   10194                 :       42818 :             TREE_TYPE (v[i]) = TREE_TYPE (tt);
   10195                 :       42818 :             layout_decl (v[i], 0);
   10196                 :       42818 :             if (!processing_template_decl)
   10197                 :             :               {
   10198                 :       32889 :                 SET_DECL_VALUE_EXPR (v[i], tt);
   10199                 :       32889 :                 DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10200                 :             :               }
   10201                 :       42818 :             i++;
   10202                 :             :           }
   10203                 :             :     }
   10204                 :       42748 :   if (processing_template_decl)
   10205                 :             :     {
   10206                 :       22901 :       for (unsigned int i = 0; i < count; i++)
   10207                 :       15301 :         if (!DECL_HAS_VALUE_EXPR_P (v[i]))
   10208                 :             :           {
   10209                 :       15166 :             tree a = build_nt (ARRAY_REF, decl, size_int (i),
   10210                 :             :                                NULL_TREE, NULL_TREE);
   10211                 :       15166 :             SET_DECL_VALUE_EXPR (v[i], a);
   10212                 :       15166 :             DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10213                 :             :           }
   10214                 :             :     }
   10215                 :             :   return false;
   10216                 :             : }
   10217                 :             : 
   10218                 :             : /* Returns a declaration for a VAR_DECL as if:
   10219                 :             : 
   10220                 :             :      extern "C" TYPE NAME;
   10221                 :             : 
   10222                 :             :    had been seen.  Used to create compiler-generated global
   10223                 :             :    variables.  */
   10224                 :             : 
   10225                 :             : static tree
   10226                 :        2244 : declare_global_var (tree name, tree type)
   10227                 :             : {
   10228                 :        2244 :   auto cookie = push_abi_namespace (global_namespace);
   10229                 :        2244 :   tree decl = build_decl (input_location, VAR_DECL, name, type);
   10230                 :        2244 :   TREE_PUBLIC (decl) = 1;
   10231                 :        2244 :   DECL_EXTERNAL (decl) = 1;
   10232                 :        2244 :   DECL_ARTIFICIAL (decl) = 1;
   10233                 :        2244 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   10234                 :             :   /* If the user has explicitly declared this variable (perhaps
   10235                 :             :      because the code we are compiling is part of a low-level runtime
   10236                 :             :      library), then it is possible that our declaration will be merged
   10237                 :             :      with theirs by pushdecl.  */
   10238                 :        2244 :   decl = pushdecl (decl);
   10239                 :        2244 :   cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
   10240                 :        2244 :   pop_abi_namespace (cookie, global_namespace);
   10241                 :             : 
   10242                 :        2244 :   return decl;
   10243                 :             : }
   10244                 :             : 
   10245                 :             : /* Returns the type for the argument to "atexit" corresponding to the function
   10246                 :             :    to be called when the program exits.  */
   10247                 :             : 
   10248                 :             : static tree
   10249                 :          24 : get_atexit_fn_ptr_type ()
   10250                 :             : {
   10251                 :          24 :   if (!atexit_fn_ptr_type_node)
   10252                 :             :     {
   10253                 :          12 :       tree fn_type = build_function_type_list (void_type_node, NULL_TREE);
   10254                 :          12 :       atexit_fn_ptr_type_node = build_pointer_type (fn_type);
   10255                 :             :     }
   10256                 :             : 
   10257                 :          24 :   return atexit_fn_ptr_type_node;
   10258                 :             : }
   10259                 :             : 
   10260                 :             : /* Returns the type for the argument to "__cxa_atexit", "__cxa_thread_atexit"
   10261                 :             :    or "__cxa_throw" corresponding to the destructor to be called when the
   10262                 :             :    program exits.  */
   10263                 :             : 
   10264                 :             : tree
   10265                 :       18706 : get_cxa_atexit_fn_ptr_type ()
   10266                 :             : {
   10267                 :       18706 :   if (!cleanup_type)
   10268                 :             :     {
   10269                 :       14007 :       tree fntype = build_function_type_list (void_type_node,
   10270                 :             :                                               ptr_type_node, NULL_TREE);
   10271                 :       14007 :       fntype = targetm.cxx.adjust_cdtor_callabi_fntype (fntype);
   10272                 :       14007 :       cleanup_type = build_pointer_type (fntype);
   10273                 :             :     }
   10274                 :             : 
   10275                 :       18706 :   return cleanup_type;
   10276                 :             : }
   10277                 :             : 
   10278                 :             : /* Returns a pointer to the `atexit' function.  Note that if
   10279                 :             :    FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
   10280                 :             :    `__cxa_atexit' function specified in the IA64 C++ ABI.  */
   10281                 :             : 
   10282                 :             : static tree
   10283                 :        3503 : get_atexit_node (void)
   10284                 :             : {
   10285                 :        3503 :   tree atexit_fndecl;
   10286                 :        3503 :   tree fn_type;
   10287                 :        3503 :   tree fn_ptr_type;
   10288                 :        3503 :   const char *name;
   10289                 :        3503 :   bool use_aeabi_atexit;
   10290                 :        3503 :   tree ctx = global_namespace;
   10291                 :             : 
   10292                 :        3503 :   if (atexit_node)
   10293                 :             :     return atexit_node;
   10294                 :             : 
   10295                 :        2211 :   if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
   10296                 :             :     {
   10297                 :             :       /* The declaration for `__cxa_atexit' is:
   10298                 :             : 
   10299                 :             :            int __cxa_atexit (void (*)(void *), void *, void *)
   10300                 :             : 
   10301                 :             :          We build up the argument types and then the function type
   10302                 :             :          itself.  */
   10303                 :        2199 :       tree argtype0, argtype1, argtype2;
   10304                 :             : 
   10305                 :        2199 :       use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
   10306                 :             :       /* First, build the pointer-to-function type for the first
   10307                 :             :          argument.  */
   10308                 :        2199 :       fn_ptr_type = get_cxa_atexit_fn_ptr_type ();
   10309                 :             :       /* Then, build the rest of the argument types.  */
   10310                 :        2199 :       argtype2 = ptr_type_node;
   10311                 :        2199 :       if (use_aeabi_atexit)
   10312                 :             :         {
   10313                 :             :           argtype1 = fn_ptr_type;
   10314                 :             :           argtype0 = ptr_type_node;
   10315                 :             :         }
   10316                 :             :       else
   10317                 :             :         {
   10318                 :        2199 :           argtype1 = ptr_type_node;
   10319                 :        2199 :           argtype0 = fn_ptr_type;
   10320                 :             :         }
   10321                 :             :       /* And the final __cxa_atexit type.  */
   10322                 :        2199 :       fn_type = build_function_type_list (integer_type_node,
   10323                 :             :                                           argtype0, argtype1, argtype2,
   10324                 :             :                                           NULL_TREE);
   10325                 :             :       /* ... which needs noexcept.  */
   10326                 :        2199 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   10327                 :        2199 :       if (use_aeabi_atexit)
   10328                 :             :         {
   10329                 :           0 :           name = "__aeabi_atexit";
   10330                 :           0 :           push_to_top_level ();
   10331                 :           0 :           int n = push_namespace (get_identifier ("__aeabiv1"), false);
   10332                 :           0 :           ctx = current_namespace;
   10333                 :           0 :           while (n--)
   10334                 :           0 :             pop_namespace ();
   10335                 :           0 :           pop_from_top_level ();
   10336                 :             :         }
   10337                 :             :       else
   10338                 :             :         {
   10339                 :        2199 :           name = "__cxa_atexit";
   10340                 :        2199 :           ctx = abi_node;
   10341                 :             :         }
   10342                 :             :     }
   10343                 :             :   else
   10344                 :             :     {
   10345                 :             :       /* The declaration for `atexit' is:
   10346                 :             : 
   10347                 :             :            int atexit (void (*)());
   10348                 :             : 
   10349                 :             :          We build up the argument types and then the function type
   10350                 :             :          itself.  */
   10351                 :          12 :       fn_ptr_type = get_atexit_fn_ptr_type ();
   10352                 :             :       /* Build the final atexit type.  */
   10353                 :          12 :       fn_type = build_function_type_list (integer_type_node,
   10354                 :             :                                           fn_ptr_type, NULL_TREE);
   10355                 :             :       /* ... which needs noexcept.  */
   10356                 :          12 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   10357                 :          12 :       name = "atexit";
   10358                 :             :     }
   10359                 :             : 
   10360                 :             :   /* Now, build the function declaration.  */
   10361                 :        2211 :   push_lang_context (lang_name_c);
   10362                 :        2211 :   auto cookie = push_abi_namespace (ctx);
   10363                 :        2211 :   atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
   10364                 :        2211 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   10365                 :             :   /* Install as hidden builtin so we're (a) more relaxed about
   10366                 :             :     exception spec matching and (b) will not give a confusing location
   10367                 :             :     in diagnostic and (c) won't magically appear in user-visible name
   10368                 :             :     lookups.  */
   10369                 :        2211 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   10370                 :        2211 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   10371                 :        2211 :   pop_abi_namespace (cookie, ctx);
   10372                 :        2211 :   mark_used (atexit_fndecl);
   10373                 :        2211 :   pop_lang_context ();
   10374                 :        2211 :   atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   10375                 :             : 
   10376                 :        2211 :   return atexit_node;
   10377                 :             : }
   10378                 :             : 
   10379                 :             : /* Like get_atexit_node, but for thread-local cleanups.  */
   10380                 :             : 
   10381                 :             : static tree
   10382                 :          85 : get_thread_atexit_node (void)
   10383                 :             : {
   10384                 :          85 :   if (thread_atexit_node)
   10385                 :             :     return thread_atexit_node;
   10386                 :             : 
   10387                 :             :   /* The declaration for `__cxa_thread_atexit' is:
   10388                 :             : 
   10389                 :             :      int __cxa_thread_atexit (void (*)(void *), void *, void *) */
   10390                 :          55 :   tree fn_type = build_function_type_list (integer_type_node,
   10391                 :             :                                            get_cxa_atexit_fn_ptr_type (),
   10392                 :             :                                            ptr_type_node, ptr_type_node,
   10393                 :             :                                            NULL_TREE);
   10394                 :             : 
   10395                 :             :   /* Now, build the function declaration, as with __cxa_atexit.  */
   10396                 :          55 :   unsigned flags = push_abi_namespace ();
   10397                 :          55 :   tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
   10398                 :             :                                              ECF_LEAF | ECF_NOTHROW);
   10399                 :          55 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   10400                 :          55 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   10401                 :          55 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   10402                 :          55 :   pop_abi_namespace (flags);
   10403                 :          55 :   mark_used (atexit_fndecl);
   10404                 :          55 :   thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   10405                 :             : 
   10406                 :          55 :   return thread_atexit_node;
   10407                 :             : }
   10408                 :             : 
   10409                 :             : /* Returns the __dso_handle VAR_DECL.  */
   10410                 :             : 
   10411                 :             : static tree
   10412                 :        3576 : get_dso_handle_node (void)
   10413                 :             : {
   10414                 :        3576 :   if (dso_handle_node)
   10415                 :             :     return dso_handle_node;
   10416                 :             : 
   10417                 :             :   /* Declare the variable.  */
   10418                 :        2244 :   dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
   10419                 :             :                                         ptr_type_node);
   10420                 :             : 
   10421                 :             : #ifdef HAVE_GAS_HIDDEN
   10422                 :        2244 :   if (dso_handle_node != error_mark_node)
   10423                 :             :     {
   10424                 :        2241 :       DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
   10425                 :        2241 :       DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
   10426                 :             :     }
   10427                 :             : #endif
   10428                 :             : 
   10429                 :        2244 :   return dso_handle_node;
   10430                 :             : }
   10431                 :             : 
   10432                 :             : /* Begin a new function with internal linkage whose job will be simply
   10433                 :             :    to destroy some particular DECL.  OB_PARM is true if object pointer
   10434                 :             :    is passed to the cleanup function, otherwise no argument is passed.  */
   10435                 :             : 
   10436                 :             : static tree
   10437                 :         367 : start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
   10438                 :             : {
   10439                 :         367 :   push_to_top_level ();
   10440                 :             : 
   10441                 :             :   /* No need to mangle this.  */
   10442                 :         367 :   push_lang_context (lang_name_c);
   10443                 :             : 
   10444                 :             :   /* Build the name of the function.  */
   10445                 :         367 :   gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
   10446                 :         367 :   const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   10447                 :         367 :   dname = targetm.strip_name_encoding (dname);
   10448                 :         731 :   char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
   10449                 :             : 
   10450                 :         367 :   tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
   10451                 :             :                                    : get_atexit_fn_ptr_type ());
   10452                 :             :   /* Build the function declaration.  */
   10453                 :         367 :   tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
   10454                 :         367 :   DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
   10455                 :             :   /* It's a function with internal linkage, generated by the
   10456                 :             :      compiler.  */
   10457                 :         367 :   TREE_PUBLIC (fndecl) = 0;
   10458                 :         367 :   DECL_ARTIFICIAL (fndecl) = 1;
   10459                 :             :   /* Make the function `inline' so that it is only emitted if it is
   10460                 :             :      actually needed.  It is unlikely that it will be inlined, since
   10461                 :             :      it is only called via a function pointer, but we avoid unnecessary
   10462                 :             :      emissions this way.  */
   10463                 :         367 :   DECL_DECLARED_INLINE_P (fndecl) = 1;
   10464                 :         367 :   DECL_INTERFACE_KNOWN (fndecl) = 1;
   10465                 :         367 :   if (ob_parm)
   10466                 :             :     {
   10467                 :             :       /* Build the parameter.  */
   10468                 :         355 :       tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
   10469                 :         355 :       TREE_USED (parmdecl) = 1;
   10470                 :         355 :       DECL_READ_P (parmdecl) = 1;
   10471                 :         355 :       DECL_ARGUMENTS (fndecl) = parmdecl;
   10472                 :             :     }
   10473                 :             : 
   10474                 :         367 :   fndecl = pushdecl (fndecl, /*hidden=*/true);
   10475                 :         367 :   if (omp_target)
   10476                 :             :     {
   10477                 :           3 :       DECL_ATTRIBUTES (fndecl)
   10478                 :           3 :         = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
   10479                 :           3 :                      DECL_ATTRIBUTES (fndecl));
   10480                 :           3 :       DECL_ATTRIBUTES (fndecl)
   10481                 :           6 :         = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
   10482                 :           3 :                      DECL_ATTRIBUTES (fndecl));
   10483                 :             :     }
   10484                 :         367 :   start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
   10485                 :             : 
   10486                 :         367 :   pop_lang_context ();
   10487                 :             : 
   10488                 :         367 :   return current_function_decl;
   10489                 :             : }
   10490                 :             : 
   10491                 :             : /* Finish the cleanup function begun by start_cleanup_fn.  */
   10492                 :             : 
   10493                 :             : static void
   10494                 :         367 : end_cleanup_fn (void)
   10495                 :             : {
   10496                 :         367 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
   10497                 :             : 
   10498                 :         367 :   pop_from_top_level ();
   10499                 :         367 : }
   10500                 :             : 
   10501                 :             : /* Generate code to handle the destruction of DECL, an object with
   10502                 :             :    static storage duration.  */
   10503                 :             : 
   10504                 :             : tree
   10505                 :       14971 : register_dtor_fn (tree decl, bool omp_target)
   10506                 :             : {
   10507                 :       14971 :   tree cleanup;
   10508                 :       14971 :   tree addr;
   10509                 :       14971 :   tree compound_stmt;
   10510                 :       14971 :   tree fcall;
   10511                 :       14971 :   tree type;
   10512                 :       14971 :   bool ob_parm, dso_parm, use_dtor;
   10513                 :       14971 :   tree arg0, arg1, arg2;
   10514                 :       14971 :   tree atex_node;
   10515                 :             : 
   10516                 :       14971 :   type = TREE_TYPE (decl);
   10517                 :       14971 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   10518                 :       11383 :     return void_node;
   10519                 :             : 
   10520                 :        3588 :   if (decl_maybe_constant_destruction (decl, type)
   10521                 :        3588 :       && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   10522                 :             :     {
   10523                 :           0 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   10524                 :           0 :       return void_node;
   10525                 :             :     }
   10526                 :             : 
   10527                 :             :   /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
   10528                 :             :      "__aeabi_atexit"), and DECL is a class object, we can just pass the
   10529                 :             :      destructor to "__cxa_atexit"; we don't have to build a temporary
   10530                 :             :      function to do the cleanup.  */
   10531                 :        7176 :   dso_parm = (flag_use_cxa_atexit
   10532                 :        3588 :               && !targetm.cxx.use_atexit_for_cxa_atexit ());
   10533                 :        3588 :   ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
   10534                 :        3576 :   use_dtor = ob_parm && CLASS_TYPE_P (type);
   10535                 :        3588 :   if (use_dtor)
   10536                 :             :     {
   10537                 :        3221 :       cleanup = get_class_binding (type, complete_dtor_identifier);
   10538                 :             : 
   10539                 :             :       /* Make sure it is accessible.  */
   10540                 :        3221 :       perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
   10541                 :             :                                      tf_warning_or_error);
   10542                 :             :     }
   10543                 :             :   else
   10544                 :             :     {
   10545                 :             :       /* Call build_cleanup before we enter the anonymous function so
   10546                 :             :          that any access checks will be done relative to the current
   10547                 :             :          scope, rather than the scope of the anonymous function.  */
   10548                 :         367 :       build_cleanup (decl);
   10549                 :             : 
   10550                 :             :       /* Now start the function.  */
   10551                 :         367 :       cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
   10552                 :             : 
   10553                 :             :       /* Now, recompute the cleanup.  It may contain SAVE_EXPRs that refer
   10554                 :             :          to the original function, rather than the anonymous one.  That
   10555                 :             :          will make the back end think that nested functions are in use,
   10556                 :             :          which causes confusion.  */
   10557                 :         367 :       push_deferring_access_checks (dk_no_check);
   10558                 :         367 :       fcall = build_cleanup (decl);
   10559                 :         367 :       pop_deferring_access_checks ();
   10560                 :             : 
   10561                 :             :       /* Create the body of the anonymous function.  */
   10562                 :         367 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
   10563                 :         367 :       finish_expr_stmt (fcall);
   10564                 :         367 :       finish_compound_stmt (compound_stmt);
   10565                 :         367 :       end_cleanup_fn ();
   10566                 :             :     }
   10567                 :             : 
   10568                 :             :   /* Call atexit with the cleanup function.  */
   10569                 :        3588 :   mark_used (cleanup);
   10570                 :        3588 :   cleanup = build_address (cleanup);
   10571                 :             : 
   10572                 :        3588 :   if (CP_DECL_THREAD_LOCAL_P (decl))
   10573                 :          85 :     atex_node = get_thread_atexit_node ();
   10574                 :             :   else
   10575                 :        3503 :     atex_node = get_atexit_node ();
   10576                 :             : 
   10577                 :        3588 :   if (use_dtor)
   10578                 :             :     {
   10579                 :             :       /* We must convert CLEANUP to the type that "__cxa_atexit"
   10580                 :             :          expects.  */
   10581                 :        3221 :       cleanup = build_nop (get_cxa_atexit_fn_ptr_type (), cleanup);
   10582                 :             :       /* "__cxa_atexit" will pass the address of DECL to the
   10583                 :             :          cleanup function.  */
   10584                 :        3221 :       mark_used (decl);
   10585                 :        3221 :       addr = build_address (decl);
   10586                 :             :       /* The declared type of the parameter to "__cxa_atexit" is
   10587                 :             :          "void *".  For plain "T*", we could just let the
   10588                 :             :          machinery in cp_build_function_call convert it -- but if the
   10589                 :             :          type is "cv-qualified T *", then we need to convert it
   10590                 :             :          before passing it in, to avoid spurious errors.  */
   10591                 :        3221 :       addr = build_nop (ptr_type_node, addr);
   10592                 :             :     }
   10593                 :             :   else
   10594                 :             :     /* Since the cleanup functions we build ignore the address
   10595                 :             :        they're given, there's no reason to pass the actual address
   10596                 :             :        in, and, in general, it's cheaper to pass NULL than any
   10597                 :             :        other value.  */
   10598                 :         367 :     addr = null_pointer_node;
   10599                 :             : 
   10600                 :        3588 :   if (dso_parm)
   10601                 :        3576 :     arg2 = cp_build_addr_expr (get_dso_handle_node (),
   10602                 :             :                                tf_warning_or_error);
   10603                 :          12 :   else if (ob_parm)
   10604                 :             :     /* Just pass NULL to the dso handle parm if we don't actually
   10605                 :             :        have a DSO handle on this target.  */
   10606                 :           0 :     arg2 = null_pointer_node;
   10607                 :             :   else
   10608                 :             :     arg2 = NULL_TREE;
   10609                 :             : 
   10610                 :        3576 :   if (ob_parm)
   10611                 :             :     {
   10612                 :        3576 :       if (!CP_DECL_THREAD_LOCAL_P (decl)
   10613                 :        3576 :           && targetm.cxx.use_aeabi_atexit ())
   10614                 :             :         {
   10615                 :             :           arg1 = cleanup;
   10616                 :             :           arg0 = addr;
   10617                 :             :         }
   10618                 :             :       else
   10619                 :             :         {
   10620                 :             :           arg1 = addr;
   10621                 :             :           arg0 = cleanup;
   10622                 :             :         }
   10623                 :             :     }
   10624                 :             :   else
   10625                 :             :     {
   10626                 :             :       arg0 = cleanup;
   10627                 :             :       arg1 = NULL_TREE;
   10628                 :             :     }
   10629                 :        3588 :   return cp_build_function_call_nary (atex_node, tf_warning_or_error,
   10630                 :        3588 :                                       arg0, arg1, arg2, NULL_TREE);
   10631                 :             : }
   10632                 :             : 
   10633                 :             : /* DECL is a VAR_DECL with static storage duration.  INIT, if present,
   10634                 :             :    is its initializer.  Generate code to handle the construction
   10635                 :             :    and destruction of DECL.  */
   10636                 :             : 
   10637                 :             : static void
   10638                 :    15906893 : expand_static_init (tree decl, tree init)
   10639                 :             : {
   10640                 :    15906893 :   gcc_assert (VAR_P (decl));
   10641                 :    15906893 :   gcc_assert (TREE_STATIC (decl));
   10642                 :             : 
   10643                 :             :   /* Some variables require no dynamic initialization.  */
   10644                 :    15906893 :   if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
   10645                 :             :     {
   10646                 :             :       /* Make sure the destructor is callable.  */
   10647                 :    15903391 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   10648                 :    15903391 :       if (!init)
   10649                 :             :         return;
   10650                 :             :     }
   10651                 :             : 
   10652                 :       15717 :   if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
   10653                 :       14858 :       && !DECL_FUNCTION_SCOPE_P (decl))
   10654                 :             :     {
   10655                 :          15 :       auto_diagnostic_group d;
   10656                 :          15 :       location_t dloc = DECL_SOURCE_LOCATION (decl);
   10657                 :          15 :       if (init)
   10658                 :          12 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   10659                 :             :                   "needs dynamic initialization", decl);
   10660                 :             :       else
   10661                 :           3 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   10662                 :             :                   "has a non-trivial destructor", decl);
   10663                 :          15 :       static bool informed;
   10664                 :          15 :       if (!informed)
   10665                 :             :         {
   10666                 :           6 :           inform (dloc, "C++11 %<thread_local%> allows dynamic "
   10667                 :             :                   "initialization and destruction");
   10668                 :           6 :           informed = true;
   10669                 :             :         }
   10670                 :          15 :       return;
   10671                 :          15 :     }
   10672                 :             : 
   10673                 :       14814 :   if (DECL_FUNCTION_SCOPE_P (decl))
   10674                 :             :     {
   10675                 :             :       /* Emit code to perform this initialization but once.  */
   10676                 :        3770 :       tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
   10677                 :        3770 :       tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
   10678                 :        3770 :       tree guard, guard_addr;
   10679                 :        3770 :       tree flag, begin;
   10680                 :             :       /* We don't need thread-safety code for thread-local vars.  */
   10681                 :        3770 :       bool thread_guard = (flag_threadsafe_statics
   10682                 :        3770 :                            && !CP_DECL_THREAD_LOCAL_P (decl));
   10683                 :             : 
   10684                 :             :       /* Emit code to perform this initialization but once.  This code
   10685                 :             :          looks like:
   10686                 :             : 
   10687                 :             :            static <type> guard;
   10688                 :             :            if (!__atomic_load (guard.first_byte)) {
   10689                 :             :              if (__cxa_guard_acquire (&guard)) {
   10690                 :             :                bool flag = false;
   10691                 :             :                try {
   10692                 :             :                  // Do initialization.
   10693                 :             :                  flag = true; __cxa_guard_release (&guard);
   10694                 :             :                  // Register variable for destruction at end of program.
   10695                 :             :                } catch {
   10696                 :             :                  if (!flag) __cxa_guard_abort (&guard);
   10697                 :             :                }
   10698                 :             :              }
   10699                 :             :            }
   10700                 :             : 
   10701                 :             :          Note that the `flag' variable is only set to 1 *after* the
   10702                 :             :          initialization is complete.  This ensures that an exception,
   10703                 :             :          thrown during the construction, will cause the variable to
   10704                 :             :          reinitialized when we pass through this code again, as per:
   10705                 :             : 
   10706                 :             :            [stmt.dcl]
   10707                 :             : 
   10708                 :             :            If the initialization exits by throwing an exception, the
   10709                 :             :            initialization is not complete, so it will be tried again
   10710                 :             :            the next time control enters the declaration.
   10711                 :             : 
   10712                 :             :          This process should be thread-safe, too; multiple threads
   10713                 :             :          should not be able to initialize the variable more than
   10714                 :             :          once.  */
   10715                 :             : 
   10716                 :             :       /* Create the guard variable.  */
   10717                 :        3770 :       guard = get_guard (decl);
   10718                 :             : 
   10719                 :             :       /* Begin the conditional initialization.  */
   10720                 :        3770 :       if_stmt = begin_if_stmt ();
   10721                 :             : 
   10722                 :        3770 :       finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
   10723                 :        3770 :       then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   10724                 :             : 
   10725                 :        3770 :       if (thread_guard)
   10726                 :             :         {
   10727                 :        3689 :           tree vfntype = NULL_TREE;
   10728                 :        3689 :           tree acquire_name, release_name, abort_name;
   10729                 :        3689 :           tree acquire_fn, release_fn, abort_fn;
   10730                 :        3689 :           guard_addr = build_address (guard);
   10731                 :             : 
   10732                 :        3689 :           acquire_name = get_identifier ("__cxa_guard_acquire");
   10733                 :        3689 :           release_name = get_identifier ("__cxa_guard_release");
   10734                 :        3689 :           abort_name = get_identifier ("__cxa_guard_abort");
   10735                 :        3689 :           acquire_fn = get_global_binding (acquire_name);
   10736                 :        3689 :           release_fn = get_global_binding (release_name);
   10737                 :        3689 :           abort_fn = get_global_binding (abort_name);
   10738                 :        3689 :           if (!acquire_fn)
   10739                 :        2158 :             acquire_fn = push_library_fn
   10740                 :        2158 :               (acquire_name, build_function_type_list (integer_type_node,
   10741                 :        2158 :                                                        TREE_TYPE (guard_addr),
   10742                 :             :                                                        NULL_TREE),
   10743                 :             :                NULL_TREE, ECF_NOTHROW);
   10744                 :        3689 :           if (!release_fn || !abort_fn)
   10745                 :        2161 :             vfntype = build_function_type_list (void_type_node,
   10746                 :        2161 :                                                 TREE_TYPE (guard_addr),
   10747                 :             :                                                 NULL_TREE);
   10748                 :        2161 :           if (!release_fn)
   10749                 :        2161 :             release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
   10750                 :             :                                           ECF_NOTHROW);
   10751                 :        3689 :           if (!abort_fn)
   10752                 :        2161 :             abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
   10753                 :             :                                         ECF_NOTHROW | ECF_LEAF);
   10754                 :             : 
   10755                 :        3689 :           inner_if_stmt = begin_if_stmt ();
   10756                 :        3689 :           finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
   10757                 :             :                                inner_if_stmt);
   10758                 :             : 
   10759                 :        3689 :           inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   10760                 :        3689 :           begin = get_internal_target_expr (boolean_false_node);
   10761                 :        3689 :           flag = TARGET_EXPR_SLOT (begin);
   10762                 :             : 
   10763                 :        3689 :           TARGET_EXPR_CLEANUP (begin)
   10764                 :        3689 :             = build3 (COND_EXPR, void_type_node, flag,
   10765                 :             :                       void_node,
   10766                 :             :                       build_call_n (abort_fn, 1, guard_addr));
   10767                 :        3689 :           CLEANUP_EH_ONLY (begin) = 1;
   10768                 :             : 
   10769                 :             :           /* Do the initialization itself.  */
   10770                 :        3689 :           init = add_stmt_to_compound (begin, init);
   10771                 :        3689 :           init = add_stmt_to_compound (init,
   10772                 :             :                                        build2 (MODIFY_EXPR, void_type_node,
   10773                 :             :                                                flag, boolean_true_node));
   10774                 :             : 
   10775                 :             :           /* Use atexit to register a function for destroying this static
   10776                 :             :              variable.  Do this before calling __cxa_guard_release.  */
   10777                 :        3689 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   10778                 :             : 
   10779                 :        3689 :           init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
   10780                 :             :                                                            guard_addr));
   10781                 :             :         }
   10782                 :             :       else
   10783                 :             :         {
   10784                 :          81 :           init = add_stmt_to_compound (init, set_guard (guard));
   10785                 :             : 
   10786                 :             :           /* Use atexit to register a function for destroying this static
   10787                 :             :              variable.  */
   10788                 :          81 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   10789                 :             :         }
   10790                 :             : 
   10791                 :        3770 :       finish_expr_stmt (init);
   10792                 :             : 
   10793                 :        3770 :       if (thread_guard)
   10794                 :             :         {
   10795                 :        3689 :           finish_compound_stmt (inner_then_clause);
   10796                 :        3689 :           finish_then_clause (inner_if_stmt);
   10797                 :        3689 :           finish_if_stmt (inner_if_stmt);
   10798                 :             :         }
   10799                 :             : 
   10800                 :        3770 :       finish_compound_stmt (then_clause);
   10801                 :        3770 :       finish_then_clause (if_stmt);
   10802                 :        3770 :       finish_if_stmt (if_stmt);
   10803                 :             :     }
   10804                 :       11044 :   else if (CP_DECL_THREAD_LOCAL_P (decl))
   10805                 :         795 :     tls_aggregates = tree_cons (init, decl, tls_aggregates);
   10806                 :             :   else
   10807                 :       10249 :     static_aggregates = tree_cons (init, decl, static_aggregates);
   10808                 :             : }
   10809                 :             : 
   10810                 :             : 
   10811                 :             : /* Make TYPE a complete type based on INITIAL_VALUE.
   10812                 :             :    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
   10813                 :             :    2 if there was no information (in which case assume 0 if DO_DEFAULT),
   10814                 :             :    3 if the initializer list is empty (in pedantic mode). */
   10815                 :             : 
   10816                 :             : int
   10817                 :      526047 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
   10818                 :             : {
   10819                 :      526047 :   int failure;
   10820                 :      526047 :   tree type, elt_type;
   10821                 :             : 
   10822                 :             :   /* Don't get confused by a CONSTRUCTOR for some other type.  */
   10823                 :      526017 :   if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
   10824                 :       94507 :       && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
   10825                 :      526369 :       && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
   10826                 :             :     return 1;
   10827                 :             : 
   10828                 :      526044 :   if (initial_value)
   10829                 :             :     {
   10830                 :             :       /* An array of character type can be initialized from a
   10831                 :             :          brace-enclosed string constant so call reshape_init to
   10832                 :             :          remove the optional braces from a braced string literal.  */
   10833                 :      526014 :       if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
   10834                 :      526014 :           && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
   10835                 :       28888 :         initial_value = reshape_init (*ptype, initial_value,
   10836                 :             :                                       tf_warning_or_error);
   10837                 :             : 
   10838                 :             :       /* If any of the elements are parameter packs, we can't actually
   10839                 :             :          complete this type now because the array size is dependent.  */
   10840                 :      526014 :       if (TREE_CODE (initial_value) == CONSTRUCTOR)
   10841                 :    15355600 :         for (auto &e: CONSTRUCTOR_ELTS (initial_value))
   10842                 :    15072453 :           if (PACK_EXPANSION_P (e.value))
   10843                 :             :             return 0;
   10844                 :             :     }
   10845                 :             : 
   10846                 :      526044 :   failure = complete_array_type (ptype, initial_value, do_default);
   10847                 :             : 
   10848                 :             :   /* We can create the array before the element type is complete, which
   10849                 :             :      means that we didn't have these two bits set in the original type
   10850                 :             :      either.  In completing the type, we are expected to propagate these
   10851                 :             :      bits.  See also complete_type which does the same thing for arrays
   10852                 :             :      of fixed size.  */
   10853                 :      526044 :   type = *ptype;
   10854                 :     1052085 :   if (type != error_mark_node && TYPE_DOMAIN (type))
   10855                 :             :     {
   10856                 :      526017 :       elt_type = TREE_TYPE (type);
   10857                 :      526017 :       TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
   10858                 :     1052034 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   10859                 :      526017 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
   10860                 :             :     }
   10861                 :             : 
   10862                 :             :   return failure;
   10863                 :             : }
   10864                 :             : 
   10865                 :             : /* As above, but either give an error or reject zero-size arrays, depending
   10866                 :             :    on COMPLAIN.  */
   10867                 :             : 
   10868                 :             : int
   10869                 :        1409 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
   10870                 :             :                                  bool do_default, tsubst_flags_t complain)
   10871                 :             : {
   10872                 :        1409 :   int failure;
   10873                 :        1409 :   bool sfinae = !(complain & tf_error);
   10874                 :             :   /* In SFINAE context we can't be lenient about zero-size arrays.  */
   10875                 :        1409 :   if (sfinae)
   10876                 :           3 :     ++pedantic;
   10877                 :        1409 :   failure = cp_complete_array_type (ptype, initial_value, do_default);
   10878                 :        1409 :   if (sfinae)
   10879                 :           3 :     --pedantic;
   10880                 :        1409 :   if (failure)
   10881                 :             :     {
   10882                 :           3 :       if (sfinae)
   10883                 :             :         /* Not an error.  */;
   10884                 :           0 :       else if (failure == 1)
   10885                 :           0 :         error ("initializer fails to determine size of %qT", *ptype);
   10886                 :           0 :       else if (failure == 2)
   10887                 :             :         {
   10888                 :           0 :           if (do_default)
   10889                 :           0 :             error ("array size missing in %qT", *ptype);
   10890                 :             :         }
   10891                 :           0 :       else if (failure == 3)
   10892                 :           0 :         error ("zero-size array %qT", *ptype);
   10893                 :           3 :       *ptype = error_mark_node;
   10894                 :             :     }
   10895                 :        1409 :   return failure;
   10896                 :             : }
   10897                 :             : 
   10898                 :             : /* Return zero if something is declared to be a member of type
   10899                 :             :    CTYPE when in the context of CUR_TYPE.  STRING is the error
   10900                 :             :    message to print in that case.  Otherwise, quietly return 1.  */
   10901                 :             : 
   10902                 :             : static int
   10903                 :    24828937 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
   10904                 :             : {
   10905                 :    24828937 :   if (ctype && ctype != cur_type)
   10906                 :             :     {
   10907                 :           0 :       if (flags == DTOR_FLAG)
   10908                 :           0 :         error ("destructor for alien class %qT cannot be a member", ctype);
   10909                 :             :       else
   10910                 :           0 :         error ("constructor for alien class %qT cannot be a member", ctype);
   10911                 :           0 :       return 0;
   10912                 :             :     }
   10913                 :             :   return 1;
   10914                 :             : }
   10915                 :             : 
   10916                 :             : /* Subroutine of `grokdeclarator'.  */
   10917                 :             : 
   10918                 :             : /* Generate errors possibly applicable for a given set of specifiers.
   10919                 :             :    This is for ARM $7.1.2.  */
   10920                 :             : 
   10921                 :             : static void
   10922                 :   407767895 : bad_specifiers (tree object,
   10923                 :             :                 enum bad_spec_place type,
   10924                 :             :                 int virtualp,
   10925                 :             :                 int quals,
   10926                 :             :                 int inlinep,
   10927                 :             :                 int friendp,
   10928                 :             :                 int raises,
   10929                 :             :                 const location_t* locations)
   10930                 :             : {
   10931                 :   407767895 :   switch (type)
   10932                 :             :     {
   10933                 :    56988626 :       case BSP_VAR:
   10934                 :    56988626 :         if (virtualp)
   10935                 :           0 :           error_at (locations[ds_virtual],
   10936                 :             :                     "%qD declared as a %<virtual%> variable", object);
   10937                 :    56988626 :         if (quals)
   10938                 :           3 :           error ("%<const%> and %<volatile%> function specifiers on "
   10939                 :             :                  "%qD invalid in variable declaration", object);
   10940                 :             :         break;
   10941                 :   278459990 :       case BSP_PARM:
   10942                 :   278459990 :         if (virtualp)
   10943                 :           0 :           error_at (locations[ds_virtual],
   10944                 :             :                     "%qD declared as a %<virtual%> parameter", object);
   10945                 :   278459990 :         if (inlinep)
   10946                 :           6 :           error_at (locations[ds_inline],
   10947                 :             :                     "%qD declared as an %<inline%> parameter", object);
   10948                 :   278459990 :         if (quals)
   10949                 :           3 :           error ("%<const%> and %<volatile%> function specifiers on "
   10950                 :             :                  "%qD invalid in parameter declaration", object);
   10951                 :             :         break;
   10952                 :    44373097 :       case BSP_TYPE:
   10953                 :    44373097 :         if (virtualp)
   10954                 :           0 :           error_at (locations[ds_virtual],
   10955                 :             :                     "%qD declared as a %<virtual%> type", object);
   10956                 :    44373097 :         if (inlinep)
   10957                 :           6 :           error_at (locations[ds_inline],
   10958                 :             :                     "%qD declared as an %<inline%> type", object);
   10959                 :    44373097 :         if (quals)
   10960                 :           0 :           error ("%<const%> and %<volatile%> function specifiers on "
   10961                 :             :                  "%qD invalid in type declaration", object);
   10962                 :             :         break;
   10963                 :    27946182 :       case BSP_FIELD:
   10964                 :    27946182 :         if (virtualp)
   10965                 :           6 :           error_at (locations[ds_virtual],
   10966                 :             :                     "%qD declared as a %<virtual%> field", object);
   10967                 :    27946182 :         if (inlinep)
   10968                 :           6 :           error_at (locations[ds_inline],
   10969                 :             :                     "%qD declared as an %<inline%> field", object);
   10970                 :    27946182 :         if (quals)
   10971                 :           0 :           error ("%<const%> and %<volatile%> function specifiers on "
   10972                 :             :                  "%qD invalid in field declaration", object);
   10973                 :             :         break;
   10974                 :           0 :       default:
   10975                 :           0 :         gcc_unreachable();
   10976                 :             :     }
   10977                 :   407767895 :   if (friendp)
   10978                 :           0 :     error ("%q+D declared as a friend", object);
   10979                 :   407767895 :   if (raises
   10980                 :         109 :       && !flag_noexcept_type
   10981                 :   407767916 :       && (TREE_CODE (object) == TYPE_DECL
   10982                 :          15 :           || (!TYPE_PTRFN_P (TREE_TYPE (object))
   10983                 :           5 :               && !TYPE_REFFN_P (TREE_TYPE (object))
   10984                 :           4 :               && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
   10985                 :           6 :     error ("%q+D declared with an exception specification", object);
   10986                 :   407767895 : }
   10987                 :             : 
   10988                 :             : /* DECL is a member function or static data member and is presently
   10989                 :             :    being defined.  Check that the definition is taking place in a
   10990                 :             :    valid namespace.  */
   10991                 :             : 
   10992                 :             : static void
   10993                 :    85375132 : check_class_member_definition_namespace (tree decl)
   10994                 :             : {
   10995                 :             :   /* These checks only apply to member functions and static data
   10996                 :             :      members.  */
   10997                 :    85375132 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
   10998                 :             :   /* We check for problems with specializations in pt.cc in
   10999                 :             :      check_specialization_namespace, where we can issue better
   11000                 :             :      diagnostics.  */
   11001                 :    85375132 :   if (processing_specialization)
   11002                 :             :     return;
   11003                 :             :   /* We check this in check_explicit_instantiation_namespace.  */
   11004                 :    85215720 :   if (processing_explicit_instantiation)
   11005                 :             :     return;
   11006                 :             :   /* [class.mfct]
   11007                 :             : 
   11008                 :             :      A member function definition that appears outside of the
   11009                 :             :      class definition shall appear in a namespace scope enclosing
   11010                 :             :      the class definition.
   11011                 :             : 
   11012                 :             :      [class.static.data]
   11013                 :             : 
   11014                 :             :      The definition for a static data member shall appear in a
   11015                 :             :      namespace scope enclosing the member's class definition.  */
   11016                 :    85215648 :   if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
   11017                 :          18 :     permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
   11018                 :          18 :                decl, DECL_CONTEXT (decl));
   11019                 :             : }
   11020                 :             : 
   11021                 :             : /* Build a PARM_DECL for the "this" parameter of FN.  TYPE is the
   11022                 :             :    METHOD_TYPE for a non-static member function; QUALS are the
   11023                 :             :    cv-qualifiers that apply to the function.  */
   11024                 :             : 
   11025                 :             : tree
   11026                 :   208482829 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
   11027                 :             : {
   11028                 :   208482829 :   tree this_type;
   11029                 :   208482829 :   tree qual_type;
   11030                 :   208482829 :   tree parm;
   11031                 :   208482829 :   cp_cv_quals this_quals;
   11032                 :             : 
   11033                 :   208482829 :   if (CLASS_TYPE_P (type))
   11034                 :             :     {
   11035                 :    93787180 :       this_type
   11036                 :    93787180 :         = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
   11037                 :    93787180 :       this_type = build_pointer_type (this_type);
   11038                 :             :     }
   11039                 :             :   else
   11040                 :   114695649 :     this_type = type_of_this_parm (type);
   11041                 :             :   /* The `this' parameter is implicitly `const'; it cannot be
   11042                 :             :      assigned to.  */
   11043                 :   208482829 :   this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
   11044                 :   208482829 :   qual_type = cp_build_qualified_type (this_type, this_quals);
   11045                 :   208482829 :   parm = build_artificial_parm (fn, this_identifier, qual_type);
   11046                 :   208482829 :   cp_apply_type_quals_to_decl (this_quals, parm);
   11047                 :   208482829 :   return parm;
   11048                 :             : }
   11049                 :             : 
   11050                 :             : /* DECL is a static member function.  Complain if it was declared
   11051                 :             :    with function-cv-quals.  */
   11052                 :             : 
   11053                 :             : static void
   11054                 :     8881605 : check_static_quals (tree decl, cp_cv_quals quals)
   11055                 :             : {
   11056                 :           0 :   if (quals != TYPE_UNQUALIFIED)
   11057                 :           6 :     error ("static member function %q#D declared with type qualifiers",
   11058                 :             :            decl);
   11059                 :           0 : }
   11060                 :             : 
   11061                 :             : /* Helper function.  Replace the temporary this parameter injected
   11062                 :             :    during cp_finish_omp_declare_simd with the real this parameter.  */
   11063                 :             : 
   11064                 :             : static tree
   11065                 :        2500 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
   11066                 :             : {
   11067                 :        2500 :   tree this_parm = (tree) data;
   11068                 :        2500 :   if (TREE_CODE (*tp) == PARM_DECL
   11069                 :         450 :       && DECL_NAME (*tp) == this_identifier
   11070                 :        2773 :       && *tp != this_parm)
   11071                 :         273 :     *tp = this_parm;
   11072                 :        2227 :   else if (TYPE_P (*tp))
   11073                 :          33 :     *walk_subtrees = 0;
   11074                 :        2500 :   return NULL_TREE;
   11075                 :             : }
   11076                 :             : 
   11077                 :             : /* CTYPE is class type, or null if non-class.
   11078                 :             :    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
   11079                 :             :    or METHOD_TYPE.
   11080                 :             :    DECLARATOR is the function's name.
   11081                 :             :    PARMS is a chain of PARM_DECLs for the function.
   11082                 :             :    VIRTUALP is truthvalue of whether the function is virtual or not.
   11083                 :             :    FLAGS are to be passed through to `grokclassfn'.
   11084                 :             :    QUALS are qualifiers indicating whether the function is `const'
   11085                 :             :    or `volatile'.
   11086                 :             :    RAISES is a list of exceptions that this function can raise.
   11087                 :             :    CHECK is 1 if we must find this method in CTYPE, 0 if we should
   11088                 :             :    not look, and -1 if we should not call `grokclassfn' at all.
   11089                 :             : 
   11090                 :             :    SFK is the kind of special function (if any) for the new function.
   11091                 :             : 
   11092                 :             :    Returns `NULL_TREE' if something goes wrong, after issuing
   11093                 :             :    applicable error messages.  */
   11094                 :             : 
   11095                 :             : static tree
   11096                 :   174116615 : grokfndecl (tree ctype,
   11097                 :             :             tree type,
   11098                 :             :             tree declarator,
   11099                 :             :             tree parms,
   11100                 :             :             tree orig_declarator,
   11101                 :             :             const cp_decl_specifier_seq *declspecs,
   11102                 :             :             tree decl_reqs,
   11103                 :             :             int virtualp,
   11104                 :             :             enum overload_flags flags,
   11105                 :             :             cp_cv_quals quals,
   11106                 :             :             cp_ref_qualifier rqual,
   11107                 :             :             tree raises,
   11108                 :             :             int check,
   11109                 :             :             int friendp,
   11110                 :             :             int publicp,
   11111                 :             :             int inlinep,
   11112                 :             :             bool deletedp,
   11113                 :             :             bool xobj_func_p,
   11114                 :             :             special_function_kind sfk,
   11115                 :             :             bool funcdef_flag,
   11116                 :             :             bool late_return_type_p,
   11117                 :             :             int template_count,
   11118                 :             :             tree in_namespace,
   11119                 :             :             tree* attrlist,
   11120                 :             :             location_t location)
   11121                 :             : {
   11122                 :   174116615 :   tree decl;
   11123                 :   174116615 :   tree t;
   11124                 :             : 
   11125                 :   174116615 :   if (location == UNKNOWN_LOCATION)
   11126                 :           0 :     location = input_location;
   11127                 :             : 
   11128                 :             :   /* Was the concept specifier present?  */
   11129                 :   174116615 :   bool concept_p = inlinep & 4;
   11130                 :             : 
   11131                 :   174116615 :   if (concept_p)
   11132                 :             :     {
   11133                 :          15 :       error_at (location, "function concepts are no longer supported");
   11134                 :          15 :       return NULL_TREE;
   11135                 :             :     }
   11136                 :             : 
   11137                 :   174116600 :   type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
   11138                 :             : 
   11139                 :   174116600 :   decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
   11140                 :             : 
   11141                 :             :   /* Set the constraints on the declaration. */
   11142                 :   174116600 :   if (flag_concepts)
   11143                 :             :     {
   11144                 :    49267910 :       tree tmpl_reqs = NULL_TREE;
   11145                 :    49267910 :       tree ctx = friendp ? current_class_type : ctype;
   11146                 :    49267910 :       bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
   11147                 :    49267910 :       bool memtmpl = (!block_local
   11148                 :    49267910 :                       && (current_template_depth
   11149                 :    49255217 :                           > template_class_depth (ctx)));
   11150                 :    13962650 :       if (memtmpl)
   11151                 :             :         {
   11152                 :    13962650 :           if (!current_template_parms)
   11153                 :             :             /* If there are no template parameters, something must have
   11154                 :             :                gone wrong.  */
   11155                 :           0 :             gcc_assert (seen_error ());
   11156                 :             :           else
   11157                 :    13962650 :             tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
   11158                 :             :         }
   11159                 :    49267910 :       tree ci = build_constraints (tmpl_reqs, decl_reqs);
   11160                 :             :       /* C++20 CA378: Remove non-templated constrained functions.  */
   11161                 :             :       /* [temp.friend]/9 A non-template friend declaration with a
   11162                 :             :          requires-clause shall be a definition. A friend function template with
   11163                 :             :          a constraint that depends on a template parameter from an enclosing
   11164                 :             :          template shall be a definition. */
   11165                 :    49267910 :       if (ci
   11166                 :     3588443 :           && (block_local
   11167                 :     3588440 :               || !processing_template_decl
   11168                 :     3588385 :               || (friendp && !memtmpl && !funcdef_flag)))
   11169                 :             :         {
   11170                 :          67 :           if (!friendp || !processing_template_decl)
   11171                 :          58 :             error_at (location, "constraints on a non-templated function");
   11172                 :             :           else
   11173                 :           9 :             error_at (location, "constrained non-template friend declaration"
   11174                 :             :                       " must be a definition");
   11175                 :             :           ci = NULL_TREE;
   11176                 :             :         }
   11177                 :    49267910 :       set_constraints (decl, ci);
   11178                 :      473843 :       if (ci && friendp && memtmpl && !funcdef_flag
   11179                 :    49277267 :           && uses_outer_template_parms_in_constraints (decl, ctx))
   11180                 :           6 :         error_at (location, "friend function template with constraints that "
   11181                 :             :                   "depend on outer template parameters must be a definition");
   11182                 :             :     }
   11183                 :             : 
   11184                 :   174116600 :   if (TREE_CODE (type) == METHOD_TYPE)
   11185                 :             :     {
   11186                 :    91833804 :       tree parm = build_this_parm (decl, type, quals);
   11187                 :    91833804 :       DECL_CHAIN (parm) = parms;
   11188                 :    91833804 :       parms = parm;
   11189                 :             : 
   11190                 :             :       /* Allocate space to hold the vptr bit if needed.  */
   11191                 :    91833804 :       SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
   11192                 :             :     }
   11193                 :             : 
   11194                 :   174116600 :   DECL_ARGUMENTS (decl) = parms;
   11195                 :   528925909 :   for (t = parms; t; t = DECL_CHAIN (t))
   11196                 :   354809309 :     DECL_CONTEXT (t) = decl;
   11197                 :             : 
   11198                 :             :   /* Propagate volatile out from type to decl.  */
   11199                 :   174116600 :   if (TYPE_VOLATILE (type))
   11200                 :           0 :     TREE_THIS_VOLATILE (decl) = 1;
   11201                 :             : 
   11202                 :             :   /* Setup decl according to sfk.  */
   11203                 :   174116600 :   switch (sfk)
   11204                 :             :     {
   11205                 :    22613316 :     case sfk_constructor:
   11206                 :    22613316 :     case sfk_copy_constructor:
   11207                 :    22613316 :     case sfk_move_constructor:
   11208                 :    22613316 :       DECL_CXX_CONSTRUCTOR_P (decl) = 1;
   11209                 :    22613316 :       DECL_NAME (decl) = ctor_identifier;
   11210                 :    22613316 :       break;
   11211                 :     3197027 :     case sfk_destructor:
   11212                 :     3197027 :       DECL_CXX_DESTRUCTOR_P (decl) = 1;
   11213                 :     3197027 :       DECL_NAME (decl) = dtor_identifier;
   11214                 :     3197027 :       break;
   11215                 :     1079434 :     case sfk_deduction_guide:
   11216                 :             :       /* Give deduction guides a definition even though they don't really
   11217                 :             :          have one: the restriction that you can't repeat a deduction guide
   11218                 :             :          makes them more like a definition anyway.  */
   11219                 :     1079434 :       DECL_INITIAL (decl) = void_node;
   11220                 :             :       /* But to ensure that external-linkage deduction guides in header units
   11221                 :             :          don't fall afoul of [module.import] p6, mark them as inline.  */
   11222                 :     1079434 :       DECL_DECLARED_INLINE_P (decl) = true;
   11223                 :     1079434 :       break;
   11224                 :             :     default:
   11225                 :             :       break;
   11226                 :             :     }
   11227                 :             : 
   11228                 :   174116600 :   if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
   11229                 :             :     {
   11230                 :       14752 :       if (funcdef_flag)
   11231                 :           3 :         error_at (location,
   11232                 :             :                   "defining explicit specialization %qD in friend declaration",
   11233                 :             :                   orig_declarator);
   11234                 :             :       else
   11235                 :             :         {
   11236                 :       14749 :           tree fns = TREE_OPERAND (orig_declarator, 0);
   11237                 :       14749 :           tree args = TREE_OPERAND (orig_declarator, 1);
   11238                 :             : 
   11239                 :       14749 :           if (PROCESSING_REAL_TEMPLATE_DECL_P ())
   11240                 :             :             {
   11241                 :             :               /* Something like `template <class T> friend void f<T>()'.  */
   11242                 :           6 :               error_at (location,
   11243                 :             :                         "invalid use of template-id %qD in declaration "
   11244                 :             :                         "of primary template",
   11245                 :             :                         orig_declarator);
   11246                 :           6 :               return NULL_TREE;
   11247                 :             :             }
   11248                 :             : 
   11249                 :             :           /* A friend declaration of the form friend void f<>().  Record
   11250                 :             :              the information in the TEMPLATE_ID_EXPR.  */
   11251                 :       14743 :           SET_DECL_IMPLICIT_INSTANTIATION (decl);
   11252                 :             : 
   11253                 :       14743 :           gcc_assert (identifier_p (fns) || OVL_P (fns));
   11254                 :       14743 :           DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
   11255                 :             : 
   11256                 :       71866 :           for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
   11257                 :       57127 :             if (TREE_PURPOSE (t)
   11258                 :       57127 :                 && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
   11259                 :             :             {
   11260                 :           4 :               error_at (defparse_location (TREE_PURPOSE (t)),
   11261                 :             :                         "default arguments are not allowed in declaration "
   11262                 :             :                         "of friend template specialization %qD",
   11263                 :             :                         decl);
   11264                 :           4 :               return NULL_TREE;
   11265                 :             :             }
   11266                 :             : 
   11267                 :       14739 :           if (inlinep & 1)
   11268                 :             :             {
   11269                 :           4 :               error_at (declspecs->locations[ds_inline],
   11270                 :             :                         "%<inline%> is not allowed in declaration of friend "
   11271                 :             :                         "template specialization %qD",
   11272                 :             :                         decl);
   11273                 :           4 :               return NULL_TREE;
   11274                 :             :             }
   11275                 :             :         }
   11276                 :             :     }
   11277                 :             : 
   11278                 :             :   /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
   11279                 :             :      expression, that declaration shall be a definition..."  */
   11280                 :   174116586 :   if (friendp && !funcdef_flag)
   11281                 :             :     {
   11282                 :     1261233 :       bool has_errored = false;
   11283                 :     1261233 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
   11284                 :     3680930 :            t && t != void_list_node; t = TREE_CHAIN (t))
   11285                 :     2419697 :         if (TREE_PURPOSE (t))
   11286                 :             :           {
   11287                 :          48 :             enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
   11288                 :             :             /* For templates, mark the default argument as erroneous and give a
   11289                 :             :                hard error.  */
   11290                 :          48 :             if (processing_template_decl)
   11291                 :             :               {
   11292                 :          30 :                 diag_kind = diagnostics::kind::error;
   11293                 :          30 :                 TREE_PURPOSE (t) = error_mark_node;
   11294                 :             :               }
   11295                 :          48 :             if (!has_errored)
   11296                 :             :               {
   11297                 :          45 :                 has_errored = true;
   11298                 :          45 :                 emit_diagnostic (diag_kind,
   11299                 :          45 :                                  DECL_SOURCE_LOCATION (decl),
   11300                 :          45 :                                  /*diagnostics::option_id=*/0,
   11301                 :             :                                  "friend declaration of %qD specifies default "
   11302                 :             :                                  "arguments and isn%'t a definition", decl);
   11303                 :             :               }
   11304                 :             :           }
   11305                 :             :     }
   11306                 :             : 
   11307                 :             :   /* If this decl has namespace scope, set that up.  */
   11308                 :   174116586 :   if (in_namespace)
   11309                 :      151551 :     set_decl_namespace (decl, in_namespace, friendp);
   11310                 :   173965035 :   else if (ctype)
   11311                 :   100577950 :     DECL_CONTEXT (decl) = ctype;
   11312                 :             :   else
   11313                 :    73387085 :     DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
   11314                 :             : 
   11315                 :             :   /* `main' and builtins have implicit 'C' linkage.  */
   11316                 :   174116586 :   if (ctype == NULL_TREE
   11317                 :    73538636 :       && DECL_FILE_SCOPE_P (decl)
   11318                 :    31179835 :       && current_lang_name == lang_name_cplusplus
   11319                 :   176946162 :       && (MAIN_NAME_P (declarator)
   11320                 :     2796375 :           || (IDENTIFIER_LENGTH (declarator) > 10
   11321                 :     1953179 :               && IDENTIFIER_POINTER (declarator)[0] == '_'
   11322                 :     1485260 :               && IDENTIFIER_POINTER (declarator)[1] == '_'
   11323                 :      362450 :               && startswith (IDENTIFIER_POINTER (declarator) + 2,
   11324                 :             :                              "builtin_"))
   11325                 :     2796357 :           || (targetcm.cxx_implicit_extern_c
   11326                 :           0 :               && (targetcm.cxx_implicit_extern_c
   11327                 :           0 :                   (IDENTIFIER_POINTER (declarator))))))
   11328                 :       33219 :     SET_DECL_LANGUAGE (decl, lang_c);
   11329                 :             : 
   11330                 :   174116586 :   DECL_STATIC_FUNCTION_P (decl)
   11331                 :   174116586 :     = !xobj_func_p && ctype && TREE_CODE (type) == FUNCTION_TYPE;
   11332                 :   174116586 :   DECL_FUNCTION_XOBJ_FLAG (decl) = xobj_func_p;
   11333                 :             : 
   11334                 :   174116586 :   if (deletedp)
   11335                 :     3565869 :     DECL_DELETED_FN (decl) = 1;
   11336                 :             : 
   11337                 :   174116586 :   if (ctype && funcdef_flag)
   11338                 :    84978480 :     check_class_member_definition_namespace (decl);
   11339                 :             : 
   11340                 :   174116586 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   11341                 :             :     {
   11342                 :       33207 :       if (PROCESSING_REAL_TEMPLATE_DECL_P())
   11343                 :           9 :         error_at (location, "cannot declare %<::main%> to be a template");
   11344                 :       33207 :       if (inlinep & 1)
   11345                 :           3 :         error_at (declspecs->locations[ds_inline],
   11346                 :             :                   "cannot declare %<::main%> to be inline");
   11347                 :       33207 :       if (inlinep & 2)
   11348                 :           6 :         error_at (declspecs->locations[ds_constexpr],
   11349                 :             :                   "cannot declare %<::main%> to be %qs", "constexpr");
   11350                 :       33207 :       if (inlinep & 8)
   11351                 :           3 :         error_at (declspecs->locations[ds_consteval],
   11352                 :             :                   "cannot declare %<::main%> to be %qs", "consteval");
   11353                 :       33207 :       if (!publicp)
   11354                 :           0 :         error_at (location, "cannot declare %<::main%> to be static");
   11355                 :       33207 :       if (current_lang_name != lang_name_cplusplus)
   11356                 :          12 :         pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
   11357                 :             :                  " linkage specification other than %<extern \"C++\"%>");
   11358                 :       33207 :       if (module_attach_p ())
   11359                 :             :         {
   11360                 :           3 :           auto_diagnostic_group adg;
   11361                 :           3 :           error_at (location, "cannot attach %<::main%> to a named module");
   11362                 :           3 :           inform (location, "use %<extern \"C++\"%> to attach it to the "
   11363                 :             :                   "global module instead");
   11364                 :           3 :         }
   11365                 :             :       inlinep = 0;
   11366                 :             :       publicp = 1;
   11367                 :             :     }
   11368                 :             : 
   11369                 :             :   /* Members of anonymous types and local classes have no linkage; make
   11370                 :             :      them internal.  If a typedef is made later, this will be changed.  */
   11371                 :   174116586 :   if (ctype && !TREE_PUBLIC (TYPE_MAIN_DECL (ctype)))
   11372                 :             :     publicp = 0;
   11373                 :   174088244 :   else if (ctype && decl_function_context (TYPE_MAIN_DECL (ctype)))
   11374                 :             :     /* But members of local classes in a module CMI should have their
   11375                 :             :        definitions exported, in case they are (directly or indirectly)
   11376                 :             :        used by an importer.  We don't just use module_has_cmi_p here
   11377                 :             :        because for entities in the GMF we don't yet know whether this
   11378                 :             :        module will have a CMI, so we'll conservatively assume it might.  */
   11379                 :     1083269 :     publicp = module_maybe_has_cmi_p ();
   11380                 :             : 
   11381                 :   174088244 :   if (publicp && cxx_dialect == cxx98)
   11382                 :             :     {
   11383                 :             :       /* [basic.link]: A name with no linkage (notably, the name of a class
   11384                 :             :          or enumeration declared in a local scope) shall not be used to
   11385                 :             :          declare an entity with linkage.
   11386                 :             : 
   11387                 :             :          DR 757 relaxes this restriction for C++0x.  */
   11388                 :     1084436 :       no_linkage_error (decl);
   11389                 :             :     }
   11390                 :             : 
   11391                 :   174116586 :   TREE_PUBLIC (decl) = publicp;
   11392                 :   174116586 :   if (! publicp)
   11393                 :             :     {
   11394                 :     1218364 :       DECL_INTERFACE_KNOWN (decl) = 1;
   11395                 :     1218364 :       DECL_NOT_REALLY_EXTERN (decl) = 1;
   11396                 :             :     }
   11397                 :             : 
   11398                 :             :   /* If the declaration was declared inline, mark it as such.  */
   11399                 :   174116586 :   if (inlinep)
   11400                 :             :     {
   11401                 :    52014826 :       DECL_DECLARED_INLINE_P (decl) = 1;
   11402                 :    52014826 :       if (publicp)
   11403                 :    51866735 :         DECL_COMDAT (decl) = 1;
   11404                 :             :     }
   11405                 :    52014826 :   if (inlinep & 2)
   11406                 :    30825702 :     DECL_DECLARED_CONSTEXPR_P (decl) = true;
   11407                 :   143290884 :   else if (inlinep & 8)
   11408                 :             :     {
   11409                 :      226928 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
   11410                 :      226928 :       SET_DECL_IMMEDIATE_FUNCTION_P (decl);
   11411                 :             :     }
   11412                 :             : 
   11413                 :   174116586 :   DECL_EXTERNAL (decl) = 1;
   11414                 :   174116586 :   if (TREE_CODE (type) == FUNCTION_TYPE)
   11415                 :             :     {
   11416                 :    82282782 :       if (quals || rqual)
   11417                 :         272 :         TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
   11418                 :             :                                               TYPE_UNQUALIFIED,
   11419                 :             :                                               REF_QUAL_NONE);
   11420                 :    82282782 :       auto_diagnostic_group d;
   11421                 :    82282782 :       if (quals)
   11422                 :         423 :         error (!ctype
   11423                 :             :                ? G_("non-member function %qD cannot have cv-qualifier")
   11424                 :             :                : !xobj_func_p
   11425                 :         198 :                  ? G_("static member function %qD cannot have cv-qualifier")
   11426                 :             :                  : G_("explicit object member function "
   11427                 :             :                       "%qD cannot have cv-qualifier"),
   11428                 :             :                decl);
   11429                 :    82282782 :       if (rqual)
   11430                 :         355 :         error (!ctype
   11431                 :             :                ? G_("non-member function %qD cannot have ref-qualifier")
   11432                 :             :                : !xobj_func_p
   11433                 :         176 :                  ? G_("static member function %qD cannot have ref-qualifier")
   11434                 :             :                  : G_("explicit object member function "
   11435                 :             :                       "%qD cannot have ref-qualifier"),
   11436                 :             :                  decl);
   11437                 :             : 
   11438                 :    82282782 :       if (xobj_func_p && (quals || rqual))
   11439                 :         242 :         inform (DECL_SOURCE_LOCATION (DECL_ARGUMENTS (decl)),
   11440                 :             :                 "explicit object parameter declared here");
   11441                 :    82282782 :       quals = TYPE_UNQUALIFIED;
   11442                 :    82282782 :       rqual = REF_QUAL_NONE;
   11443                 :             : 
   11444                 :    82282782 :     }
   11445                 :             : 
   11446                 :   174116586 :   if (deduction_guide_p (decl))
   11447                 :             :     {
   11448                 :     1079434 :       tree type = TREE_TYPE (DECL_NAME (decl));
   11449                 :     1079434 :       if (in_namespace == NULL_TREE
   11450                 :     1079434 :           && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
   11451                 :             :         {
   11452                 :           3 :           auto_diagnostic_group d;
   11453                 :           3 :           error_at (location, "deduction guide %qD must be declared in the "
   11454                 :             :                               "same scope as %qT", decl, type);
   11455                 :           3 :           inform (location_of (type), "  declared here");
   11456                 :           3 :           return NULL_TREE;
   11457                 :           3 :         }
   11458                 :     2158862 :       if (DECL_CLASS_SCOPE_P (decl)
   11459                 :     1079470 :           && current_access_specifier != declared_access (TYPE_NAME (type)))
   11460                 :             :         {
   11461                 :           3 :           auto_diagnostic_group d;
   11462                 :           3 :           error_at (location, "deduction guide %qD must have the same access "
   11463                 :             :                               "as %qT", decl, type);
   11464                 :           3 :           inform (location_of (type), "  declared here");
   11465                 :           3 :         }
   11466                 :     1079431 :       if (funcdef_flag)
   11467                 :           3 :         error_at (location,
   11468                 :             :                   "deduction guide %qD must not have a function body", decl);
   11469                 :             :     }
   11470                 :   324898157 :   else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
   11471                 :   183677010 :            && !grok_op_properties (decl, /*complain=*/true))
   11472                 :             :     return NULL_TREE;
   11473                 :   173037002 :   else if (UDLIT_OPER_P (DECL_NAME (decl)))
   11474                 :             :     {
   11475                 :      285784 :       bool long_long_unsigned_p;
   11476                 :      285784 :       bool long_double_p;
   11477                 :      285784 :       const char *suffix = NULL;
   11478                 :             :       /* [over.literal]/6: Literal operators shall not have C linkage. */
   11479                 :      285784 :       if (DECL_LANGUAGE (decl) == lang_c)
   11480                 :             :         {
   11481                 :           6 :           auto_diagnostic_group d;
   11482                 :           6 :           error_at (location, "literal operator with C linkage");
   11483                 :           6 :           maybe_show_extern_c_location ();
   11484                 :           6 :           return NULL_TREE;
   11485                 :           6 :         }
   11486                 :             : 
   11487                 :      285778 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   11488                 :             :         {
   11489                 :      285772 :           if (!check_literal_operator_args (decl, &long_long_unsigned_p,
   11490                 :             :                                             &long_double_p))
   11491                 :             :             {
   11492                 :          42 :               error_at (location, "%qD has invalid argument list", decl);
   11493                 :          42 :               return NULL_TREE;
   11494                 :             :             }
   11495                 :             : 
   11496                 :      285730 :           suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
   11497                 :      285730 :           if (long_long_unsigned_p)
   11498                 :             :             {
   11499                 :       34152 :               if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
   11500                 :          68 :                 warning_at (location, 0, "integer suffix %qs"
   11501                 :             :                             " shadowed by implementation", suffix);
   11502                 :             :             }
   11503                 :      251578 :           else if (long_double_p)
   11504                 :             :             {
   11505                 :       89913 :               if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
   11506                 :          80 :                 warning_at (location, 0, "floating-point suffix %qs"
   11507                 :             :                             " shadowed by implementation", suffix);
   11508                 :             :             }
   11509                 :             :           /* 17.6.3.3.5  */
   11510                 :      285730 :           if (suffix[0] != '_'
   11511                 :      285184 :               && !current_function_decl && !(friendp && !funcdef_flag))
   11512                 :      285178 :             warning_at (location, OPT_Wliteral_suffix,
   11513                 :             :                         "literal operator suffixes not preceded by %<_%>"
   11514                 :             :                         " are reserved for future standardization");
   11515                 :             :         }
   11516                 :             :       else
   11517                 :             :         {
   11518                 :           6 :           error_at (location, "%qD must be a non-member function", decl);
   11519                 :           6 :           return NULL_TREE;
   11520                 :             :         }
   11521                 :             :     }
   11522                 :             : 
   11523                 :   173036951 :   if (funcdef_flag)
   11524                 :             :     /* Make the init_value nonzero so pushdecl knows this is not
   11525                 :             :        tentative.  error_mark_node is replaced later with the BLOCK.  */
   11526                 :   119091813 :     DECL_INITIAL (decl) = error_mark_node;
   11527                 :             : 
   11528                 :   174116379 :   if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
   11529                 :    64814975 :     TREE_NOTHROW (decl) = 1;
   11530                 :             : 
   11531                 :   174116379 :   if (flag_openmp || flag_openmp_simd)
   11532                 :             :     {
   11533                 :             :       /* Adjust "omp declare simd" attributes.  */
   11534                 :      446637 :       tree ods = lookup_attribute ("omp declare simd", *attrlist);
   11535                 :      446637 :       if (ods)
   11536                 :             :         {
   11537                 :             :           tree attr;
   11538                 :        2006 :           for (attr = ods; attr;
   11539                 :        1060 :                attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
   11540                 :             :             {
   11541                 :        1060 :               if (TREE_CODE (type) == METHOD_TYPE)
   11542                 :         204 :                 walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
   11543                 :             :                            DECL_ARGUMENTS (decl), NULL);
   11544                 :        1060 :               if (TREE_VALUE (attr) != NULL_TREE)
   11545                 :             :                 {
   11546                 :         854 :                   tree cl = TREE_VALUE (TREE_VALUE (attr));
   11547                 :         854 :                   cl = c_omp_declare_simd_clauses_to_numbers
   11548                 :         854 :                                                 (DECL_ARGUMENTS (decl), cl);
   11549                 :         854 :                   if (cl)
   11550                 :         854 :                     TREE_VALUE (TREE_VALUE (attr)) = cl;
   11551                 :             :                   else
   11552                 :           0 :                     TREE_VALUE (attr) = NULL_TREE;
   11553                 :             :                 }
   11554                 :             :             }
   11555                 :             :         }
   11556                 :             :     }
   11557                 :             : 
   11558                 :             :   /* Caller will do the rest of this.  */
   11559                 :   174116379 :   if (check < 0)
   11560                 :     4169895 :     return decl;
   11561                 :             : 
   11562                 :   169946484 :   if (ctype != NULL_TREE)
   11563                 :   100577654 :     grokclassfn (ctype, decl, flags);
   11564                 :             : 
   11565                 :             :   /* 12.4/3  */
   11566                 :   169946484 :   if (cxx_dialect >= cxx11
   11567                 :   337743164 :       && DECL_DESTRUCTOR_P (decl)
   11568                 :     3175686 :       && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
   11569                 :   170121471 :       && !processing_template_decl)
   11570                 :       88741 :     deduce_noexcept_on_destructor (decl);
   11571                 :             : 
   11572                 :   169946484 :   set_originating_module (decl);
   11573                 :             : 
   11574                 :   169946484 :   decl = check_explicit_specialization (orig_declarator, decl,
   11575                 :             :                                         template_count,
   11576                 :   169946484 :                                         2 * funcdef_flag +
   11577                 :   169946484 :                                         4 * (friendp != 0),
   11578                 :             :                                         *attrlist);
   11579                 :   169946484 :   if (decl == error_mark_node)
   11580                 :             :     return NULL_TREE;
   11581                 :             : 
   11582                 :   169946236 :   if (DECL_STATIC_FUNCTION_P (decl))
   11583                 :     8718291 :     check_static_quals (decl, quals);
   11584                 :             : 
   11585                 :   169946236 :   if (attrlist)
   11586                 :             :     {
   11587                 :   169946236 :       cplus_decl_attributes (&decl, *attrlist, 0);
   11588                 :   169946236 :       *attrlist = NULL_TREE;
   11589                 :             :     }
   11590                 :             : 
   11591                 :   169946236 :   if (DECL_HAS_CONTRACTS_P (decl))
   11592                 :         467 :     rebuild_postconditions (decl);
   11593                 :             : 
   11594                 :             :   /* Check main's type after attributes have been applied.  */
   11595                 :   169946236 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   11596                 :             :     {
   11597                 :       33195 :       if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
   11598                 :             :                         integer_type_node))
   11599                 :             :         {
   11600                 :          19 :           tree oldtypeargs = TYPE_ARG_TYPES (TREE_TYPE (decl));
   11601                 :          19 :           tree newtype;
   11602                 :          19 :           error_at (declspecs->locations[ds_type_spec],
   11603                 :             :                     "%<::main%> must return %<int%>");
   11604                 :          19 :           newtype = build_function_type (integer_type_node, oldtypeargs);
   11605                 :          19 :           TREE_TYPE (decl) = newtype;
   11606                 :             :         }
   11607                 :       33195 :       if (warn_main)
   11608                 :       33173 :         check_main_parameter_types (decl);
   11609                 :             :     }
   11610                 :             : 
   11611                 :   169946236 :   if (ctype != NULL_TREE && check)
   11612                 :             :     {
   11613                 :     9257704 :       tree old_decl = check_classfn (ctype, decl,
   11614                 :     9257704 :                                      (current_template_depth
   11615                 :     9257704 :                                       > template_class_depth (ctype))
   11616                 :     2166137 :                                      ? current_template_parms
   11617                 :             :                                      : NULL_TREE);
   11618                 :             : 
   11619                 :     9257704 :       if (old_decl == error_mark_node)
   11620                 :             :         return NULL_TREE;
   11621                 :             : 
   11622                 :     9257623 :       if (old_decl)
   11623                 :             :         {
   11624                 :     8838603 :           tree ok;
   11625                 :     8838603 :           tree pushed_scope;
   11626                 :             : 
   11627                 :     8838603 :           if (TREE_CODE (old_decl) == TEMPLATE_DECL)
   11628                 :             :             /* Because grokfndecl is always supposed to return a
   11629                 :             :                FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
   11630                 :             :                here.  We depend on our callers to figure out that its
   11631                 :             :                really a template that's being returned.  */
   11632                 :     2166125 :             old_decl = DECL_TEMPLATE_RESULT (old_decl);
   11633                 :             : 
   11634                 :     8838603 :           if (DECL_STATIC_FUNCTION_P (old_decl)
   11635                 :     8838603 :               && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
   11636                 :             :             {
   11637                 :             :               /* Remove the `this' parm added by grokclassfn.  */
   11638                 :      163314 :               revert_static_member_fn (decl);
   11639                 :      163314 :               check_static_quals (decl, quals);
   11640                 :             :             }
   11641                 :     8838603 :           if (DECL_ARTIFICIAL (old_decl))
   11642                 :             :             {
   11643                 :           9 :               error ("definition of implicitly-declared %qD", old_decl);
   11644                 :           9 :               return NULL_TREE;
   11645                 :             :             }
   11646                 :     8838594 :           else if (DECL_DEFAULTED_FN (old_decl))
   11647                 :             :             {
   11648                 :           3 :               auto_diagnostic_group d;
   11649                 :           3 :               error ("definition of explicitly-defaulted %q+D", decl);
   11650                 :           3 :               inform (DECL_SOURCE_LOCATION (old_decl),
   11651                 :             :                       "%q#D explicitly defaulted here", old_decl);
   11652                 :           3 :               return NULL_TREE;
   11653                 :           3 :             }
   11654                 :             : 
   11655                 :             :           /* Since we've smashed OLD_DECL to its
   11656                 :             :              DECL_TEMPLATE_RESULT, we must do the same to DECL.  */
   11657                 :     8838591 :           if (TREE_CODE (decl) == TEMPLATE_DECL)
   11658                 :        1187 :             decl = DECL_TEMPLATE_RESULT (decl);
   11659                 :             : 
   11660                 :             :           /* Attempt to merge the declarations.  This can fail, in
   11661                 :             :              the case of some invalid specialization declarations.  */
   11662                 :     8838591 :           pushed_scope = push_scope (ctype);
   11663                 :     8838591 :           ok = duplicate_decls (decl, old_decl);
   11664                 :     8838591 :           if (pushed_scope)
   11665                 :     8838591 :             pop_scope (pushed_scope);
   11666                 :     8838591 :           if (!ok)
   11667                 :             :             {
   11668                 :           0 :               error ("no %q#D member function declared in class %qT",
   11669                 :             :                      decl, ctype);
   11670                 :           0 :               return NULL_TREE;
   11671                 :             :             }
   11672                 :     8838591 :           if (ok == error_mark_node)
   11673                 :             :             return NULL_TREE;
   11674                 :             :           return old_decl;
   11675                 :             :         }
   11676                 :             :     }
   11677                 :             : 
   11678                 :   322215104 :   if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
   11679                 :             :     return NULL_TREE;
   11680                 :             : 
   11681                 :   161107549 :   if (ctype == NULL_TREE || check)
   11682                 :    69787659 :     return decl;
   11683                 :             : 
   11684                 :    91319890 :   if (virtualp)
   11685                 :     4137693 :     DECL_VIRTUAL_P (decl) = 1;
   11686                 :             : 
   11687                 :    91319890 :   return decl;
   11688                 :             : }
   11689                 :             : 
   11690                 :             : /* decl is a FUNCTION_DECL.
   11691                 :             :    specifiers are the parsed virt-specifiers.
   11692                 :             : 
   11693                 :             :    Set flags to reflect the virt-specifiers.
   11694                 :             : 
   11695                 :             :    Returns decl.  */
   11696                 :             : 
   11697                 :             : static tree
   11698                 :    95489883 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
   11699                 :             : {
   11700                 :    95489883 :   if (decl == NULL_TREE)
   11701                 :             :     return decl;
   11702                 :    95489785 :   if (specifiers & VIRT_SPEC_OVERRIDE)
   11703                 :      179658 :     DECL_OVERRIDE_P (decl) = 1;
   11704                 :    95489785 :   if (specifiers & VIRT_SPEC_FINAL)
   11705                 :        2892 :     DECL_FINAL_P (decl) = 1;
   11706                 :             :   return decl;
   11707                 :             : }
   11708                 :             : 
   11709                 :             : /* DECL is a VAR_DECL for a static data member.  Set flags to reflect
   11710                 :             :    the linkage that DECL will receive in the object file.  */
   11711                 :             : 
   11712                 :             : static void
   11713                 :    11015965 : set_linkage_for_static_data_member (tree decl)
   11714                 :             : {
   11715                 :             :   /* A static data member always has static storage duration and
   11716                 :             :      external linkage.  Note that static data members are forbidden in
   11717                 :             :      local classes -- the only situation in which a class has
   11718                 :             :      non-external linkage.  */
   11719                 :    11015965 :   TREE_PUBLIC (decl) = 1;
   11720                 :    11015965 :   TREE_STATIC (decl) = 1;
   11721                 :             :   /* For non-template classes, static data members are always put
   11722                 :             :      out in exactly those files where they are defined, just as
   11723                 :             :      with ordinary namespace-scope variables.  */
   11724                 :    11015965 :   if (!processing_template_decl)
   11725                 :     8200730 :     DECL_INTERFACE_KNOWN (decl) = 1;
   11726                 :    11015965 : }
   11727                 :             : 
   11728                 :             : /* Create a VAR_DECL named NAME with the indicated TYPE.
   11729                 :             : 
   11730                 :             :    If SCOPE is non-NULL, it is the class type or namespace containing
   11731                 :             :    the variable.  If SCOPE is NULL, the variable should is created in
   11732                 :             :    the innermost enclosing scope.  */
   11733                 :             : 
   11734                 :             : static tree
   11735                 :    56988675 : grokvardecl (tree type,
   11736                 :             :              tree name,
   11737                 :             :              tree orig_declarator,
   11738                 :             :              const cp_decl_specifier_seq *declspecs,
   11739                 :             :              int initialized,
   11740                 :             :              int type_quals,
   11741                 :             :              int inlinep,
   11742                 :             :              bool conceptp,
   11743                 :             :              int template_count,
   11744                 :             :              tree scope,
   11745                 :             :              location_t location)
   11746                 :             : {
   11747                 :    56988675 :   tree decl;
   11748                 :    56988675 :   tree explicit_scope;
   11749                 :             : 
   11750                 :    56988675 :   gcc_assert (!name || identifier_p (name));
   11751                 :             : 
   11752                 :    56988675 :   bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
   11753                 :    56988675 :   bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
   11754                 :             : 
   11755                 :             :   /* Compute the scope in which to place the variable, but remember
   11756                 :             :      whether or not that scope was explicitly specified by the user.   */
   11757                 :    56988675 :   explicit_scope = scope;
   11758                 :    56988675 :   if (!scope)
   11759                 :             :     {
   11760                 :             :       /* An explicit "extern" specifier indicates a namespace-scope
   11761                 :             :          variable.  */
   11762                 :    56587524 :       if (declspecs->storage_class == sc_extern)
   11763                 :      569982 :         scope = current_decl_namespace ();
   11764                 :    56017542 :       else if (!at_function_scope_p ())
   11765                 :     4350040 :         scope = current_scope ();
   11766                 :             :     }
   11767                 :             : 
   11768                 :    56587524 :   if (scope
   11769                 :     5321173 :       && (/* If the variable is a namespace-scope variable declared in a
   11770                 :             :              template, we need DECL_LANG_SPECIFIC.  */
   11771                 :     5321173 :           (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
   11772                 :             :           /* Similarly for namespace-scope variables with language linkage
   11773                 :             :              other than C++.  */
   11774                 :     4924521 :           || (TREE_CODE (scope) == NAMESPACE_DECL
   11775                 :     2478923 :               && current_lang_name != lang_name_cplusplus)
   11776                 :             :           /* Similarly for static data members.  */
   11777                 :     2633009 :           || TYPE_P (scope)
   11778                 :             :           /* Similarly for explicit specializations.  */
   11779                 :     2236357 :           || (orig_declarator
   11780                 :     2235915 :               && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
   11781                 :     3434391 :     decl = build_lang_decl_loc (location, VAR_DECL, name, type);
   11782                 :             :   else
   11783                 :    53554284 :     decl = build_decl (location, VAR_DECL, name, type);
   11784                 :             : 
   11785                 :    56988675 :   if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
   11786                 :        4499 :     set_decl_namespace (decl, explicit_scope, 0);
   11787                 :             :   else
   11788                 :    56984176 :     DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
   11789                 :             : 
   11790                 :    56988675 :   if (declspecs->storage_class == sc_extern)
   11791                 :             :     {
   11792                 :      569982 :       DECL_THIS_EXTERN (decl) = 1;
   11793                 :      569982 :       DECL_EXTERNAL (decl) = !initialized;
   11794                 :             :     }
   11795                 :             : 
   11796                 :    56988675 :   if (DECL_CLASS_SCOPE_P (decl))
   11797                 :             :     {
   11798                 :      396652 :       set_linkage_for_static_data_member (decl);
   11799                 :             :       /* This function is only called with out-of-class definitions.  */
   11800                 :      396652 :       DECL_EXTERNAL (decl) = 0;
   11801                 :      396652 :       check_class_member_definition_namespace (decl);
   11802                 :             :     }
   11803                 :             :   /* At top level, either `static' or no s.c. makes a definition
   11804                 :             :      (perhaps tentative), and absence of `static' makes it public.  */
   11805                 :    56592023 :   else if (toplevel_bindings_p ())
   11806                 :             :     {
   11807                 :     9846754 :       TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
   11808                 :     4923377 :                             && (DECL_THIS_EXTERN (decl)
   11809                 :     4315862 :                                 || ! constp
   11810                 :     4315862 :                                 || volatilep
   11811                 :     4241819 :                                 || inlinep
   11812                 :      308079 :                                 || in_template_context
   11813                 :       27515 :                                 || processing_specialization
   11814                 :       27424 :                                 || module_attach_p ()));
   11815                 :     4923377 :       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
   11816                 :             :     }
   11817                 :             :   /* Not at top level, only `static' makes a static definition.  */
   11818                 :             :   else
   11819                 :             :     {
   11820                 :    51668646 :       TREE_STATIC (decl) = declspecs->storage_class == sc_static;
   11821                 :    51668646 :       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
   11822                 :             :     }
   11823                 :             : 
   11824                 :    56988675 :   set_originating_module (decl);
   11825                 :             : 
   11826                 :    56988675 :   if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
   11827                 :             :     {
   11828                 :       20713 :       if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
   11829                 :             :         {
   11830                 :       20705 :           CP_DECL_THREAD_LOCAL_P (decl) = true;
   11831                 :       20705 :           if (!processing_template_decl)
   11832                 :       20662 :             set_decl_tls_model (decl, decl_default_tls_model (decl));
   11833                 :             :         }
   11834                 :       20713 :       if (declspecs->gnu_thread_keyword_p)
   11835                 :       19805 :         SET_DECL_GNU_TLS_P (decl);
   11836                 :             :     }
   11837                 :             : 
   11838                 :             :   /* If the type of the decl has no linkage, make sure that we'll
   11839                 :             :      notice that in mark_used.  */
   11840                 :    56988675 :   if (cxx_dialect > cxx98
   11841                 :    56702219 :       && decl_linkage (decl) != lk_none
   11842                 :    56132899 :       && DECL_LANG_SPECIFIC (decl) == NULL
   11843                 :    52629075 :       && !DECL_EXTERN_C_P (decl)
   11844                 :   109617750 :       && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
   11845                 :        3385 :     retrofit_lang_decl (decl);
   11846                 :             : 
   11847                 :    56988675 :   if (TREE_PUBLIC (decl))
   11848                 :             :     {
   11849                 :             :       /* [basic.link]: A name with no linkage (notably, the name of a class
   11850                 :             :          or enumeration declared in a local scope) shall not be used to
   11851                 :             :          declare an entity with linkage.
   11852                 :             : 
   11853                 :             :          DR 757 relaxes this restriction for C++0x.  */
   11854                 :     5255087 :       if (cxx_dialect < cxx11)
   11855                 :       22777 :         no_linkage_error (decl);
   11856                 :             :     }
   11857                 :             :   else
   11858                 :    51733588 :     DECL_INTERFACE_KNOWN (decl) = 1;
   11859                 :             : 
   11860                 :    56988675 :   if (DECL_NAME (decl)
   11861                 :    56988675 :       && MAIN_NAME_P (DECL_NAME (decl)))
   11862                 :             :     {
   11863                 :          12 :       if (scope == global_namespace)
   11864                 :           6 :         error_at (DECL_SOURCE_LOCATION (decl),
   11865                 :             :                   "cannot declare %<::main%> to be a global variable");
   11866                 :           6 :       else if (DECL_EXTERN_C_P (decl))
   11867                 :           3 :         error_at (DECL_SOURCE_LOCATION (decl),
   11868                 :             :                   "an entity named %<main%> cannot be declared with "
   11869                 :             :                   "C language linkage");
   11870                 :             :     }
   11871                 :             : 
   11872                 :             :   /* Check if a variable is being declared as a concept.  */
   11873                 :    56988675 :   if (conceptp)
   11874                 :             :     {
   11875                 :          27 :       if (!processing_template_decl)
   11876                 :          11 :         error_at (declspecs->locations[ds_concept],
   11877                 :             :                   "a non-template variable cannot be %<concept%>");
   11878                 :          16 :       else if (!at_namespace_scope_p ())
   11879                 :           1 :         error_at (declspecs->locations[ds_concept],
   11880                 :             :                   "concept must be defined at namespace scope");
   11881                 :             :       else
   11882                 :          15 :         error_at (declspecs->locations[ds_concept],
   11883                 :             :                   "variable concepts are no longer supported");
   11884                 :          27 :       return NULL_TREE;
   11885                 :             :     }
   11886                 :    56988648 :   else if (flag_concepts
   11887                 :    56988648 :            && current_template_depth > template_class_depth (scope))
   11888                 :             :     {
   11889                 :    15617641 :       tree ci = current_template_constraints ();
   11890                 :    15617641 :       set_constraints (decl, ci);
   11891                 :             :     }
   11892                 :             : 
   11893                 :             :   // Handle explicit specializations and instantiations of variable templates.
   11894                 :    56988648 :   if (orig_declarator)
   11895                 :    56410108 :     decl = check_explicit_specialization (orig_declarator, decl,
   11896                 :             :                                           template_count, 0);
   11897                 :             : 
   11898                 :    56988648 :   return decl != error_mark_node ? decl : NULL_TREE;
   11899                 :             : }
   11900                 :             : 
   11901                 :             : /* Create and return a canonical pointer to member function type, for
   11902                 :             :    TYPE, which is a POINTER_TYPE to a METHOD_TYPE.  */
   11903                 :             : 
   11904                 :             : tree
   11905                 :     3695519 : build_ptrmemfunc_type (tree type)
   11906                 :             : {
   11907                 :     3695519 :   tree field, fields;
   11908                 :     3695519 :   tree t;
   11909                 :             : 
   11910                 :     3695519 :   if (type == error_mark_node)
   11911                 :             :     return type;
   11912                 :             : 
   11913                 :             :   /* Make sure that we always have the unqualified pointer-to-member
   11914                 :             :      type first.  */
   11915                 :     3695519 :   if (cp_cv_quals quals = cp_type_quals (type))
   11916                 :             :     {
   11917                 :           0 :       tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
   11918                 :           0 :       return cp_build_qualified_type (unqual, quals);
   11919                 :             :     }
   11920                 :             : 
   11921                 :             :   /* If a canonical type already exists for this type, use it.  We use
   11922                 :             :      this method instead of type_hash_canon, because it only does a
   11923                 :             :      simple equality check on the list of field members.  */
   11924                 :             : 
   11925                 :     3695519 :   t = TYPE_PTRMEMFUNC_TYPE (type);
   11926                 :     3695519 :   if (t)
   11927                 :             :     return t;
   11928                 :             : 
   11929                 :     1172001 :   t = make_node (RECORD_TYPE);
   11930                 :             : 
   11931                 :             :   /* Let the front end know this is a pointer to member function.  */
   11932                 :     1172001 :   TYPE_PTRMEMFUNC_FLAG (t) = 1;
   11933                 :             : 
   11934                 :     1172001 :   field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
   11935                 :     1172001 :   DECL_NONADDRESSABLE_P (field) = 1;
   11936                 :     1172001 :   fields = field;
   11937                 :             : 
   11938                 :     1172001 :   field = build_decl (input_location, FIELD_DECL, delta_identifier,
   11939                 :             :                       delta_type_node);
   11940                 :     1172001 :   DECL_NONADDRESSABLE_P (field) = 1;
   11941                 :     1172001 :   DECL_CHAIN (field) = fields;
   11942                 :     1172001 :   fields = field;
   11943                 :             : 
   11944                 :     1172001 :   finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
   11945                 :             : 
   11946                 :             :   /* Zap out the name so that the back end will give us the debugging
   11947                 :             :      information for this anonymous RECORD_TYPE.  */
   11948                 :     1172001 :   TYPE_NAME (t) = NULL_TREE;
   11949                 :             : 
   11950                 :             :   /* Cache this pointer-to-member type so that we can find it again
   11951                 :             :      later.  */
   11952                 :     1172001 :   TYPE_PTRMEMFUNC_TYPE (type) = t;
   11953                 :             : 
   11954                 :     1172001 :   if (TYPE_STRUCTURAL_EQUALITY_P (type))
   11955                 :      640176 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
   11956                 :      531825 :   else if (TYPE_CANONICAL (type) != type)
   11957                 :      345124 :     TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
   11958                 :             : 
   11959                 :             :   return t;
   11960                 :             : }
   11961                 :             : 
   11962                 :             : /* Create and return a pointer to data member type.  */
   11963                 :             : 
   11964                 :             : tree
   11965                 :      320321 : build_ptrmem_type (tree class_type, tree member_type)
   11966                 :             : {
   11967                 :      320321 :   if (TREE_CODE (member_type) == METHOD_TYPE)
   11968                 :             :     {
   11969                 :       62809 :       cp_cv_quals quals = type_memfn_quals (member_type);
   11970                 :       62809 :       cp_ref_qualifier rqual = type_memfn_rqual (member_type);
   11971                 :       62809 :       member_type = build_memfn_type (member_type, class_type, quals, rqual);
   11972                 :       62809 :       return build_ptrmemfunc_type (build_pointer_type (member_type));
   11973                 :             :     }
   11974                 :             :   else
   11975                 :             :     {
   11976                 :      257512 :       gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
   11977                 :      257512 :       return build_offset_type (class_type, member_type);
   11978                 :             :     }
   11979                 :             : }
   11980                 :             : 
   11981                 :             : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
   11982                 :             :    Check to see that the definition is valid.  Issue appropriate error
   11983                 :             :    messages.  */
   11984                 :             : 
   11985                 :             : static void
   11986                 :    13949925 : check_static_variable_definition (tree decl, tree type)
   11987                 :             : {
   11988                 :             :   /* Avoid redundant diagnostics on out-of-class definitions.  */
   11989                 :    13949925 :   if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
   11990                 :             :     ;
   11991                 :             :   /* Can't check yet if we don't know the type.  */
   11992                 :    12996958 :   else if (dependent_type_p (type))
   11993                 :             :     ;
   11994                 :             :   /* If DECL is declared constexpr, we'll do the appropriate checks
   11995                 :             :      in check_initializer.  Similarly for inline static data members.  */
   11996                 :    12710995 :   else if (DECL_P (decl)
   11997                 :    12710995 :       && (DECL_DECLARED_CONSTEXPR_P (decl)
   11998                 :     2344878 :           || DECL_VAR_DECLARED_INLINE_P (decl)))
   11999                 :             :     ;
   12000                 :     2344335 :   else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   12001                 :             :     {
   12002                 :          52 :       if (!COMPLETE_TYPE_P (type))
   12003                 :          11 :         error_at (DECL_SOURCE_LOCATION (decl),
   12004                 :             :                   "in-class initialization of static data member %q#D of "
   12005                 :             :                   "incomplete type", decl);
   12006                 :          41 :       else if (literal_type_p (type))
   12007                 :          35 :         permerror (DECL_SOURCE_LOCATION (decl),
   12008                 :             :                    "%<constexpr%> needed for in-class initialization of "
   12009                 :             :                    "static data member %q#D of non-integral type", decl);
   12010                 :             :       else
   12011                 :           6 :         error_at (DECL_SOURCE_LOCATION (decl),
   12012                 :             :                   "in-class initialization of static data member %q#D of "
   12013                 :             :                   "non-literal type", decl);
   12014                 :             :     }
   12015                 :             :   /* Motion 10 at San Diego: If a static const integral data member is
   12016                 :             :      initialized with an integral constant expression, the initializer
   12017                 :             :      may appear either in the declaration (within the class), or in
   12018                 :             :      the definition, but not both.  If it appears in the class, the
   12019                 :             :      member is a member constant.  The file-scope definition is always
   12020                 :             :      required.  */
   12021                 :     2344283 :   else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
   12022                 :          11 :     error_at (DECL_SOURCE_LOCATION (decl),
   12023                 :             :               "invalid in-class initialization of static data member "
   12024                 :             :               "of non-integral type %qT",
   12025                 :             :               type);
   12026                 :     2344272 :   else if (!CP_TYPE_CONST_P (type))
   12027                 :           5 :     error_at (DECL_SOURCE_LOCATION (decl),
   12028                 :             :               "ISO C++ forbids in-class initialization of non-const "
   12029                 :             :               "static member %qD",
   12030                 :             :               decl);
   12031                 :     2344267 :   else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   12032                 :           5 :     pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   12033                 :             :              "ISO C++ forbids initialization of member constant "
   12034                 :             :              "%qD of non-integral type %qT", decl, type);
   12035                 :    13949925 : }
   12036                 :             : 
   12037                 :             : /* *expr_p is part of the TYPE_SIZE of a variably-sized array.  If any
   12038                 :             :    SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
   12039                 :             :    expressions out into temporary variables so that walk_tree doesn't
   12040                 :             :    step into them (c++/15764).  */
   12041                 :             : 
   12042                 :             : static tree
   12043                 :        3148 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
   12044                 :             : {
   12045                 :        3148 :   hash_set<tree> *pset = (hash_set<tree> *)data;
   12046                 :        3148 :   tree expr = *expr_p;
   12047                 :        3148 :   if (TREE_CODE (expr) == SAVE_EXPR)
   12048                 :             :     {
   12049                 :        1355 :       tree op = TREE_OPERAND (expr, 0);
   12050                 :        1355 :       cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
   12051                 :        1355 :       if (TREE_SIDE_EFFECTS (op))
   12052                 :          56 :         TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
   12053                 :        1355 :       *walk_subtrees = 0;
   12054                 :             :     }
   12055                 :        1793 :   else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
   12056                 :        1618 :     *walk_subtrees = 0;
   12057                 :        3148 :   return NULL;
   12058                 :             : }
   12059                 :             : 
   12060                 :             : /* Entry point for the above.  */
   12061                 :             : 
   12062                 :             : static void
   12063                 :        1414 : stabilize_vla_size (tree size)
   12064                 :             : {
   12065                 :        1414 :   hash_set<tree> pset;
   12066                 :             :   /* Break out any function calls into temporary variables.  */
   12067                 :        1414 :   cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
   12068                 :        1414 : }
   12069                 :             : 
   12070                 :             : /* Reduce a SIZEOF_EXPR to its value.  */
   12071                 :             : 
   12072                 :             : tree
   12073                 :     9487702 : fold_sizeof_expr (tree t)
   12074                 :             : {
   12075                 :     9487702 :   tree r;
   12076                 :     9487702 :   if (SIZEOF_EXPR_TYPE_P (t))
   12077                 :     8775774 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   12078                 :     8775774 :                                     TREE_TYPE (TREE_OPERAND (t, 0)),
   12079                 :             :                                     SIZEOF_EXPR, false, false);
   12080                 :      711928 :   else if (TYPE_P (TREE_OPERAND (t, 0)))
   12081                 :           0 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   12082                 :           0 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   12083                 :             :                                     false, false);
   12084                 :             :   else
   12085                 :      711928 :     r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
   12086                 :      711928 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   12087                 :             :                                     false, false);
   12088                 :     9487702 :   if (r == error_mark_node)
   12089                 :          63 :     r = size_one_node;
   12090                 :     9487702 :   r = cp_fold_convert (size_type_node, r);
   12091                 :     9487702 :   return r;
   12092                 :             : }
   12093                 :             : 
   12094                 :             : /* Given the SIZE (i.e., number of elements) in an array, compute
   12095                 :             :    an appropriate index type for the array.  If non-NULL, NAME is
   12096                 :             :    the name of the entity being declared.  */
   12097                 :             : 
   12098                 :             : static tree
   12099                 :     2766801 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
   12100                 :             :                               tsubst_flags_t complain)
   12101                 :             : {
   12102                 :     2766801 :   if (error_operand_p (size))
   12103                 :          37 :     return error_mark_node;
   12104                 :             : 
   12105                 :             :   /* The type of the index being computed.  */
   12106                 :     2766764 :   tree itype;
   12107                 :             : 
   12108                 :             :   /* The original numeric size as seen in the source code before
   12109                 :             :      conversion to size_t.  */
   12110                 :     2766764 :   tree origsize = size;
   12111                 :             : 
   12112                 :     2766764 :   location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
   12113                 :             : 
   12114                 :     2766764 :   if (!type_dependent_expression_p (size))
   12115                 :             :     {
   12116                 :     2726834 :       origsize = size = mark_rvalue_use (size);
   12117                 :             : 
   12118                 :       37509 :       if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
   12119                 :     2726990 :           && TREE_SIDE_EFFECTS (size))
   12120                 :             :         /* In C++98, we mark a non-constant array bound with a magic
   12121                 :             :            NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case.  */;
   12122                 :             :       else
   12123                 :             :         {
   12124                 :     2726833 :           size = build_converted_constant_expr (size_type_node, size, complain);
   12125                 :             :           /* Pedantically a constant expression is required here and so
   12126                 :             :              __builtin_is_constant_evaluated () should fold to true if it
   12127                 :             :              is successfully folded into a constant.  */
   12128                 :     2726833 :           size = fold_non_dependent_expr (size, complain,
   12129                 :             :                                           /*manifestly_const_eval=*/true);
   12130                 :             : 
   12131                 :     2726833 :           if (!TREE_CONSTANT (size))
   12132                 :      103301 :             size = origsize;
   12133                 :             :         }
   12134                 :             : 
   12135                 :     2726834 :       if (error_operand_p (size))
   12136                 :           3 :         return error_mark_node;
   12137                 :             : 
   12138                 :             :       /* The array bound must be an integer type.  */
   12139                 :     2726831 :       tree type = TREE_TYPE (size);
   12140                 :     2726831 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
   12141                 :             :         {
   12142                 :          21 :           if (!(complain & tf_error))
   12143                 :           0 :             return error_mark_node;
   12144                 :          21 :           if (name)
   12145                 :          18 :             error_at (loc, "size of array %qD has non-integral type %qT",
   12146                 :             :                       name, type);
   12147                 :             :           else
   12148                 :           3 :             error_at (loc, "size of array has non-integral type %qT", type);
   12149                 :          21 :           size = integer_one_node;
   12150                 :             :         }
   12151                 :             :     }
   12152                 :             : 
   12153                 :             :   /* A type is dependent if it is...an array type constructed from any
   12154                 :             :      dependent type or whose size is specified by a constant expression
   12155                 :             :      that is value-dependent.  */
   12156                 :             :   /* We can only call value_dependent_expression_p on integral constant
   12157                 :             :      expressions.  */
   12158                 :     2766761 :   if (processing_template_decl
   12159                 :     1164482 :       && potential_constant_expression (size)
   12160                 :     3931218 :       && value_dependent_expression_p (size))
   12161                 :             :     {
   12162                 :             :       /* Just build the index type and mark that it requires
   12163                 :             :          structural equality checks.  */
   12164                 :      664452 :     in_template:
   12165                 :      664452 :       itype = build_index_type (build_min (MINUS_EXPR, sizetype,
   12166                 :             :                                            size, size_one_node));
   12167                 :      664452 :       TYPE_DEPENDENT_P (itype) = 1;
   12168                 :      664452 :       TYPE_DEPENDENT_P_VALID (itype) = 1;
   12169                 :      664452 :       SET_TYPE_STRUCTURAL_EQUALITY (itype);
   12170                 :      664452 :       return itype;
   12171                 :             :     }
   12172                 :             : 
   12173                 :     2102418 :   if (TREE_CODE (size) != INTEGER_CST)
   12174                 :             :     {
   12175                 :        1935 :       tree folded = cp_fully_fold (size);
   12176                 :        1935 :       if (TREE_CODE (folded) == INTEGER_CST)
   12177                 :             :         {
   12178                 :         223 :           if (name)
   12179                 :         149 :             pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
   12180                 :             :                      "integral constant-expression", name);
   12181                 :             :           else
   12182                 :          74 :             pedwarn (loc, OPT_Wpedantic,
   12183                 :             :                      "size of array is not an integral constant-expression");
   12184                 :             :         }
   12185                 :        1935 :       if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
   12186                 :             :         /* We might have lost the TREE_CONSTANT flag e.g. when we are
   12187                 :             :            folding a conversion from a pointer to integral type.  In that
   12188                 :             :            case issue an error below and don't treat this as a VLA.  */;
   12189                 :             :       else
   12190                 :             :         /* Use the folded result for VLAs, too; it will have resolved
   12191                 :             :            SIZEOF_EXPR.  */
   12192                 :             :         size = folded;
   12193                 :             :     }
   12194                 :             : 
   12195                 :             :   /* Normally, the array-bound will be a constant.  */
   12196                 :     2102418 :   if (TREE_CODE (size) == INTEGER_CST)
   12197                 :             :     {
   12198                 :             :       /* The size to use in diagnostics that reflects the constant
   12199                 :             :          size used in the source, rather than SIZE massaged above.  */
   12200                 :     2100706 :       tree diagsize = size;
   12201                 :             : 
   12202                 :             :       /* If the original size before conversion to size_t was signed
   12203                 :             :          and negative, convert it to ssizetype to restore the sign.  */
   12204                 :     2100706 :       if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
   12205                 :             :           && TREE_CODE (size) == INTEGER_CST
   12206                 :     2100706 :           && tree_int_cst_sign_bit (size))
   12207                 :             :         {
   12208                 :         242 :           diagsize = fold_convert (ssizetype, size);
   12209                 :             : 
   12210                 :             :           /* Clear the overflow bit that may have been set as a result
   12211                 :             :              of the conversion from the sizetype of the new size to
   12212                 :             :              ssizetype.  */
   12213                 :         242 :           TREE_OVERFLOW (diagsize) = false;
   12214                 :             :         }
   12215                 :             : 
   12216                 :             :       /* Verify that the array has a positive number of elements
   12217                 :             :          and issue the appropriate diagnostic if it doesn't.  */
   12218                 :     2100706 :       if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
   12219                 :             :         {
   12220                 :         473 :           if (!(complain & tf_error))
   12221                 :          15 :             return error_mark_node;
   12222                 :         458 :           size = integer_one_node;
   12223                 :             :         }
   12224                 :             :       /* As an extension we allow zero-sized arrays.  */
   12225                 :     2100233 :       else if (integer_zerop (size))
   12226                 :             :         {
   12227                 :        3173 :           if (!(complain & tf_error))
   12228                 :             :             /* We must fail if performing argument deduction (as
   12229                 :             :                indicated by the state of complain), so that
   12230                 :             :                another substitution can be found.  */
   12231                 :           8 :             return error_mark_node;
   12232                 :        3165 :           else if (name)
   12233                 :        2901 :             pedwarn (loc, OPT_Wpedantic,
   12234                 :             :                      "ISO C++ forbids zero-size array %qD", name);
   12235                 :             :           else
   12236                 :         264 :             pedwarn (loc, OPT_Wpedantic,
   12237                 :             :                      "ISO C++ forbids zero-size array");
   12238                 :             :         }
   12239                 :             :     }
   12240                 :        1712 :   else if (TREE_CONSTANT (size)
   12241                 :             :            /* We don't allow VLAs at non-function scopes, or during
   12242                 :             :               tentative template substitution.  */
   12243                 :        1697 :            || !at_function_scope_p ()
   12244                 :        3241 :            || !(complain & tf_error))
   12245                 :             :     {
   12246                 :         189 :       if (!(complain & tf_error))
   12247                 :         144 :         return error_mark_node;
   12248                 :             :       /* `(int) &fn' is not a valid array bound.  */
   12249                 :          45 :       if (name)
   12250                 :          37 :         error_at (loc,
   12251                 :             :                   "size of array %qD is not an integral constant-expression",
   12252                 :             :                   name);
   12253                 :             :       else
   12254                 :           8 :         error_at (loc, "size of array is not an integral constant-expression");
   12255                 :          45 :       size = integer_one_node;
   12256                 :             :     }
   12257                 :        1523 :   else if (pedantic && warn_vla != 0)
   12258                 :             :     {
   12259                 :          30 :       if (name)
   12260                 :          15 :         pedwarn (name_loc, OPT_Wvla,
   12261                 :             :                  "ISO C++ forbids variable length array %qD", name);
   12262                 :             :       else
   12263                 :          15 :         pedwarn (input_location, OPT_Wvla,
   12264                 :             :                  "ISO C++ forbids variable length array");
   12265                 :             :     }
   12266                 :        1493 :   else if (warn_vla > 0)
   12267                 :             :     {
   12268                 :           3 :       if (name)
   12269                 :           3 :         warning_at (name_loc, OPT_Wvla,
   12270                 :             :                     "variable length array %qD is used", name);
   12271                 :             :       else
   12272                 :           0 :         warning (OPT_Wvla,
   12273                 :             :                  "variable length array is used");
   12274                 :             :     }
   12275                 :             : 
   12276                 :     2102251 :   if (processing_template_decl && !TREE_CONSTANT (size))
   12277                 :         109 :     goto in_template;
   12278                 :             :   else
   12279                 :             :     {
   12280                 :     2102142 :       if (!TREE_CONSTANT (size))
   12281                 :             :         {
   12282                 :             :           /* A variable sized array.  Arrange for the SAVE_EXPR on the inside
   12283                 :             :              of the MINUS_EXPR, which allows the -1 to get folded with the +1
   12284                 :             :              that happens when building TYPE_SIZE.  */
   12285                 :        1414 :           size = variable_size (size);
   12286                 :        1414 :           stabilize_vla_size (size);
   12287                 :             :         }
   12288                 :             : 
   12289                 :             :       /* Compute the index of the largest element in the array.  It is
   12290                 :             :          one less than the number of elements in the array.  We save
   12291                 :             :          and restore PROCESSING_TEMPLATE_DECL so that computations in
   12292                 :             :          cp_build_binary_op will be appropriately folded.  */
   12293                 :     2102142 :       {
   12294                 :     2102142 :         processing_template_decl_sentinel s;
   12295                 :     2102142 :         itype = cp_build_binary_op (input_location,
   12296                 :             :                                     MINUS_EXPR,
   12297                 :             :                                     cp_convert (ssizetype, size, complain),
   12298                 :             :                                     cp_convert (ssizetype, integer_one_node,
   12299                 :             :                                                 complain),
   12300                 :             :                                     complain);
   12301                 :     2102142 :         itype = maybe_constant_value (itype, NULL_TREE, mce_true);
   12302                 :     2102142 :       }
   12303                 :             : 
   12304                 :     2102142 :       if (!TREE_CONSTANT (itype))
   12305                 :             :         {
   12306                 :        1414 :           if (sanitize_flags_p (SANITIZE_VLA)
   12307                 :        1414 :               && current_function_decl != NULL_TREE)
   12308                 :             :             {
   12309                 :             :               /* We have to add 1 -- in the ubsan routine we generate
   12310                 :             :                  LE_EXPR rather than LT_EXPR.  */
   12311                 :          69 :               tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
   12312                 :             :                                     build_one_cst (TREE_TYPE (itype)));
   12313                 :          69 :               t = ubsan_instrument_vla (input_location, t);
   12314                 :          69 :               finish_expr_stmt (t);
   12315                 :             :             }
   12316                 :             :         }
   12317                 :             :       /* Make sure that there was no overflow when creating to a signed
   12318                 :             :          index type.  (For example, on a 32-bit machine, an array with
   12319                 :             :          size 2^32 - 1 is too big.)  */
   12320                 :     2100728 :       else if (TREE_CODE (itype) == INTEGER_CST
   12321                 :     2100728 :                && TREE_OVERFLOW (itype))
   12322                 :             :         {
   12323                 :           0 :           if (!(complain & tf_error))
   12324                 :           0 :             return error_mark_node;
   12325                 :           0 :           error ("overflow in array dimension");
   12326                 :           0 :           TREE_OVERFLOW (itype) = 0;
   12327                 :             :         }
   12328                 :             :     }
   12329                 :             : 
   12330                 :             :   /* Create and return the appropriate index type.  */
   12331                 :     2102142 :   itype = build_index_type (itype);
   12332                 :             : 
   12333                 :             :   /* If the index type were dependent, we would have returned early, so
   12334                 :             :      remember that it isn't.  */
   12335                 :     2102142 :   TYPE_DEPENDENT_P (itype) = 0;
   12336                 :     2102142 :   TYPE_DEPENDENT_P_VALID (itype) = 1;
   12337                 :     2102142 :   return itype;
   12338                 :             : }
   12339                 :             : 
   12340                 :             : tree
   12341                 :      323538 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
   12342                 :             : {
   12343                 :      323538 :   return compute_array_index_type_loc (input_location, name, size, complain);
   12344                 :             : }
   12345                 :             : 
   12346                 :             : /* Returns the scope (if any) in which the entity declared by
   12347                 :             :    DECLARATOR will be located.  If the entity was declared with an
   12348                 :             :    unqualified name, NULL_TREE is returned.  */
   12349                 :             : 
   12350                 :             : tree
   12351                 :   689357349 : get_scope_of_declarator (const cp_declarator *declarator)
   12352                 :             : {
   12353                 :   804184961 :   while (declarator && declarator->kind != cdk_id)
   12354                 :   114827612 :     declarator = declarator->declarator;
   12355                 :             : 
   12356                 :             :   /* If the declarator-id is a SCOPE_REF, the scope in which the
   12357                 :             :      declaration occurs is the first operand.  */
   12358                 :   689357349 :   if (declarator
   12359                 :   688046712 :       && declarator->u.id.qualifying_scope)
   12360                 :             :     return declarator->u.id.qualifying_scope;
   12361                 :             : 
   12362                 :             :   /* Otherwise, the declarator is not a qualified name; the entity will
   12363                 :             :      be declared in the current scope.  */
   12364                 :             :   return NULL_TREE;
   12365                 :             : }
   12366                 :             : 
   12367                 :             : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
   12368                 :             :    indicated TYPE.  If non-NULL, NAME is the NAME of the declaration
   12369                 :             :    with this type.  */
   12370                 :             : 
   12371                 :             : static tree
   12372                 :     3173609 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
   12373                 :             : {
   12374                 :     3173609 :   tree itype = NULL_TREE;
   12375                 :             : 
   12376                 :             :   /* If things have already gone awry, bail now.  */
   12377                 :     3173609 :   if (type == error_mark_node || size == error_mark_node)
   12378                 :             :     return error_mark_node;
   12379                 :             : 
   12380                 :             :   /* [dcl.type.class.deduct] prohibits forming an array of placeholder
   12381                 :             :      for a deduced class type.  */
   12382                 :     3173546 :   if (template_placeholder_p (type))
   12383                 :             :     {
   12384                 :           6 :       if (name)
   12385                 :           0 :         error_at (loc, "%qD declared as array of template placeholder "
   12386                 :             :                   "type %qT", name, type);
   12387                 :             :       else
   12388                 :           6 :         error ("creating array of template placeholder type %qT", type);
   12389                 :           6 :       return error_mark_node;
   12390                 :             :     }
   12391                 :             : 
   12392                 :             :   /* If there are some types which cannot be array elements,
   12393                 :             :      issue an error-message and return.  */
   12394                 :     3173540 :   switch (TREE_CODE (type))
   12395                 :             :     {
   12396                 :           3 :     case VOID_TYPE:
   12397                 :           3 :       if (name)
   12398                 :           0 :         error_at (loc, "declaration of %qD as array of void", name);
   12399                 :             :       else
   12400                 :           3 :         error ("creating array of void");
   12401                 :           3 :       return error_mark_node;
   12402                 :             : 
   12403                 :           6 :     case FUNCTION_TYPE:
   12404                 :           6 :       if (name)
   12405                 :           6 :         error_at (loc, "declaration of %qD as array of functions", name);
   12406                 :             :       else
   12407                 :           0 :         error ("creating array of functions");
   12408                 :           6 :       return error_mark_node;
   12409                 :             : 
   12410                 :          21 :     case REFERENCE_TYPE:
   12411                 :          21 :       if (name)
   12412                 :          15 :         error_at (loc, "declaration of %qD as array of references", name);
   12413                 :             :       else
   12414                 :           6 :         error ("creating array of references");
   12415                 :          21 :       return error_mark_node;
   12416                 :             : 
   12417                 :           0 :     case METHOD_TYPE:
   12418                 :           0 :       if (name)
   12419                 :           0 :         error_at (loc, "declaration of %qD as array of function members",
   12420                 :             :                   name);
   12421                 :             :       else
   12422                 :           0 :         error ("creating array of function members");
   12423                 :           0 :       return error_mark_node;
   12424                 :             : 
   12425                 :     3173510 :     default:
   12426                 :     3173510 :       break;
   12427                 :             :     }
   12428                 :             : 
   12429                 :     3173510 :   if (!verify_type_context (name ? loc : input_location,
   12430                 :             :                             TCTX_ARRAY_ELEMENT, type))
   12431                 :           0 :     return error_mark_node;
   12432                 :             : 
   12433                 :             :   /* [dcl.array]
   12434                 :             : 
   12435                 :             :      The constant expressions that specify the bounds of the arrays
   12436                 :             :      can be omitted only for the first member of the sequence.  */
   12437                 :     3173510 :   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   12438                 :             :     {
   12439                 :          30 :       if (name)
   12440                 :          24 :         error_at (loc, "declaration of %qD as multidimensional array must "
   12441                 :             :                   "have bounds for all dimensions except the first",
   12442                 :             :                   name);
   12443                 :             :       else
   12444                 :           6 :         error ("multidimensional array must have bounds for all "
   12445                 :             :                "dimensions except the first");
   12446                 :             : 
   12447                 :          30 :       return error_mark_node;
   12448                 :             :     }
   12449                 :             : 
   12450                 :             :   /* Figure out the index type for the array.  */
   12451                 :     3173480 :   if (size)
   12452                 :             :     {
   12453                 :     2443263 :       itype = compute_array_index_type_loc (loc, name, size,
   12454                 :             :                                             tf_warning_or_error);
   12455                 :     2443263 :       if (type_uses_auto (type)
   12456                 :     2443263 :           && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
   12457                 :             :         {
   12458                 :           9 :           sorry_at (loc, "variable-length array of %<auto%>");
   12459                 :           9 :           return error_mark_node;
   12460                 :             :         }
   12461                 :             :     }
   12462                 :             : 
   12463                 :     3173471 :   return build_cplus_array_type (type, itype);
   12464                 :             : }
   12465                 :             : 
   12466                 :             : /* Returns the smallest location that is not UNKNOWN_LOCATION.  */
   12467                 :             : 
   12468                 :             : static location_t
   12469                 :   928833523 : min_location (location_t loca, location_t locb)
   12470                 :             : {
   12471                 :   928833523 :   if (loca == UNKNOWN_LOCATION
   12472                 :   928833523 :       || (locb != UNKNOWN_LOCATION
   12473                 :   103457160 :           && linemap_location_before_p (line_table, locb, loca)))
   12474                 :   826836321 :     return locb;
   12475                 :             :   return loca;
   12476                 :             : }
   12477                 :             : 
   12478                 :             : /* Returns the smallest location != UNKNOWN_LOCATION among the
   12479                 :             :    three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
   12480                 :             :    and LOCATIONS[ds_restrict].  */
   12481                 :             : 
   12482                 :             : static location_t
   12483                 :   927223761 : smallest_type_quals_location (int type_quals, const location_t* locations)
   12484                 :             : {
   12485                 :   927223761 :   location_t loc = UNKNOWN_LOCATION;
   12486                 :             : 
   12487                 :   927223761 :   if (type_quals & TYPE_QUAL_CONST)
   12488                 :   102036400 :     loc = locations[ds_const];
   12489                 :             : 
   12490                 :   927223761 :   if (type_quals & TYPE_QUAL_VOLATILE)
   12491                 :     1609671 :     loc = min_location (loc, locations[ds_volatile]);
   12492                 :             : 
   12493                 :   927223761 :   if (type_quals & TYPE_QUAL_RESTRICT)
   12494                 :          43 :     loc = min_location (loc, locations[ds_restrict]);
   12495                 :             : 
   12496                 :   927223761 :   return loc;
   12497                 :             : }
   12498                 :             : 
   12499                 :             : /* Returns the smallest among the latter and locations[ds_type_spec].  */
   12500                 :             : 
   12501                 :             : static location_t
   12502                 :   927223740 : smallest_type_location (int type_quals, const location_t* locations)
   12503                 :             : {
   12504                 :   927223740 :   location_t loc = smallest_type_quals_location (type_quals, locations);
   12505                 :   927223740 :   return min_location (loc, locations[ds_type_spec]);
   12506                 :             : }
   12507                 :             : 
   12508                 :             : static location_t
   12509                 :          26 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
   12510                 :             : {
   12511                 :          26 :   int type_quals = get_type_quals (declspecs);
   12512                 :          26 :   return smallest_type_location (type_quals, declspecs->locations);
   12513                 :             : }
   12514                 :             : 
   12515                 :             : /* Returns whether DECLARATOR represented a pointer or a reference and if so,
   12516                 :             :    strip out the pointer/reference declarator(s).  */
   12517                 :             : 
   12518                 :             : static bool
   12519                 :    27530035 : maybe_strip_indirect_ref (const cp_declarator** declarator)
   12520                 :             : {
   12521                 :    27530035 :   bool indirect_ref_p = false;
   12522                 :    55060217 :   while (declarator && *declarator
   12523                 :    27530182 :          && ((*declarator)->kind == cdk_pointer
   12524                 :    27530182 :              || (*declarator)->kind == cdk_reference))
   12525                 :             :     {
   12526                 :         147 :       indirect_ref_p = true;
   12527                 :         147 :       *declarator = (*declarator)->declarator;
   12528                 :             :     }
   12529                 :    27530035 :   return indirect_ref_p;
   12530                 :             : }
   12531                 :             : 
   12532                 :             : /* Check that it's OK to declare a function with the indicated TYPE, TYPE_QUALS
   12533                 :             :    and DECLARATOR.  SFK indicates the kind of special function (if any) that
   12534                 :             :    this function is.  OPTYPE is the type given in a conversion operator
   12535                 :             :    declaration, or the class type for a constructor/destructor.
   12536                 :             :    Returns the actual return type of the function; that may be different
   12537                 :             :    than TYPE if an error occurs, or for certain special functions.  */
   12538                 :             : 
   12539                 :             : static tree
   12540                 :    27530035 : check_special_function_return_type (special_function_kind sfk,
   12541                 :             :                                     tree type,
   12542                 :             :                                     tree optype,
   12543                 :             :                                     int type_quals,
   12544                 :             :                                     const cp_declarator** declarator,
   12545                 :             :                                     const location_t* locations)
   12546                 :             : {
   12547                 :    27530035 :   gcc_assert (declarator);
   12548                 :    27530035 :   location_t rettype_loc = (type
   12549                 :    27530035 :                             ? smallest_type_location (type_quals, locations)
   12550                 :    27529954 :                             : (*declarator)->id_loc);
   12551                 :    27530035 :   switch (sfk)
   12552                 :             :     {
   12553                 :    22613358 :     case sfk_constructor:
   12554                 :    22613358 :       if (maybe_strip_indirect_ref (declarator) || type)
   12555                 :          81 :         error_at (rettype_loc,
   12556                 :             :                   "return type specification for constructor invalid");
   12557                 :    22613277 :       else if (type_quals != TYPE_UNQUALIFIED)
   12558                 :          15 :         error_at (smallest_type_quals_location (type_quals, locations),
   12559                 :             :                   "qualifiers are not allowed on constructor declaration");
   12560                 :             : 
   12561                 :    22613358 :       if (targetm.cxx.cdtor_returns_this ())
   12562                 :           0 :         type = build_pointer_type (optype);
   12563                 :             :       else
   12564                 :    22613358 :         type = void_type_node;
   12565                 :             :       break;
   12566                 :             : 
   12567                 :     3197078 :     case sfk_destructor:
   12568                 :     3197078 :       if (maybe_strip_indirect_ref (declarator) || type)
   12569                 :          45 :         error_at (rettype_loc,
   12570                 :             :                   "return type specification for destructor invalid");
   12571                 :     3197033 :       else if (type_quals != TYPE_UNQUALIFIED)
   12572                 :           3 :         error_at (smallest_type_quals_location (type_quals, locations),
   12573                 :             :                   "qualifiers are not allowed on destructor declaration");
   12574                 :             : 
   12575                 :             :       /* We can't use the proper return type here because we run into
   12576                 :             :          problems with ambiguous bases and covariant returns.  */
   12577                 :     3197078 :       if (targetm.cxx.cdtor_returns_this ())
   12578                 :           0 :         type = build_pointer_type (void_type_node);
   12579                 :             :       else
   12580                 :     3197078 :         type = void_type_node;
   12581                 :             :       break;
   12582                 :             : 
   12583                 :      640159 :     case sfk_conversion:
   12584                 :      640159 :       if (maybe_strip_indirect_ref (declarator) || type)
   12585                 :          42 :         error_at (rettype_loc,
   12586                 :             :                   "return type specified for %<operator %T%>", optype);
   12587                 :      640117 :       else if (type_quals != TYPE_UNQUALIFIED)
   12588                 :           3 :         error_at (smallest_type_quals_location (type_quals, locations),
   12589                 :             :                   "qualifiers are not allowed on declaration of "
   12590                 :             :                   "%<operator %T%>", optype);
   12591                 :             : 
   12592                 :             :       type = optype;
   12593                 :             :       break;
   12594                 :             : 
   12595                 :     1079440 :     case sfk_deduction_guide:
   12596                 :     1079440 :       if (maybe_strip_indirect_ref (declarator) || type)
   12597                 :           0 :         error_at (rettype_loc,
   12598                 :             :                   "return type specified for deduction guide");
   12599                 :     1079440 :       else if (type_quals != TYPE_UNQUALIFIED)
   12600                 :           0 :         error_at (smallest_type_quals_location (type_quals, locations),
   12601                 :             :                   "qualifiers are not allowed on declaration of "
   12602                 :             :                   "deduction guide");
   12603                 :     1079440 :       if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
   12604                 :             :         {
   12605                 :           3 :           error ("template template parameter %qT in declaration of "
   12606                 :             :                  "deduction guide", optype);
   12607                 :           3 :           type = error_mark_node;
   12608                 :             :         }
   12609                 :             :       else
   12610                 :     1079437 :         type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
   12611                 :    29144880 :       for (int i = 0; i < ds_last; ++i)
   12612                 :    28065440 :         if (i != ds_explicit && locations[i])
   12613                 :           3 :           error_at (locations[i],
   12614                 :             :                     "%<decl-specifier%> in declaration of deduction guide");
   12615                 :             :       break;
   12616                 :             : 
   12617                 :           0 :     default:
   12618                 :           0 :       gcc_unreachable ();
   12619                 :             :     }
   12620                 :             : 
   12621                 :    27530035 :   return type;
   12622                 :             : }
   12623                 :             : 
   12624                 :             : /* A variable or data member (whose unqualified name is IDENTIFIER)
   12625                 :             :    has been declared with the indicated TYPE.  If the TYPE is not
   12626                 :             :    acceptable, issue an error message and return a type to use for
   12627                 :             :    error-recovery purposes.  */
   12628                 :             : 
   12629                 :             : tree
   12630                 :   287118879 : check_var_type (tree identifier, tree type, location_t loc)
   12631                 :             : {
   12632                 :   287118879 :   if (VOID_TYPE_P (type))
   12633                 :             :     {
   12634                 :          88 :       if (!identifier)
   12635                 :           0 :         error_at (loc, "unnamed variable or field declared void");
   12636                 :          88 :       else if (identifier_p (identifier))
   12637                 :             :         {
   12638                 :          88 :           gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
   12639                 :          88 :           error_at (loc, "variable or field %qE declared void",
   12640                 :             :                     identifier);
   12641                 :             :         }
   12642                 :             :       else
   12643                 :           0 :         error_at (loc, "variable or field declared void");
   12644                 :          88 :       type = error_mark_node;
   12645                 :             :     }
   12646                 :             : 
   12647                 :   287118879 :   return type;
   12648                 :             : }
   12649                 :             : 
   12650                 :             : /* Handle declaring DECL as an inline variable.  */
   12651                 :             : 
   12652                 :             : static void
   12653                 :     3989972 : mark_inline_variable (tree decl, location_t loc)
   12654                 :             : {
   12655                 :     3989972 :   bool inlinep = true;
   12656                 :     3989972 :   if (! toplevel_bindings_p ())
   12657                 :             :     {
   12658                 :          12 :       error_at (loc, "%<inline%> specifier invalid for variable "
   12659                 :             :                 "%qD declared at block scope", decl);
   12660                 :          12 :       inlinep = false;
   12661                 :             :     }
   12662                 :     3989960 :   else if (cxx_dialect < cxx17)
   12663                 :         688 :     pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
   12664                 :             :              "with %<-std=c++17%> or %<-std=gnu++17%>");
   12665                 :         700 :   if (inlinep)
   12666                 :             :     {
   12667                 :     3989960 :       retrofit_lang_decl (decl);
   12668                 :     3989960 :       SET_DECL_VAR_DECLARED_INLINE_P (decl);
   12669                 :             :     }
   12670                 :     3989972 : }
   12671                 :             : 
   12672                 :             : 
   12673                 :             : /* Assign a typedef-given name to a class or enumeration type declared
   12674                 :             :    as anonymous at first.  This was split out of grokdeclarator
   12675                 :             :    because it is also used in libcc1.  */
   12676                 :             : 
   12677                 :             : void
   12678                 :      399870 : name_unnamed_type (tree type, tree decl)
   12679                 :             : {
   12680                 :     1199610 :   gcc_assert (TYPE_UNNAMED_P (type));
   12681                 :             : 
   12682                 :             :   /* Replace the anonymous decl with the real decl.  Be careful not to
   12683                 :             :      rename other typedefs (such as the self-reference) of type.  */
   12684                 :      399870 :   tree orig = TYPE_NAME (type);
   12685                 :     1198042 :   for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   12686                 :      798172 :     if (TYPE_NAME (t) == orig)
   12687                 :      399870 :       TYPE_NAME (t) = decl;
   12688                 :             : 
   12689                 :             :   /* If this is a typedef within a template class, the nested
   12690                 :             :      type is a (non-primary) template.  The name for the
   12691                 :             :      template needs updating as well.  */
   12692                 :      399870 :   if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
   12693                 :          64 :     DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
   12694                 :             : 
   12695                 :             :   /* Adjust linkage now that we aren't unnamed anymore.  */
   12696                 :      399870 :   reset_type_linkage (type);
   12697                 :             : 
   12698                 :             :   /* FIXME remangle member functions; member functions of a
   12699                 :             :      type with external linkage have external linkage.  */
   12700                 :             : 
   12701                 :             :   /* Check that our job is done, and that it would fail if we
   12702                 :             :      attempted to do it again.  */
   12703                 :      799740 :   gcc_assert (!TYPE_UNNAMED_P (type));
   12704                 :      399870 : }
   12705                 :             : 
   12706                 :             : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
   12707                 :             :    is allowed.  TYPE might contain a decltype(auto).  Returns true if
   12708                 :             :    there was a problem, false otherwise.  */
   12709                 :             : 
   12710                 :             : static bool
   12711                 :   584369130 : check_decltype_auto (location_t loc, tree type)
   12712                 :             : {
   12713                 :   584369130 :   if (tree a = type_uses_auto (type))
   12714                 :             :     {
   12715                 :     9683253 :       if (AUTO_IS_DECLTYPE (a))
   12716                 :             :         {
   12717                 :      326234 :           if (a != type)
   12718                 :             :             {
   12719                 :          33 :               error_at (loc, "%qT as type rather than plain "
   12720                 :             :                         "%<decltype(auto)%>", type);
   12721                 :          33 :               return true;
   12722                 :             :             }
   12723                 :      326201 :           else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
   12724                 :             :             {
   12725                 :          35 :               error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
   12726                 :          35 :               return true;
   12727                 :             :             }
   12728                 :             :         }
   12729                 :             :     }
   12730                 :             :   return false;
   12731                 :             : }
   12732                 :             : 
   12733                 :             : /* Issue an error about two mutually incompatible declspecs
   12734                 :             :    with the given names and locations
   12735                 :             :    e.g. "error: `signed' and `unsigned' specified together" */
   12736                 :             : 
   12737                 :             : static void
   12738                 :          66 : complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
   12739                 :             :                                        const char *name_b, location_t loc_b)
   12740                 :             : {
   12741                 :          66 :   gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
   12742                 :          66 :   richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
   12743                 :             :                      nullptr, highlight_colors::rhs);
   12744                 :          66 :   pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
   12745                 :          66 :   pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
   12746                 :          66 :   error_at (&richloc, "%e and %e specified together",
   12747                 :             :             &e_name_a, &e_name_b);
   12748                 :          66 : }
   12749                 :             : 
   12750                 :             : /* Given declspecs and a declarator (abstract or otherwise), determine
   12751                 :             :    the name and type of the object declared and construct a DECL node
   12752                 :             :    for it.
   12753                 :             : 
   12754                 :             :    DECLSPECS points to the representation of declaration-specifier
   12755                 :             :    sequence that precedes declarator.
   12756                 :             : 
   12757                 :             :    DECL_CONTEXT says which syntactic context this declaration is in:
   12758                 :             :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
   12759                 :             :      FUNCDEF for a function definition.  Like NORMAL but a few different
   12760                 :             :       error messages in each case.  Return value may be zero meaning
   12761                 :             :       this definition is too screwy to try to parse.
   12762                 :             :      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
   12763                 :             :       handle member functions (which have FIELD context).
   12764                 :             :       Return value may be zero meaning this definition is too screwy to
   12765                 :             :       try to parse.
   12766                 :             :      PARM for a parameter declaration (either within a function prototype
   12767                 :             :       or before a function body).  Make a PARM_DECL, or return void_type_node.
   12768                 :             :      TPARM for a template parameter declaration.
   12769                 :             :      CATCHPARM for a parameter declaration before a catch clause.
   12770                 :             :      TYPENAME if for a typename (in a cast or sizeof).
   12771                 :             :       Don't make a DECL node; just return the ..._TYPE node.
   12772                 :             :      FIELD for a struct or union field; make a FIELD_DECL.
   12773                 :             :      BITFIELD for a field with specified width.
   12774                 :             : 
   12775                 :             :    INITIALIZED is as for start_decl.
   12776                 :             : 
   12777                 :             :    ATTRLIST is a pointer to the list of attributes, which may be NULL
   12778                 :             :    if there are none; *ATTRLIST may be modified if attributes from inside
   12779                 :             :    the declarator should be applied to the declaration.
   12780                 :             : 
   12781                 :             :    When this function is called, scoping variables (such as
   12782                 :             :    CURRENT_CLASS_TYPE) should reflect the scope in which the
   12783                 :             :    declaration occurs, not the scope in which the new declaration will
   12784                 :             :    be placed.  For example, on:
   12785                 :             : 
   12786                 :             :      void S::f() { ... }
   12787                 :             : 
   12788                 :             :    when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
   12789                 :             :    should not be `S'.
   12790                 :             : 
   12791                 :             :    Returns a DECL (if a declarator is present), a TYPE (if there is no
   12792                 :             :    declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
   12793                 :             :    error occurs. */
   12794                 :             : 
   12795                 :             : tree
   12796                 :   927223633 : grokdeclarator (const cp_declarator *declarator,
   12797                 :             :                 cp_decl_specifier_seq *declspecs,
   12798                 :             :                 enum decl_context decl_context,
   12799                 :             :                 int initialized,
   12800                 :             :                 tree* attrlist)
   12801                 :             : {
   12802                 :   927223633 :   tree type = NULL_TREE;
   12803                 :   927223633 :   int longlong = 0;
   12804                 :   927223633 :   int explicit_intN = 0;
   12805                 :   927223633 :   int int_n_alt = 0;
   12806                 :   927223633 :   int virtualp, explicitp, friendp, inlinep, staticp;
   12807                 :   927223633 :   int explicit_int = 0;
   12808                 :   927223633 :   int explicit_char = 0;
   12809                 :   927223633 :   int defaulted_int = 0;
   12810                 :             : 
   12811                 :   927223633 :   tree typedef_decl = NULL_TREE;
   12812                 :   927223633 :   const char *name = NULL;
   12813                 :   927223633 :   tree typedef_type = NULL_TREE;
   12814                 :             :   /* True if this declarator is a function definition.  */
   12815                 :   927223633 :   bool funcdef_flag = false;
   12816                 :   927223633 :   cp_declarator_kind innermost_code = cdk_error;
   12817                 :   927223633 :   int bitfield = 0;
   12818                 :             : #if 0
   12819                 :             :   /* See the code below that used this.  */
   12820                 :             :   tree decl_attr = NULL_TREE;
   12821                 :             : #endif
   12822                 :             : 
   12823                 :             :   /* Keep track of what sort of function is being processed
   12824                 :             :      so that we can warn about default return values, or explicit
   12825                 :             :      return values which do not match prescribed defaults.  */
   12826                 :   927223633 :   special_function_kind sfk = sfk_none;
   12827                 :             : 
   12828                 :   927223633 :   tree dname = NULL_TREE;
   12829                 :   927223633 :   tree ctor_return_type = NULL_TREE;
   12830                 :   927223633 :   enum overload_flags flags = NO_SPECIAL;
   12831                 :             :   /* cv-qualifiers that apply to the declarator, for a declaration of
   12832                 :             :      a member function.  */
   12833                 :   927223633 :   cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
   12834                 :             :   /* virt-specifiers that apply to the declarator, for a declaration of
   12835                 :             :      a member function.  */
   12836                 :   927223633 :   cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
   12837                 :             :   /* ref-qualifier that applies to the declarator, for a declaration of
   12838                 :             :      a member function.  */
   12839                 :   927223633 :   cp_ref_qualifier rqual = REF_QUAL_NONE;
   12840                 :             :   /* cv-qualifiers that apply to the type specified by the DECLSPECS.  */
   12841                 :   927223633 :   int type_quals = get_type_quals (declspecs);
   12842                 :   927223633 :   tree raises = NULL_TREE;
   12843                 :   927223633 :   int template_count = 0;
   12844                 :   927223633 :   tree returned_attrs = NULL_TREE;
   12845                 :   927223633 :   tree parms = NULL_TREE;
   12846                 :   927223633 :   const cp_declarator *id_declarator;
   12847                 :             :   /* The unqualified name of the declarator; either an
   12848                 :             :      IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR.  */
   12849                 :   927223633 :   tree unqualified_id;
   12850                 :             :   /* The class type, if any, in which this entity is located,
   12851                 :             :      or NULL_TREE if none.  Note that this value may be different from
   12852                 :             :      the current class type; for example if an attempt is made to declare
   12853                 :             :      "A::f" inside "B", this value will be "A".  */
   12854                 :   927223633 :   tree ctype = current_class_type;
   12855                 :             :   /* The NAMESPACE_DECL for the namespace in which this entity is
   12856                 :             :      located.  If an unqualified name is used to declare the entity,
   12857                 :             :      this value will be NULL_TREE, even if the entity is located at
   12858                 :             :      namespace scope.  */
   12859                 :   927223633 :   tree in_namespace = NULL_TREE;
   12860                 :   927223633 :   cp_storage_class storage_class;
   12861                 :   927223633 :   bool unsigned_p, signed_p, short_p, long_p, thread_p;
   12862                 :   927223633 :   bool type_was_error_mark_node = false;
   12863                 :   927223633 :   bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
   12864                 :   927223633 :   bool template_type_arg = false;
   12865                 :   927223633 :   bool template_parm_flag = false;
   12866                 :   927223633 :   bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
   12867                 :   927223633 :   bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
   12868                 :   927223633 :   bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
   12869                 :   927223633 :   bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
   12870                 :   927223633 :   bool late_return_type_p = false;
   12871                 :   927223633 :   bool array_parameter_p = false;
   12872                 :   927223633 :   tree reqs = NULL_TREE;
   12873                 :             : 
   12874                 :   927223633 :   signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
   12875                 :   927223633 :   unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
   12876                 :   927223633 :   short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
   12877                 :   927223633 :   long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
   12878                 :   927223633 :   longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
   12879                 :   927223633 :   explicit_intN = declspecs->explicit_intN_p;
   12880                 :   927223633 :   int_n_alt = declspecs->int_n_alt;
   12881                 :   927223633 :   thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
   12882                 :             : 
   12883                 :             :   // Was concept_p specified? Note that ds_concept
   12884                 :             :   // implies ds_constexpr!
   12885                 :   927223633 :   bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
   12886                 :   927223633 :   if (concept_p)
   12887                 :         114 :     constexpr_p = true;
   12888                 :             : 
   12889                 :   927223633 :   if (decl_context == FUNCDEF)
   12890                 :             :     funcdef_flag = true, decl_context = NORMAL;
   12891                 :             :   else if (decl_context == MEMFUNCDEF)
   12892                 :             :     funcdef_flag = true, decl_context = FIELD;
   12893                 :             :   else if (decl_context == BITFIELD)
   12894                 :             :     bitfield = 1, decl_context = FIELD;
   12895                 :             :   else if (decl_context == TEMPLATE_TYPE_ARG)
   12896                 :             :     template_type_arg = true, decl_context = TYPENAME;
   12897                 :             :   else if (decl_context == TPARM)
   12898                 :    12094236 :     template_parm_flag = true, decl_context = PARM;
   12899                 :             : 
   12900                 :   927223633 :   if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
   12901                 :     9412423 :     funcdef_flag = true;
   12902                 :             : 
   12903                 :   927223633 :   location_t typespec_loc = loc_or_input_loc (smallest_type_location
   12904                 :             :                                               (type_quals,
   12905                 :   927223633 :                                                declspecs->locations));
   12906                 :   927223633 :   location_t id_loc;
   12907                 :   927223633 :   location_t init_loc;
   12908                 :   927223633 :   if (declarator)
   12909                 :             :     {
   12910                 :   574236511 :       id_loc = loc_or_input_loc (declarator->id_loc);
   12911                 :   574236511 :       init_loc = loc_or_input_loc (declarator->init_loc);
   12912                 :             :     }
   12913                 :             :   else
   12914                 :   352987122 :     init_loc = id_loc = input_location;
   12915                 :             : 
   12916                 :             :   /* Look inside a declarator for the name being declared
   12917                 :             :      and get it as a string, for an error message.  */
   12918                 :   927223633 :   for (id_declarator = declarator;
   12919                 :  1289302230 :        id_declarator;
   12920                 :   362078597 :        id_declarator = id_declarator->declarator)
   12921                 :             :     {
   12922                 :   899232947 :       if (id_declarator->kind != cdk_id)
   12923                 :   362078622 :         innermost_code = id_declarator->kind;
   12924                 :             : 
   12925                 :   899232947 :       switch (id_declarator->kind)
   12926                 :             :         {
   12927                 :   176748500 :         case cdk_function:
   12928                 :   176748500 :           if (id_declarator->declarator
   12929                 :   176254863 :               && id_declarator->declarator->kind == cdk_id)
   12930                 :             :             {
   12931                 :   174263930 :               sfk = id_declarator->declarator->u.id.sfk;
   12932                 :   174263930 :               if (sfk == sfk_destructor)
   12933                 :     3197081 :                 flags = DTOR_FLAG;
   12934                 :             :             }
   12935                 :             :           break;
   12936                 :             : 
   12937                 :   537154325 :         case cdk_id:
   12938                 :   537154325 :           {
   12939                 :   537154325 :             tree qualifying_scope = id_declarator->u.id.qualifying_scope;
   12940                 :   537154325 :             tree decl = id_declarator->u.id.unqualified_name;
   12941                 :   537154325 :             if (!decl)
   12942                 :             :               break;
   12943                 :   537154325 :             if (qualifying_scope)
   12944                 :             :               {
   12945                 :     9810941 :                 if (check_for_bare_parameter_packs (qualifying_scope,
   12946                 :     9810941 :                                                     id_declarator->id_loc))
   12947                 :           6 :                   return error_mark_node;
   12948                 :     9810935 :                 if (at_function_scope_p ())
   12949                 :             :                   {
   12950                 :             :                     /* [dcl.meaning]
   12951                 :             : 
   12952                 :             :                        A declarator-id shall not be qualified except
   12953                 :             :                        for ...
   12954                 :             : 
   12955                 :             :                        None of the cases are permitted in block
   12956                 :             :                        scope.  */
   12957                 :           0 :                     if (qualifying_scope == global_namespace)
   12958                 :           0 :                       error ("invalid use of qualified-name %<::%D%>",
   12959                 :             :                              decl);
   12960                 :           0 :                     else if (TYPE_P (qualifying_scope))
   12961                 :           0 :                       error ("invalid use of qualified-name %<%T::%D%>",
   12962                 :             :                              qualifying_scope, decl);
   12963                 :             :                     else
   12964                 :           0 :                       error ("invalid use of qualified-name %<%D::%D%>",
   12965                 :             :                              qualifying_scope, decl);
   12966                 :           0 :                     return error_mark_node;
   12967                 :             :                   }
   12968                 :     9810935 :                 else if (TYPE_P (qualifying_scope))
   12969                 :             :                   {
   12970                 :     9654843 :                     ctype = qualifying_scope;
   12971                 :     9654843 :                     if (!MAYBE_CLASS_TYPE_P (ctype))
   12972                 :             :                       {
   12973                 :           6 :                         error_at (id_declarator->id_loc,
   12974                 :             :                                   "%q#T is not a class or namespace", ctype);
   12975                 :           6 :                         ctype = NULL_TREE;
   12976                 :             :                       }
   12977                 :     9654837 :                     else if (innermost_code != cdk_function
   12978                 :      396704 :                              && current_class_type
   12979                 :     9654852 :                              && !uniquely_derived_from_p (ctype,
   12980                 :             :                                                           current_class_type))
   12981                 :             :                       {
   12982                 :           9 :                         error_at (id_declarator->id_loc,
   12983                 :             :                                   "invalid use of qualified-name %<%T::%D%>",
   12984                 :             :                                   qualifying_scope, decl);
   12985                 :           9 :                         return error_mark_node;
   12986                 :             :                       }
   12987                 :             :                   }
   12988                 :      156092 :                 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
   12989                 :   537154310 :                   in_namespace = qualifying_scope;
   12990                 :             :               }
   12991                 :   537154310 :             switch (TREE_CODE (decl))
   12992                 :             :               {
   12993                 :     3197096 :               case BIT_NOT_EXPR:
   12994                 :     3197096 :                 {
   12995                 :     3197096 :                   if (innermost_code != cdk_function)
   12996                 :             :                     {
   12997                 :           6 :                       error_at (EXPR_LOCATION (decl),
   12998                 :             :                                 "declaration of %qE as non-function", decl);
   12999                 :           6 :                       return error_mark_node;
   13000                 :             :                     }
   13001                 :     3197090 :                   else if (!qualifying_scope
   13002                 :     3197090 :                            && !(current_class_type && at_class_scope_p ()))
   13003                 :             :                     {
   13004                 :           9 :                       error_at (EXPR_LOCATION (decl),
   13005                 :             :                                 "declaration of %qE as non-member", decl);
   13006                 :           9 :                       return error_mark_node;
   13007                 :             :                     }
   13008                 :             : 
   13009                 :     3197081 :                   tree type = TREE_OPERAND (decl, 0);
   13010                 :     3197081 :                   if (TYPE_P (type))
   13011                 :     3197078 :                     type = constructor_name (type);
   13012                 :     3197081 :                   name = identifier_to_locale (IDENTIFIER_POINTER (type));
   13013                 :     3197081 :                   dname = decl;
   13014                 :             :                 }
   13015                 :     3197081 :                 break;
   13016                 :             : 
   13017                 :     1937548 :               case TEMPLATE_ID_EXPR:
   13018                 :     1937548 :                 {
   13019                 :     1937548 :                   tree fns = TREE_OPERAND (decl, 0);
   13020                 :             : 
   13021                 :     1937548 :                   dname = fns;
   13022                 :     2841705 :                   if (!identifier_p (dname))
   13023                 :     1937533 :                     dname = OVL_NAME (dname);
   13024                 :             :                 }
   13025                 :             :                 /* Fall through.  */
   13026                 :             : 
   13027                 :   533957214 :               case IDENTIFIER_NODE:
   13028                 :   533957214 :                 if (identifier_p (decl))
   13029                 :   532019666 :                   dname = decl;
   13030                 :             : 
   13031                 :   533957214 :                 if (IDENTIFIER_KEYWORD_P (dname))
   13032                 :             :                   {
   13033                 :           0 :                     error ("declarator-id missing; using reserved word %qD",
   13034                 :             :                            dname);
   13035                 :           0 :                     name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   13036                 :             :                   }
   13037                 :   533957214 :                 else if (!IDENTIFIER_CONV_OP_P (dname))
   13038                 :   533317052 :                   name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   13039                 :             :                 else
   13040                 :             :                   {
   13041                 :      640162 :                     gcc_assert (flags == NO_SPECIAL);
   13042                 :      640162 :                     flags = TYPENAME_FLAG;
   13043                 :      640162 :                     sfk = sfk_conversion;
   13044                 :      640162 :                     tree glob = get_global_binding (dname);
   13045                 :      640162 :                     if (glob && TREE_CODE (glob) == TYPE_DECL)
   13046                 :           0 :                       name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   13047                 :             :                     else
   13048                 :             :                       name = "<invalid operator>";
   13049                 :             :                   }
   13050                 :             :                 break;
   13051                 :             : 
   13052                 :           0 :               default:
   13053                 :           0 :                 gcc_unreachable ();
   13054                 :             :               }
   13055                 :             :             break;
   13056                 :             :           }
   13057                 :             : 
   13058                 :             :         case cdk_array:
   13059                 :             :         case cdk_pointer:
   13060                 :             :         case cdk_reference:
   13061                 :             :         case cdk_ptrmem:
   13062                 :             :           break;
   13063                 :             : 
   13064                 :             :         case cdk_decomp:
   13065                 :   899232892 :           name = "structured binding";
   13066                 :             :           break;
   13067                 :             : 
   13068                 :          25 :         case cdk_error:
   13069                 :          25 :           return error_mark_node;
   13070                 :             : 
   13071                 :           0 :         default:
   13072                 :           0 :           gcc_unreachable ();
   13073                 :             :         }
   13074                 :   899232892 :       if (id_declarator->kind == cdk_id)
   13075                 :             :         break;
   13076                 :             :     }
   13077                 :             : 
   13078                 :             :   /* [dcl.fct.edf]
   13079                 :             : 
   13080                 :             :      The declarator in a function-definition shall have the form
   13081                 :             :      D1 ( parameter-declaration-clause) ...  */
   13082                 :   927223578 :   if (funcdef_flag && innermost_code != cdk_function)
   13083                 :             :     {
   13084                 :           3 :       error_at (id_loc, "function definition does not declare parameters");
   13085                 :           3 :       return error_mark_node;
   13086                 :             :     }
   13087                 :             : 
   13088                 :   927223575 :   if (flags == TYPENAME_FLAG
   13089                 :   927223575 :       && innermost_code != cdk_function
   13090                 :           3 :       && ! (ctype && !declspecs->any_specifiers_p))
   13091                 :             :     {
   13092                 :           3 :       error_at (id_loc, "declaration of %qD as non-function", dname);
   13093                 :           3 :       return error_mark_node;
   13094                 :             :     }
   13095                 :             : 
   13096                 :   927223572 :   if (dname && identifier_p (dname))
   13097                 :             :     {
   13098                 :   533957208 :       if (UDLIT_OPER_P (dname)
   13099                 :   533957208 :           && innermost_code != cdk_function)
   13100                 :             :         {
   13101                 :           6 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   13102                 :           6 :           return error_mark_node;
   13103                 :             :         }
   13104                 :             : 
   13105                 :   533957202 :       if (IDENTIFIER_ANY_OP_P (dname))
   13106                 :             :         {
   13107                 :    31816063 :           if (typedef_p)
   13108                 :             :             {
   13109                 :           3 :               error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
   13110                 :           3 :               return error_mark_node;
   13111                 :             :             }
   13112                 :    31816060 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   13113                 :             :             {
   13114                 :          15 :               error_at (id_loc, "declaration of %qD as parameter", dname);
   13115                 :          15 :               return error_mark_node;
   13116                 :             :             }
   13117                 :             :         }
   13118                 :             :     }
   13119                 :             : 
   13120                 :             :   /* Anything declared one level down from the top level
   13121                 :             :      must be one of the parameters of a function
   13122                 :             :      (because the body is at least two levels down).  */
   13123                 :             : 
   13124                 :             :   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
   13125                 :             :      by not allowing C++ class definitions to specify their parameters
   13126                 :             :      with xdecls (must be spec.d in the parmlist).
   13127                 :             : 
   13128                 :             :      Since we now wait to push a class scope until we are sure that
   13129                 :             :      we are in a legitimate method context, we must set oldcname
   13130                 :             :      explicitly (since current_class_name is not yet alive).
   13131                 :             : 
   13132                 :             :      We also want to avoid calling this a PARM if it is in a namespace.  */
   13133                 :             : 
   13134                 :   927223548 :   if (decl_context == NORMAL && !toplevel_bindings_p ())
   13135                 :             :     {
   13136                 :    62897397 :       cp_binding_level *b = current_binding_level;
   13137                 :    62897397 :       current_binding_level = b->level_chain;
   13138                 :    62897397 :       if (current_binding_level != 0 && toplevel_bindings_p ())
   13139                 :             :         decl_context = PARM;
   13140                 :    62897397 :       current_binding_level = b;
   13141                 :             :     }
   13142                 :             : 
   13143                 :   927223548 :   if (name == NULL)
   13144                 :   389985390 :     name = decl_context == PARM ? "parameter" : "type name";
   13145                 :             : 
   13146                 :   927223548 :   if (consteval_p && constexpr_p)
   13147                 :             :     {
   13148                 :           6 :       error_at (declspecs->locations[ds_consteval],
   13149                 :             :                 "both %qs and %qs specified", "constexpr", "consteval");
   13150                 :           6 :       return error_mark_node;
   13151                 :             :     }
   13152                 :             : 
   13153                 :   927223542 :   if (concept_p && typedef_p)
   13154                 :             :     {
   13155                 :           9 :       error_at (declspecs->locations[ds_concept],
   13156                 :             :                 "%qs cannot appear in a typedef declaration", "concept");
   13157                 :           9 :       return error_mark_node;
   13158                 :             :     }
   13159                 :             : 
   13160                 :   927223533 :   if (constexpr_p && typedef_p)
   13161                 :             :     {
   13162                 :           3 :       error_at (declspecs->locations[ds_constexpr],
   13163                 :             :                 "%qs cannot appear in a typedef declaration", "constexpr");
   13164                 :           3 :       return error_mark_node;
   13165                 :             :     }
   13166                 :             : 
   13167                 :   927223530 :   if (consteval_p && typedef_p)
   13168                 :             :     {
   13169                 :           3 :       error_at (declspecs->locations[ds_consteval],
   13170                 :             :                 "%qs cannot appear in a typedef declaration", "consteval");
   13171                 :           3 :       return error_mark_node;
   13172                 :             :     }
   13173                 :             : 
   13174                 :   927223527 :   if (constinit_p && typedef_p)
   13175                 :             :     {
   13176                 :           3 :       error_at (declspecs->locations[ds_constinit],
   13177                 :             :                 "%qs cannot appear in a typedef declaration", "constinit");
   13178                 :           3 :       return error_mark_node;
   13179                 :             :     }
   13180                 :             : 
   13181                 :             :   /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
   13182                 :             :      keywords shall appear in a decl-specifier-seq."  */
   13183                 :   927223524 :   if (constinit_p && constexpr_p)
   13184                 :             :     {
   13185                 :           6 :       gcc_rich_location richloc (declspecs->locations[ds_constinit]);
   13186                 :           6 :       richloc.add_range (declspecs->locations[ds_constexpr]);
   13187                 :           6 :       error_at (&richloc,
   13188                 :             :                 "can use at most one of the %<constinit%> and %<constexpr%> "
   13189                 :             :                 "specifiers");
   13190                 :           6 :       return error_mark_node;
   13191                 :           6 :     }
   13192                 :             : 
   13193                 :             :   /* If there were multiple types specified in the decl-specifier-seq,
   13194                 :             :      issue an error message.  */
   13195                 :   927223518 :   if (declspecs->multiple_types_p)
   13196                 :             :     {
   13197                 :        1500 :       error_at (typespec_loc,
   13198                 :             :                 "two or more data types in declaration of %qs", name);
   13199                 :        1500 :       return error_mark_node;
   13200                 :             :     }
   13201                 :             : 
   13202                 :   927222018 :   if (declspecs->conflicting_specifiers_p)
   13203                 :          31 :     return error_mark_node;
   13204                 :             : 
   13205                 :             :   /* Extract the basic type from the decl-specifier-seq.  */
   13206                 :   927221987 :   type = declspecs->type;
   13207                 :   927221987 :   if (type == error_mark_node)
   13208                 :             :     {
   13209                 :        1165 :       type = NULL_TREE;
   13210                 :        1165 :       type_was_error_mark_node = true;
   13211                 :             :     }
   13212                 :             : 
   13213                 :             :   /* Ignore erroneous attributes.  */
   13214                 :   927221987 :   if (attrlist && *attrlist == error_mark_node)
   13215                 :          12 :     *attrlist = NULL_TREE;
   13216                 :             : 
   13217                 :             :   /* An object declared as __attribute__((unavailable)) suppresses
   13218                 :             :      any reports of being declared with unavailable or deprecated
   13219                 :             :      items.  An object declared as __attribute__((deprecated))
   13220                 :             :      suppresses warnings of uses of other deprecated items.  */
   13221                 :   927221987 :   auto ds = make_temp_override (deprecated_state);
   13222                 :   927221987 :   if (attrlist && lookup_attribute ("unavailable", *attrlist))
   13223                 :         159 :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
   13224                 :   927221828 :   else if (attrlist && lookup_attribute ("deprecated", *attrlist))
   13225                 :      718120 :     deprecated_state = DEPRECATED_SUPPRESS;
   13226                 :             : 
   13227                 :   927221987 :   cp_handle_deprecated_or_unavailable (type);
   13228                 :   927221987 :   if (type && TREE_CODE (type) == TYPE_DECL)
   13229                 :             :     {
   13230                 :   638206949 :       cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
   13231                 :   638206949 :       typedef_decl = type;
   13232                 :   638206949 :       type = TREE_TYPE (typedef_decl);
   13233                 :   638206949 :       if (DECL_ARTIFICIAL (typedef_decl))
   13234                 :   461228808 :         cp_handle_deprecated_or_unavailable (type);
   13235                 :             :     }
   13236                 :             :   /* No type at all: default to `int', and set DEFAULTED_INT
   13237                 :             :      because it was not a user-defined typedef.  */
   13238                 :   927221987 :   if (type == NULL_TREE)
   13239                 :             :     {
   13240                 :    35879798 :       if (signed_p || unsigned_p || long_p || short_p)
   13241                 :             :         {
   13242                 :             :           /* These imply 'int'.  */
   13243                 :     8348197 :           type = integer_type_node;
   13244                 :     8348197 :           defaulted_int = 1;
   13245                 :             :         }
   13246                 :             :       /* If we just have "complex", it is equivalent to "complex double".  */
   13247                 :    27531601 :       else if (!longlong && !explicit_intN
   13248                 :    27531601 :                && decl_spec_seq_has_spec_p (declspecs, ds_complex))
   13249                 :             :         {
   13250                 :          81 :           type = double_type_node;
   13251                 :          81 :           pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
   13252                 :             :                    "ISO C++ does not support plain %<complex%> meaning "
   13253                 :             :                    "%<double complex%>");
   13254                 :             :         }
   13255                 :             :     }
   13256                 :             :   /* Gather flags.  */
   13257                 :   927221987 :   explicit_int = declspecs->explicit_int_p;
   13258                 :   927221987 :   explicit_char = declspecs->explicit_char_p;
   13259                 :             : 
   13260                 :             : #if 0
   13261                 :             :   /* See the code below that used this.  */
   13262                 :             :   if (typedef_decl)
   13263                 :             :     decl_attr = DECL_ATTRIBUTES (typedef_decl);
   13264                 :             : #endif
   13265                 :   927221987 :   typedef_type = type;
   13266                 :             : 
   13267                 :   927221987 :   if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
   13268                 :     1719599 :     ctor_return_type = TREE_TYPE (dname);
   13269                 :             :   else
   13270                 :             :     ctor_return_type = ctype;
   13271                 :             : 
   13272                 :   927221987 :   if (sfk != sfk_none)
   13273                 :             :     {
   13274                 :    27530035 :       type = check_special_function_return_type (sfk, type,
   13275                 :             :                                                  ctor_return_type,
   13276                 :             :                                                  type_quals,
   13277                 :             :                                                  &declarator,
   13278                 :             :                                                  declspecs->locations);
   13279                 :    27530035 :       type_quals = TYPE_UNQUALIFIED;
   13280                 :             :     }
   13281                 :   899691952 :   else if (type == NULL_TREE)
   13282                 :             :     {
   13283                 :        1566 :       int is_main;
   13284                 :             : 
   13285                 :        1566 :       explicit_int = -1;
   13286                 :             : 
   13287                 :             :       /* We handle `main' specially here, because 'main () { }' is so
   13288                 :             :          common.  With no options, it is allowed.  With -Wreturn-type,
   13289                 :             :          it is a warning.  It is only an error with -pedantic-errors.  */
   13290                 :        3132 :       is_main = (funcdef_flag
   13291                 :        3367 :                  && dname && identifier_p (dname)
   13292                 :         235 :                  && MAIN_NAME_P (dname)
   13293                 :          68 :                  && ctype == NULL_TREE
   13294                 :          68 :                  && in_namespace == NULL_TREE
   13295                 :        1634 :                  && current_namespace == global_namespace);
   13296                 :             : 
   13297                 :        1566 :       if (type_was_error_mark_node)
   13298                 :             :         /* We've already issued an error, don't complain more.  */;
   13299                 :         401 :       else if (in_system_header_at (id_loc) || flag_ms_extensions)
   13300                 :             :         /* Allow it, sigh.  */;
   13301                 :         339 :       else if (! is_main)
   13302                 :         277 :         permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
   13303                 :             :                    name);
   13304                 :          62 :       else if (pedantic)
   13305                 :           4 :         pedwarn (id_loc, OPT_Wpedantic,
   13306                 :             :                  "ISO C++ forbids declaration of %qs with no type", name);
   13307                 :             :       else
   13308                 :          58 :         warning_at (id_loc, OPT_Wreturn_type,
   13309                 :             :                     "ISO C++ forbids declaration of %qs with no type", name);
   13310                 :             : 
   13311                 :        1566 :       if (type_was_error_mark_node && template_parm_flag)
   13312                 :             :         /* FIXME we should be able to propagate the error_mark_node as is
   13313                 :             :            for other contexts too.  */
   13314                 :         151 :         type = error_mark_node;
   13315                 :             :       else
   13316                 :        1415 :         type = integer_type_node;
   13317                 :             :     }
   13318                 :             : 
   13319                 :   927221987 :   ctype = NULL_TREE;
   13320                 :             : 
   13321                 :   927221987 :   if (explicit_intN)
   13322                 :             :     {
   13323                 :      972458 :       if (! int_n_enabled_p[declspecs->int_n_idx])
   13324                 :             :         {
   13325                 :           0 :           error_at (declspecs->locations[ds_type_spec],
   13326                 :             :                     "%<__int%d%> is not supported by this target",
   13327                 :           0 :                     int_n_data[declspecs->int_n_idx].bitsize);
   13328                 :           0 :           explicit_intN = false;
   13329                 :             :         }
   13330                 :             :       /* Don't pedwarn if the alternate "__intN__" form has been used instead
   13331                 :             :          of "__intN".  */
   13332                 :      972458 :       else if (!int_n_alt && pedantic)
   13333                 :        3914 :         pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
   13334                 :             :                  "ISO C++ does not support %<__int%d%> for %qs",
   13335                 :        3914 :                  int_n_data[declspecs->int_n_idx].bitsize, name);
   13336                 :             :     }
   13337                 :             : 
   13338                 :             :   /* Now process the modifiers that were specified
   13339                 :             :      and check for invalid combinations.  */
   13340                 :             : 
   13341                 :             :   /* Long double is a special combination.  */
   13342                 :   927221987 :   if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
   13343                 :             :     {
   13344                 :     8775990 :       long_p = false;
   13345                 :     8775990 :       type = cp_build_qualified_type (long_double_type_node,
   13346                 :             :                                       cp_type_quals (type));
   13347                 :             :     }
   13348                 :             : 
   13349                 :             :   /* Check all other uses of type modifiers.  */
   13350                 :             : 
   13351                 :   927221987 :   if (unsigned_p || signed_p || long_p || short_p)
   13352                 :             :     {
   13353                 :    19446177 :       location_t loc;
   13354                 :    19446177 :       const char *key;
   13355                 :    19446177 :       if (unsigned_p)
   13356                 :             :         {
   13357                 :    13100265 :           key = "unsigned";
   13358                 :    13100265 :           loc = declspecs->locations[ds_unsigned];
   13359                 :             :         }
   13360                 :     6345912 :       else if (signed_p)
   13361                 :             :         {
   13362                 :     1100081 :           key = "signed";
   13363                 :     1100081 :           loc = declspecs->locations[ds_signed];
   13364                 :             :         }
   13365                 :     5245831 :       else if (longlong)
   13366                 :             :         {
   13367                 :     1698091 :           key = "long long";
   13368                 :     1698091 :           loc = declspecs->locations[ds_long_long];
   13369                 :             :         }
   13370                 :     3547740 :       else if (long_p)
   13371                 :             :         {
   13372                 :     3029461 :           key = "long";
   13373                 :     3029461 :           loc = declspecs->locations[ds_long];
   13374                 :             :         }
   13375                 :             :       else /* if (short_p) */
   13376                 :             :         {
   13377                 :      518279 :           key = "short";
   13378                 :      518279 :           loc = declspecs->locations[ds_short];
   13379                 :             :         }
   13380                 :             : 
   13381                 :    19446177 :       int ok = 0;
   13382                 :             : 
   13383                 :    19446177 :       if (signed_p && unsigned_p)
   13384                 :          54 :         complain_about_incompatible_declspecs
   13385                 :          54 :           ("signed", declspecs->locations[ds_signed],
   13386                 :             :            "unsigned", declspecs->locations[ds_unsigned]);
   13387                 :    19446123 :       else if (long_p && short_p)
   13388                 :          12 :         complain_about_incompatible_declspecs
   13389                 :          12 :           ("long", declspecs->locations[ds_long],
   13390                 :             :            "short", declspecs->locations[ds_short]);
   13391                 :    19446111 :       else if (TREE_CODE (type) != INTEGER_TYPE
   13392                 :    19446098 :                || type == char8_type_node
   13393                 :    19446074 :                || type == char16_type_node
   13394                 :    19446050 :                || type == char32_type_node
   13395                 :    19446026 :                || ((long_p || short_p)
   13396                 :    10358972 :                    && (explicit_char || explicit_intN)))
   13397                 :         418 :         error_at (loc, "%qs specified with %qT", key, type);
   13398                 :    19445693 :       else if (!explicit_int && !defaulted_int
   13399                 :    19445693 :                && !explicit_char && !explicit_intN)
   13400                 :             :         {
   13401                 :          30 :           if (typedef_decl)
   13402                 :             :             {
   13403                 :          27 :               pedwarn (loc, OPT_Wpedantic,
   13404                 :             :                        "%qs specified with typedef-name %qD",
   13405                 :             :                        key, typedef_decl);
   13406                 :          27 :               ok = !flag_pedantic_errors;
   13407                 :             :               /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
   13408                 :             :                  and is not built as a typedef.  */
   13409                 :          27 :               if (is_typedef_decl (typedef_decl))
   13410                 :          18 :                 type = DECL_ORIGINAL_TYPE (typedef_decl);
   13411                 :             :             }
   13412                 :           3 :           else if (declspecs->decltype_p)
   13413                 :           0 :             error_at (loc, "%qs specified with %<decltype%>", key);
   13414                 :             :           else
   13415                 :           3 :             error_at (loc, "%qs specified with %<typeof%>", key);
   13416                 :             :         }
   13417                 :             :       else
   13418                 :             :         ok = 1;
   13419                 :             : 
   13420                 :             :       /* Discard the type modifiers if they are invalid.  */
   13421                 :         514 :       if (! ok)
   13422                 :             :         {
   13423                 :             :           unsigned_p = false;
   13424                 :             :           signed_p = false;
   13425                 :             :           long_p = false;
   13426                 :             :           short_p = false;
   13427                 :             :           longlong = 0;
   13428                 :             :         }
   13429                 :             :     }
   13430                 :             : 
   13431                 :             :   /* Decide whether an integer type is signed or not.
   13432                 :             :      Optionally treat bitfields as signed by default.  */
   13433                 :   927221497 :   if (unsigned_p
   13434                 :             :       /* [class.bit]
   13435                 :             : 
   13436                 :             :          It is implementation-defined whether a plain (neither
   13437                 :             :          explicitly signed or unsigned) char, short, int, or long
   13438                 :             :          bit-field is signed or unsigned.
   13439                 :             : 
   13440                 :             :          Naturally, we extend this to long long as well.  Note that
   13441                 :             :          this does not include wchar_t.  */
   13442                 :   927221987 :       || (bitfield && !flag_signed_bitfields
   13443                 :          18 :           && !signed_p
   13444                 :             :           /* A typedef for plain `int' without `signed' can be
   13445                 :             :              controlled just like plain `int', but a typedef for
   13446                 :             :              `signed int' cannot be so controlled.  */
   13447                 :          18 :           && !(typedef_decl
   13448                 :          18 :                && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
   13449                 :          13 :           && TREE_CODE (type) == INTEGER_TYPE
   13450                 :          10 :           && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
   13451                 :             :     {
   13452                 :    13100050 :       if (explicit_intN)
   13453                 :      461173 :         type = int_n_trees[declspecs->int_n_idx].unsigned_type;
   13454                 :    12638877 :       else if (longlong)
   13455                 :     1362405 :         type = long_long_unsigned_type_node;
   13456                 :    11276472 :       else if (long_p)
   13457                 :     2195411 :         type = long_unsigned_type_node;
   13458                 :     9081061 :       else if (short_p)
   13459                 :     1301365 :         type = short_unsigned_type_node;
   13460                 :     7779696 :       else if (type == char_type_node)
   13461                 :     1571925 :         type = unsigned_char_type_node;
   13462                 :     6207771 :       else if (typedef_decl)
   13463                 :          25 :         type = c_common_unsigned_type (type);
   13464                 :             :       else
   13465                 :     6207746 :         type = unsigned_type_node;
   13466                 :             :     }
   13467                 :   914121937 :   else if (signed_p && type == char_type_node)
   13468                 :      682316 :     type = signed_char_type_node;
   13469                 :   913439621 :   else if (explicit_intN)
   13470                 :      511285 :     type = int_n_trees[declspecs->int_n_idx].signed_type;
   13471                 :   912928336 :   else if (longlong)
   13472                 :     1776513 :     type = long_long_integer_type_node;
   13473                 :   911151823 :   else if (long_p)
   13474                 :     3111447 :     type = long_integer_type_node;
   13475                 :   908040376 :   else if (short_p)
   13476                 :      611498 :     type = short_integer_type_node;
   13477                 :   907428878 :   else if (signed_p && typedef_decl)
   13478                 :           9 :     type = c_common_signed_type (type);
   13479                 :             : 
   13480                 :   927221987 :   if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
   13481                 :             :     {
   13482                 :     1418912 :       if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
   13483                 :           3 :         error_at (declspecs->locations[ds_complex],
   13484                 :             :                   "complex invalid for %qs", name);
   13485                 :             :       /* If a modifier is specified, the resulting complex is the complex
   13486                 :             :          form of TYPE.  E.g, "complex short" is "complex short int".  */
   13487                 :     1418909 :       else if (type == integer_type_node)
   13488                 :         164 :         type = complex_integer_type_node;
   13489                 :     1418745 :       else if (type == float_type_node)
   13490                 :      361839 :         type = complex_float_type_node;
   13491                 :     1056906 :       else if (type == double_type_node)
   13492                 :      362360 :         type = complex_double_type_node;
   13493                 :      694546 :       else if (type == long_double_type_node)
   13494                 :      361880 :         type = complex_long_double_type_node;
   13495                 :             :       else
   13496                 :      332666 :         type = build_complex_type (type);
   13497                 :             :     }
   13498                 :             : 
   13499                 :             :   /* If we're using the injected-class-name to form a compound type or a
   13500                 :             :      declaration, replace it with the underlying class so we don't get
   13501                 :             :      redundant typedefs in the debug output.  But if we are returning the
   13502                 :             :      type unchanged, leave it alone so that it's available to
   13503                 :             :      maybe_get_template_decl_from_type_decl.  */
   13504                 :   184810975 :   if (CLASS_TYPE_P (type)
   13505                 :   184760547 :       && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
   13506                 :    29668749 :       && type == TREE_TYPE (TYPE_NAME (type))
   13507                 :   956890736 :       && (declarator || type_quals))
   13508                 :    28494210 :     type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
   13509                 :             : 
   13510                 :   927221987 :   type_quals |= cp_type_quals (type);
   13511                 :  1854443974 :   type = cp_build_qualified_type
   13512                 :  1854443974 :     (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
   13513                 :   750243846 :                           || declspecs->decltype_p)
   13514                 :             :                          ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
   13515                 :             :   /* We might have ignored or rejected some of the qualifiers.  */
   13516                 :   927221987 :   type_quals = cp_type_quals (type);
   13517                 :             : 
   13518                 :   912103565 :   if (cxx_dialect >= cxx17 && type && is_auto (type)
   13519                 :    13093484 :       && innermost_code != cdk_function
   13520                 :             :       /* Placeholder in parm gets a better error below.  */
   13521                 :     7936917 :       && !(decl_context == PARM || decl_context == CATCHPARM)
   13522                 :   935133995 :       && id_declarator && declarator != id_declarator)
   13523                 :      968281 :     if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
   13524                 :             :       {
   13525                 :          16 :         auto_diagnostic_group g;
   13526                 :          16 :         gcc_rich_location richloc (typespec_loc);
   13527                 :          16 :         richloc.add_fixit_insert_after ("<>");
   13528                 :          16 :         error_at (&richloc, "missing template argument list after %qE; "
   13529                 :             :                   "for deduction, template placeholder must be followed "
   13530                 :             :                   "by a simple declarator-id", tmpl);
   13531                 :          16 :         inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
   13532                 :          16 :         type = error_mark_node;
   13533                 :          16 :       }
   13534                 :             : 
   13535                 :   927221987 :   staticp = 0;
   13536                 :   927221987 :   inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
   13537                 :   927221987 :   virtualp =  decl_spec_seq_has_spec_p (declspecs, ds_virtual);
   13538                 :   927221987 :   explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
   13539                 :             : 
   13540                 :   927221987 :   storage_class = declspecs->storage_class;
   13541                 :   927221987 :   if (storage_class == sc_static)
   13542                 :    19653477 :     staticp = 1 + (decl_context == FIELD);
   13543                 :   907568510 :   else if (decl_context == FIELD && sfk == sfk_deduction_guide)
   13544                 :             :     /* Treat class-scope deduction guides as static member functions
   13545                 :             :        so that they get a FUNCTION_TYPE instead of a METHOD_TYPE.  */
   13546                 :    19324155 :     staticp = 2;
   13547                 :             : 
   13548                 :   927221987 :   if (virtualp)
   13549                 :             :     {
   13550                 :     4137784 :       if (staticp == 2)
   13551                 :             :         {
   13552                 :          21 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   13553                 :          21 :           richloc.add_range (declspecs->locations[ds_storage_class]);
   13554                 :          21 :           error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
   13555                 :             :                     "and %<static%>", dname);
   13556                 :          21 :           storage_class = sc_none;
   13557                 :          21 :           staticp = 0;
   13558                 :          21 :         }
   13559                 :     4137784 :       if (constexpr_p && pedantic && cxx_dialect < cxx20)
   13560                 :             :         {
   13561                 :           6 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   13562                 :           6 :           richloc.add_range (declspecs->locations[ds_constexpr]);
   13563                 :           6 :           pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
   13564                 :             :                    "declared both %<virtual%> and %<constexpr%> only in "
   13565                 :             :                    "%<-std=c++20%> or %<-std=gnu++20%>", dname);
   13566                 :           6 :         }
   13567                 :             :     }
   13568                 :   927221987 :   friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   13569                 :             : 
   13570                 :             :   /* Issue errors about use of storage classes for parameters.  */
   13571                 :   927221987 :   if (decl_context == PARM)
   13572                 :             :     {
   13573                 :   278460139 :       if (typedef_p)
   13574                 :             :         {
   13575                 :          24 :           error_at (declspecs->locations[ds_typedef],
   13576                 :             :                     "typedef declaration invalid in parameter declaration");
   13577                 :          24 :           return error_mark_node;
   13578                 :             :         }
   13579                 :   278460115 :       else if (template_parm_flag && storage_class != sc_none)
   13580                 :             :         {
   13581                 :          16 :           error_at (min_location (declspecs->locations[ds_thread],
   13582                 :             :                                   declspecs->locations[ds_storage_class]),
   13583                 :             :                     "storage class specified for template parameter %qs",
   13584                 :             :                     name);
   13585                 :          16 :           return error_mark_node;
   13586                 :             :         }
   13587                 :   278460099 :       else if (storage_class == sc_static
   13588                 :   278460099 :                || storage_class == sc_extern
   13589                 :   278460096 :                || thread_p)
   13590                 :             :         {
   13591                 :           9 :           error_at (min_location (declspecs->locations[ds_thread],
   13592                 :             :                                   declspecs->locations[ds_storage_class]),
   13593                 :             :                     "storage class specified for parameter %qs", name);
   13594                 :           9 :           return error_mark_node;
   13595                 :             :         }
   13596                 :             : 
   13597                 :             :       /* Function parameters cannot be concept. */
   13598                 :   278460090 :       if (concept_p)
   13599                 :             :         {
   13600                 :           9 :           error_at (declspecs->locations[ds_concept],
   13601                 :             :                     "a parameter cannot be declared %qs", "concept");
   13602                 :           9 :           concept_p = 0;
   13603                 :           9 :           constexpr_p = 0;
   13604                 :             :         }
   13605                 :             :       /* Function parameters cannot be constexpr.  If we saw one, moan
   13606                 :             :          and pretend it wasn't there.  */
   13607                 :   278460081 :       else if (constexpr_p)
   13608                 :             :         {
   13609                 :           9 :           error_at (declspecs->locations[ds_constexpr],
   13610                 :             :                     "a parameter cannot be declared %qs", "constexpr");
   13611                 :           9 :           constexpr_p = 0;
   13612                 :             :         }
   13613                 :   278460090 :       if (constinit_p)
   13614                 :             :         {
   13615                 :           6 :           error_at (declspecs->locations[ds_constinit],
   13616                 :             :                     "a parameter cannot be declared %qs", "constinit");
   13617                 :           6 :           constinit_p = 0;
   13618                 :             :         }
   13619                 :   278460090 :       if (consteval_p)
   13620                 :             :         {
   13621                 :           3 :           error_at (declspecs->locations[ds_consteval],
   13622                 :             :                     "a parameter cannot be declared %qs", "consteval");
   13623                 :           3 :           consteval_p = 0;
   13624                 :             :         }
   13625                 :             :     }
   13626                 :             : 
   13627                 :             :   /* Give error if `virtual' is used outside of class declaration.  */
   13628                 :   927221938 :   if (virtualp
   13629                 :     4137784 :       && (current_class_name == NULL_TREE || decl_context != FIELD))
   13630                 :             :     {
   13631                 :          36 :       error_at (declspecs->locations[ds_virtual],
   13632                 :             :                 "%<virtual%> outside class declaration");
   13633                 :          36 :       virtualp = 0;
   13634                 :             :     }
   13635                 :             : 
   13636                 :   927221938 :   if (innermost_code == cdk_decomp)
   13637                 :             :     {
   13638                 :       73587 :       location_t loc = (declarator->kind == cdk_reference
   13639                 :       83893 :                         ? declarator->declarator->id_loc : declarator->id_loc);
   13640                 :       83893 :       if (inlinep)
   13641                 :           9 :         error_at (declspecs->locations[ds_inline],
   13642                 :             :                   "structured binding declaration cannot be %qs", "inline");
   13643                 :       83893 :       if (typedef_p)
   13644                 :           9 :         error_at (declspecs->locations[ds_typedef],
   13645                 :             :                   "structured binding declaration cannot be %qs", "typedef");
   13646                 :       83893 :       if (constexpr_p && !concept_p && cxx_dialect < cxx26)
   13647                 :          96 :         pedwarn (declspecs->locations[ds_constexpr], OPT_Wc__26_extensions,
   13648                 :             :                  "structured binding declaration can be %qs only with "
   13649                 :             :                  "%<-std=c++2c%> or %<-std=gnu++2c%>", "constexpr");
   13650                 :       83893 :       if (consteval_p)
   13651                 :           5 :         error_at (declspecs->locations[ds_consteval], "structured "
   13652                 :             :                   "binding declaration cannot be %qs", "consteval");
   13653                 :       83893 :       if (thread_p && cxx_dialect < cxx20)
   13654                 :          41 :         pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
   13655                 :             :                  "structured binding declaration can be %qs only in "
   13656                 :             :                  "%<-std=c++20%> or %<-std=gnu++20%>",
   13657                 :          41 :                  declspecs->gnu_thread_keyword_p
   13658                 :             :                  ? "__thread" : "thread_local");
   13659                 :       83893 :       if (concept_p)
   13660                 :             :         {
   13661                 :           0 :           error_at (declspecs->locations[ds_concept],
   13662                 :             :                     "structured binding declaration cannot be %qs", "concept");
   13663                 :           0 :           constexpr_p = 0;
   13664                 :             :         }
   13665                 :             :       /* [dcl.struct.bind] "A cv that includes volatile is deprecated."  */
   13666                 :       83893 :       if (type_quals & TYPE_QUAL_VOLATILE)
   13667                 :          26 :         warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
   13668                 :             :                     "%<volatile%>-qualified structured binding is deprecated");
   13669                 :       83893 :       switch (storage_class)
   13670                 :             :         {
   13671                 :             :         case sc_none:
   13672                 :             :           break;
   13673                 :           8 :         case sc_register:
   13674                 :           8 :           error_at (loc, "structured binding declaration cannot be %qs",
   13675                 :             :                     "register");
   13676                 :           8 :           break;
   13677                 :         184 :         case sc_static:
   13678                 :         184 :           if (cxx_dialect < cxx20)
   13679                 :         150 :             pedwarn (loc, OPT_Wc__20_extensions,
   13680                 :             :                      "structured binding declaration can be %qs only in "
   13681                 :             :                      "%<-std=c++20%> or %<-std=gnu++20%>", "static");
   13682                 :             :           break;
   13683                 :           9 :         case sc_extern:
   13684                 :           9 :           error_at (loc, "structured binding declaration cannot be %qs",
   13685                 :             :                     "extern");
   13686                 :           9 :           break;
   13687                 :           8 :         case sc_mutable:
   13688                 :           8 :           error_at (loc, "structured binding declaration cannot be %qs",
   13689                 :             :                     "mutable");
   13690                 :           8 :           break;
   13691                 :           0 :         case sc_auto:
   13692                 :           0 :           error_at (loc, "structured binding declaration cannot be "
   13693                 :             :                     "C++98 %<auto%>");
   13694                 :           0 :           break;
   13695                 :           0 :         default:
   13696                 :           0 :           gcc_unreachable ();
   13697                 :             :         }
   13698                 :       83893 :       if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
   13699                 :       83893 :           || TYPE_IDENTIFIER (type) != auto_identifier)
   13700                 :             :         {
   13701                 :           3 :           if (type != error_mark_node)
   13702                 :             :             {
   13703                 :           3 :               auto_diagnostic_group d;
   13704                 :           3 :               error_at (loc, "structured binding declaration cannot have "
   13705                 :             :                         "type %qT", type);
   13706                 :           3 :               inform (loc,
   13707                 :             :                       "type must be cv-qualified %<auto%> or reference to "
   13708                 :             :                       "cv-qualified %<auto%>");
   13709                 :           3 :             }
   13710                 :           3 :           type = build_qualified_type (make_auto (), type_quals);
   13711                 :           3 :           declspecs->type = type;
   13712                 :             :         }
   13713                 :       83890 :       else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
   13714                 :          51 :         pedwarn (loc, OPT_Wpedantic,
   13715                 :             :                  "structured binding declaration cannot have constrained "
   13716                 :             :                  "%<auto%> type %qT", type);
   13717                 :       83893 :       inlinep = 0;
   13718                 :       83893 :       typedef_p = 0;
   13719                 :       83893 :       consteval_p = 0;
   13720                 :       83893 :       concept_p = 0;
   13721                 :       83893 :       if (storage_class != sc_static)
   13722                 :             :         {
   13723                 :       83709 :           storage_class = sc_none;
   13724                 :       83709 :           declspecs->storage_class = sc_none;
   13725                 :             :         }
   13726                 :             :     }
   13727                 :             : 
   13728                 :             :   /* Static anonymous unions are dealt with here.  */
   13729                 :   927221938 :   if (staticp && decl_context == TYPENAME
   13730                 :           0 :       && declspecs->type
   13731                 :   927221938 :       && ANON_AGGR_TYPE_P (declspecs->type))
   13732                 :             :     decl_context = FIELD;
   13733                 :             : 
   13734                 :             :   /* Warn about storage classes that are invalid for certain
   13735                 :             :      kinds of declarations (parameters, typenames, etc.).  */
   13736                 :   927221938 :   if (thread_p
   13737                 :       21151 :       && ((storage_class
   13738                 :       21151 :            && storage_class != sc_extern
   13739                 :         517 :            && storage_class != sc_static)
   13740                 :       21140 :           || typedef_p))
   13741                 :             :     {
   13742                 :          17 :       location_t loc
   13743                 :          17 :         = min_location (declspecs->locations[ds_thread],
   13744                 :             :                         declspecs->locations[ds_storage_class]);
   13745                 :          17 :       error_at (loc, "multiple storage classes in declaration of %qs", name);
   13746                 :          17 :       thread_p = false;
   13747                 :             :     }
   13748                 :   927221938 :   if (decl_context != NORMAL
   13749                 :   771878781 :       && ((storage_class != sc_none
   13750                 :   771878781 :            && storage_class != sc_mutable)
   13751                 :   752554638 :           || thread_p))
   13752                 :             :     {
   13753                 :    19324146 :       if ((decl_context == PARM || decl_context == CATCHPARM)
   13754                 :          36 :           && (storage_class == sc_register
   13755                 :          36 :               || storage_class == sc_auto))
   13756                 :             :         ;
   13757                 :    19324110 :       else if (typedef_p)
   13758                 :             :         ;
   13759                 :    19324110 :       else if (decl_context == FIELD
   13760                 :             :                /* C++ allows static class elements.  */
   13761                 :    19324110 :                && storage_class == sc_static)
   13762                 :             :         /* C++ also allows inlines and signed and unsigned elements,
   13763                 :             :            but in those cases we don't come in here.  */
   13764                 :             :         ;
   13765                 :             :       else
   13766                 :             :         {
   13767                 :          15 :           location_t loc
   13768                 :          15 :             = min_location (declspecs->locations[ds_thread],
   13769                 :             :                             declspecs->locations[ds_storage_class]);
   13770                 :          15 :           if (decl_context == FIELD)
   13771                 :          15 :             error_at (loc, "storage class specified for %qs", name);
   13772                 :           0 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   13773                 :           0 :             error_at (loc, "storage class specified for parameter %qs", name);
   13774                 :             :           else
   13775                 :           0 :             error_at (loc, "storage class specified for typename");
   13776                 :          15 :           if (storage_class == sc_register
   13777                 :          15 :               || storage_class == sc_auto
   13778                 :          15 :               || storage_class == sc_extern
   13779                 :           3 :               || thread_p)
   13780                 :          15 :             storage_class = sc_none;
   13781                 :             :         }
   13782                 :             :     }
   13783                 :   907897792 :   else if (storage_class == sc_extern && funcdef_flag
   13784                 :   907897792 :            && ! toplevel_bindings_p ())
   13785                 :           0 :     error ("nested function %qs declared %<extern%>", name);
   13786                 :   907897792 :   else if (toplevel_bindings_p ())
   13787                 :             :     {
   13788                 :   419390074 :       if (storage_class == sc_auto)
   13789                 :           2 :         error_at (declspecs->locations[ds_storage_class],
   13790                 :             :                   "top-level declaration of %qs specifies %<auto%>", name);
   13791                 :             :     }
   13792                 :   488507718 :   else if (thread_p
   13793                 :   488507718 :            && storage_class != sc_extern
   13794                 :         125 :            && storage_class != sc_static)
   13795                 :             :     {
   13796                 :          93 :       if (declspecs->gnu_thread_keyword_p)
   13797                 :          17 :         pedwarn (declspecs->locations[ds_thread],
   13798                 :          17 :                  0, "function-scope %qs implicitly auto and "
   13799                 :             :                  "declared %<__thread%>", name);
   13800                 :             : 
   13801                 :             :       /* When thread_local is applied to a variable of block scope the
   13802                 :             :          storage-class-specifier static is implied if it does not appear
   13803                 :             :          explicitly.  */
   13804                 :          93 :       storage_class = declspecs->storage_class = sc_static;
   13805                 :          93 :       staticp = 1;
   13806                 :             :     }
   13807                 :             : 
   13808                 :   927221938 :   if (storage_class && friendp)
   13809                 :             :     {
   13810                 :          12 :       error_at (min_location (declspecs->locations[ds_thread],
   13811                 :             :                               declspecs->locations[ds_storage_class]),
   13812                 :             :                 "storage class specifiers invalid in friend function "
   13813                 :             :                 "declarations");
   13814                 :          12 :       storage_class = sc_none;
   13815                 :          12 :       staticp = 0;
   13816                 :             :     }
   13817                 :             : 
   13818                 :   927221938 :   if (!id_declarator)
   13819                 :             :     unqualified_id = NULL_TREE;
   13820                 :             :   else
   13821                 :             :     {
   13822                 :   537152734 :       unqualified_id = id_declarator->u.id.unqualified_name;
   13823                 :   537152734 :       switch (TREE_CODE (unqualified_id))
   13824                 :             :         {
   13825                 :     3197081 :         case BIT_NOT_EXPR:
   13826                 :     3197081 :           unqualified_id = TREE_OPERAND (unqualified_id, 0);
   13827                 :     3197081 :           if (TYPE_P (unqualified_id))
   13828                 :     3197078 :             unqualified_id = constructor_name (unqualified_id);
   13829                 :             :           break;
   13830                 :             : 
   13831                 :             :         case IDENTIFIER_NODE:
   13832                 :             :         case TEMPLATE_ID_EXPR:
   13833                 :             :           break;
   13834                 :             : 
   13835                 :           0 :         default:
   13836                 :           0 :           gcc_unreachable ();
   13837                 :             :         }
   13838                 :             :     }
   13839                 :             : 
   13840                 :   927221938 :   if (declspecs->std_attributes
   13841                 :   927221938 :       && !diagnose_misapplied_contracts (declspecs->std_attributes))
   13842                 :             :     {
   13843                 :         651 :       location_t attr_loc = declspecs->locations[ds_std_attribute];
   13844                 :         651 :       auto_diagnostic_group d;
   13845                 :         651 :       if (any_nonignored_attribute_p (declspecs->std_attributes)
   13846                 :         651 :           && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
   13847                 :         648 :         inform (attr_loc, "an attribute that appertains to a type-specifier "
   13848                 :             :                 "is ignored");
   13849                 :         651 :     }
   13850                 :             : 
   13851                 :   927221938 :   if (attrlist)
   13852                 :   914881856 :     diagnose_misapplied_contracts (*attrlist);
   13853                 :             : 
   13854                 :             :   /* Skip over build_memfn_type when a FUNCTION_DECL is an xobj memfn.  */
   13855                 :             :   bool is_xobj_member_function = false;
   13856                 :             :   /* Determine the type of the entity declared by recurring on the
   13857                 :             :      declarator.  */
   13858                 :  1289214635 :   for (; declarator; declarator = declarator->declarator)
   13859                 :             :     {
   13860                 :   899229349 :       const cp_declarator *inner_declarator;
   13861                 :   899229349 :       tree attrs;
   13862                 :             : 
   13863                 :   899229349 :       if (type == error_mark_node)
   13864                 :         599 :         return error_mark_node;
   13865                 :             : 
   13866                 :   899229023 :       attrs = declarator->attributes;
   13867                 :   899229023 :       if (attrs)
   13868                 :             :         {
   13869                 :       13442 :           int attr_flags;
   13870                 :             : 
   13871                 :       13442 :           attr_flags = 0;
   13872                 :       13442 :           if (declarator->kind == cdk_id)
   13873                 :       12765 :             attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
   13874                 :       13442 :           if (declarator->kind == cdk_function)
   13875                 :         657 :             attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
   13876                 :       13442 :           if (declarator->kind == cdk_array)
   13877                 :           2 :             attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
   13878                 :       13442 :           tree late_attrs = NULL_TREE;
   13879                 :       13442 :           if (decl_context != PARM && decl_context != TYPENAME)
   13880                 :             :             /* Assume that any attributes that get applied late to
   13881                 :             :                templates will DTRT when applied to the declaration
   13882                 :             :                as a whole.  */
   13883                 :       13430 :             late_attrs = splice_template_attributes (&attrs, type);
   13884                 :       13442 :           returned_attrs = decl_attributes (&type,
   13885                 :             :                                             attr_chainon (returned_attrs,
   13886                 :             :                                                           attrs),
   13887                 :             :                                             attr_flags);
   13888                 :       13442 :           returned_attrs = attr_chainon (late_attrs, returned_attrs);
   13889                 :             :         }
   13890                 :             : 
   13891                 :   899229023 :       inner_declarator = declarator->declarator;
   13892                 :             : 
   13893                 :             :       /* Check that contracts aren't misapplied.  */
   13894                 :   899229023 :       if (tree contract_attr = find_contract (declarator->std_attributes))
   13895                 :         484 :         if (declarator->kind != cdk_function
   13896                 :         479 :             || innermost_code != cdk_function)
   13897                 :           7 :           diagnose_misapplied_contracts (contract_attr);
   13898                 :             : 
   13899                 :             :       /* We don't want to warn in parameter context because we don't
   13900                 :             :          yet know if the parse will succeed, and this might turn out
   13901                 :             :          to be a constructor call.  */
   13902                 :   899229023 :       if (decl_context != PARM
   13903                 :   899229023 :           && decl_context != TYPENAME
   13904                 :   516141457 :           && !typedef_p
   13905                 :   470474587 :           && declarator->parenthesized != UNKNOWN_LOCATION
   13906                 :             :           /* If the type is class-like and the inner name used a
   13907                 :             :              global namespace qualifier, we need the parens.
   13908                 :             :              Unfortunately all we can tell is whether a qualified name
   13909                 :             :              was used or not.  */
   13910                 :   899229204 :           && !(inner_declarator
   13911                 :         126 :                && inner_declarator->kind == cdk_id
   13912                 :         108 :                && inner_declarator->u.id.qualifying_scope
   13913                 :          18 :                && (MAYBE_CLASS_TYPE_P (type)
   13914                 :          12 :                    || TREE_CODE (type) == ENUMERAL_TYPE)))
   13915                 :             :         {
   13916                 :         169 :           auto_diagnostic_group d;
   13917                 :         169 :           if (warning_at (declarator->parenthesized, OPT_Wparentheses,
   13918                 :             :                           "unnecessary parentheses in declaration of %qs",
   13919                 :             :                           name))
   13920                 :             :             {
   13921                 :          42 :               gcc_rich_location iloc (declarator->parenthesized);
   13922                 :          42 :               iloc.add_fixit_remove (get_start (declarator->parenthesized));
   13923                 :          42 :               iloc.add_fixit_remove (get_finish (declarator->parenthesized));
   13924                 :          42 :               inform (&iloc, "remove parentheses");
   13925                 :          42 :             }
   13926                 :         169 :         }
   13927                 :   899229023 :       if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
   13928                 :             :         break;
   13929                 :             : 
   13930                 :   361992970 :       switch (declarator->kind)
   13931                 :             :         {
   13932                 :     3173609 :         case cdk_array:
   13933                 :     6347218 :           type = create_array_type_for_decl (dname, type,
   13934                 :     3173609 :                                              declarator->u.array.bounds,
   13935                 :     3173609 :                                              declarator->id_loc);
   13936                 :     3173609 :           if (!valid_array_size_p (dname
   13937                 :             :                                    ? declarator->id_loc : input_location,
   13938                 :             :                                    type, dname))
   13939                 :         267 :             type = error_mark_node;
   13940                 :             : 
   13941                 :     3173609 :           if (declarator->std_attributes)
   13942                 :             :             /* [dcl.array]/1:
   13943                 :             : 
   13944                 :             :                The optional attribute-specifier-seq appertains to the
   13945                 :             :                array type.  */
   13946                 :         174 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   13947                 :             :           break;
   13948                 :             : 
   13949                 :   176748464 :         case cdk_function:
   13950                 :   176748464 :           {
   13951                 :   176748464 :             tree arg_types;
   13952                 :   176748464 :             int funcdecl_p;
   13953                 :             : 
   13954                 :             :             /* Declaring a function type.  */
   13955                 :             : 
   13956                 :             :             /* Pick up type qualifiers which should be applied to `this'.  */
   13957                 :   176748464 :             memfn_quals = declarator->u.function.qualifiers;
   13958                 :             :             /* Pick up virt-specifiers.  */
   13959                 :   176748464 :             virt_specifiers = declarator->u.function.virt_specifiers;
   13960                 :             :             /* And ref-qualifier, too */
   13961                 :   176748464 :             rqual = declarator->u.function.ref_qualifier;
   13962                 :             :             /* And tx-qualifier.  */
   13963                 :   176748464 :             tree tx_qual = declarator->u.function.tx_qualifier;
   13964                 :             :             /* Pick up the exception specifications.  */
   13965                 :   176748464 :             raises = declarator->u.function.exception_specification;
   13966                 :             :             /* If the exception-specification is ill-formed, let's pretend
   13967                 :             :                there wasn't one.  */
   13968                 :   176748464 :             if (raises == error_mark_node)
   13969                 :           9 :               raises = NULL_TREE;
   13970                 :             : 
   13971                 :   353496928 :             auto find_xobj_parm = [](tree parm_list)
   13972                 :             :               {
   13973                 :             :                 /* There is no need to iterate over the list,
   13974                 :             :                    only the first parm can be a valid xobj parm.  */
   13975                 :   353260554 :                 if (!parm_list || TREE_PURPOSE (parm_list) != this_identifier)
   13976                 :             :                   return NULL_TREE;
   13977                 :             :                 /* If we make it here, we are looking at an xobj parm.
   13978                 :             : 
   13979                 :             :                    Non-null 'purpose' usually means the parm has a default
   13980                 :             :                    argument, we don't want to violate this assumption.  */
   13981                 :       27177 :                 TREE_PURPOSE (parm_list) = NULL_TREE;
   13982                 :       27177 :                 return TREE_VALUE (parm_list);
   13983                 :             :               };
   13984                 :             : 
   13985                 :   176748464 :             tree xobj_parm
   13986                 :   176748464 :               = find_xobj_parm (declarator->u.function.parameters);
   13987                 :   176748464 :             is_xobj_member_function = xobj_parm;
   13988                 :             : 
   13989                 :   176748464 :             if (xobj_parm && cxx_dialect < cxx23)
   13990                 :          24 :               pedwarn (DECL_SOURCE_LOCATION (xobj_parm), OPT_Wc__23_extensions,
   13991                 :             :                        "explicit object member function only available "
   13992                 :             :                        "with %<-std=c++23%> or %<-std=gnu++23%>");
   13993                 :             : 
   13994                 :   176748464 :             if (xobj_parm && decl_context == TYPENAME)
   13995                 :             :               {
   13996                 :             :                 /* We inform in every case, just differently depending on what
   13997                 :             :                    case it is.  */
   13998                 :           6 :                 auto_diagnostic_group d;
   13999                 :           6 :                 bool ptr_type = true;
   14000                 :             :                 /* If declarator->kind is cdk_function and we are at the end of
   14001                 :             :                    the declarator chain, we are looking at a function type.  */
   14002                 :           6 :                 if (!declarator->declarator)
   14003                 :             :                   {
   14004                 :           2 :                     error_at (DECL_SOURCE_LOCATION (xobj_parm),
   14005                 :             :                               "a function type cannot "
   14006                 :             :                               "have an explicit object parameter");
   14007                 :           2 :                     ptr_type = false;
   14008                 :             :                   }
   14009                 :           4 :                 else if (declarator->declarator->kind == cdk_pointer)
   14010                 :           2 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   14011                 :             :                             "a pointer to function type cannot "
   14012                 :             :                             "have an explicit object parameter");
   14013                 :           2 :                 else if (declarator->declarator->kind == cdk_ptrmem)
   14014                 :           2 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   14015                 :             :                             "a pointer to member function type "
   14016                 :             :                             "cannot have an explicit object parameter");
   14017                 :             :                 else
   14018                 :           0 :                   gcc_unreachable ();
   14019                 :             : 
   14020                 :             :                 /* The locations being used here are probably not correct.  */
   14021                 :           4 :                 if (ptr_type)
   14022                 :           4 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   14023                 :             :                           "the type of a pointer to explicit object member "
   14024                 :             :                           "function is a regular pointer to function type");
   14025                 :             :                 else
   14026                 :           2 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   14027                 :             :                           "the type of an explicit object "
   14028                 :             :                           "member function is a regular function type");
   14029                 :             :                 /* Ideally we should synthesize the correct syntax
   14030                 :             :                    for the user, perhaps this could be added later.  */
   14031                 :           6 :               }
   14032                 :             :             /* Since a valid xobj parm has its purpose cleared in find_xobj_parm
   14033                 :             :                the first parm node will never erroneously be detected here.  */
   14034                 :   176748464 :             {
   14035                 :   176748464 :               auto_diagnostic_group d;
   14036                 :   176748464 :               bool bad_xobj_parm_encountered = false;
   14037                 :   176748464 :               for (tree parm = declarator->u.function.parameters;
   14038                 :   443754129 :                    parm && parm != void_list_node;
   14039                 :   267005665 :                    parm = TREE_CHAIN (parm))
   14040                 :             :                 {
   14041                 :   267005665 :                   if (TREE_PURPOSE (parm) != this_identifier)
   14042                 :   267005659 :                     continue;
   14043                 :           6 :                   bad_xobj_parm_encountered = true;
   14044                 :           6 :                   TREE_PURPOSE (parm) = NULL_TREE;
   14045                 :           6 :                   gcc_rich_location bad_xobj_parm
   14046                 :           6 :                     (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
   14047                 :           6 :                   error_at (&bad_xobj_parm,
   14048                 :             :                             "only the first parameter of a member function "
   14049                 :             :                             "can be declared as an explicit object parameter");
   14050                 :           6 :                 }
   14051                 :   176748464 :               if (bad_xobj_parm_encountered && xobj_parm)
   14052                 :           0 :                 inform (DECL_SOURCE_LOCATION (xobj_parm),
   14053                 :             :                         "valid explicit object parameter declared here");
   14054                 :   176748464 :             }
   14055                 :             : 
   14056                 :   176748464 :             if (reqs)
   14057                 :           3 :               error_at (location_of (reqs), "requires-clause on return type");
   14058                 :   176748464 :             reqs = declarator->u.function.requires_clause;
   14059                 :             : 
   14060                 :             :             /* Say it's a definition only for the CALL_EXPR
   14061                 :             :                closest to the identifier.  */
   14062                 :   176748464 :             funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
   14063                 :             : 
   14064                 :             :             /* Handle a late-specified return type.  */
   14065                 :   176748464 :             tree late_return_type = declarator->u.function.late_return_type;
   14066                 :   176748464 :             if (tree auto_node = type_uses_auto (type))
   14067                 :             :               {
   14068                 :     5166119 :                 if (!late_return_type)
   14069                 :             :                   {
   14070                 :     2127012 :                     if (!funcdecl_p)
   14071                 :             :                       /* auto (*fp)() = f; is OK.  */;
   14072                 :     2126980 :                     else if (current_class_type
   14073                 :     3916601 :                              && LAMBDA_TYPE_P (current_class_type))
   14074                 :             :                       /* OK for C++11 lambdas.  */;
   14075                 :     1550815 :                     else if (cxx_dialect < cxx14)
   14076                 :             :                       {
   14077                 :           7 :                         auto_diagnostic_group d;
   14078                 :           7 :                         error_at (typespec_loc, "%qs function uses "
   14079                 :             :                                   "%<auto%> type specifier without "
   14080                 :             :                                   "trailing return type", name);
   14081                 :           7 :                         inform (typespec_loc,
   14082                 :             :                                 "deduced return type only available "
   14083                 :             :                                 "with %<-std=c++14%> or %<-std=gnu++14%>");
   14084                 :           7 :                       }
   14085                 :     1550808 :                     else if (virtualp)
   14086                 :             :                       {
   14087                 :           6 :                         error_at (typespec_loc, "virtual function "
   14088                 :             :                                   "cannot have deduced return type");
   14089                 :           6 :                         virtualp = false;
   14090                 :             :                       }
   14091                 :             :                   }
   14092                 :     3039107 :                 else if (!is_auto (type) && sfk != sfk_conversion)
   14093                 :             :                   {
   14094                 :          15 :                     error_at (typespec_loc, "%qs function with trailing "
   14095                 :             :                               "return type has %qT as its type rather "
   14096                 :             :                               "than plain %<auto%>", name, type);
   14097                 :         270 :                     return error_mark_node;
   14098                 :             :                   }
   14099                 :     3039092 :                 else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
   14100                 :             :                   {
   14101                 :           9 :                     if (funcdecl_p)
   14102                 :           3 :                       error_at (typespec_loc,
   14103                 :             :                                 "%qs function with trailing return type "
   14104                 :             :                                 "has %<decltype(auto)%> as its type "
   14105                 :             :                                 "rather than plain %<auto%>", name);
   14106                 :             :                     else
   14107                 :           6 :                       error_at (typespec_loc,
   14108                 :             :                                 "invalid use of %<decltype(auto)%>");
   14109                 :           9 :                     return error_mark_node;
   14110                 :             :                   }
   14111                 :     3039083 :                 else if (is_constrained_auto (type))
   14112                 :             :                   {
   14113                 :           6 :                     if (funcdecl_p)
   14114                 :           3 :                       error_at (typespec_loc,
   14115                 :             :                                 "%qs function with trailing return type "
   14116                 :             :                                 "has constrained %<auto%> type specifier "
   14117                 :             :                                 "rather than plain %<auto%>",
   14118                 :             :                                 name);
   14119                 :             :                     else
   14120                 :           3 :                       error_at (typespec_loc,
   14121                 :             :                                 "invalid use of constrained %<auto%> type");
   14122                 :           6 :                     return error_mark_node;
   14123                 :             :                   }
   14124                 :     5166089 :                 tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
   14125                 :     5166089 :                 if (!tmpl)
   14126                 :     4086646 :                   if (tree late_auto = type_uses_auto (late_return_type))
   14127                 :       21820 :                     tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
   14128                 :     4086646 :                 if (tmpl)
   14129                 :             :                   {
   14130                 :     1079447 :                     if (!funcdecl_p || !dguide_name_p (unqualified_id))
   14131                 :             :                       {
   14132                 :          10 :                         auto_diagnostic_group g;
   14133                 :          10 :                         error_at (typespec_loc, "deduced class "
   14134                 :             :                                   "type %qD in function return type",
   14135                 :          10 :                                   DECL_NAME (tmpl));
   14136                 :          10 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   14137                 :             :                                 "%qD declared here", tmpl);
   14138                 :          10 :                         return error_mark_node;
   14139                 :          10 :                       }
   14140                 :     1079437 :                     else if (!late_return_type)
   14141                 :             :                       {
   14142                 :           3 :                         auto_diagnostic_group d;
   14143                 :           3 :                         error_at (declarator->id_loc, "deduction guide "
   14144                 :             :                                   "for %qT must have trailing return "
   14145                 :           3 :                                   "type", TREE_TYPE (tmpl));
   14146                 :           3 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   14147                 :             :                                 "%qD declared here", tmpl);
   14148                 :           3 :                         return error_mark_node;
   14149                 :           3 :                       }
   14150                 :     1079434 :                     else if (CLASS_TYPE_P (late_return_type)
   14151                 :     1079434 :                               && CLASSTYPE_TEMPLATE_INFO (late_return_type)
   14152                 :     2158868 :                               && (CLASSTYPE_TI_TEMPLATE (late_return_type)
   14153                 :             :                                   == tmpl))
   14154                 :             :                       /* OK */;
   14155                 :             :                     else
   14156                 :           0 :                       error ("trailing return type %qT of deduction guide "
   14157                 :             :                               "is not a specialization of %qT",
   14158                 :           0 :                               late_return_type, TREE_TYPE (tmpl));
   14159                 :             :                   }
   14160                 :             :               }
   14161                 :   171582345 :             else if (late_return_type
   14162                 :   171582345 :                      && sfk != sfk_conversion)
   14163                 :             :               {
   14164                 :          37 :                 if (late_return_type == error_mark_node)
   14165                 :             :                   return error_mark_node;
   14166                 :          37 :                 if (cxx_dialect < cxx11)
   14167                 :             :                   /* Not using maybe_warn_cpp0x because this should
   14168                 :             :                      always be an error.  */
   14169                 :           1 :                   error_at (typespec_loc,
   14170                 :             :                             "trailing return type only available "
   14171                 :             :                             "with %<-std=c++11%> or %<-std=gnu++11%>");
   14172                 :             :                 else
   14173                 :          36 :                   error_at (typespec_loc, "%qs function with trailing "
   14174                 :             :                             "return type not declared with %<auto%> "
   14175                 :             :                             "type specifier", name);
   14176                 :          37 :                 return error_mark_node;
   14177                 :             :               }
   14178                 :   176748384 :             if (late_return_type && sfk == sfk_conversion)
   14179                 :             :               {
   14180                 :          14 :                 error ("a conversion function cannot have a trailing return type");
   14181                 :          14 :                 return error_mark_node;
   14182                 :             :               }
   14183                 :   176748370 :             type = splice_late_return_type (type, late_return_type);
   14184                 :   176748370 :             if (type == error_mark_node)
   14185                 :             :               return error_mark_node;
   14186                 :             : 
   14187                 :   176748294 :             if (late_return_type)
   14188                 :             :               {
   14189                 :     3038989 :                 late_return_type_p = true;
   14190                 :     3038989 :                 type_quals = cp_type_quals (type);
   14191                 :             :               }
   14192                 :             : 
   14193                 :   176748294 :             if (type_quals != TYPE_UNQUALIFIED)
   14194                 :             :               {
   14195                 :             :                 /* It's wrong, for instance, to issue a -Wignored-qualifiers
   14196                 :             :                    warning for
   14197                 :             :                     static_assert(!is_same_v<void(*)(), const void(*)()>);
   14198                 :             :                     because there the qualifier matters.  */
   14199                 :       12439 :                 if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
   14200                 :         232 :                   warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
   14201                 :             :                               "qualifiers ignored on function return type");
   14202                 :             :                 /* [dcl.fct] "A volatile-qualified return type is
   14203                 :             :                    deprecated."  */
   14204                 :       12439 :                 if (type_quals & TYPE_QUAL_VOLATILE)
   14205                 :         599 :                   warning_at (typespec_loc, OPT_Wvolatile,
   14206                 :             :                               "%<volatile%>-qualified return type is "
   14207                 :             :                               "deprecated");
   14208                 :             : 
   14209                 :             :                 /* We now know that the TYPE_QUALS don't apply to the
   14210                 :             :                    decl, but to its return type.  */
   14211                 :             :                 type_quals = TYPE_UNQUALIFIED;
   14212                 :             :               }
   14213                 :             : 
   14214                 :             :             /* Error about some types functions can't return.  */
   14215                 :             : 
   14216                 :   176748294 :             if (TREE_CODE (type) == FUNCTION_TYPE)
   14217                 :             :               {
   14218                 :          30 :                 error_at (typespec_loc, "%qs declared as function returning "
   14219                 :             :                           "a function", name);
   14220                 :          30 :                 return error_mark_node;
   14221                 :             :               }
   14222                 :   176748264 :             if (TREE_CODE (type) == ARRAY_TYPE)
   14223                 :             :               {
   14224                 :           6 :                 error_at (typespec_loc, "%qs declared as function returning "
   14225                 :             :                           "an array", name);
   14226                 :           6 :                 return error_mark_node;
   14227                 :             :               }
   14228                 :   176748258 :             if (constinit_p && funcdecl_p)
   14229                 :             :               {
   14230                 :          15 :                 error_at (declspecs->locations[ds_constinit],
   14231                 :             :                           "%<constinit%> on function return type is not "
   14232                 :             :                           "allowed");
   14233                 :          15 :                 return error_mark_node;
   14234                 :             :               }
   14235                 :             : 
   14236                 :   176748243 :             if (check_decltype_auto (typespec_loc, type))
   14237                 :          49 :               return error_mark_node;
   14238                 :             : 
   14239                 :   176748194 :             if (ctype == NULL_TREE
   14240                 :   176748194 :                 && decl_context == FIELD
   14241                 :             :                 && funcdecl_p
   14242                 :    95801651 :                 && friendp == 0)
   14243                 :    91320177 :               ctype = current_class_type;
   14244                 :             : 
   14245                 :   176748194 :             if (ctype && (sfk == sfk_constructor
   14246                 :    91320177 :                           || sfk == sfk_destructor))
   14247                 :             :               {
   14248                 :             :                 /* We are within a class's scope. If our declarator name
   14249                 :             :                    is the same as the class name, and we are defining
   14250                 :             :                    a function, then it is a constructor/destructor, and
   14251                 :             :                    therefore returns a void type.  */
   14252                 :             : 
   14253                 :             :                 /* ISO C++ 12.4/2.  A destructor may not be declared
   14254                 :             :                    const or volatile.  A destructor may not be static.
   14255                 :             :                    A destructor may not be declared with ref-qualifier.
   14256                 :             : 
   14257                 :             :                    ISO C++ 12.1.  A constructor may not be declared
   14258                 :             :                    const or volatile.  A constructor may not be
   14259                 :             :                    virtual.  A constructor may not be static.
   14260                 :             :                    A constructor may not be declared with ref-qualifier. */
   14261                 :    24828937 :                 if (staticp == 2)
   14262                 :           9 :                   error_at (declspecs->locations[ds_storage_class],
   14263                 :             :                             (flags == DTOR_FLAG)
   14264                 :             :                             ? G_("destructor cannot be static member "
   14265                 :             :                                  "function")
   14266                 :             :                             : G_("constructor cannot be static member "
   14267                 :             :                                  "function"));
   14268                 :    24828937 :                 if (memfn_quals)
   14269                 :             :                   {
   14270                 :           9 :                     error ((flags == DTOR_FLAG)
   14271                 :             :                            ? G_("destructors may not be cv-qualified")
   14272                 :             :                            : G_("constructors may not be cv-qualified"));
   14273                 :           9 :                     memfn_quals = TYPE_UNQUALIFIED;
   14274                 :             :                   }
   14275                 :             : 
   14276                 :    24828937 :                 if (rqual)
   14277                 :             :                   {
   14278                 :           6 :                     maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
   14279                 :           6 :                     error ((flags == DTOR_FLAG)
   14280                 :             :                            ? G_("destructors may not be ref-qualified")
   14281                 :             :                            : G_("constructors may not be ref-qualified"));
   14282                 :           6 :                     rqual = REF_QUAL_NONE;
   14283                 :             :                   }
   14284                 :             : 
   14285                 :    24828937 :                 if (decl_context == FIELD
   14286                 :    24828937 :                     && !member_function_or_else (ctype,
   14287                 :             :                                                  current_class_type,
   14288                 :             :                                                  flags))
   14289                 :           0 :                   return error_mark_node;
   14290                 :             : 
   14291                 :    24828937 :                 if (flags != DTOR_FLAG)
   14292                 :             :                   {
   14293                 :             :                     /* It's a constructor.  */
   14294                 :    21808351 :                     if (explicitp == 1)
   14295                 :     5292080 :                       explicitp = 2;
   14296                 :    21808351 :                     if (virtualp)
   14297                 :             :                       {
   14298                 :           3 :                         permerror (declspecs->locations[ds_virtual],
   14299                 :             :                                    "constructors cannot be declared %<virtual%>");
   14300                 :           3 :                         virtualp = 0;
   14301                 :             :                       }
   14302                 :    21808351 :                     if (decl_context == FIELD
   14303                 :    21808351 :                         && sfk != sfk_constructor)
   14304                 :           0 :                       return error_mark_node;
   14305                 :             :                   }
   14306                 :    24828937 :                 if (decl_context == FIELD)
   14307                 :    24828937 :                   staticp = 0;
   14308                 :             :               }
   14309                 :   151919257 :             else if (friendp)
   14310                 :             :               {
   14311                 :     4169984 :                 if (virtualp)
   14312                 :             :                   {
   14313                 :             :                     /* Cannot be both friend and virtual.  */
   14314                 :          12 :                     gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   14315                 :          12 :                     richloc.add_range (declspecs->locations[ds_friend]);
   14316                 :          12 :                     error_at (&richloc, "virtual functions cannot be friends");
   14317                 :          12 :                     friendp = 0;
   14318                 :          12 :                   }
   14319                 :     4169984 :                 if (decl_context == NORMAL)
   14320                 :           0 :                   error_at (declarator->id_loc,
   14321                 :             :                             "friend declaration not in class definition");
   14322                 :     4169984 :                 if (current_function_decl && funcdef_flag)
   14323                 :             :                   {
   14324                 :           9 :                     error_at (declarator->id_loc,
   14325                 :             :                               "cannot define friend function %qs in a local "
   14326                 :             :                               "class definition", name);
   14327                 :           9 :                     friendp = 0;
   14328                 :             :                   }
   14329                 :             :                 /* [class.friend]/6: A function can be defined in a friend
   14330                 :             :                    declaration if the function name is unqualified.  */
   14331                 :     4169984 :                 if (funcdef_flag && in_namespace)
   14332                 :             :                   {
   14333                 :           6 :                     if (in_namespace == global_namespace)
   14334                 :           3 :                       error_at (declarator->id_loc,
   14335                 :             :                                 "friend function definition %qs cannot have "
   14336                 :             :                                 "a name qualified with %<::%>", name);
   14337                 :             :                     else
   14338                 :           3 :                       error_at (declarator->id_loc,
   14339                 :             :                                 "friend function definition %qs cannot have "
   14340                 :             :                                 "a name qualified with %<%D::%>", name,
   14341                 :             :                                 in_namespace);
   14342                 :             :                   }
   14343                 :             :               }
   14344                 :   147749273 :             else if (ctype && sfk == sfk_conversion)
   14345                 :             :               {
   14346                 :      639690 :                 if (explicitp == 1)
   14347                 :             :                   {
   14348                 :      303763 :                     maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
   14349                 :      303763 :                     explicitp = 2;
   14350                 :             :                   }
   14351                 :             :               }
   14352                 :   147109583 :             else if (sfk == sfk_deduction_guide)
   14353                 :             :               {
   14354                 :     1079434 :                 if (explicitp == 1)
   14355                 :   176748194 :                   explicitp = 2;
   14356                 :             :               }
   14357                 :             : 
   14358                 :   176748194 :             if (xobj_parm)
   14359                 :             :               {
   14360                 :       27177 :                 if (!ctype
   14361                 :       27177 :                     && decl_context == NORMAL
   14362                 :          49 :                     && (in_namespace
   14363                 :          49 :                         || !declarator->declarator->u.id.qualifying_scope))
   14364                 :           4 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   14365                 :             :                             "a non-member function cannot have "
   14366                 :             :                             "an explicit object parameter");
   14367                 :             :                 else
   14368                 :             :                   {
   14369                 :       27173 :                     if (virtualp)
   14370                 :             :                       {
   14371                 :          16 :                         auto_diagnostic_group d;
   14372                 :          16 :                         error_at (declspecs->locations[ds_virtual],
   14373                 :             :                                   "an explicit object member function cannot "
   14374                 :             :                                   "be %<virtual%>");
   14375                 :          16 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   14376                 :             :                                 "explicit object parameter declared here");
   14377                 :          16 :                         virtualp = false;
   14378                 :          16 :                       }
   14379                 :       27173 :                     if (staticp >= 2)
   14380                 :             :                       {
   14381                 :           2 :                         auto_diagnostic_group d;
   14382                 :           2 :                         error_at (declspecs->locations[ds_storage_class],
   14383                 :             :                                   "an explicit object member function cannot "
   14384                 :             :                                   "be %<static%>");
   14385                 :           2 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   14386                 :             :                                 "explicit object parameter declared here");
   14387                 :           2 :                       }
   14388                 :       27173 :                     if (unqualified_id
   14389                 :   176775361 :                         && identifier_p (unqualified_id)
   14390                 :       54340 :                         && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   14391                 :           8 :                       error_at (DECL_SOURCE_LOCATION (xobj_parm),
   14392                 :             :                                 "%qD cannot be an explicit object member "
   14393                 :             :                                 "function", unqualified_id);
   14394                 :             :                   }
   14395                 :             :               }
   14396                 :   176748194 :             tree pushed_scope = NULL_TREE;
   14397                 :   176748194 :             if (funcdecl_p
   14398                 :   176748194 :                 && decl_context != FIELD
   14399                 :    78773509 :                 && inner_declarator->u.id.qualifying_scope
   14400                 :   186007310 :                 && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
   14401                 :     9257797 :               pushed_scope
   14402                 :     9257797 :                 = push_scope (inner_declarator->u.id.qualifying_scope);
   14403                 :             : 
   14404                 :   176748194 :             arg_types = grokparms (declarator->u.function.parameters, &parms);
   14405                 :             : 
   14406                 :   176748194 :             if (pushed_scope)
   14407                 :     9257797 :               pop_scope (pushed_scope);
   14408                 :             : 
   14409                 :   176748194 :             if (inner_declarator
   14410                 :   176254573 :                 && inner_declarator->kind == cdk_id
   14411                 :   174263670 :                 && inner_declarator->u.id.sfk == sfk_destructor
   14412                 :     3197072 :                 && arg_types != void_list_node)
   14413                 :             :               {
   14414                 :          20 :                 error_at (declarator->id_loc,
   14415                 :             :                           "destructors may not have parameters");
   14416                 :          20 :                 arg_types = void_list_node;
   14417                 :          20 :                 parms = NULL_TREE;
   14418                 :          20 :                 is_xobj_member_function = false;
   14419                 :             :               }
   14420                 :             : 
   14421                 :   176748194 :             type = build_function_type (type, arg_types);
   14422                 :             : 
   14423                 :   176748194 :             tree attrs = declarator->std_attributes;
   14424                 :   176748194 :             if (tx_qual)
   14425                 :             :               {
   14426                 :         242 :                 tree att = build_tree_list (tx_qual, NULL_TREE);
   14427                 :             :                 /* transaction_safe applies to the type, but
   14428                 :             :                    transaction_safe_dynamic applies to the function.  */
   14429                 :         242 :                 if (is_attribute_p ("transaction_safe", tx_qual))
   14430                 :         213 :                   attrs = attr_chainon (attrs, att);
   14431                 :             :                 else
   14432                 :          29 :                   returned_attrs = attr_chainon (returned_attrs, att);
   14433                 :             :               }
   14434                 :             : 
   14435                 :             :             /* Actually apply the contract attributes to the declaration.  */
   14436                 :   176749348 :             for (tree *p = &attrs; *p;)
   14437                 :             :               {
   14438                 :        1154 :                 tree l = *p;
   14439                 :        1154 :                 if (cxx_contract_attribute_p (l))
   14440                 :             :                   {
   14441                 :         667 :                     *p = TREE_CHAIN (l);
   14442                 :             :                     /* Intentionally reverse order of contracts so they're
   14443                 :             :                        reversed back into their lexical order.  */
   14444                 :         667 :                     TREE_CHAIN (l) = NULL_TREE;
   14445                 :         667 :                     returned_attrs = chainon (l, returned_attrs);
   14446                 :             :                   }
   14447                 :             :                 else
   14448                 :         487 :                   p = &TREE_CHAIN (l);
   14449                 :             :              }
   14450                 :             : 
   14451                 :   176748194 :             if (attrs)
   14452                 :             :               /* [dcl.fct]/2:
   14453                 :             : 
   14454                 :             :                  The optional attribute-specifier-seq appertains to
   14455                 :             :                  the function type.  */
   14456                 :         475 :               cplus_decl_attributes (&type, attrs, 0);
   14457                 :             : 
   14458                 :   176748194 :             if (raises)
   14459                 :    68774307 :               type = build_exception_variant (type, raises);
   14460                 :             :           }
   14461                 :   176748194 :           break;
   14462                 :             : 
   14463                 :   182070897 :         case cdk_pointer:
   14464                 :   182070897 :         case cdk_reference:
   14465                 :   182070897 :         case cdk_ptrmem:
   14466                 :             :           /* Filter out pointers-to-references and references-to-references.
   14467                 :             :              We can get these if a TYPE_DECL is used.  */
   14468                 :             : 
   14469                 :   182070897 :           if (TYPE_REF_P (type))
   14470                 :             :             {
   14471                 :         238 :               if (declarator->kind != cdk_reference)
   14472                 :             :                 {
   14473                 :           3 :                   error ("cannot declare pointer to %q#T", type);
   14474                 :           3 :                   type = TREE_TYPE (type);
   14475                 :             :                 }
   14476                 :             : 
   14477                 :             :               /* In C++0x, we allow reference to reference declarations
   14478                 :             :                  that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
   14479                 :             :                  and template type arguments [14.3.1/4 temp.arg.type]. The
   14480                 :             :                  check for direct reference to reference declarations, which
   14481                 :             :                  are still forbidden, occurs below. Reasoning behind the change
   14482                 :             :                  can be found in DR106, DR540, and the rvalue reference
   14483                 :             :                  proposals. */
   14484                 :         235 :               else if (cxx_dialect == cxx98)
   14485                 :             :                 {
   14486                 :           0 :                   error ("cannot declare reference to %q#T", type);
   14487                 :           0 :                   type = TREE_TYPE (type);
   14488                 :             :                 }
   14489                 :             :             }
   14490                 :   182070659 :           else if (VOID_TYPE_P (type))
   14491                 :             :             {
   14492                 :     4713362 :               if (declarator->kind == cdk_reference)
   14493                 :           4 :                 error ("cannot declare reference to %q#T", type);
   14494                 :     4713358 :               else if (declarator->kind == cdk_ptrmem)
   14495                 :           3 :                 error ("cannot declare pointer to %q#T member", type);
   14496                 :             :             }
   14497                 :             : 
   14498                 :             :           /* We now know that the TYPE_QUALS don't apply to the decl,
   14499                 :             :              but to the target of the pointer.  */
   14500                 :   182070897 :           type_quals = TYPE_UNQUALIFIED;
   14501                 :             : 
   14502                 :             :           /* This code used to handle METHOD_TYPE, but I don't think it's
   14503                 :             :              possible to get it here anymore.  */
   14504                 :   182070897 :           gcc_assert (TREE_CODE (type) != METHOD_TYPE);
   14505                 :   182070897 :           if (declarator->kind == cdk_ptrmem
   14506                 :     1223160 :               && TREE_CODE (type) == FUNCTION_TYPE)
   14507                 :             :             {
   14508                 :     1022007 :               memfn_quals |= type_memfn_quals (type);
   14509                 :     2044014 :               type = build_memfn_type (type,
   14510                 :     1022007 :                                        declarator->u.pointer.class_type,
   14511                 :             :                                        memfn_quals,
   14512                 :             :                                        rqual);
   14513                 :     1022007 :               if (type == error_mark_node)
   14514                 :             :                 return error_mark_node;
   14515                 :             : 
   14516                 :             :               rqual = REF_QUAL_NONE;
   14517                 :             :               memfn_quals = TYPE_UNQUALIFIED;
   14518                 :             :             }
   14519                 :             : 
   14520                 :   182070894 :           if (TREE_CODE (type) == FUNCTION_TYPE
   14521                 :   182070894 :               && (type_memfn_quals (type) != TYPE_UNQUALIFIED
   14522                 :     1028437 :                   || type_memfn_rqual (type) != REF_QUAL_NONE))
   14523                 :          15 :             error (declarator->kind == cdk_reference
   14524                 :             :                    ? G_("cannot declare reference to qualified function type %qT")
   14525                 :             :                    : G_("cannot declare pointer to qualified function type %qT"),
   14526                 :             :                    type);
   14527                 :             : 
   14528                 :             :           /* When the pointed-to type involves components of variable size,
   14529                 :             :              care must be taken to ensure that the size evaluation code is
   14530                 :             :              emitted early enough to dominate all the possible later uses
   14531                 :             :              and late enough for the variables on which it depends to have
   14532                 :             :              been assigned.
   14533                 :             : 
   14534                 :             :              This is expected to happen automatically when the pointed-to
   14535                 :             :              type has a name/declaration of it's own, but special attention
   14536                 :             :              is required if the type is anonymous.
   14537                 :             : 
   14538                 :             :              We handle the NORMAL and FIELD contexts here by inserting a
   14539                 :             :              dummy statement that just evaluates the size at a safe point
   14540                 :             :              and ensures it is not deferred until e.g. within a deeper
   14541                 :             :              conditional context (c++/43555).
   14542                 :             : 
   14543                 :             :              We expect nothing to be needed here for PARM or TYPENAME.
   14544                 :             :              Evaluating the size at this point for TYPENAME would
   14545                 :             :              actually be incorrect, as we might be in the middle of an
   14546                 :             :              expression with side effects on the pointed-to type size
   14547                 :             :              "arguments" prior to the pointer declaration point and the
   14548                 :             :              size evaluation could end up prior to the side effects.  */
   14549                 :             : 
   14550                 :   182070894 :           if (!TYPE_NAME (type)
   14551                 :     5506220 :               && (decl_context == NORMAL || decl_context == FIELD)
   14552                 :      623634 :               && at_function_scope_p ()
   14553                 :   182113133 :               && variably_modified_type_p (type, NULL_TREE))
   14554                 :             :             {
   14555                 :          96 :               TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
   14556                 :             :                                              NULL_TREE, type);
   14557                 :          96 :               add_decl_expr (TYPE_NAME (type));
   14558                 :             :             }
   14559                 :             : 
   14560                 :   182070894 :           if (declarator->kind == cdk_reference)
   14561                 :             :             {
   14562                 :             :               /* In C++0x, the type we are creating a reference to might be
   14563                 :             :                  a typedef which is itself a reference type. In that case,
   14564                 :             :                  we follow the reference collapsing rules in
   14565                 :             :                  [7.1.3/8 dcl.typedef] to create the final reference type:
   14566                 :             : 
   14567                 :             :                  "If a typedef TD names a type that is a reference to a type
   14568                 :             :                  T, an attempt to create the type 'lvalue reference to cv TD'
   14569                 :             :                  creates the type 'lvalue reference to T,' while an attempt
   14570                 :             :                  to create the type "rvalue reference to cv TD' creates the
   14571                 :             :                  type TD."
   14572                 :             :               */
   14573                 :   119274458 :               if (VOID_TYPE_P (type))
   14574                 :             :                 /* We already gave an error.  */;
   14575                 :   119274454 :               else if (TYPE_REF_P (type))
   14576                 :             :                 {
   14577                 :         235 :                   if (declarator->u.reference.rvalue_ref)
   14578                 :             :                     /* Leave type alone.  */;
   14579                 :             :                   else
   14580                 :         116 :                     type = cp_build_reference_type (TREE_TYPE (type), false);
   14581                 :             :                 }
   14582                 :             :               else
   14583                 :   119274219 :                 type = cp_build_reference_type
   14584                 :   119274219 :                   (type, declarator->u.reference.rvalue_ref);
   14585                 :             : 
   14586                 :             :               /* In C++0x, we need this check for direct reference to
   14587                 :             :                  reference declarations, which are forbidden by
   14588                 :             :                  [8.3.2/5 dcl.ref]. Reference to reference declarations
   14589                 :             :                  are only allowed indirectly through typedefs and template
   14590                 :             :                  type arguments. Example:
   14591                 :             : 
   14592                 :             :                    void foo(int & &);      // invalid ref-to-ref decl
   14593                 :             : 
   14594                 :             :                    typedef int & int_ref;
   14595                 :             :                    void foo(int_ref &);    // valid ref-to-ref decl
   14596                 :             :               */
   14597                 :   119274458 :               if (inner_declarator && inner_declarator->kind == cdk_reference)
   14598                 :           0 :                 error ("cannot declare reference to %q#T, which is not "
   14599                 :             :                        "a typedef or a template type argument", type);
   14600                 :             :             }
   14601                 :    62796436 :           else if (TREE_CODE (type) == METHOD_TYPE)
   14602                 :     1022004 :             type = build_ptrmemfunc_type (build_pointer_type (type));
   14603                 :    61774432 :           else if (declarator->kind == cdk_ptrmem)
   14604                 :             :             {
   14605                 :      201153 :               gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
   14606                 :             :                           != NAMESPACE_DECL);
   14607                 :      201153 :               if (declarator->u.pointer.class_type == error_mark_node)
   14608                 :             :                 /* We will already have complained.  */
   14609                 :           3 :                 type = error_mark_node;
   14610                 :             :               else
   14611                 :      201150 :                 type = build_ptrmem_type (declarator->u.pointer.class_type,
   14612                 :             :                                           type);
   14613                 :             :             }
   14614                 :             :           else
   14615                 :    61573279 :             type = build_pointer_type (type);
   14616                 :             : 
   14617                 :             :           /* Process a list of type modifier keywords (such as
   14618                 :             :              const or volatile) that were given inside the `*' or `&'.  */
   14619                 :             : 
   14620                 :   182070894 :           if (declarator->u.pointer.qualifiers)
   14621                 :             :             {
   14622                 :     8601978 :               type
   14623                 :     8601978 :                 = cp_build_qualified_type (type,
   14624                 :             :                                            declarator->u.pointer.qualifiers);
   14625                 :     8601978 :               type_quals = cp_type_quals (type);
   14626                 :             :             }
   14627                 :             : 
   14628                 :             :           /* Apply C++11 attributes to the pointer, and not to the
   14629                 :             :              type pointed to.  This is unlike what is done for GNU
   14630                 :             :              attributes above.  It is to comply with [dcl.ptr]/1:
   14631                 :             : 
   14632                 :             :                  [the optional attribute-specifier-seq (7.6.1) appertains
   14633                 :             :                   to the pointer and not to the object pointed to].  */
   14634                 :   182070894 :           if (declarator->std_attributes)
   14635                 :         157 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   14636                 :             : 
   14637                 :             :           ctype = NULL_TREE;
   14638                 :             :           break;
   14639                 :             : 
   14640                 :             :         case cdk_error:
   14641                 :             :           break;
   14642                 :             : 
   14643                 :           0 :         default:
   14644                 :           0 :           gcc_unreachable ();
   14645                 :             :         }
   14646                 :             :     }
   14647                 :             : 
   14648                 :   927221339 :   id_loc = declarator ? declarator->id_loc : input_location;
   14649                 :             : 
   14650                 :   927221339 :   if (innermost_code != cdk_function
   14651                 :             :     /* Don't check this if it can be the artifical decltype(auto)
   14652                 :             :        we created when building a constraint in a compound-requirement:
   14653                 :             :        that the type-constraint is plain is going to be checked in
   14654                 :             :        cp_parser_compound_requirement.  */
   14655                 :   927221339 :       && decl_context != TYPENAME
   14656                 :   927221339 :       && check_decltype_auto (id_loc, type))
   14657                 :          19 :     return error_mark_node;
   14658                 :             : 
   14659                 :             :   /* A `constexpr' specifier used in an object declaration declares
   14660                 :             :      the object as `const'.  */
   14661                 :   927221320 :   if (constexpr_p && innermost_code != cdk_function)
   14662                 :             :     {
   14663                 :             :       /* DR1688 says that a `constexpr' specifier in combination with
   14664                 :             :          `volatile' is valid.  */
   14665                 :             : 
   14666                 :    13805293 :       if (!TYPE_REF_P (type))
   14667                 :             :         {
   14668                 :    13795269 :           type_quals |= TYPE_QUAL_CONST;
   14669                 :    13795269 :           type = cp_build_qualified_type (type, type_quals);
   14670                 :             :         }
   14671                 :             :     }
   14672                 :             : 
   14673                 :   537152144 :   if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
   14674                 :     1937546 :       && !FUNC_OR_METHOD_TYPE_P (type)
   14675                 :   928254694 :       && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
   14676                 :             :     {
   14677                 :           0 :       error ("template-id %qD used as a declarator",
   14678                 :             :              unqualified_id);
   14679                 :           0 :       unqualified_id = dname;
   14680                 :             :     }
   14681                 :             : 
   14682                 :             :   /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
   14683                 :             :      qualified with a class-name, turn it into a METHOD_TYPE, unless
   14684                 :             :      we know that the function is static.  We take advantage of this
   14685                 :             :      opportunity to do other processing that pertains to entities
   14686                 :             :      explicitly declared to be class members.  Note that if DECLARATOR
   14687                 :             :      is non-NULL, we know it is a cdk_id declarator; otherwise, we
   14688                 :             :      would not have exited the loop above.  */
   14689                 :   927221320 :   if (declarator
   14690                 :   537236037 :       && declarator->kind == cdk_id
   14691                 :   537152144 :       && declarator->u.id.qualifying_scope
   14692                 :   937032246 :       && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
   14693                 :             :     {
   14694                 :     9654828 :       ctype = declarator->u.id.qualifying_scope;
   14695                 :     9654828 :       ctype = TYPE_MAIN_VARIANT (ctype);
   14696                 :     9654828 :       template_count = num_template_headers_for_class (ctype);
   14697                 :             : 
   14698                 :     9654828 :       if (ctype == current_class_type)
   14699                 :             :         {
   14700                 :          54 :           if (friendp)
   14701                 :             :             {
   14702                 :          15 :               permerror (declspecs->locations[ds_friend],
   14703                 :             :                          "member functions are implicitly "
   14704                 :             :                          "friends of their class");
   14705                 :          15 :               friendp = 0;
   14706                 :             :             }
   14707                 :             :           else
   14708                 :          39 :             permerror (id_loc, "extra qualification %<%T::%> on member %qs",
   14709                 :             :                        ctype, name);
   14710                 :             :         }
   14711                 :     9654774 :       else if (/* If the qualifying type is already complete, then we
   14712                 :             :                   can skip the following checks.  */
   14713                 :     9654774 :                !COMPLETE_TYPE_P (ctype)
   14714                 :         150 :                && (/* If the function is being defined, then
   14715                 :             :                       qualifying type must certainly be complete.  */
   14716                 :             :                    funcdef_flag
   14717                 :             :                    /* A friend declaration of "T::f" is OK, even if
   14718                 :             :                       "T" is a template parameter.  But, if this
   14719                 :             :                       function is not a friend, the qualifying type
   14720                 :             :                       must be a class.  */
   14721                 :         111 :                    || (!friendp && !CLASS_TYPE_P (ctype))
   14722                 :             :                    /* For a declaration, the type need not be
   14723                 :             :                       complete, if either it is dependent (since there
   14724                 :             :                       is no meaningful definition of complete in that
   14725                 :             :                       case) or the qualifying class is currently being
   14726                 :             :                       defined.  */
   14727                 :         123 :                    || !(dependent_type_p (ctype)
   14728                 :          24 :                         || currently_open_class (ctype)))
   14729                 :             :                /* Check that the qualifying type is complete.  */
   14730                 :     9654840 :                && !complete_type_or_else (ctype, NULL_TREE))
   14731                 :          66 :         return error_mark_node;
   14732                 :     9654708 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   14733                 :             :         {
   14734                 :     9258034 :           if (current_class_type
   14735                 :         264 :               && (!friendp || funcdef_flag || initialized))
   14736                 :             :             {
   14737                 :          59 :               error_at (id_loc, funcdef_flag || initialized
   14738                 :             :                         ? G_("cannot define member function %<%T::%s%> "
   14739                 :             :                              "within %qT")
   14740                 :             :                         : G_("cannot declare member function %<%T::%s%> "
   14741                 :             :                              "within %qT"),
   14742                 :             :                         ctype, name, current_class_type);
   14743                 :          49 :               return error_mark_node;
   14744                 :             :             }
   14745                 :             :         }
   14746                 :      396674 :       else if (typedef_p && current_class_type)
   14747                 :             :         {
   14748                 :           0 :           error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
   14749                 :             :                     ctype, name, current_class_type);
   14750                 :           0 :           return error_mark_node;
   14751                 :             :         }
   14752                 :             :     }
   14753                 :             : 
   14754                 :   927221205 :   if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
   14755                 :    52083314 :     ctype = current_class_type;
   14756                 :             : 
   14757                 :             :   /* Now TYPE has the actual type.  */
   14758                 :             : 
   14759                 :   927221205 :   if (returned_attrs)
   14760                 :             :     {
   14761                 :        3337 :       if (attrlist)
   14762                 :        3337 :         *attrlist = attr_chainon (returned_attrs, *attrlist);
   14763                 :             :       else
   14764                 :             :         attrlist = &returned_attrs;
   14765                 :             :     }
   14766                 :             : 
   14767                 :   927221205 :   if (declarator
   14768                 :   537235922 :       && declarator->kind == cdk_id
   14769                 :   537152029 :       && declarator->std_attributes
   14770                 :      361410 :       && attrlist != NULL)
   14771                 :             :     {
   14772                 :             :       /* [dcl.meaning]/1: The optional attribute-specifier-seq following
   14773                 :             :          a declarator-id appertains to the entity that is declared.  */
   14774                 :      361407 :       if (declarator->std_attributes != error_mark_node)
   14775                 :      361389 :         *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
   14776                 :             :       else
   14777                 :             :         /* We should have already diagnosed the issue (c++/78344).  */
   14778                 :          18 :         gcc_assert (seen_error ());
   14779                 :             :     }
   14780                 :             : 
   14781                 :             :   /* Handle parameter packs. */
   14782                 :   927221205 :   if (parameter_pack_p)
   14783                 :             :     {
   14784                 :     2960816 :       if (decl_context == PARM)
   14785                 :             :         /* Turn the type into a pack expansion.*/
   14786                 :     2960816 :         type = make_pack_expansion (type);
   14787                 :             :       else
   14788                 :           0 :         error ("non-parameter %qs cannot be a parameter pack", name);
   14789                 :             :     }
   14790                 :             : 
   14791                 :   927221205 :   if ((decl_context == FIELD || decl_context == PARM)
   14792                 :   426033428 :       && !processing_template_decl
   14793                 :  1062261210 :       && variably_modified_type_p (type, NULL_TREE))
   14794                 :             :     {
   14795                 :          12 :       if (decl_context == FIELD)
   14796                 :           6 :         error_at (id_loc,
   14797                 :             :                   "data member may not have variably modified type %qT", type);
   14798                 :             :       else
   14799                 :           6 :         error_at (id_loc,
   14800                 :             :                   "parameter may not have variably modified type %qT", type);
   14801                 :          12 :       type = error_mark_node;
   14802                 :             :     }
   14803                 :             : 
   14804                 :   927221205 :   if (explicitp == 1 || (explicitp && friendp))
   14805                 :             :     {
   14806                 :             :       /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
   14807                 :             :          in the declaration of a constructor or conversion function within
   14808                 :             :          a class definition.  */
   14809                 :          42 :       if (!current_class_type)
   14810                 :          27 :         error_at (declspecs->locations[ds_explicit],
   14811                 :             :                   "%<explicit%> outside class declaration");
   14812                 :          15 :       else if (friendp)
   14813                 :          12 :         error_at (declspecs->locations[ds_explicit],
   14814                 :             :                   "%<explicit%> in friend declaration");
   14815                 :             :       else
   14816                 :           3 :         error_at (declspecs->locations[ds_explicit],
   14817                 :             :                   "only declarations of constructors and conversion operators "
   14818                 :             :                   "can be %<explicit%>");
   14819                 :             :       explicitp = 0;
   14820                 :             :     }
   14821                 :             : 
   14822                 :   927221205 :   if (storage_class == sc_mutable)
   14823                 :             :     {
   14824                 :      149499 :       location_t sloc = declspecs->locations[ds_storage_class];
   14825                 :      149499 :       if (decl_context != FIELD || friendp)
   14826                 :             :         {
   14827                 :          18 :           error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
   14828                 :             :                     name);
   14829                 :          18 :           storage_class = sc_none;
   14830                 :             :         }
   14831                 :      149481 :       else if (decl_context == TYPENAME || typedef_p)
   14832                 :             :         {
   14833                 :           0 :           error_at (sloc,
   14834                 :             :                     "non-object member %qs cannot be declared %<mutable%>",
   14835                 :             :                     name);
   14836                 :           0 :           storage_class = sc_none;
   14837                 :             :         }
   14838                 :      149481 :       else if (FUNC_OR_METHOD_TYPE_P (type))
   14839                 :             :         {
   14840                 :           3 :           error_at (sloc, "function %qs cannot be declared %<mutable%>",
   14841                 :             :                     name);
   14842                 :           3 :           storage_class = sc_none;
   14843                 :             :         }
   14844                 :      149478 :       else if (staticp)
   14845                 :             :         {
   14846                 :           0 :           error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
   14847                 :             :                     name);
   14848                 :           0 :           storage_class = sc_none;
   14849                 :             :         }
   14850                 :      149478 :       else if (type_quals & TYPE_QUAL_CONST)
   14851                 :             :         {
   14852                 :           9 :           error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
   14853                 :             :                     name);
   14854                 :           9 :           storage_class = sc_none;
   14855                 :             :         }
   14856                 :      149469 :       else if (TYPE_REF_P (type))
   14857                 :             :         {
   14858                 :           6 :           permerror (sloc, "reference %qs cannot be declared %<mutable%>",
   14859                 :             :                      name);
   14860                 :           6 :           storage_class = sc_none;
   14861                 :             :         }
   14862                 :             :     }
   14863                 :             : 
   14864                 :             :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
   14865                 :   927221205 :   if (typedef_p && decl_context != TYPENAME)
   14866                 :             :     {
   14867                 :    44373103 :       bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
   14868                 :    44373103 :       tree decl;
   14869                 :             : 
   14870                 :    44373103 :       if (funcdef_flag)
   14871                 :             :         {
   14872                 :           6 :           if (decl_context == NORMAL)
   14873                 :           3 :             error_at (id_loc,
   14874                 :             :                       "typedef may not be a function definition");
   14875                 :             :           else
   14876                 :           3 :             error_at (id_loc,
   14877                 :             :                       "typedef may not be a member function definition");
   14878                 :           6 :           return error_mark_node;
   14879                 :             :         }
   14880                 :             : 
   14881                 :             :       /* This declaration:
   14882                 :             : 
   14883                 :             :            typedef void f(int) const;
   14884                 :             : 
   14885                 :             :          declares a function type which is not a member of any
   14886                 :             :          particular class, but which is cv-qualified; for
   14887                 :             :          example "f S::*" declares a pointer to a const-qualified
   14888                 :             :          member function of S.  We record the cv-qualification in the
   14889                 :             :          function type.  */
   14890                 :    44373097 :       if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
   14891                 :             :         {
   14892                 :          62 :           type = apply_memfn_quals (type, memfn_quals, rqual);
   14893                 :             : 
   14894                 :             :           /* We have now dealt with these qualifiers.  */
   14895                 :          62 :           memfn_quals = TYPE_UNQUALIFIED;
   14896                 :          62 :           rqual = REF_QUAL_NONE;
   14897                 :             :         }
   14898                 :             : 
   14899                 :    44373097 :       if (type_uses_auto (type))
   14900                 :             :         {
   14901                 :          47 :           if (alias_p)
   14902                 :          19 :             error_at (declspecs->locations[ds_type_spec],
   14903                 :             :                       "%<auto%> not allowed in alias declaration");
   14904                 :             :           else
   14905                 :          28 :             error_at (declspecs->locations[ds_type_spec],
   14906                 :             :                       "typedef declared %<auto%>");
   14907                 :          47 :           type = error_mark_node;
   14908                 :             :         }
   14909                 :             : 
   14910                 :    44373097 :       if (reqs)
   14911                 :           3 :         error_at (location_of (reqs), "requires-clause on typedef");
   14912                 :             : 
   14913                 :    44373097 :       if (id_declarator && declarator->u.id.qualifying_scope)
   14914                 :             :         {
   14915                 :          22 :           error_at (id_loc, "typedef name may not be a nested-name-specifier");
   14916                 :          22 :           type = error_mark_node;
   14917                 :             :         }
   14918                 :             : 
   14919                 :    44373097 :       if (decl_context == FIELD)
   14920                 :    24137271 :         decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
   14921                 :             :       else
   14922                 :    20235826 :         decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
   14923                 :             : 
   14924                 :    44373097 :       if (decl_context != FIELD)
   14925                 :             :         {
   14926                 :    20235826 :           if (!current_function_decl)
   14927                 :     8535784 :             DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   14928                 :    11700042 :           else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
   14929                 :             :             /* The TYPE_DECL is "abstract" because there will be
   14930                 :             :                clones of this constructor/destructor, and there will
   14931                 :             :                be copies of this TYPE_DECL generated in those
   14932                 :             :                clones.  The decloning optimization (for space) may
   14933                 :             :                revert this subsequently if it determines that
   14934                 :             :                the clones should share a common implementation.  */
   14935                 :      157193 :             DECL_ABSTRACT_P (decl) = true;
   14936                 :             : 
   14937                 :    20235826 :           set_originating_module (decl);
   14938                 :             :         }
   14939                 :    24137271 :       else if (current_class_type
   14940                 :    24137271 :                && constructor_name_p (unqualified_id, current_class_type))
   14941                 :           3 :         permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
   14942                 :             :                    "as enclosing class",
   14943                 :             :                    unqualified_id);
   14944                 :             : 
   14945                 :             :       /* If the user declares "typedef struct {...} foo" then the
   14946                 :             :          struct will have an anonymous name.  Fill that name in now.
   14947                 :             :          Nothing can refer to it, so nothing needs know about the name
   14948                 :             :          change.  */
   14949                 :    44373097 :       if (type != error_mark_node
   14950                 :    44373028 :           && unqualified_id
   14951                 :    44373025 :           && TYPE_NAME (type)
   14952                 :    41434376 :           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   14953                 :    82958780 :           && TYPE_UNNAMED_P (type)
   14954                 :      399961 :           && declspecs->type_definition_p
   14955                 :      399891 :           && attributes_naming_typedef_ok (*attrlist)
   14956                 :    44772985 :           && cp_type_quals (type) == TYPE_UNQUALIFIED)
   14957                 :      399870 :         name_unnamed_type (type, decl);
   14958                 :             : 
   14959                 :    44373097 :       if (signed_p
   14960                 :    44373097 :           || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
   14961                 :      385701 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
   14962                 :             : 
   14963                 :    44373097 :       bad_specifiers (decl, BSP_TYPE, virtualp,
   14964                 :             :                       memfn_quals != TYPE_UNQUALIFIED,
   14965                 :             :                       inlinep, friendp, raises != NULL_TREE,
   14966                 :             :                       declspecs->locations);
   14967                 :             : 
   14968                 :    44373097 :       if (alias_p)
   14969                 :             :         /* Acknowledge that this was written:
   14970                 :             :              `using analias = atype;'.  */
   14971                 :    16885915 :         TYPE_DECL_ALIAS_P (decl) = 1;
   14972                 :             : 
   14973                 :    44373097 :       return decl;
   14974                 :             :     }
   14975                 :             : 
   14976                 :             :   /* Detect the case of an array type of unspecified size
   14977                 :             :      which came, as such, direct from a typedef name.
   14978                 :             :      We must copy the type, so that the array's domain can be
   14979                 :             :      individually set by the object's initializer.  */
   14980                 :             : 
   14981                 :   882848102 :   if (type && typedef_type
   14982                 :   855316782 :       && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
   14983                 :   883378411 :       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
   14984                 :          79 :     type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   14985                 :             : 
   14986                 :             :   /* Detect where we're using a typedef of function type to declare a
   14987                 :             :      function. PARMS will not be set, so we must create it now.  */
   14988                 :             : 
   14989                 :   882848102 :   if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
   14990                 :             :     {
   14991                 :       15618 :       tree decls = NULL_TREE;
   14992                 :       15618 :       tree args;
   14993                 :             : 
   14994                 :       15618 :       for (args = TYPE_ARG_TYPES (type);
   14995                 :       33702 :            args && args != void_list_node;
   14996                 :       18084 :            args = TREE_CHAIN (args))
   14997                 :             :         {
   14998                 :       18084 :           tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
   14999                 :       18084 :                                           TREE_VALUE (args));
   15000                 :             : 
   15001                 :       18084 :           DECL_CHAIN (decl) = decls;
   15002                 :       18084 :           decls = decl;
   15003                 :             :         }
   15004                 :             : 
   15005                 :       15618 :       parms = nreverse (decls);
   15006                 :             : 
   15007                 :       15618 :       if (decl_context != TYPENAME)
   15008                 :             :         {
   15009                 :             :           /* The qualifiers on the function type become the qualifiers on
   15010                 :             :              the non-static member function. */
   15011                 :       14928 :           memfn_quals |= type_memfn_quals (type);
   15012                 :       14928 :           rqual = type_memfn_rqual (type);
   15013                 :       14928 :           type_quals = TYPE_UNQUALIFIED;
   15014                 :       14928 :           raises = TYPE_RAISES_EXCEPTIONS (type);
   15015                 :             :         }
   15016                 :             :     }
   15017                 :             : 
   15018                 :             :   /* If this is a type name (such as, in a cast or sizeof),
   15019                 :             :      compute the type and return it now.  */
   15020                 :             : 
   15021                 :   882847412 :   if (decl_context == TYPENAME)
   15022                 :             :     {
   15023                 :             :       /* Note that here we don't care about type_quals.  */
   15024                 :             : 
   15025                 :             :       /* Special case: "friend class foo" looks like a TYPENAME context.  */
   15026                 :   345336458 :       if (friendp)
   15027                 :             :         {
   15028                 :           0 :           if (inlinep)
   15029                 :             :             {
   15030                 :           0 :               error ("%<inline%> specified for friend class declaration");
   15031                 :           0 :               inlinep = 0;
   15032                 :             :             }
   15033                 :             : 
   15034                 :           0 :           if (!current_aggr)
   15035                 :             :             {
   15036                 :             :               /* Don't allow friend declaration without a class-key.  */
   15037                 :           0 :               if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   15038                 :           0 :                 permerror (input_location, "template parameters cannot be friends");
   15039                 :           0 :               else if (TREE_CODE (type) == TYPENAME_TYPE)
   15040                 :           0 :                 permerror (input_location, "friend declaration requires class-key, "
   15041                 :             :                            "i.e. %<friend class %T::%D%>",
   15042                 :           0 :                            TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
   15043                 :             :               else
   15044                 :           0 :                 permerror (input_location, "friend declaration requires class-key, "
   15045                 :             :                            "i.e. %<friend %#T%>",
   15046                 :             :                            type);
   15047                 :             :             }
   15048                 :             : 
   15049                 :             :           /* Only try to do this stuff if we didn't already give up.  */
   15050                 :           0 :           if (type != integer_type_node)
   15051                 :             :             {
   15052                 :             :               /* A friendly class?  */
   15053                 :           0 :               if (current_class_type)
   15054                 :           0 :                 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
   15055                 :             :                                    /*complain=*/true);
   15056                 :             :               else
   15057                 :           0 :                 error ("trying to make class %qT a friend of global scope",
   15058                 :             :                        type);
   15059                 :             : 
   15060                 :           0 :               type = void_type_node;
   15061                 :             :             }
   15062                 :             :         }
   15063                 :   345336458 :       else if (memfn_quals || rqual)
   15064                 :             :         {
   15065                 :       75559 :           if (ctype == NULL_TREE
   15066                 :       75559 :               && TREE_CODE (type) == METHOD_TYPE)
   15067                 :           0 :             ctype = TYPE_METHOD_BASETYPE (type);
   15068                 :             : 
   15069                 :       75559 :           if (ctype)
   15070                 :           0 :             type = build_memfn_type (type, ctype, memfn_quals, rqual);
   15071                 :             :           /* Core issue #547: need to allow this in template type args.
   15072                 :             :              Allow it in general in C++11 for alias-declarations.  */
   15073                 :       75559 :           else if ((template_type_arg || cxx_dialect >= cxx11)
   15074                 :       75557 :                    && TREE_CODE (type) == FUNCTION_TYPE)
   15075                 :       75555 :             type = apply_memfn_quals (type, memfn_quals, rqual);
   15076                 :             :           else
   15077                 :           4 :             error ("invalid qualifiers on non-member function type");
   15078                 :             :         }
   15079                 :             : 
   15080                 :   345336458 :       if (reqs)
   15081                 :           3 :         error_at (location_of (reqs), "requires-clause on type-id");
   15082                 :             : 
   15083                 :   345336458 :       return type;
   15084                 :             :     }
   15085                 :   537511644 :   else if (unqualified_id == NULL_TREE && decl_context != PARM
   15086                 :      719397 :            && decl_context != CATCHPARM
   15087                 :      224987 :            && TREE_CODE (type) != UNION_TYPE
   15088                 :      224750 :            && ! bitfield
   15089                 :      224750 :            && innermost_code != cdk_decomp)
   15090                 :             :     {
   15091                 :           9 :       error ("abstract declarator %qT used as declaration", type);
   15092                 :           9 :       return error_mark_node;
   15093                 :             :     }
   15094                 :             : 
   15095                 :   537511635 :   if (!FUNC_OR_METHOD_TYPE_P (type))
   15096                 :             :     {
   15097                 :             :       /* Only functions may be declared using an operator-function-id.  */
   15098                 :   363287439 :       if (dname && IDENTIFIER_ANY_OP_P (dname))
   15099                 :             :         {
   15100                 :           8 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   15101                 :           8 :           return error_mark_node;
   15102                 :             :         }
   15103                 :             : 
   15104                 :   363287431 :       if (reqs)
   15105                 :          15 :         error_at (location_of (reqs),
   15106                 :             :                   "requires-clause on declaration of non-function type %qT",
   15107                 :             :                   type);
   15108                 :             :     }
   15109                 :             : 
   15110                 :             :   /* We don't check parameter types here because we can emit a better
   15111                 :             :      error message later.  */
   15112                 :   537511627 :   if (decl_context != PARM)
   15113                 :             :     {
   15114                 :   259051637 :       type = check_var_type (unqualified_id, type, id_loc);
   15115                 :   259051637 :       if (type == error_mark_node)
   15116                 :             :         return error_mark_node;
   15117                 :             :     }
   15118                 :             : 
   15119                 :             :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
   15120                 :             :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
   15121                 :             : 
   15122                 :   537511545 :   if (decl_context == PARM || decl_context == CATCHPARM)
   15123                 :             :     {
   15124                 :   278968590 :       if (ctype || in_namespace)
   15125                 :           0 :         error ("cannot use %<::%> in parameter declaration");
   15126                 :             : 
   15127                 :   278968590 :       tree auto_node = type_uses_auto (type);
   15128                 :   278968590 :       if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
   15129                 :             :         {
   15130                 :         119 :           bool err_p = true;
   15131                 :         119 :           if (cxx_dialect >= cxx14)
   15132                 :             :             {
   15133                 :         210 :               if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
   15134                 :           3 :                 error_at (typespec_loc,
   15135                 :             :                           "cannot declare a parameter with %<decltype(auto)%>");
   15136                 :         108 :               else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   15137                 :             :                 {
   15138                 :           4 :                   auto_diagnostic_group g;
   15139                 :           4 :                   gcc_rich_location richloc (typespec_loc);
   15140                 :           4 :                   richloc.add_fixit_insert_after ("<>");
   15141                 :           4 :                   error_at (&richloc,
   15142                 :             :                             "missing template argument list after %qE; template "
   15143                 :             :                             "placeholder not permitted in parameter", c);
   15144                 :           4 :                   if (decl_context == PARM && cxx_dialect >= cxx20)
   15145                 :           3 :                     inform (typespec_loc, "or use %<auto%> for an "
   15146                 :             :                             "abbreviated function template");
   15147                 :           4 :                   inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
   15148                 :           4 :                 }
   15149                 :         104 :               else if (decl_context == CATCHPARM || template_parm_flag)
   15150                 :          14 :                 error_at (typespec_loc,
   15151                 :             :                           "%<auto%> parameter not permitted in this context");
   15152                 :             :               else
   15153                 :             :                 /* Do not issue an error while tentatively parsing a function
   15154                 :             :                    parameter: for T t(auto(a), 42);, when we just saw the 1st
   15155                 :             :                    parameter, we don't know yet that this construct won't be
   15156                 :             :                    a function declaration.  Defer the checking to
   15157                 :             :                    cp_parser_parameter_declaration_clause.  */
   15158                 :             :                 err_p = false;
   15159                 :             :             }
   15160                 :             :           else
   15161                 :           8 :             error_at (typespec_loc, "parameter declared %<auto%>");
   15162                 :          29 :           if (err_p)
   15163                 :          29 :             type = error_mark_node;
   15164                 :             :         }
   15165                 :             : 
   15166                 :             :       /* A parameter declared as an array of T is really a pointer to T.
   15167                 :             :          One declared as a function is really a pointer to a function.
   15168                 :             :          One declared as a member is really a pointer to member.  */
   15169                 :             : 
   15170                 :   278968590 :       if (TREE_CODE (type) == ARRAY_TYPE)
   15171                 :             :         {
   15172                 :             :           /* Transfer const-ness of array into that of type pointed to.  */
   15173                 :      751845 :           type = build_pointer_type (TREE_TYPE (type));
   15174                 :      751845 :           type_quals = TYPE_UNQUALIFIED;
   15175                 :      751845 :           array_parameter_p = true;
   15176                 :             :         }
   15177                 :   278216745 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   15178                 :      107521 :         type = build_pointer_type (type);
   15179                 :             :     }
   15180                 :             : 
   15181                 :   128920835 :   if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
   15182                 :             :       /* Don't convert xobj member functions to METHOD_TYPE.  */
   15183                 :   100577995 :       && !is_xobj_member_function
   15184                 :   629357580 :       && !(unqualified_id
   15185                 :   183679572 :            && identifier_p (unqualified_id)
   15186                 :    91845723 :            && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
   15187                 :             :     {
   15188                 :    91833849 :       cp_cv_quals real_quals = memfn_quals;
   15189                 :    91833849 :       if (cxx_dialect < cxx14 && constexpr_p
   15190                 :      710964 :           && sfk != sfk_constructor && sfk != sfk_destructor)
   15191                 :        3762 :         real_quals |= TYPE_QUAL_CONST;
   15192                 :    91833849 :       type = build_memfn_type (type, ctype, real_quals, rqual);
   15193                 :             :     }
   15194                 :             : 
   15195                 :   537511545 :   {
   15196                 :   537511545 :     tree decl = NULL_TREE;
   15197                 :             : 
   15198                 :   537511545 :     if (decl_context == PARM)
   15199                 :             :       {
   15200                 :   278459990 :         decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
   15201                 :   278459990 :         DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
   15202                 :             : 
   15203                 :   278459990 :         bad_specifiers (decl, BSP_PARM, virtualp,
   15204                 :             :                         memfn_quals != TYPE_UNQUALIFIED,
   15205                 :             :                         inlinep, friendp, raises != NULL_TREE,
   15206                 :             :                         declspecs->locations);
   15207                 :             :       }
   15208                 :   259051555 :     else if (decl_context == FIELD)
   15209                 :             :       {
   15210                 :   123436148 :         if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
   15211                 :    17326875 :           if (tree auto_node = type_uses_auto (type))
   15212                 :             :             {
   15213                 :          19 :               location_t tloc = declspecs->locations[ds_type_spec];
   15214                 :          19 :               if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   15215                 :           4 :                 error_at (tloc, "invalid use of template-name %qE without an "
   15216                 :             :                           "argument list",
   15217                 :           4 :                           CLASS_PLACEHOLDER_TEMPLATE (auto_node));
   15218                 :             :               else
   15219                 :          15 :                 error_at (tloc, "non-static data member declared with "
   15220                 :             :                           "placeholder %qT", auto_node);
   15221                 :          19 :               type = error_mark_node;
   15222                 :             :             }
   15223                 :             : 
   15224                 :             :         /* The C99 flexible array extension.  */
   15225                 :   104112038 :         if (!staticp && TREE_CODE (type) == ARRAY_TYPE
   15226                 :   124556555 :             && TYPE_DOMAIN (type) == NULL_TREE)
   15227                 :             :           {
   15228                 :        1395 :             if (ctype
   15229                 :        1395 :                 && (TREE_CODE (ctype) == UNION_TYPE
   15230                 :        1395 :                     || TREE_CODE (ctype) == QUAL_UNION_TYPE))
   15231                 :          84 :               pedwarn (id_loc, OPT_Wpedantic,
   15232                 :             :                        "flexible array member in union is a GCC extension");
   15233                 :             : 
   15234                 :             :             else
   15235                 :             :               {
   15236                 :             :                 /* Array is a flexible member.  */
   15237                 :        1311 :                 if (name)
   15238                 :        1311 :                   pedwarn (id_loc, OPT_Wpedantic,
   15239                 :             :                            "ISO C++ forbids flexible array member %qs", name);
   15240                 :             :                 else
   15241                 :             :                   pedwarn (input_location, OPT_Wpedantic,
   15242                 :             :                            "ISO C++ forbids flexible array members");
   15243                 :             : 
   15244                 :             :                 /* Flexible array member has a null domain.  */
   15245                 :        1311 :                 type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   15246                 :             :               }
   15247                 :             :           }
   15248                 :             : 
   15249                 :   123436148 :         if (type == error_mark_node)
   15250                 :             :           {
   15251                 :             :             /* Happens when declaring arrays of sizes which
   15252                 :             :                are error_mark_node, for example.  */
   15253                 :          19 :             decl = NULL_TREE;
   15254                 :             :           }
   15255                 :   123436129 :         else if (in_namespace && !friendp)
   15256                 :             :           {
   15257                 :             :             /* Something like struct S { int N::j; };  */
   15258                 :           6 :             error_at (id_loc, "invalid use of %<::%>");
   15259                 :           6 :             return error_mark_node;
   15260                 :             :           }
   15261                 :   123436123 :         else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
   15262                 :             :           {
   15263                 :    95489937 :             int publicp = 0;
   15264                 :    95489937 :             tree function_context;
   15265                 :             : 
   15266                 :    95489937 :             if (friendp == 0)
   15267                 :             :               {
   15268                 :             :                 /* This should never happen in pure C++ (the check
   15269                 :             :                    could be an assert).  It could happen in
   15270                 :             :                    Objective-C++ if someone writes invalid code that
   15271                 :             :                    uses a function declaration for an instance
   15272                 :             :                    variable or property (instance variables and
   15273                 :             :                    properties are parsed as FIELD_DECLs, but they are
   15274                 :             :                    part of an Objective-C class, not a C++ class).
   15275                 :             :                    That code is invalid and is caught by this
   15276                 :             :                    check.  */
   15277                 :    91320010 :                 if (!ctype)
   15278                 :             :                   {
   15279                 :           0 :                     error ("declaration of function %qD in invalid context",
   15280                 :             :                            unqualified_id);
   15281                 :           0 :                     return error_mark_node;
   15282                 :             :                   }
   15283                 :             : 
   15284                 :             :                 /* ``A union may [ ... ] not [ have ] virtual functions.''
   15285                 :             :                    ARM 9.5 */
   15286                 :    91320010 :                 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
   15287                 :             :                   {
   15288                 :           3 :                     error_at (declspecs->locations[ds_virtual],
   15289                 :             :                               "function %qD declared %<virtual%> inside a union",
   15290                 :             :                               unqualified_id);
   15291                 :           3 :                     return error_mark_node;
   15292                 :             :                   }
   15293                 :             : 
   15294                 :     4137702 :                 if (virtualp
   15295                 :    99627636 :                     && identifier_p (unqualified_id)
   15296                 :     4137702 :                     && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   15297                 :             :                   {
   15298                 :           9 :                     error_at (declspecs->locations[ds_virtual],
   15299                 :             :                               "%qD cannot be declared %<virtual%>, since it "
   15300                 :             :                               "is always static", unqualified_id);
   15301                 :           9 :                     virtualp = 0;
   15302                 :             :                   }
   15303                 :             :               }
   15304                 :             : 
   15305                 :             :             /* Check that the name used for a destructor makes sense.  */
   15306                 :    95489934 :             if (sfk == sfk_destructor)
   15307                 :             :               {
   15308                 :     3020622 :                 tree uqname = id_declarator->u.id.unqualified_name;
   15309                 :             : 
   15310                 :     3020622 :                 if (!ctype)
   15311                 :             :                   {
   15312                 :          12 :                     gcc_assert (friendp);
   15313                 :          12 :                     error_at (id_loc, "expected qualified name in friend "
   15314                 :             :                               "declaration for destructor %qD", uqname);
   15315                 :          12 :                     return error_mark_node;
   15316                 :             :                   }
   15317                 :             : 
   15318                 :     3020610 :                 if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
   15319                 :             :                   {
   15320                 :           9 :                     error_at (id_loc, "declaration of %qD as member of %qT",
   15321                 :             :                               uqname, ctype);
   15322                 :           9 :                     return error_mark_node;
   15323                 :             :                   }
   15324                 :     3020601 :                 if (concept_p)
   15325                 :             :                   {
   15326                 :           9 :                     error_at (declspecs->locations[ds_concept],
   15327                 :             :                               "a destructor cannot be %qs", "concept");
   15328                 :           9 :                     return error_mark_node;
   15329                 :             :                   }
   15330                 :     3020592 :                 if (constexpr_p && cxx_dialect < cxx20)
   15331                 :             :                   {
   15332                 :           6 :                     error_at (declspecs->locations[ds_constexpr],
   15333                 :             :                               "%<constexpr%> destructors only available"
   15334                 :             :                               " with %<-std=c++20%> or %<-std=gnu++20%>");
   15335                 :           6 :                     return error_mark_node;
   15336                 :             :                   }
   15337                 :     3020586 :                 if (consteval_p)
   15338                 :             :                   {
   15339                 :           3 :                     error_at (declspecs->locations[ds_consteval],
   15340                 :             :                               "a destructor cannot be %qs", "consteval");
   15341                 :           3 :                     return error_mark_node;
   15342                 :             :                   }
   15343                 :             :               }
   15344                 :    92469312 :             else if (sfk == sfk_constructor && friendp && !ctype)
   15345                 :             :               {
   15346                 :           0 :                 error ("expected qualified name in friend declaration "
   15347                 :             :                        "for constructor %qD",
   15348                 :           0 :                        id_declarator->u.id.unqualified_name);
   15349                 :           0 :                 return error_mark_node;
   15350                 :             :               }
   15351                 :    95489895 :             if (sfk == sfk_constructor)
   15352                 :    21808375 :               if (concept_p)
   15353                 :             :                 {
   15354                 :           9 :                   error_at (declspecs->locations[ds_concept],
   15355                 :             :                             "a constructor cannot be %<concept%>");
   15356                 :           9 :                   return error_mark_node;
   15357                 :             :                 }
   15358                 :    73681520 :             if (concept_p)
   15359                 :             :               {
   15360                 :           9 :                 error_at (declspecs->locations[ds_concept],
   15361                 :             :                           "a concept cannot be a member function");
   15362                 :           9 :                 concept_p = false;
   15363                 :             :               }
   15364                 :    95489877 :             else if (consteval_p
   15365                 :    95678838 :                      && identifier_p (unqualified_id)
   15366                 :    95678829 :                      && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   15367                 :             :               {
   15368                 :           9 :                 error_at (declspecs->locations[ds_consteval],
   15369                 :             :                           "%qD cannot be %qs", unqualified_id, "consteval");
   15370                 :           9 :                 consteval_p = false;
   15371                 :             :               }
   15372                 :             : 
   15373                 :    95489886 :             if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   15374                 :             :               {
   15375                 :       14773 :                 tree tmpl = TREE_OPERAND (unqualified_id, 0);
   15376                 :       14773 :                 if (variable_template_p (tmpl))
   15377                 :             :                   {
   15378                 :           3 :                     auto_diagnostic_group d;
   15379                 :           3 :                     error_at (id_loc, "specialization of variable template "
   15380                 :             :                               "%qD declared as function", tmpl);
   15381                 :           3 :                     inform (DECL_SOURCE_LOCATION (tmpl),
   15382                 :             :                             "variable template declared here");
   15383                 :           3 :                     return error_mark_node;
   15384                 :           3 :                   }
   15385                 :             :               }
   15386                 :             : 
   15387                 :             :             /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
   15388                 :    95489883 :             function_context
   15389                 :             :               = (ctype != NULL_TREE
   15390                 :    95489883 :                  ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
   15391                 :   190979766 :             publicp = ((! friendp || ! staticp)
   15392                 :    95489883 :                        && function_context == NULL_TREE);
   15393                 :             : 
   15394                 :    95489883 :             decl = grokfndecl (ctype, type,
   15395                 :    95489883 :                                TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
   15396                 :             :                                ? unqualified_id : dname,
   15397                 :             :                                parms,
   15398                 :             :                                unqualified_id,
   15399                 :             :                                declspecs,
   15400                 :             :                                reqs,
   15401                 :             :                                virtualp, flags, memfn_quals, rqual, raises,
   15402                 :             :                                friendp ? -1 : 0, friendp, publicp,
   15403                 :    95489883 :                                inlinep | (2 * constexpr_p) | (4 * concept_p)
   15404                 :    95489883 :                                        | (8 * consteval_p),
   15405                 :             :                                initialized == SD_DELETED,
   15406                 :             :                                is_xobj_member_function, sfk,
   15407                 :             :                                funcdef_flag, late_return_type_p,
   15408                 :             :                                template_count, in_namespace,
   15409                 :             :                                attrlist, id_loc);
   15410                 :    95489883 :             decl = set_virt_specifiers (decl, virt_specifiers);
   15411                 :    95489883 :             if (decl == NULL_TREE)
   15412                 :          98 :               return error_mark_node;
   15413                 :             : #if 0
   15414                 :             :             /* This clobbers the attrs stored in `decl' from `attrlist'.  */
   15415                 :             :             /* The decl and setting of decl_attr is also turned off.  */
   15416                 :             :             decl = build_decl_attribute_variant (decl, decl_attr);
   15417                 :             : #endif
   15418                 :             : 
   15419                 :             :             /* [class.conv.ctor]
   15420                 :             : 
   15421                 :             :                A constructor declared without the function-specifier
   15422                 :             :                explicit that can be called with a single parameter
   15423                 :             :                specifies a conversion from the type of its first
   15424                 :             :                parameter to the type of its class.  Such a constructor
   15425                 :             :                is called a converting constructor.  */
   15426                 :    95489785 :             if (explicitp == 2)
   15427                 :     5595843 :               DECL_NONCONVERTING_P (decl) = 1;
   15428                 :             : 
   15429                 :    95489785 :             if (declspecs->explicit_specifier)
   15430                 :      156407 :               store_explicit_specifier (decl, declspecs->explicit_specifier);
   15431                 :             :           }
   15432                 :    27946186 :         else if (!staticp
   15433                 :    27946186 :                  && ((current_class_type
   15434                 :    17326873 :                       && same_type_p (TYPE_MAIN_VARIANT (type),
   15435                 :             :                                       current_class_type))
   15436                 :    17326777 :                      || (!dependent_type_p (type)
   15437                 :    10709938 :                          && !COMPLETE_TYPE_P (complete_type (type))
   15438                 :        1437 :                          && (!complete_or_array_type_p (type)
   15439                 :        1368 :                              || initialized == SD_UNINITIALIZED))))
   15440                 :             :           {
   15441                 :        1500 :             if (TREE_CODE (type) != ARRAY_TYPE
   15442                 :        1500 :                 || !COMPLETE_TYPE_P (TREE_TYPE (type)))
   15443                 :             :               {
   15444                 :         165 :                 if (unqualified_id)
   15445                 :             :                   {
   15446                 :         120 :                     auto_diagnostic_group d;
   15447                 :         120 :                     error_at (id_loc, "field %qD has incomplete type %qT",
   15448                 :             :                               unqualified_id, type);
   15449                 :         120 :                     cxx_incomplete_type_inform (strip_array_types (type));
   15450                 :         120 :                   }
   15451                 :             :                 else
   15452                 :          45 :                   error ("name %qT has incomplete type", type);
   15453                 :             : 
   15454                 :         165 :                 type = error_mark_node;
   15455                 :         165 :                 decl = NULL_TREE;
   15456                 :             :               }
   15457                 :             :           }
   15458                 :    45270047 :         else if (!verify_type_context (input_location,
   15459                 :             :                                        staticp
   15460                 :             :                                        ? TCTX_STATIC_STORAGE
   15461                 :             :                                        : TCTX_FIELD, type))
   15462                 :             :           {
   15463                 :           0 :             type = error_mark_node;
   15464                 :           0 :             decl = NULL_TREE;
   15465                 :             :           }
   15466                 :             :         else
   15467                 :             :           {
   15468                 :    27944680 :             if (friendp)
   15469                 :             :               {
   15470                 :          14 :                 if (unqualified_id)
   15471                 :          11 :                   error_at (id_loc,
   15472                 :             :                             "%qE is neither function nor member function; "
   15473                 :             :                             "cannot be declared friend", unqualified_id);
   15474                 :             :                 else
   15475                 :           3 :                   error ("unnamed field is neither function nor member "
   15476                 :             :                          "function; cannot be declared friend");
   15477                 :          14 :                 return error_mark_node;
   15478                 :             :               }
   15479                 :    27944666 :             decl = NULL_TREE;
   15480                 :             :           }
   15481                 :             : 
   15482                 :   123435970 :         if (friendp)
   15483                 :             :           {
   15484                 :             :             /* Packages tend to use GNU attributes on friends, so we only
   15485                 :             :                warn for standard attributes.  */
   15486                 :     4169898 :             if (attrlist
   15487                 :     4169898 :                 && !funcdef_flag
   15488                 :     1261233 :                 && cxx11_attribute_p (*attrlist)
   15489                 :     4169927 :                 && !all_attributes_are_contracts_p (*attrlist))
   15490                 :             :               {
   15491                 :          27 :                 *attrlist = NULL_TREE;
   15492                 :          27 :                 auto_diagnostic_group d;
   15493                 :          27 :                 if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
   15494                 :          27 :                   inform (id_loc, "an attribute that appertains to a friend "
   15495                 :             :                           "declaration that is not a definition is ignored");
   15496                 :          27 :               }
   15497                 :             :             /* Friends are treated specially.  */
   15498                 :     4169898 :             if (ctype == current_class_type)
   15499                 :             :               ;  /* We already issued a permerror.  */
   15500                 :     4169898 :             else if (decl && DECL_NAME (decl))
   15501                 :             :               {
   15502                 :     4169895 :                 set_originating_module (decl, true);
   15503                 :             : 
   15504                 :     4169895 :                 if (initialized)
   15505                 :             :                   /* Kludge: We need funcdef_flag to be true in do_friend for
   15506                 :             :                      in-class defaulted functions, but that breaks grokfndecl.
   15507                 :             :                      So set it here.  */
   15508                 :       54235 :                   funcdef_flag = true;
   15509                 :             : 
   15510                 :     4169895 :                 cplus_decl_attributes (&decl, *attrlist, 0);
   15511                 :     4169895 :                 *attrlist = NULL_TREE;
   15512                 :             : 
   15513                 :     4169895 :                 tree scope = ctype ? ctype : in_namespace;
   15514                 :     4169895 :                 decl = do_friend (scope, unqualified_id, decl,
   15515                 :             :                                   flags, funcdef_flag);
   15516                 :     4169895 :                 return decl;
   15517                 :             :               }
   15518                 :             :             else
   15519                 :           3 :               return error_mark_node;
   15520                 :             :           }
   15521                 :             : 
   15522                 :             :         /* Structure field.  It may not be a function, except for C++.  */
   15523                 :             : 
   15524                 :   119266072 :         if (decl == NULL_TREE)
   15525                 :             :           {
   15526                 :    27946182 :             if (staticp)
   15527                 :             :               {
   15528                 :             :                 /* C++ allows static class members.  All other work
   15529                 :             :                    for this is done by grokfield.  */
   15530                 :    10619313 :                 decl = build_lang_decl_loc (id_loc, VAR_DECL,
   15531                 :             :                                             dname, type);
   15532                 :    10619313 :                 if (unqualified_id
   15533                 :    10619310 :                     && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   15534                 :             :                   {
   15535                 :       86004 :                     decl = check_explicit_specialization (unqualified_id, decl,
   15536                 :             :                                                           template_count,
   15537                 :             :                                                           concept_p * 8);
   15538                 :       86004 :                     if (decl == error_mark_node)
   15539                 :             :                       return error_mark_node;
   15540                 :             :                   }
   15541                 :    10619313 :                 set_linkage_for_static_data_member (decl);
   15542                 :    10619313 :                 if (concept_p)
   15543                 :          15 :                   error_at (declspecs->locations[ds_concept],
   15544                 :             :                             "static data member %qE declared %qs",
   15545                 :             :                             unqualified_id, "concept");
   15546                 :    10619298 :                 else if (constexpr_p && !initialized)
   15547                 :             :                   {
   15548                 :           9 :                     error_at (DECL_SOURCE_LOCATION (decl),
   15549                 :             :                               "%<constexpr%> static data member %qD must "
   15550                 :             :                               "have an initializer", decl);
   15551                 :           9 :                     constexpr_p = false;
   15552                 :             :                   }
   15553                 :    10619313 :                 if (consteval_p)
   15554                 :           3 :                   error_at (declspecs->locations[ds_consteval],
   15555                 :             :                             "static data member %qE declared %qs",
   15556                 :             :                             unqualified_id, "consteval");
   15557                 :             : 
   15558                 :    10619313 :                 if (inlinep)
   15559                 :       10929 :                   mark_inline_variable (decl, declspecs->locations[ds_inline]);
   15560                 :             : 
   15561                 :    10619313 :                 if (!DECL_VAR_DECLARED_INLINE_P (decl)
   15562                 :    10619313 :                     && !(cxx_dialect >= cxx17 && constexpr_p))
   15563                 :             :                   /* Even if there is an in-class initialization, DECL
   15564                 :             :                      is considered undefined until an out-of-class
   15565                 :             :                      definition is provided, unless this is an inline
   15566                 :             :                      variable.  */
   15567                 :     1765019 :                   DECL_EXTERNAL (decl) = 1;
   15568                 :             : 
   15569                 :    10619313 :                 if (thread_p)
   15570                 :             :                   {
   15571                 :         414 :                     CP_DECL_THREAD_LOCAL_P (decl) = true;
   15572                 :         414 :                     if (!processing_template_decl)
   15573                 :         374 :                       set_decl_tls_model (decl, decl_default_tls_model (decl));
   15574                 :         414 :                     if (declspecs->gnu_thread_keyword_p)
   15575                 :          31 :                       SET_DECL_GNU_TLS_P (decl);
   15576                 :             :                   }
   15577                 :             : 
   15578                 :             :                 /* Set the constraints on the declaration.  */
   15579                 :    10619313 :                 bool memtmpl = (current_template_depth
   15580                 :    10619313 :                                 > template_class_depth (current_class_type));
   15581                 :    10619313 :                 if (memtmpl)
   15582                 :             :                   {
   15583                 :      317025 :                     tree ci = current_template_constraints ();
   15584                 :      317025 :                     set_constraints (decl, ci);
   15585                 :             :                   }
   15586                 :             :               }
   15587                 :             :             else
   15588                 :             :               {
   15589                 :    17326869 :                 if (concept_p)
   15590                 :             :                   {
   15591                 :          12 :                     error_at (declspecs->locations[ds_concept],
   15592                 :             :                               "non-static data member %qE declared %qs",
   15593                 :             :                               unqualified_id, "concept");
   15594                 :          12 :                     concept_p = false;
   15595                 :          12 :                     constexpr_p = false;
   15596                 :             :                   }
   15597                 :    17326857 :                 else if (constexpr_p)
   15598                 :             :                   {
   15599                 :           9 :                     error_at (declspecs->locations[ds_constexpr],
   15600                 :             :                               "non-static data member %qE declared %qs",
   15601                 :             :                               unqualified_id, "constexpr");
   15602                 :           9 :                     constexpr_p = false;
   15603                 :             :                   }
   15604                 :    17326869 :                 if (constinit_p)
   15605                 :             :                   {
   15606                 :           6 :                     error_at (declspecs->locations[ds_constinit],
   15607                 :             :                               "non-static data member %qE declared %qs",
   15608                 :             :                               unqualified_id, "constinit");
   15609                 :           6 :                     constinit_p = false;
   15610                 :             :                   }
   15611                 :    17326869 :                 if (consteval_p)
   15612                 :             :                   {
   15613                 :           3 :                     error_at (declspecs->locations[ds_consteval],
   15614                 :             :                               "non-static data member %qE declared %qs",
   15615                 :             :                               unqualified_id, "consteval");
   15616                 :           3 :                     consteval_p = false;
   15617                 :             :                   }
   15618                 :    17326869 :                 decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
   15619                 :    17326869 :                 DECL_NONADDRESSABLE_P (decl) = bitfield;
   15620                 :    17326869 :                 if (bitfield && !unqualified_id)
   15621                 :      140839 :                   DECL_PADDING_P (decl) = 1;
   15622                 :             : 
   15623                 :    17326869 :                 if (storage_class == sc_mutable)
   15624                 :             :                   {
   15625                 :      149463 :                     DECL_MUTABLE_P (decl) = 1;
   15626                 :      149463 :                     storage_class = sc_none;
   15627                 :             :                   }
   15628                 :             : 
   15629                 :    17326869 :                 if (initialized)
   15630                 :             :                   {
   15631                 :             :                     /* An attempt is being made to initialize a non-static
   15632                 :             :                        member.  This is new in C++11.  */
   15633                 :     1225291 :                     maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
   15634                 :             : 
   15635                 :             :                     /* If this has been parsed with static storage class, but
   15636                 :             :                        errors forced staticp to be cleared, ensure NSDMI is
   15637                 :             :                        not present.  */
   15638                 :     1225291 :                     if (declspecs->storage_class == sc_static)
   15639                 :           3 :                       DECL_INITIAL (decl) = error_mark_node;
   15640                 :             :                   }
   15641                 :             :               }
   15642                 :             : 
   15643                 :    45273051 :             bad_specifiers (decl, BSP_FIELD, virtualp,
   15644                 :             :                             memfn_quals != TYPE_UNQUALIFIED,
   15645                 :             :                             staticp ? false : inlinep, friendp,
   15646                 :             :                             raises != NULL_TREE,
   15647                 :             :                             declspecs->locations);
   15648                 :             :           }
   15649                 :             :       }
   15650                 :   135615407 :     else if (FUNC_OR_METHOD_TYPE_P (type))
   15651                 :             :       {
   15652                 :    78626732 :         tree original_name;
   15653                 :    78626732 :         int publicp = 0;
   15654                 :             : 
   15655                 :    78626732 :         if (!unqualified_id)
   15656                 :           0 :           return error_mark_node;
   15657                 :             : 
   15658                 :    78626732 :         if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   15659                 :             :           original_name = dname;
   15660                 :             :         else
   15661                 :    77737339 :           original_name = unqualified_id;
   15662                 :             :         // FIXME:gcc_assert (original_name == dname);
   15663                 :             : 
   15664                 :    78626732 :         if (storage_class == sc_auto)
   15665                 :           1 :           error_at (declspecs->locations[ds_storage_class],
   15666                 :             :                     "storage class %<auto%> invalid for function %qs", name);
   15667                 :    78626731 :         else if (storage_class == sc_register)
   15668                 :           7 :           error_at (declspecs->locations[ds_storage_class],
   15669                 :             :                     "storage class %<register%> invalid for function %qs",
   15670                 :             :                     name);
   15671                 :    78626724 :         else if (thread_p)
   15672                 :             :           {
   15673                 :          12 :             if (declspecs->gnu_thread_keyword_p)
   15674                 :          12 :               error_at (declspecs->locations[ds_thread],
   15675                 :             :                         "storage class %<__thread%> invalid for function %qs",
   15676                 :             :                         name);
   15677                 :             :             else
   15678                 :           0 :               error_at (declspecs->locations[ds_thread],
   15679                 :             :                         "storage class %<thread_local%> invalid for "
   15680                 :             :                         "function %qs", name);
   15681                 :             :           }
   15682                 :    78626712 :         else if (constinit_p)
   15683                 :           3 :           error_at (declspecs->locations[ds_constinit],
   15684                 :             :                     "%<constinit%> specifier invalid for function %qs", name);
   15685                 :             : 
   15686                 :    78626732 :         if (virt_specifiers)
   15687                 :           6 :           error ("virt-specifiers in %qs not allowed outside a class "
   15688                 :             :                  "definition", name);
   15689                 :             :         /* Function declaration not at top level.
   15690                 :             :            Storage classes other than `extern' are not allowed
   15691                 :             :            and `extern' makes no difference.  */
   15692                 :    78626732 :         if (! toplevel_bindings_p ()
   15693                 :       37229 :             && (storage_class == sc_static
   15694                 :       37220 :                 || decl_spec_seq_has_spec_p (declspecs, ds_inline))
   15695                 :    78626744 :             && pedantic)
   15696                 :             :           {
   15697                 :           9 :             if (storage_class == sc_static)
   15698                 :           6 :               pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic,
   15699                 :             :                        "%<static%> specifier invalid for function %qs "
   15700                 :             :                        "declared out of global scope", name);
   15701                 :             :             else
   15702                 :           3 :               pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic,
   15703                 :             :                        "%<inline%> specifier invalid for function %qs "
   15704                 :             :                        "declared out of global scope", name);
   15705                 :             :           }
   15706                 :             : 
   15707                 :    78626732 :         if (ctype == NULL_TREE)
   15708                 :             :           {
   15709                 :    69368968 :             if (virtualp)
   15710                 :             :               {
   15711                 :           0 :                 error ("virtual non-class function %qs", name);
   15712                 :           0 :                 virtualp = 0;
   15713                 :             :               }
   15714                 :    69368968 :             else if (sfk == sfk_constructor
   15715                 :    69368968 :                      || sfk == sfk_destructor)
   15716                 :             :               {
   15717                 :           3 :                 error (funcdef_flag
   15718                 :             :                        ? G_("%qs defined in a non-class scope")
   15719                 :             :                        : G_("%qs declared in a non-class scope"), name);
   15720                 :           3 :                 sfk = sfk_none;
   15721                 :             :               }
   15722                 :             :           }
   15723                 :    78626732 :         if (consteval_p
   15724                 :    78664729 :             && identifier_p (unqualified_id)
   15725                 :    78664729 :             && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   15726                 :             :           {
   15727                 :           9 :             error_at (declspecs->locations[ds_consteval],
   15728                 :             :                       "%qD cannot be %qs", unqualified_id, "consteval");
   15729                 :           9 :             consteval_p = false;
   15730                 :             :           }
   15731                 :             : 
   15732                 :             :         /* Record whether the function is public.  */
   15733                 :    78626732 :         publicp = (ctype != NULL_TREE
   15734                 :    78626732 :                    || storage_class != sc_static);
   15735                 :             : 
   15736                 :   157253464 :         decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
   15737                 :             :                            declspecs,
   15738                 :             :                            reqs, virtualp, flags, memfn_quals, rqual, raises,
   15739                 :             :                            1, friendp,
   15740                 :             :                            publicp,
   15741                 :    78626732 :                            inlinep | (2 * constexpr_p) | (4 * concept_p)
   15742                 :    78626732 :                                    | (8 * consteval_p),
   15743                 :             :                            initialized == SD_DELETED,
   15744                 :             :                            is_xobj_member_function, sfk,
   15745                 :             :                            funcdef_flag,
   15746                 :             :                            late_return_type_p,
   15747                 :             :                            template_count, in_namespace, attrlist,
   15748                 :             :                            id_loc);
   15749                 :    78626732 :         if (decl == NULL_TREE)
   15750                 :         506 :           return error_mark_node;
   15751                 :             : 
   15752                 :    78626226 :         if (explicitp == 2)
   15753                 :        5176 :           DECL_NONCONVERTING_P (decl) = 1;
   15754                 :    78626226 :         if (staticp == 1)
   15755                 :             :           {
   15756                 :      110938 :             int invalid_static = 0;
   15757                 :             : 
   15758                 :             :             /* Don't allow a static member function in a class, and forbid
   15759                 :             :                declaring main to be static.  */
   15760                 :      110938 :             if (TREE_CODE (type) == METHOD_TYPE)
   15761                 :             :               {
   15762                 :           0 :                 permerror (input_location, "cannot declare member function %qD to have "
   15763                 :             :                            "static linkage", decl);
   15764                 :           0 :                 invalid_static = 1;
   15765                 :             :               }
   15766                 :      110938 :             else if (current_function_decl)
   15767                 :             :               {
   15768                 :             :                 /* 7.1.1: There can be no static function declarations within a
   15769                 :             :                    block.  */
   15770                 :           9 :                 error_at (declspecs->locations[ds_storage_class],
   15771                 :             :                           "cannot declare static function inside another function");
   15772                 :           9 :                 invalid_static = 1;
   15773                 :             :               }
   15774                 :             : 
   15775                 :           9 :             if (invalid_static)
   15776                 :             :               {
   15777                 :    78626226 :                 staticp = 0;
   15778                 :             :                 storage_class = sc_none;
   15779                 :             :               }
   15780                 :             :           }
   15781                 :    78626226 :         if (declspecs->explicit_specifier)
   15782                 :           3 :           store_explicit_specifier (decl, declspecs->explicit_specifier);
   15783                 :             :       }
   15784                 :             :     else
   15785                 :             :       {
   15786                 :             :         /* It's a variable.  */
   15787                 :             : 
   15788                 :             :         /* An uninitialized decl with `extern' is a reference.  */
   15789                 :   113580698 :         decl = grokvardecl (type, dname, unqualified_id,
   15790                 :             :                             declspecs,
   15791                 :             :                             initialized,
   15792                 :             :                             type_quals,
   15793                 :             :                             inlinep,
   15794                 :             :                             concept_p,
   15795                 :             :                             template_count,
   15796                 :             :                             ctype ? ctype : in_namespace,
   15797                 :             :                             id_loc);
   15798                 :    56988675 :         if (decl == NULL_TREE)
   15799                 :          49 :           return error_mark_node;
   15800                 :             : 
   15801                 :    56988626 :         bad_specifiers (decl, BSP_VAR, virtualp,
   15802                 :             :                         memfn_quals != TYPE_UNQUALIFIED,
   15803                 :             :                         inlinep, friendp, raises != NULL_TREE,
   15804                 :             :                         declspecs->locations);
   15805                 :             : 
   15806                 :    56988626 :         if (ctype)
   15807                 :             :           {
   15808                 :      396646 :             DECL_CONTEXT (decl) = ctype;
   15809                 :      396646 :             if (staticp == 1)
   15810                 :             :               {
   15811                 :           6 :                 permerror (declspecs->locations[ds_storage_class],
   15812                 :             :                            "%<static%> may not be used when defining "
   15813                 :             :                            "(as opposed to declaring) a static data member");
   15814                 :           6 :                 staticp = 0;
   15815                 :           6 :                 storage_class = sc_none;
   15816                 :             :               }
   15817                 :      396646 :             if (storage_class == sc_register && TREE_STATIC (decl))
   15818                 :             :               {
   15819                 :           0 :                 error ("static member %qD declared %<register%>", decl);
   15820                 :           0 :                 storage_class = sc_none;
   15821                 :             :               }
   15822                 :      396646 :             if (storage_class == sc_extern && pedantic)
   15823                 :             :               {
   15824                 :           0 :                 pedwarn (input_location, OPT_Wpedantic,
   15825                 :             :                          "cannot explicitly declare member %q#D to have "
   15826                 :             :                          "extern linkage", decl);
   15827                 :           0 :                 storage_class = sc_none;
   15828                 :             :               }
   15829                 :             :           }
   15830                 :    56591980 :         else if (constexpr_p && DECL_EXTERNAL (decl))
   15831                 :             :           {
   15832                 :          12 :             error_at (DECL_SOURCE_LOCATION (decl),
   15833                 :             :                       "declaration of %<constexpr%> variable %qD "
   15834                 :             :                       "is not a definition", decl);
   15835                 :          12 :             constexpr_p = false;
   15836                 :             :           }
   15837                 :    56988626 :         if (consteval_p)
   15838                 :             :           {
   15839                 :           5 :             error_at (DECL_SOURCE_LOCATION (decl),
   15840                 :             :                       "a variable cannot be declared %<consteval%>");
   15841                 :           5 :             consteval_p = false;
   15842                 :             :           }
   15843                 :             : 
   15844                 :    56988626 :         if (inlinep)
   15845                 :     3979043 :           mark_inline_variable (decl, declspecs->locations[ds_inline]);
   15846                 :    56988626 :         if (innermost_code == cdk_decomp)
   15847                 :             :           {
   15848                 :       83893 :             gcc_assert (declarator && declarator->kind == cdk_decomp);
   15849                 :       83893 :             DECL_SOURCE_LOCATION (decl) = id_loc;
   15850                 :       83893 :             DECL_ARTIFICIAL (decl) = 1;
   15851                 :       83893 :             fit_decomposition_lang_decl (decl, NULL_TREE);
   15852                 :             :           }
   15853                 :             :       }
   15854                 :             : 
   15855                 :   533340914 :     if (VAR_P (decl) && !initialized)
   15856                 :     6886099 :       if (tree auto_node = type_uses_auto (type))
   15857                 :          94 :         if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   15858                 :             :           {
   15859                 :          18 :             location_t loc = declspecs->locations[ds_type_spec];
   15860                 :          18 :             error_at (loc, "declaration of %q#D has no initializer", decl);
   15861                 :          18 :             TREE_TYPE (decl) = error_mark_node;
   15862                 :             :           }
   15863                 :             : 
   15864                 :   533340914 :     if (storage_class == sc_extern && initialized && !funcdef_flag)
   15865                 :             :       {
   15866                 :         246 :         if (toplevel_bindings_p ())
   15867                 :             :           {
   15868                 :             :             /* It's common practice (and completely valid) to have a const
   15869                 :             :                be initialized and declared extern.  */
   15870                 :         234 :             if (!(type_quals & TYPE_QUAL_CONST))
   15871                 :          19 :               warning_at (DECL_SOURCE_LOCATION (decl), 0,
   15872                 :             :                           "%qs initialized and declared %<extern%>", name);
   15873                 :             :           }
   15874                 :             :         else
   15875                 :             :           {
   15876                 :          12 :             error_at (DECL_SOURCE_LOCATION (decl),
   15877                 :             :                       "%qs has both %<extern%> and initializer", name);
   15878                 :          12 :             return error_mark_node;
   15879                 :             :           }
   15880                 :             :       }
   15881                 :             : 
   15882                 :             :     /* Record `register' declaration for warnings on &
   15883                 :             :        and in case doing stupid register allocation.  */
   15884                 :             : 
   15885                 :   533340902 :     if (storage_class == sc_register)
   15886                 :             :       {
   15887                 :        2048 :         DECL_REGISTER (decl) = 1;
   15888                 :             :         /* Warn about register storage specifiers on PARM_DECLs.  */
   15889                 :        2048 :         if (TREE_CODE (decl) == PARM_DECL)
   15890                 :             :           {
   15891                 :          35 :             if (cxx_dialect >= cxx17)
   15892                 :          22 :               pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   15893                 :             :                        "ISO C++17 does not allow %<register%> storage "
   15894                 :             :                        "class specifier");
   15895                 :             :             else
   15896                 :          13 :               warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   15897                 :             :                           "%<register%> storage class specifier used");
   15898                 :             :           }
   15899                 :             :       }
   15900                 :   533338854 :     else if (storage_class == sc_extern)
   15901                 :    30603692 :       DECL_THIS_EXTERN (decl) = 1;
   15902                 :   502735162 :     else if (storage_class == sc_static)
   15903                 :    19653468 :       DECL_THIS_STATIC (decl) = 1;
   15904                 :             : 
   15905                 :   533340902 :     if (VAR_P (decl))
   15906                 :             :       {
   15907                 :             :         /* Set constexpr flag on vars (functions got it in grokfndecl).  */
   15908                 :    67607927 :         if (constexpr_p)
   15909                 :    13805224 :           DECL_DECLARED_CONSTEXPR_P (decl) = true;
   15910                 :             :         /* And the constinit flag (which only applies to variables).  */
   15911                 :    53802703 :         else if (constinit_p)
   15912                 :         420 :           DECL_DECLARED_CONSTINIT_P (decl) = true;
   15913                 :             :       }
   15914                 :   465732975 :     else if (TREE_CODE (decl) == FUNCTION_DECL)
   15915                 :             :       {
   15916                 :             :         /* If we saw a return type, record its location.  */
   15917                 :   169946116 :         location_t loc = declspecs->locations[ds_type_spec];
   15918                 :   169946116 :         if (loc == UNKNOWN_LOCATION)
   15919                 :             :           /* Build DECL_RESULT in start_preparsed_function.  */;
   15920                 :   140340995 :         else if (!DECL_RESULT (decl))
   15921                 :             :           {
   15922                 :   140303527 :             tree restype = TREE_TYPE (TREE_TYPE (decl));
   15923                 :   140303527 :             tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   15924                 :   140303527 :             DECL_ARTIFICIAL (resdecl) = 1;
   15925                 :   140303527 :             DECL_IGNORED_P (resdecl) = 1;
   15926                 :   140303527 :             DECL_RESULT (decl) = resdecl;
   15927                 :             :           }
   15928                 :       37468 :         else if (funcdef_flag)
   15929                 :           3 :           DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
   15930                 :             :       }
   15931                 :             : 
   15932                 :             :     /* Record constancy and volatility on the DECL itself .  There's
   15933                 :             :        no need to do this when processing a template; we'll do this
   15934                 :             :        for the instantiated declaration based on the type of DECL.  */
   15935                 :   533340902 :     if (!processing_template_decl
   15936                 :             :         /* Don't do it for instantiated variable templates either,
   15937                 :             :            cp_apply_type_quals_to_decl should have been called on it
   15938                 :             :            already and might have been overridden in cp_finish_decl
   15939                 :             :            if initializer needs runtime initialization.  */
   15940                 :   533340902 :         && (!VAR_P (decl) || !DECL_TEMPLATE_INSTANTIATED (decl)))
   15941                 :   179446648 :       cp_apply_type_quals_to_decl (type_quals, decl);
   15942                 :             : 
   15943                 :   533340902 :     return decl;
   15944                 :             :   }
   15945                 :   927221981 : }
   15946                 :             : 
   15947                 :             : /* Subroutine of start_function.  Ensure that each of the parameter
   15948                 :             :    types (as listed in PARMS) is complete, as is required for a
   15949                 :             :    function definition.  */
   15950                 :             : 
   15951                 :             : static void
   15952                 :   143956593 : require_complete_types_for_parms (tree parms)
   15953                 :             : {
   15954                 :   427360151 :   for (; parms; parms = DECL_CHAIN (parms))
   15955                 :             :     {
   15956                 :   283403558 :       if (dependent_type_p (TREE_TYPE (parms)))
   15957                 :   164296748 :         continue;
   15958                 :   119106810 :       if (!VOID_TYPE_P (TREE_TYPE (parms))
   15959                 :   119106810 :           && complete_type_or_else (TREE_TYPE (parms), parms))
   15960                 :             :         {
   15961                 :   119106729 :           relayout_decl (parms);
   15962                 :   119106729 :           DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
   15963                 :             : 
   15964                 :   119106729 :           abstract_virtuals_error (parms, TREE_TYPE (parms));
   15965                 :   119106729 :           maybe_warn_parm_abi (TREE_TYPE (parms),
   15966                 :   119106729 :                                DECL_SOURCE_LOCATION (parms));
   15967                 :             :         }
   15968                 :             :       else
   15969                 :             :         /* grokparms or complete_type_or_else will have already issued
   15970                 :             :            an error.  */
   15971                 :          81 :         TREE_TYPE (parms) = error_mark_node;
   15972                 :             :     }
   15973                 :   143956593 : }
   15974                 :             : 
   15975                 :             : /* Returns nonzero if T is a local variable.  */
   15976                 :             : 
   15977                 :             : int
   15978                 :   150409652 : local_variable_p (const_tree t)
   15979                 :             : {
   15980                 :   150409652 :   if ((VAR_P (t)
   15981                 :    67576259 :        && (DECL_LOCAL_DECL_P (t)
   15982                 :    67576259 :            || !DECL_CONTEXT (t)
   15983                 :    67533310 :            || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
   15984                 :   153980202 :       || (TREE_CODE (t) == PARM_DECL))
   15985                 :   134656188 :     return 1;
   15986                 :             : 
   15987                 :             :   return 0;
   15988                 :             : }
   15989                 :             : 
   15990                 :             : /* Like local_variable_p, but suitable for use as a tree-walking
   15991                 :             :    function.  */
   15992                 :             : 
   15993                 :             : static tree
   15994                 :     5070361 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
   15995                 :             :                          void * /*data*/)
   15996                 :             : {
   15997                 :     5070361 :   if (unevaluated_p (TREE_CODE (*tp)))
   15998                 :             :     {
   15999                 :             :       /* DR 2082 permits local variables in unevaluated contexts
   16000                 :             :          within a default argument.  */
   16001                 :          15 :       *walk_subtrees = 0;
   16002                 :          15 :       return NULL_TREE;
   16003                 :             :     }
   16004                 :             : 
   16005                 :     5070346 :   if (local_variable_p (*tp)
   16006                 :     5070346 :       && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
   16007                 :             :     return *tp;
   16008                 :     5070346 :   else if (TYPE_P (*tp))
   16009                 :          30 :     *walk_subtrees = 0;
   16010                 :             : 
   16011                 :             :   return NULL_TREE;
   16012                 :             : }
   16013                 :             : 
   16014                 :             : /* Check that ARG, which is a default-argument expression for a
   16015                 :             :    parameter DECL, is valid.  Returns ARG, or ERROR_MARK_NODE, if
   16016                 :             :    something goes wrong.  DECL may also be a _TYPE node, rather than a
   16017                 :             :    DECL, if there is no DECL available.  */
   16018                 :             : 
   16019                 :             : tree
   16020                 :     2608332 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
   16021                 :             : {
   16022                 :     2608332 :   tree var;
   16023                 :     2608332 :   tree decl_type;
   16024                 :             : 
   16025                 :     2608332 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
   16026                 :             :     /* We get a DEFERRED_PARSE when looking at an in-class declaration
   16027                 :             :        with a default argument.  Ignore the argument for now; we'll
   16028                 :             :        deal with it after the class is complete.  */
   16029                 :             :     return arg;
   16030                 :             : 
   16031                 :     1880744 :   if (TYPE_P (decl))
   16032                 :             :     {
   16033                 :             :       decl_type = decl;
   16034                 :             :       decl = NULL_TREE;
   16035                 :             :     }
   16036                 :             :   else
   16037                 :      569943 :     decl_type = TREE_TYPE (decl);
   16038                 :             : 
   16039                 :     1880744 :   if (arg == error_mark_node
   16040                 :     1880629 :       || decl == error_mark_node
   16041                 :     1880620 :       || TREE_TYPE (arg) == error_mark_node
   16042                 :     3761364 :       || decl_type == error_mark_node)
   16043                 :             :     /* Something already went wrong.  There's no need to check
   16044                 :             :        further.  */
   16045                 :             :     return error_mark_node;
   16046                 :             : 
   16047                 :             :   /* [dcl.fct.default]
   16048                 :             : 
   16049                 :             :      A default argument expression is implicitly converted to the
   16050                 :             :      parameter type.  */
   16051                 :     1880620 :   ++cp_unevaluated_operand;
   16052                 :             :   /* Avoid digest_init clobbering the initializer.  */
   16053                 :     1880620 :   tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
   16054                 :     1880620 :   perform_implicit_conversion_flags (decl_type, carg, complain,
   16055                 :             :                                      LOOKUP_IMPLICIT);
   16056                 :     1880620 :   --cp_unevaluated_operand;
   16057                 :             : 
   16058                 :             :   /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
   16059                 :             :      the call sites.  */
   16060                 :     1393108 :   if (TYPE_PTR_OR_PTRMEM_P (decl_type)
   16061                 :      487527 :       && null_ptr_cst_p (arg)
   16062                 :             :       /* Don't lose side-effects as in PR90473.  */
   16063                 :     2250582 :       && !TREE_SIDE_EFFECTS (arg))
   16064                 :      369959 :     return nullptr_node;
   16065                 :             : 
   16066                 :             :   /* [dcl.fct.default]
   16067                 :             : 
   16068                 :             :      Local variables shall not be used in default argument
   16069                 :             :      expressions.
   16070                 :             : 
   16071                 :             :      The keyword `this' shall not be used in a default argument of a
   16072                 :             :      member function.  */
   16073                 :     1510661 :   var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
   16074                 :     1510661 :   if (var)
   16075                 :             :     {
   16076                 :           0 :       if (complain & tf_warning_or_error)
   16077                 :             :         {
   16078                 :           0 :           if (DECL_NAME (var) == this_identifier)
   16079                 :           0 :             permerror (input_location, "default argument %qE uses %qD",
   16080                 :             :                        arg, var);
   16081                 :             :           else
   16082                 :           0 :             error ("default argument %qE uses local variable %qD", arg, var);
   16083                 :             :         }
   16084                 :           0 :       return error_mark_node;
   16085                 :             :     }
   16086                 :             : 
   16087                 :             :   /* All is well.  */
   16088                 :     1510661 :   return arg;
   16089                 :             : }
   16090                 :             : 
   16091                 :             : /* Returns a deprecated type used within TYPE, or NULL_TREE if none.  */
   16092                 :             : 
   16093                 :             : static tree
   16094                 :   264837084 : type_is_deprecated (tree type)
   16095                 :             : {
   16096                 :   391833579 :   enum tree_code code;
   16097                 :   391833579 :   if (TREE_DEPRECATED (type))
   16098                 :             :     return type;
   16099                 :   391790838 :   if (TYPE_NAME (type))
   16100                 :             :     {
   16101                 :   260445470 :       if (TREE_DEPRECATED (TYPE_NAME (type)))
   16102                 :             :         return type;
   16103                 :             :       else
   16104                 :             :         {
   16105                 :   260445464 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   16106                 :   260445464 :           return NULL_TREE;
   16107                 :             :         }
   16108                 :             :     }
   16109                 :             : 
   16110                 :             :   /* Do warn about using typedefs to a deprecated class.  */
   16111                 :   131345368 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   16112                 :           0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   16113                 :             : 
   16114                 :   131345368 :   code = TREE_CODE (type);
   16115                 :             : 
   16116                 :   131345368 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   16117                 :   131345368 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   16118                 :             :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   16119                 :   126882740 :     return type_is_deprecated (TREE_TYPE (type));
   16120                 :             : 
   16121                 :      113755 :   if (TYPE_PTRMEMFUNC_P (type))
   16122                 :      113755 :     return type_is_deprecated
   16123                 :      113755 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   16124                 :             : 
   16125                 :             :   return NULL_TREE;
   16126                 :             : }
   16127                 :             : 
   16128                 :             : /* Returns an unavailable type used within TYPE, or NULL_TREE if none.  */
   16129                 :             : 
   16130                 :             : static tree
   16131                 :   265738937 : type_is_unavailable (tree type)
   16132                 :             : {
   16133                 :   393289054 :   enum tree_code code;
   16134                 :   393289054 :   if (TREE_UNAVAILABLE (type))
   16135                 :             :     return type;
   16136                 :   393289048 :   if (TYPE_NAME (type))
   16137                 :             :     {
   16138                 :   261360046 :       if (TREE_UNAVAILABLE (TYPE_NAME (type)))
   16139                 :             :         return type;
   16140                 :             :       else
   16141                 :             :         {
   16142                 :   261360040 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   16143                 :   261360040 :           return NULL_TREE;
   16144                 :             :         }
   16145                 :             :     }
   16146                 :             : 
   16147                 :             :   /* Do warn about using typedefs to a deprecated class.  */
   16148                 :   131929002 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   16149                 :           0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   16150                 :             : 
   16151                 :   131929002 :   code = TREE_CODE (type);
   16152                 :             : 
   16153                 :   131929002 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   16154                 :   131929002 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   16155                 :             :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   16156                 :   127328986 :     return type_is_unavailable (TREE_TYPE (type));
   16157                 :             : 
   16158                 :      221131 :   if (TYPE_PTRMEMFUNC_P (type))
   16159                 :      221131 :     return type_is_unavailable
   16160                 :      221131 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   16161                 :             : 
   16162                 :             :   return NULL_TREE;
   16163                 :             : }
   16164                 :             : 
   16165                 :             : /* Decode the list of parameter types for a function type.
   16166                 :             :    Given the list of things declared inside the parens,
   16167                 :             :    return a list of types.
   16168                 :             : 
   16169                 :             :    If this parameter does not end with an ellipsis, we append
   16170                 :             :    void_list_node.
   16171                 :             : 
   16172                 :             :    *PARMS is set to the chain of PARM_DECLs created.  */
   16173                 :             : 
   16174                 :             : tree
   16175                 :   177496269 : grokparms (tree parmlist, tree *parms)
   16176                 :             : {
   16177                 :   177496269 :   tree result = NULL_TREE;
   16178                 :   177496269 :   tree decls = NULL_TREE;
   16179                 :   177496269 :   tree parm;
   16180                 :   177496269 :   int any_error = 0;
   16181                 :             : 
   16182                 :   443860426 :   for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
   16183                 :             :     {
   16184                 :   442438114 :       tree type = NULL_TREE;
   16185                 :   442438114 :       tree init = TREE_PURPOSE (parm);
   16186                 :   442438114 :       tree decl = TREE_VALUE (parm);
   16187                 :             : 
   16188                 :   442438114 :       if (parm == void_list_node || parm == explicit_void_list_node)
   16189                 :             :         break;
   16190                 :             : 
   16191                 :   266364169 :       if (! decl || TREE_TYPE (decl) == error_mark_node)
   16192                 :             :         {
   16193                 :         185 :           any_error = 1;
   16194                 :         185 :           continue;
   16195                 :             :         }
   16196                 :             : 
   16197                 :   266363984 :       type = TREE_TYPE (decl);
   16198                 :   266363984 :       if (VOID_TYPE_P (type))
   16199                 :             :         {
   16200                 :          78 :           if (same_type_p (type, void_type_node)
   16201                 :          69 :               && !init
   16202                 :          57 :               && !DECL_NAME (decl) && !result
   16203                 :         102 :               && TREE_CHAIN (parm) == void_list_node)
   16204                 :             :             /* DR 577: A parameter list consisting of a single
   16205                 :             :                unnamed parameter of non-dependent type 'void'.  */
   16206                 :             :             break;
   16207                 :          66 :           else if (cv_qualified_p (type))
   16208                 :           9 :             error_at (DECL_SOURCE_LOCATION (decl),
   16209                 :             :                       "invalid use of cv-qualified type %qT in "
   16210                 :             :                       "parameter declaration", type);
   16211                 :             :           else
   16212                 :          57 :             error_at (DECL_SOURCE_LOCATION (decl),
   16213                 :             :                       "invalid use of type %<void%> in parameter "
   16214                 :             :                       "declaration");
   16215                 :             :           /* It's not a good idea to actually create parameters of
   16216                 :             :              type `void'; other parts of the compiler assume that a
   16217                 :             :              void type terminates the parameter list.  */
   16218                 :          66 :           type = error_mark_node;
   16219                 :          66 :           TREE_TYPE (decl) = error_mark_node;
   16220                 :             :         }
   16221                 :             : 
   16222                 :   266363972 :       if (type != error_mark_node)
   16223                 :             :         {
   16224                 :   266363906 :           if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   16225                 :             :             {
   16226                 :   265738937 :               tree unavailtype = type_is_unavailable (type);
   16227                 :   265738937 :               if (unavailtype)
   16228                 :          12 :                 cp_handle_deprecated_or_unavailable (unavailtype);
   16229                 :             :             }
   16230                 :   266363906 :           if (deprecated_state != DEPRECATED_SUPPRESS
   16231                 :   266363906 :               && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   16232                 :             :             {
   16233                 :   264837084 :               tree deptype = type_is_deprecated (type);
   16234                 :   264837084 :               if (deptype)
   16235                 :       42747 :                 cp_handle_deprecated_or_unavailable (deptype);
   16236                 :             :             }
   16237                 :             : 
   16238                 :             :           /* [dcl.fct] "A parameter with volatile-qualified type is
   16239                 :             :              deprecated."  */
   16240                 :   266363906 :           if (CP_TYPE_VOLATILE_P (type))
   16241                 :         504 :             warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
   16242                 :             :                         "%<volatile%>-qualified parameter is "
   16243                 :             :                         "deprecated");
   16244                 :             : 
   16245                 :             :           /* Top-level qualifiers on the parameters are
   16246                 :             :              ignored for function types.  */
   16247                 :   266363906 :           type = cp_build_qualified_type (type, 0);
   16248                 :   266363906 :           if (TREE_CODE (type) == METHOD_TYPE)
   16249                 :             :             {
   16250                 :           0 :               error ("parameter %qD invalidly declared method type", decl);
   16251                 :           0 :               type = build_pointer_type (type);
   16252                 :           0 :               TREE_TYPE (decl) = type;
   16253                 :             :             }
   16254                 :   266363906 :           else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
   16255                 :             :             {
   16256                 :             :               /* Before C++17 DR 393:
   16257                 :             :                  [dcl.fct]/6, parameter types cannot contain pointers
   16258                 :             :                  (references) to arrays of unknown bound.  */
   16259                 :     1709617 :               tree t = TREE_TYPE (type);
   16260                 :     1709617 :               int ptr = TYPE_PTR_P (type);
   16261                 :             : 
   16262                 :     1875659 :               while (1)
   16263                 :             :                 {
   16264                 :     1792638 :                   if (TYPE_PTR_P (t))
   16265                 :             :                     ptr = 1;
   16266                 :     1712827 :                   else if (TREE_CODE (t) != ARRAY_TYPE)
   16267                 :             :                     break;
   16268                 :        3220 :                   else if (!TYPE_DOMAIN (t))
   16269                 :             :                     break;
   16270                 :       83021 :                   t = TREE_TYPE (t);
   16271                 :             :                 }
   16272                 :     1709617 :               if (TREE_CODE (t) == ARRAY_TYPE)
   16273                 :          16 :                 pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   16274                 :             :                          ptr
   16275                 :             :                          ? G_("parameter %qD includes pointer to array of "
   16276                 :             :                               "unknown bound %qT")
   16277                 :             :                          : G_("parameter %qD includes reference to array of "
   16278                 :             :                               "unknown bound %qT"),
   16279                 :             :                          decl, t);
   16280                 :             :             }
   16281                 :             : 
   16282                 :   266363906 :           if (init && !processing_template_decl)
   16283                 :     1297522 :             init = check_default_argument (decl, init, tf_warning_or_error);
   16284                 :             :         }
   16285                 :             : 
   16286                 :   266363972 :       DECL_CHAIN (decl) = decls;
   16287                 :   266363972 :       decls = decl;
   16288                 :   266363972 :       result = tree_cons (init, type, result);
   16289                 :             :     }
   16290                 :   177496269 :   decls = nreverse (decls);
   16291                 :   177496269 :   result = nreverse (result);
   16292                 :   177496269 :   if (parm)
   16293                 :   176073957 :     result = chainon (result, void_list_node);
   16294                 :   177496269 :   *parms = decls;
   16295                 :   177496269 :   if (any_error)
   16296                 :         171 :     result = NULL_TREE;
   16297                 :             : 
   16298                 :         171 :   if (any_error)
   16299                 :             :     /* We had parm errors, recover by giving the function (...) type.  */
   16300                 :         171 :     result = NULL_TREE;
   16301                 :             : 
   16302                 :   177496269 :   return result;
   16303                 :             : }
   16304                 :             : 
   16305                 :             : 
   16306                 :             : /* D is a constructor or overloaded `operator='.
   16307                 :             : 
   16308                 :             :    Let T be the class in which D is declared. Then, this function
   16309                 :             :    returns:
   16310                 :             : 
   16311                 :             :    -1 if D's is an ill-formed constructor or copy assignment operator
   16312                 :             :       whose first parameter is of type `T'.
   16313                 :             :    0  if D is not a copy constructor or copy assignment
   16314                 :             :       operator.
   16315                 :             :    1  if D is a copy constructor or copy assignment operator whose
   16316                 :             :       first parameter is a reference to non-const qualified T.
   16317                 :             :    2  if D is a copy constructor or copy assignment operator whose
   16318                 :             :       first parameter is a reference to const qualified T.
   16319                 :             : 
   16320                 :             :    This function can be used as a predicate. Positive values indicate
   16321                 :             :    a copy constructor and nonzero values indicate a copy assignment
   16322                 :             :    operator.  */
   16323                 :             : 
   16324                 :             : int
   16325                 :   288934305 : copy_fn_p (const_tree d)
   16326                 :             : {
   16327                 :   288934305 :   tree args;
   16328                 :   288934305 :   tree arg_type;
   16329                 :   288934305 :   int result = 1;
   16330                 :             : 
   16331                 :   288934305 :   gcc_assert (DECL_FUNCTION_MEMBER_P (d));
   16332                 :             : 
   16333                 :   288934305 :   if (TREE_CODE (d) == TEMPLATE_DECL
   16334                 :   288934305 :       || (DECL_TEMPLATE_INFO (d)
   16335                 :   138654117 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   16336                 :             :     /* Instantiations of template member functions are never copy
   16337                 :             :        functions.  Note that member functions of templated classes are
   16338                 :             :        represented as template functions internally, and we must
   16339                 :             :        accept those as copy functions.  */
   16340                 :             :     return 0;
   16341                 :             : 
   16342                 :   243410452 :   if (!DECL_CONSTRUCTOR_P (d)
   16343                 :   243410452 :       && DECL_NAME (d) != assign_op_identifier)
   16344                 :             :     return 0;
   16345                 :             : 
   16346                 :   242640061 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   16347                 :             :     {
   16348                 :         154 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   16349                 :         154 :       if (!TYPE_REF_P (object_param)
   16350                 :         148 :           || TYPE_REF_IS_RVALUE (object_param)
   16351                 :             :           /* Reject unrelated object parameters. */
   16352                 :         136 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   16353                 :         290 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   16354                 :          24 :         return 0;
   16355                 :         130 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   16356                 :             :     }
   16357                 :             :   else
   16358                 :   242639907 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   16359                 :   242640037 :   if (!args)
   16360                 :             :     return 0;
   16361                 :             : 
   16362                 :   242632591 :   arg_type = TREE_VALUE (args);
   16363                 :   242632591 :   if (arg_type == error_mark_node)
   16364                 :             :     return 0;
   16365                 :             : 
   16366                 :   242632556 :   if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
   16367                 :             :     {
   16368                 :             :       /* Pass by value copy assignment operator.  */
   16369                 :             :       result = -1;
   16370                 :             :     }
   16371                 :   242630513 :   else if (TYPE_REF_P (arg_type)
   16372                 :   149296381 :            && !TYPE_REF_IS_RVALUE (arg_type)
   16373                 :   338851494 :            && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
   16374                 :             :     {
   16375                 :    75738747 :       if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
   16376                 :    75650689 :         result = 2;
   16377                 :             :     }
   16378                 :             :   else
   16379                 :             :     return 0;
   16380                 :             : 
   16381                 :    75740790 :   args = TREE_CHAIN (args);
   16382                 :             : 
   16383                 :    78383698 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   16384                 :             :     /* There are more non-optional args.  */
   16385                 :             :     return 0;
   16386                 :             : 
   16387                 :             :   return result;
   16388                 :             : }
   16389                 :             : 
   16390                 :             : /* D is a constructor or overloaded `operator='.
   16391                 :             : 
   16392                 :             :    Let T be the class in which D is declared. Then, this function
   16393                 :             :    returns true when D is a move constructor or move assignment
   16394                 :             :    operator, false otherwise.  */
   16395                 :             : 
   16396                 :             : bool
   16397                 :   116681182 : move_fn_p (const_tree d)
   16398                 :             : {
   16399                 :   116681182 :   if (cxx_dialect == cxx98)
   16400                 :             :     /* There are no move constructors if we are in C++98 mode.  */
   16401                 :             :     return false;
   16402                 :             : 
   16403                 :   116604256 :   if (TREE_CODE (d) == TEMPLATE_DECL
   16404                 :   116604256 :       || (DECL_TEMPLATE_INFO (d)
   16405                 :    52674910 :          && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   16406                 :             :     /* Instantiations of template member functions are never move
   16407                 :             :        functions.  Note that member functions of templated classes are
   16408                 :             :        represented as template functions internally, and we must
   16409                 :             :        accept those as move functions.  */
   16410                 :             :     return 0;
   16411                 :             : 
   16412                 :    96567499 :   return move_signature_fn_p (d);
   16413                 :             : }
   16414                 :             : 
   16415                 :             : /* D is a constructor or overloaded `operator='.
   16416                 :             : 
   16417                 :             :    Then, this function returns true when D has the same signature as a move
   16418                 :             :    constructor or move assignment operator (because either it is such a
   16419                 :             :    ctor/op= or it is a template specialization with the same signature),
   16420                 :             :    false otherwise.  */
   16421                 :             : 
   16422                 :             : bool
   16423                 :    96567499 : move_signature_fn_p (const_tree d)
   16424                 :             : {
   16425                 :    96567499 :   tree args;
   16426                 :    96567499 :   tree arg_type;
   16427                 :    96567499 :   bool result = false;
   16428                 :             : 
   16429                 :    96567499 :   if (!DECL_CONSTRUCTOR_P (d)
   16430                 :    96567499 :       && DECL_NAME (d) != assign_op_identifier)
   16431                 :             :     return 0;
   16432                 :             : 
   16433                 :    96567435 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   16434                 :             :     {
   16435                 :          88 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   16436                 :          88 :       if (!TYPE_REF_P (object_param)
   16437                 :          84 :           || TYPE_REF_IS_RVALUE (object_param)
   16438                 :             :           /* Reject unrelated object parameters. */
   16439                 :          76 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   16440                 :         164 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   16441                 :          16 :         return 0;
   16442                 :          72 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   16443                 :             :     }
   16444                 :             :   else
   16445                 :    96567347 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   16446                 :    96567419 :   if (!args)
   16447                 :             :     return 0;
   16448                 :             : 
   16449                 :    96564685 :   arg_type = TREE_VALUE (args);
   16450                 :    96564685 :   if (arg_type == error_mark_node)
   16451                 :             :     return 0;
   16452                 :             : 
   16453                 :    96564677 :   if (TYPE_REF_P (arg_type)
   16454                 :    47257875 :       && TYPE_REF_IS_RVALUE (arg_type)
   16455                 :   133434573 :       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
   16456                 :             :                       DECL_CONTEXT (d)))
   16457                 :             :     result = true;
   16458                 :             : 
   16459                 :    96564677 :   args = TREE_CHAIN (args);
   16460                 :             : 
   16461                 :   107199735 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   16462                 :             :     /* There are more non-optional args.  */
   16463                 :             :     return false;
   16464                 :             : 
   16465                 :             :   return result;
   16466                 :             : }
   16467                 :             : 
   16468                 :             : /* Remember any special properties of member function DECL.  */
   16469                 :             : 
   16470                 :             : void
   16471                 :   295008954 : grok_special_member_properties (tree decl)
   16472                 :             : {
   16473                 :   295008954 :   tree class_type;
   16474                 :             : 
   16475                 :   295008954 :   if (TREE_CODE (decl) == USING_DECL
   16476                 :   295008954 :       || !DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   16477                 :             :     return;
   16478                 :             : 
   16479                 :   277251999 :   class_type = DECL_CONTEXT (decl);
   16480                 :   277251999 :   if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
   16481                 :             :     {
   16482                 :   122066241 :       int ctor = copy_fn_p (decl);
   16483                 :             : 
   16484                 :   122066241 :       if (!DECL_ARTIFICIAL (decl))
   16485                 :    92056039 :         TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
   16486                 :             : 
   16487                 :   122066241 :       if (ctor > 0)
   16488                 :             :         {
   16489                 :             :           /* [class.copy]
   16490                 :             : 
   16491                 :             :              A non-template constructor for class X is a copy
   16492                 :             :              constructor if its first parameter is of type X&, const
   16493                 :             :              X&, volatile X& or const volatile X&, and either there
   16494                 :             :              are no other parameters or else all other parameters have
   16495                 :             :              default arguments.  */
   16496                 :    23777753 :           TYPE_HAS_COPY_CTOR (class_type) = 1;
   16497                 :    23777753 :           if (ctor > 1)
   16498                 :    23747386 :             TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
   16499                 :             :         }
   16500                 :             : 
   16501                 :   122066241 :       if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
   16502                 :    25288780 :         TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
   16503                 :             : 
   16504                 :   122066241 :       if (is_list_ctor (decl))
   16505                 :     1448235 :         TYPE_HAS_LIST_CTOR (class_type) = 1;
   16506                 :             : 
   16507                 :   122066241 :       if (maybe_constexpr_fn (decl)
   16508                 :   122066241 :           && !ctor && !move_fn_p (decl))
   16509                 :    30076417 :         TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
   16510                 :             :     }
   16511                 :   155185758 :   else if (DECL_NAME (decl) == assign_op_identifier)
   16512                 :             :     {
   16513                 :             :       /* [class.copy]
   16514                 :             : 
   16515                 :             :          A non-template assignment operator for class X is a copy
   16516                 :             :          assignment operator if its parameter is of type X, X&, const
   16517                 :             :          X&, volatile X& or const volatile X&.  */
   16518                 :             : 
   16519                 :    13389183 :       int assop = copy_fn_p (decl);
   16520                 :             : 
   16521                 :    13389183 :       if (assop)
   16522                 :             :         {
   16523                 :     6693787 :           TYPE_HAS_COPY_ASSIGN (class_type) = 1;
   16524                 :     6693787 :           if (assop != 1)
   16525                 :     6663846 :             TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
   16526                 :             :         }
   16527                 :             :     }
   16528                 :   141796575 :   else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
   16529                 :     1972826 :     TYPE_HAS_CONVERSION (class_type) = true;
   16530                 :             : 
   16531                 :             :   /* Destructors are handled in check_methods.  */
   16532                 :             : }
   16533                 :             : 
   16534                 :             : /* Check a constructor DECL has the correct form.  Complains
   16535                 :             :    if the class has a constructor of the form X(X).  */
   16536                 :             : 
   16537                 :             : bool
   16538                 :    43074952 : grok_ctor_properties (const_tree ctype, const_tree decl)
   16539                 :             : {
   16540                 :    43074952 :   int ctor_parm = copy_fn_p (decl);
   16541                 :             : 
   16542                 :    43074952 :   if (ctor_parm < 0)
   16543                 :             :     {
   16544                 :             :       /* [class.copy]
   16545                 :             : 
   16546                 :             :          A declaration of a constructor for a class X is ill-formed if
   16547                 :             :          its first parameter is of type (optionally cv-qualified) X
   16548                 :             :          and either there are no other parameters or else all other
   16549                 :             :          parameters have default arguments.
   16550                 :             : 
   16551                 :             :          We *don't* complain about member template instantiations that
   16552                 :             :          have this form, though; they can occur as we try to decide
   16553                 :             :          what constructor to use during overload resolution.  Since
   16554                 :             :          overload resolution will never prefer such a constructor to
   16555                 :             :          the non-template copy constructor (which is either explicitly
   16556                 :             :          or implicitly defined), there's no need to worry about their
   16557                 :             :          existence.  Theoretically, they should never even be
   16558                 :             :          instantiated, but that's hard to forestall.  */
   16559                 :           9 :       error_at (DECL_SOURCE_LOCATION (decl),
   16560                 :             :                 "invalid constructor; you probably meant %<%T (const %T&)%>",
   16561                 :             :                 ctype, ctype);
   16562                 :           9 :       return false;
   16563                 :             :     }
   16564                 :             : 
   16565                 :             :   return true;
   16566                 :             : }
   16567                 :             : 
   16568                 :             : /* DECL is a declaration for an overloaded or conversion operator.  If
   16569                 :             :    COMPLAIN is true, errors are issued for invalid declarations.  */
   16570                 :             : 
   16571                 :             : bool
   16572                 :    51570410 : grok_op_properties (tree decl, bool complain)
   16573                 :             : {
   16574                 :    51570410 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   16575                 :    51570410 :   bool const methodp = DECL_IOBJ_MEMBER_FUNCTION_P (decl);
   16576                 :    51570410 :   tree name = DECL_NAME (decl);
   16577                 :    51570410 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   16578                 :             : 
   16579                 :    51570410 :   tree class_type = DECL_CONTEXT (decl);
   16580                 :    51570410 :   if (class_type && !CLASS_TYPE_P (class_type))
   16581                 :             :     class_type = NULL_TREE;
   16582                 :             : 
   16583                 :    51570410 :   tree_code operator_code;
   16584                 :    51570410 :   unsigned op_flags;
   16585                 :    51570410 :   if (IDENTIFIER_CONV_OP_P (name))
   16586                 :             :     {
   16587                 :             :       /* Conversion operators are TYPE_EXPR for the purposes of this
   16588                 :             :          function.  */
   16589                 :             :       operator_code = TYPE_EXPR;
   16590                 :             :       op_flags = OVL_OP_FLAG_UNARY;
   16591                 :             :     }
   16592                 :             :   else
   16593                 :             :     {
   16594                 :    49932983 :       const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
   16595                 :             : 
   16596                 :    49932983 :       operator_code = ovl_op->tree_code;
   16597                 :    49932983 :       op_flags = ovl_op->flags;
   16598                 :    49932983 :       gcc_checking_assert (operator_code != ERROR_MARK);
   16599                 :    49932983 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   16600                 :             :     }
   16601                 :             : 
   16602                 :    49932983 :   if (op_flags & OVL_OP_FLAG_ALLOC)
   16603                 :             :     {
   16604                 :             :       /* operator new and operator delete are quite special.  */
   16605                 :      340354 :       if (class_type)
   16606                 :       13332 :         switch (op_flags)
   16607                 :             :           {
   16608                 :        9445 :           case OVL_OP_FLAG_ALLOC:
   16609                 :        9445 :             TYPE_HAS_NEW_OPERATOR (class_type) = 1;
   16610                 :        9445 :             break;
   16611                 :             : 
   16612                 :        3620 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
   16613                 :        3620 :             TYPE_GETS_DELETE (class_type) |= 1;
   16614                 :        3620 :             break;
   16615                 :             : 
   16616                 :         130 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
   16617                 :         130 :             TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
   16618                 :         130 :             break;
   16619                 :             : 
   16620                 :         137 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
   16621                 :         137 :             TYPE_GETS_DELETE (class_type) |= 2;
   16622                 :         137 :             break;
   16623                 :             : 
   16624                 :           0 :           default:
   16625                 :           0 :             gcc_unreachable ();
   16626                 :             :           }
   16627                 :             : 
   16628                 :             :       /* [basic.std.dynamic.allocation]/1:
   16629                 :             : 
   16630                 :             :          A program is ill-formed if an allocation function is declared
   16631                 :             :          in a namespace scope other than global scope or declared
   16632                 :             :          static in global scope.
   16633                 :             : 
   16634                 :             :          The same also holds true for deallocation functions.  */
   16635                 :      340354 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   16636                 :             :         {
   16637                 :      327022 :           if (CP_DECL_CONTEXT (decl) != global_namespace)
   16638                 :             :             {
   16639                 :           6 :               error_at (loc, "%qD may not be declared within a namespace",
   16640                 :             :                         decl);
   16641                 :           6 :               return false;
   16642                 :             :             }
   16643                 :             : 
   16644                 :      327016 :           if (!TREE_PUBLIC (decl))
   16645                 :             :             {
   16646                 :           6 :               error_at (loc, "%qD may not be declared as static", decl);
   16647                 :           6 :               return false;
   16648                 :             :             }
   16649                 :             :         }
   16650                 :             : 
   16651                 :             :       /* Check for replaceable global new/delete operators with
   16652                 :             :          const std::nothrow_t & last argument, other replaceable global
   16653                 :             :          new/delete operators are marked in cxx_init_decl_processing.  */
   16654                 :      340342 :       if (CP_DECL_CONTEXT (decl) == global_namespace)
   16655                 :             :         {
   16656                 :      327010 :           tree args = argtypes;
   16657                 :      327010 :           if (args
   16658                 :      326998 :               && args != void_list_node
   16659                 :      980988 :               && same_type_p (TREE_VALUE (args),
   16660                 :             :                               (op_flags & OVL_OP_FLAG_DELETE)
   16661                 :             :                               ? ptr_type_node : size_type_node))
   16662                 :             :             {
   16663                 :      326968 :               args = TREE_CHAIN (args);
   16664                 :      326968 :               if (aligned_allocation_fn_p (decl))
   16665                 :      105292 :                 args = TREE_CHAIN (args);
   16666                 :      326968 :               if (args
   16667                 :      326962 :                   && args != void_list_node
   16668                 :      545189 :                   && TREE_CHAIN (args) == void_list_node)
   16669                 :             :                 {
   16670                 :      191854 :                   tree t = TREE_VALUE (args);
   16671                 :      191854 :                   if (TYPE_REF_P (t)
   16672                 :      108842 :                       && !TYPE_REF_IS_RVALUE (t)
   16673                 :      108842 :                       && (t = TREE_TYPE (t))
   16674                 :      108842 :                       && TYPE_QUALS (t) == TYPE_QUAL_CONST
   16675                 :      300248 :                       && is_std_class (t, "nothrow_t"))
   16676                 :      108394 :                     DECL_IS_REPLACEABLE_OPERATOR (decl) = 1;
   16677                 :             :                 }
   16678                 :             :             }
   16679                 :             :         }
   16680                 :             : 
   16681                 :      340342 :       if (op_flags & OVL_OP_FLAG_DELETE)
   16682                 :             :         {
   16683                 :      193003 :           DECL_SET_IS_OPERATOR_DELETE (decl, true);
   16684                 :      193003 :           coerce_delete_type (decl, loc);
   16685                 :             :         }
   16686                 :             :       else
   16687                 :             :         {
   16688                 :      147339 :           DECL_SET_IS_OPERATOR_NEW (decl, true);
   16689                 :      147339 :           TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
   16690                 :             :         }
   16691                 :             : 
   16692                 :      340342 :       return true;
   16693                 :             :     }
   16694                 :             : 
   16695                 :             :   /* An operator function must either be a non-static member function
   16696                 :             :      or have at least one parameter of a class, a reference to a class,
   16697                 :             :      an enumeration, or a reference to an enumeration.  13.4.0.6 */
   16698                 :    51230056 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   16699                 :             :     {
   16700                 :    14931977 :       if (operator_code == TYPE_EXPR
   16701                 :    14931977 :           || operator_code == COMPONENT_REF
   16702                 :    14931956 :           || operator_code == NOP_EXPR)
   16703                 :             :         {
   16704                 :          33 :           error_at (loc, "%qD must be a non-static member function", decl);
   16705                 :          33 :           return false;
   16706                 :             :         }
   16707                 :             : 
   16708                 :    14931944 :       if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
   16709                 :             :         {
   16710                 :         110 :           if (! DECL_STATIC_FUNCTION_P (decl))
   16711                 :             :             {
   16712                 :          12 :               error_at (loc, "%qD must be a member function", decl);
   16713                 :          12 :               return false;
   16714                 :             :             }
   16715                 :          98 :           if (cxx_dialect < cxx23
   16716                 :             :               /* For lambdas we diagnose static lambda specifier elsewhere.  */
   16717                 :          95 :               && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
   16718                 :             :               /* For instantiations, we have diagnosed this already.  */
   16719                 :         130 :               && ! DECL_USE_TEMPLATE (decl))
   16720                 :          26 :             pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
   16721                 :             :                      "function only with %<-std=c++23%> or %<-std=gnu++23%>",
   16722                 :             :                      decl);
   16723                 :          98 :           if (operator_code == ARRAY_REF)
   16724                 :             :             /* static operator[] should have exactly one argument
   16725                 :             :                for C++20 and earlier, so that it isn't multidimensional.  */
   16726                 :             :             op_flags = OVL_OP_FLAG_UNARY;
   16727                 :             :         }
   16728                 :    14931834 :       else if (DECL_STATIC_FUNCTION_P (decl))
   16729                 :             :         {
   16730                 :           9 :           error_at (loc, "%qD must be either a non-static member "
   16731                 :             :                     "function or a non-member function", decl);
   16732                 :           9 :           return false;
   16733                 :             :         }
   16734                 :             :       else
   16735                 :      506798 :         for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
   16736                 :             :           {
   16737                 :    15438623 :             if (!arg || arg == void_list_node)
   16738                 :             :               {
   16739                 :          18 :                 if (complain)
   16740                 :          15 :                   error_at (loc, "%qD must have an argument of class or "
   16741                 :             :                             "enumerated type", decl);
   16742                 :          18 :                 return false;
   16743                 :             :               }
   16744                 :             : 
   16745                 :    15438605 :             tree type = non_reference (TREE_VALUE (arg));
   16746                 :    15438605 :             if (type == error_mark_node)
   16747                 :             :               return false;
   16748                 :             : 
   16749                 :             :             /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
   16750                 :             :                because these checks are performed even on template
   16751                 :             :                functions.  */
   16752                 :    15438602 :             if (MAYBE_CLASS_TYPE_P (type)
   16753                 :     1480710 :                 || TREE_CODE (type) == ENUMERAL_TYPE)
   16754                 :             :               break;
   16755                 :      506798 :           }
   16756                 :             :     }
   16757                 :             : 
   16758                 :    51229945 :   if (operator_code == CALL_EXPR)
   16759                 :             :     /* There are no further restrictions on the arguments to an overloaded
   16760                 :             :        "operator ()".  */
   16761                 :             :     return true;
   16762                 :             : 
   16763                 :             :   /* C++23 allows an arbitrary number of parameters and default arguments for
   16764                 :             :      operator[], and none of the other checks below apply.  */
   16765                 :    44958327 :   if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
   16766                 :             :     return true;
   16767                 :             : 
   16768                 :    44600600 :   if (operator_code == COND_EXPR)
   16769                 :             :     {
   16770                 :             :       /* 13.4.0.3 */
   16771                 :           6 :       error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
   16772                 :           6 :       return false;
   16773                 :             :     }
   16774                 :             : 
   16775                 :             :   /* Count the number of arguments and check for ellipsis.  */
   16776                 :             :   int arity = 0;
   16777                 :   127797326 :   for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
   16778                 :             :     {
   16779                 :    83196747 :       if (!arg)
   16780                 :             :         {
   16781                 :          15 :           error_at (loc, "%qD must not have variable number of arguments",
   16782                 :             :                     decl);
   16783                 :          15 :           return false;
   16784                 :             :         }
   16785                 :    83196732 :       ++arity;
   16786                 :             :     }
   16787                 :             :   /* FIXME: We need tests for these errors with xobj member functions.  */
   16788                 :             :   /* Verify correct number of arguments.  */
   16789                 :    44600579 :   switch (op_flags)
   16790                 :             :     {
   16791                 :     7739083 :     case OVL_OP_FLAG_AMBIARY:
   16792                 :     7739083 :       if (arity == 1)
   16793                 :             :         {
   16794                 :             :           /* We have a unary instance of an ambi-ary op.  Remap to the
   16795                 :             :              unary one.  */
   16796                 :     3433849 :           unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
   16797                 :     3433849 :           const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
   16798                 :     3433849 :           gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
   16799                 :     3433849 :           operator_code = ovl_op->tree_code;
   16800                 :     3433849 :           DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   16801                 :             :         }
   16802                 :     4305234 :       else if (arity != 2)
   16803                 :             :         {
   16804                 :             :           /* This was an ambiguous operator but is invalid. */
   16805                 :           3 :           error_at (loc,
   16806                 :             :                     methodp
   16807                 :             :                     ? G_("%qD must have either zero or one argument")
   16808                 :             :                     : G_("%qD must have either one or two arguments"), decl);
   16809                 :           3 :           return false;
   16810                 :             :         }
   16811                 :     4305231 :       else if ((operator_code == POSTINCREMENT_EXPR
   16812                 :     4305231 :                 || operator_code == POSTDECREMENT_EXPR)
   16813                 :     2084730 :                && ! processing_template_decl
   16814                 :             :                /* x++ and x--'s second argument must be an int.  */
   16815                 :     5686320 :                && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
   16816                 :             :                                  integer_type_node))
   16817                 :             :         {
   16818                 :          15 :           error_at (loc,
   16819                 :             :                     methodp
   16820                 :             :                     ? G_("postfix %qD must have %<int%> as its argument")
   16821                 :             :                     : G_("postfix %qD must have %<int%> as its second argument"),
   16822                 :             :                     decl);
   16823                 :          15 :           return false;
   16824                 :             :         }
   16825                 :             :       break;
   16826                 :             : 
   16827                 :     2570607 :     case OVL_OP_FLAG_UNARY:
   16828                 :     2570607 :       if (arity != 1)
   16829                 :             :         {
   16830                 :          12 :           error_at (loc,
   16831                 :             :                     methodp
   16832                 :             :                     ? G_("%qD must have no arguments")
   16833                 :             :                     : G_("%qD must have exactly one argument"), decl);
   16834                 :          12 :           return false;
   16835                 :             :         }
   16836                 :             :       break;
   16837                 :             : 
   16838                 :    34290889 :     case OVL_OP_FLAG_BINARY:
   16839                 :    34290889 :       if (arity != 2)
   16840                 :             :         {
   16841                 :           3 :           error_at (loc,
   16842                 :             :                     methodp
   16843                 :             :                     ? G_("%qD must have exactly one argument")
   16844                 :             :                     : G_("%qD must have exactly two arguments"), decl);
   16845                 :           3 :           return false;
   16846                 :             :         }
   16847                 :             :       break;
   16848                 :             : 
   16849                 :           0 :     default:
   16850                 :           0 :       gcc_unreachable ();
   16851                 :             :     }
   16852                 :             : 
   16853                 :             :   /* There can be no default arguments.  */
   16854                 :   127797179 :   for (tree arg = argtypes; arg && arg != void_list_node;
   16855                 :    83196633 :        arg = TREE_CHAIN (arg))
   16856                 :    83196648 :     if (TREE_PURPOSE (arg))
   16857                 :             :       {
   16858                 :          15 :         TREE_PURPOSE (arg) = NULL_TREE;
   16859                 :          15 :         error_at (loc, "%qD cannot have default arguments", decl);
   16860                 :          15 :         return false;
   16861                 :             :       }
   16862                 :             : 
   16863                 :             :   /* At this point the declaration is well-formed.  It may not be
   16864                 :             :      sensible though.  */
   16865                 :             : 
   16866                 :             :   /* Check member function warnings only on the in-class declaration.
   16867                 :             :      There's no point warning on an out-of-class definition.  */
   16868                 :    44600531 :   if (class_type && class_type != current_class_type)
   16869                 :             :     return true;
   16870                 :             : 
   16871                 :             :   /* Warn about conversion operators that will never be used.  */
   16872                 :    42643101 :   if (IDENTIFIER_CONV_OP_P (name)
   16873                 :     1636963 :       && ! DECL_TEMPLATE_INFO (decl)
   16874                 :    43282782 :       && warn_class_conversion)
   16875                 :             :     {
   16876                 :      639648 :       tree t = TREE_TYPE (name);
   16877                 :      639648 :       int ref = TYPE_REF_P (t);
   16878                 :             : 
   16879                 :      639648 :       if (ref)
   16880                 :       23667 :         t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
   16881                 :             : 
   16882                 :      639648 :       if (VOID_TYPE_P (t))
   16883                 :           9 :         warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
   16884                 :             :                     "will never use a type conversion operator", class_type);
   16885                 :      639639 :       else if (class_type)
   16886                 :             :         {
   16887                 :      639639 :           if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
   16888                 :          24 :             warning_at (loc, OPT_Wclass_conversion,
   16889                 :             :                         ref
   16890                 :             :                         ? G_("converting %qT to a reference to the same type "
   16891                 :             :                              "will never use a type conversion operator")
   16892                 :             :                         : G_("converting %qT to the same type "
   16893                 :             :                              "will never use a type conversion operator"),
   16894                 :             :                         class_type);
   16895                 :             :           /* Don't force t to be complete here.  */
   16896                 :      639624 :           else if (MAYBE_CLASS_TYPE_P (t)
   16897                 :      281521 :                    && COMPLETE_TYPE_P (t)
   16898                 :       60260 :                    && DERIVED_FROM_P (t, class_type))
   16899                 :          30 :             warning_at (loc, OPT_Wclass_conversion,
   16900                 :             :                         ref
   16901                 :             :                         ? G_("converting %qT to a reference to a base class "
   16902                 :             :                              "%qT will never use a type conversion operator")
   16903                 :             :                         : G_("converting %qT to a base class %qT "
   16904                 :             :                              "will never use a type conversion operator"),
   16905                 :             :                         class_type, t);
   16906                 :             :         }
   16907                 :             :     }
   16908                 :             : 
   16909                 :    42643101 :   if (!warn_ecpp)
   16910                 :             :     return true;
   16911                 :             : 
   16912                 :             :   /* Effective C++ rules below.  */
   16913                 :             : 
   16914                 :             :   /* More Effective C++ rule 7.  */
   16915                 :          54 :   if (operator_code == TRUTH_ANDIF_EXPR
   16916                 :          54 :       || operator_code == TRUTH_ORIF_EXPR
   16917                 :          54 :       || operator_code == COMPOUND_EXPR)
   16918                 :           0 :     warning_at (loc, OPT_Weffc__,
   16919                 :             :                 "user-defined %qD always evaluates both arguments", decl);
   16920                 :             : 
   16921                 :             :   /* More Effective C++ rule 6.  */
   16922                 :          54 :   if (operator_code == POSTINCREMENT_EXPR
   16923                 :             :       || operator_code == POSTDECREMENT_EXPR
   16924                 :             :       || operator_code == PREINCREMENT_EXPR
   16925                 :          54 :       || operator_code == PREDECREMENT_EXPR)
   16926                 :             :     {
   16927                 :           0 :       tree arg = TREE_VALUE (argtypes);
   16928                 :           0 :       tree ret = TREE_TYPE (TREE_TYPE (decl));
   16929                 :           0 :       if (methodp || TYPE_REF_P (arg))
   16930                 :           0 :         arg = TREE_TYPE (arg);
   16931                 :           0 :       arg = TYPE_MAIN_VARIANT (arg);
   16932                 :             : 
   16933                 :           0 :       if (operator_code == PREINCREMENT_EXPR
   16934                 :             :           || operator_code == PREDECREMENT_EXPR)
   16935                 :             :         {
   16936                 :           0 :           if (!TYPE_REF_P (ret)
   16937                 :           0 :               || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
   16938                 :           0 :             warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
   16939                 :             :                         build_reference_type (arg));
   16940                 :             :         }
   16941                 :             :       else
   16942                 :             :         {
   16943                 :           0 :           if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
   16944                 :           0 :             warning_at (loc, OPT_Weffc__,
   16945                 :             :                         "postfix %qD should return %qT", decl, arg);
   16946                 :             :         }
   16947                 :             :     }
   16948                 :             : 
   16949                 :             :   /* Effective C++ rule 23.  */
   16950                 :          54 :   if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
   16951                 :             :       && (operator_code == PLUS_EXPR
   16952                 :           9 :           || operator_code == MINUS_EXPR
   16953                 :           9 :           || operator_code == TRUNC_DIV_EXPR
   16954                 :             :           || operator_code == MULT_EXPR
   16955                 :             :           || operator_code == TRUNC_MOD_EXPR)
   16956                 :          60 :       && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
   16957                 :           3 :     warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
   16958                 :             : 
   16959                 :             :   return true;
   16960                 :             : }
   16961                 :             : 
   16962                 :             : /* Return a string giving the keyword associate with CODE.  */
   16963                 :             : 
   16964                 :             : static const char *
   16965                 :         111 : tag_name (enum tag_types code)
   16966                 :             : {
   16967                 :         111 :   switch (code)
   16968                 :             :     {
   16969                 :             :     case record_type:
   16970                 :             :       return "struct";
   16971                 :          60 :     case class_type:
   16972                 :          60 :       return "class";
   16973                 :           0 :     case union_type:
   16974                 :           0 :       return "union";
   16975                 :           3 :     case enum_type:
   16976                 :           3 :       return "enum";
   16977                 :           0 :     case typename_type:
   16978                 :           0 :       return "typename";
   16979                 :           0 :     default:
   16980                 :           0 :       gcc_unreachable ();
   16981                 :             :     }
   16982                 :             : }
   16983                 :             : 
   16984                 :             : /* Name lookup in an elaborated-type-specifier (after the keyword
   16985                 :             :    indicated by TAG_CODE) has found the TYPE_DECL DECL.  If the
   16986                 :             :    elaborated-type-specifier is invalid, issue a diagnostic and return
   16987                 :             :    error_mark_node; otherwise, return the *_TYPE to which it referred.
   16988                 :             :    If ALLOW_TEMPLATE_P is true, TYPE may be a class template.  */
   16989                 :             : 
   16990                 :             : tree
   16991                 :    11415445 : check_elaborated_type_specifier (enum tag_types tag_code,
   16992                 :             :                                  tree decl,
   16993                 :             :                                  bool allow_template_p)
   16994                 :             : {
   16995                 :    11415445 :   tree type;
   16996                 :             : 
   16997                 :             :   /* In the case of:
   16998                 :             : 
   16999                 :             :        struct S { struct S *p; };
   17000                 :             : 
   17001                 :             :      name lookup will find the TYPE_DECL for the implicit "S::S"
   17002                 :             :      typedef.  Adjust for that here.  */
   17003                 :    11415445 :   if (DECL_SELF_REFERENCE_P (decl))
   17004                 :      341366 :     decl = TYPE_NAME (TREE_TYPE (decl));
   17005                 :             : 
   17006                 :    11415445 :   type = TREE_TYPE (decl);
   17007                 :             : 
   17008                 :             :   /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
   17009                 :             :      is false for this case as well.  */
   17010                 :    11415445 :   if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   17011                 :             :     {
   17012                 :           9 :       error ("using template type parameter %qT after %qs",
   17013                 :             :              type, tag_name (tag_code));
   17014                 :           9 :       return error_mark_node;
   17015                 :             :     }
   17016                 :             :   /* Accept template template parameters.  */
   17017                 :    11415436 :   else if (allow_template_p
   17018                 :     6531687 :            && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
   17019                 :     6531675 :                || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
   17020                 :             :     ;
   17021                 :             :   /*   [dcl.type.elab]
   17022                 :             : 
   17023                 :             :        If the identifier resolves to a typedef-name or the
   17024                 :             :        simple-template-id resolves to an alias template
   17025                 :             :        specialization, the elaborated-type-specifier is ill-formed.
   17026                 :             : 
   17027                 :             :      In other words, the only legitimate declaration to use in the
   17028                 :             :      elaborated type specifier is the implicit typedef created when
   17029                 :             :      the type is declared.  */
   17030                 :    11415421 :   else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
   17031                 :      341480 :            && !DECL_SELF_REFERENCE_P (decl)
   17032                 :    11415535 :            && tag_code != typename_type)
   17033                 :             :     {
   17034                 :          78 :       auto_diagnostic_group d;
   17035                 :          78 :       if (alias_template_specialization_p (type, nt_opaque))
   17036                 :          21 :         error ("using alias template specialization %qT after %qs",
   17037                 :             :                type, tag_name (tag_code));
   17038                 :             :       else
   17039                 :          57 :         error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
   17040                 :          78 :       inform (DECL_SOURCE_LOCATION (decl),
   17041                 :             :               "%qD has a previous declaration here", decl);
   17042                 :          78 :       return error_mark_node;
   17043                 :          78 :     }
   17044                 :    11415343 :   else if (TREE_CODE (type) != RECORD_TYPE
   17045                 :    11415343 :            && TREE_CODE (type) != UNION_TYPE
   17046                 :             :            && tag_code != enum_type
   17047                 :       64467 :            && tag_code != typename_type)
   17048                 :             :     {
   17049                 :           6 :       auto_diagnostic_group d;
   17050                 :           6 :       error ("%qT referred to as %qs", type, tag_name (tag_code));
   17051                 :           6 :       inform (location_of (type), "%qT has a previous declaration here", type);
   17052                 :           6 :       return error_mark_node;
   17053                 :           6 :     }
   17054                 :    11415337 :   else if (TREE_CODE (type) != ENUMERAL_TYPE
   17055                 :    11350906 :            && tag_code == enum_type)
   17056                 :             :     {
   17057                 :           3 :       auto_diagnostic_group d;
   17058                 :           3 :       error ("%qT referred to as enum", type);
   17059                 :           3 :       inform (location_of (type), "%qT has a previous declaration here", type);
   17060                 :           3 :       return error_mark_node;
   17061                 :           3 :     }
   17062                 :    11415334 :   else if (!allow_template_p
   17063                 :     4883689 :            && TREE_CODE (type) == RECORD_TYPE
   17064                 :    16180330 :            && CLASSTYPE_IS_TEMPLATE (type))
   17065                 :             :     {
   17066                 :             :       /* If a class template appears as elaborated type specifier
   17067                 :             :          without a template header such as:
   17068                 :             : 
   17069                 :             :            template <class T> class C {};
   17070                 :             :            void f(class C);             // No template header here
   17071                 :             : 
   17072                 :             :          then the required template argument is missing.  */
   17073                 :          18 :       error ("template argument required for %<%s %T%>",
   17074                 :             :              tag_name (tag_code),
   17075                 :          18 :              DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
   17076                 :          18 :       return error_mark_node;
   17077                 :             :     }
   17078                 :             : 
   17079                 :             :   return type;
   17080                 :             : }
   17081                 :             : 
   17082                 :             : /* Lookup NAME of an elaborated type specifier according to SCOPE and
   17083                 :             :    issue diagnostics if necessary.  Return *_TYPE node upon success,
   17084                 :             :    NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
   17085                 :             :    error.  */
   17086                 :             : 
   17087                 :             : static tree
   17088                 :    22650297 : lookup_and_check_tag (enum tag_types tag_code, tree name,
   17089                 :             :                       TAG_how how, bool template_header_p)
   17090                 :             : {
   17091                 :    22650297 :   tree decl;
   17092                 :    22650297 :   if (how == TAG_how::GLOBAL)
   17093                 :             :     {
   17094                 :             :       /* First try ordinary name lookup, ignoring hidden class name
   17095                 :             :          injected via friend declaration.  */
   17096                 :     1931944 :       decl = lookup_name (name, LOOK_want::TYPE);
   17097                 :             :       /* If that fails, the name will be placed in the smallest
   17098                 :             :          non-class, non-function-prototype scope according to 3.3.1/5.
   17099                 :             :          We may already have a hidden name declared as friend in this
   17100                 :             :          scope.  So lookup again but not ignoring hidden names.
   17101                 :             :          If we find one, that name will be made visible rather than
   17102                 :             :          creating a new tag.  */
   17103                 :     1931944 :       if (!decl)
   17104                 :       18706 :         decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
   17105                 :             :     }
   17106                 :             :   else
   17107                 :    20718353 :     decl = lookup_elaborated_type (name, how);
   17108                 :             : 
   17109                 :    20737059 :   if (!decl)
   17110                 :             :     /* We found nothing.  */
   17111                 :             :     return NULL_TREE;
   17112                 :             : 
   17113                 :     5042601 :   if (TREE_CODE (decl) == TREE_LIST)
   17114                 :             :     {
   17115                 :           3 :       auto_diagnostic_group d;
   17116                 :           3 :       error ("reference to %qD is ambiguous", name);
   17117                 :           3 :       print_candidates (decl);
   17118                 :           3 :       return error_mark_node;
   17119                 :           3 :     }
   17120                 :             : 
   17121                 :     2097993 :   if (DECL_CLASS_TEMPLATE_P (decl)
   17122                 :     2097987 :       && !template_header_p
   17123                 :     7140585 :       && how == TAG_how::CURRENT_ONLY)
   17124                 :             :     {
   17125                 :          12 :       auto_diagnostic_group d;
   17126                 :          12 :       error ("class template %qD redeclared as non-template", name);
   17127                 :          12 :       inform (location_of (decl), "previous declaration here");
   17128                 :          12 :       CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
   17129                 :          12 :       return error_mark_node;
   17130                 :          12 :     }
   17131                 :             : 
   17132                 :     2097981 :   if (DECL_CLASS_TEMPLATE_P (decl)
   17133                 :             :       /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
   17134                 :             :          so ignore a template template parameter.  */
   17135                 :     5042592 :       || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
   17136                 :     2097978 :     decl = DECL_TEMPLATE_RESULT (decl);
   17137                 :             : 
   17138                 :     5042586 :   if (TREE_CODE (decl) != TYPE_DECL)
   17139                 :             :     /* Found not-a-type.  */
   17140                 :             :     return NULL_TREE;
   17141                 :             : 
   17142                 :             :   /* Look for invalid nested type:
   17143                 :             :      class C {
   17144                 :             :      class C {};
   17145                 :             :      };  */
   17146                 :     5042565 :   if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
   17147                 :             :     {
   17148                 :           6 :       error ("%qD has the same name as the class in which it is "
   17149                 :             :              "declared", decl);
   17150                 :           6 :       return error_mark_node;
   17151                 :             :     }
   17152                 :             : 
   17153                 :             :   /* Two cases we need to consider when deciding if a class
   17154                 :             :      template is allowed as an elaborated type specifier:
   17155                 :             :      1. It is a self reference to its own class.
   17156                 :             :      2. It comes with a template header.
   17157                 :             : 
   17158                 :             :      For example:
   17159                 :             : 
   17160                 :             :      template <class T> class C {
   17161                 :             :        class C *c1;             // DECL_SELF_REFERENCE_P is true
   17162                 :             :        class D;
   17163                 :             :      };
   17164                 :             :      template <class U> class C; // template_header_p is true
   17165                 :             :      template <class T> class C<T>::D {
   17166                 :             :        class C *c2;             // DECL_SELF_REFERENCE_P is true
   17167                 :             :      };  */
   17168                 :             : 
   17169                 :    15127677 :   tree t = check_elaborated_type_specifier (tag_code, decl,
   17170                 :             :                                             template_header_p
   17171                 :     9743767 :                                             | DECL_SELF_REFERENCE_P (decl));
   17172                 :     2219985 :   if (template_header_p && t && CLASS_TYPE_P (t)
   17173                 :     7262526 :       && (!CLASSTYPE_TEMPLATE_INFO (t)
   17174                 :     2219949 :           || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
   17175                 :             :     {
   17176                 :          21 :       auto_diagnostic_group d;
   17177                 :          21 :       error ("%qT is not a template", t);
   17178                 :          21 :       inform (location_of (t), "previous declaration here");
   17179                 :          42 :       if (TYPE_CLASS_SCOPE_P (t)
   17180                 :          24 :           && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
   17181                 :           3 :         inform (input_location,
   17182                 :             :                 "perhaps you want to explicitly add %<%T::%>",
   17183                 :           3 :                 TYPE_CONTEXT (t));
   17184                 :          21 :       return error_mark_node;
   17185                 :          21 :     }
   17186                 :             : 
   17187                 :             :   return t;
   17188                 :             : }
   17189                 :             : 
   17190                 :             : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
   17191                 :             :    Define the tag as a forward-reference if it is not defined.
   17192                 :             : 
   17193                 :             :    If a declaration is given, process it here, and report an error if
   17194                 :             :    multiple declarations are not identical.
   17195                 :             : 
   17196                 :             :    SCOPE is TS_CURRENT when this is also a definition.  Only look in
   17197                 :             :    the current frame for the name (since C++ allows new names in any
   17198                 :             :    scope.)  It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
   17199                 :             :    declaration.  Only look beginning from the current scope outward up
   17200                 :             :    till the nearest non-class scope.  Otherwise it is TS_GLOBAL.
   17201                 :             : 
   17202                 :             :    TEMPLATE_HEADER_P is true when this declaration is preceded by
   17203                 :             :    a set of template parameters.  */
   17204                 :             : 
   17205                 :             : tree
   17206                 :    22100359 : xref_tag (enum tag_types tag_code, tree name,
   17207                 :             :           TAG_how how, bool template_header_p)
   17208                 :             : {
   17209                 :    22100359 :   enum tree_code code;
   17210                 :    22100359 :   tree context = NULL_TREE;
   17211                 :             : 
   17212                 :    22100359 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
   17213                 :             : 
   17214                 :    22100359 :   gcc_assert (identifier_p (name));
   17215                 :             : 
   17216                 :    22100359 :   switch (tag_code)
   17217                 :             :     {
   17218                 :             :     case record_type:
   17219                 :             :     case class_type:
   17220                 :             :       code = RECORD_TYPE;
   17221                 :             :       break;
   17222                 :             :     case union_type:
   17223                 :             :       code = UNION_TYPE;
   17224                 :             :       break;
   17225                 :             :     case enum_type:
   17226                 :             :       code = ENUMERAL_TYPE;
   17227                 :             :       break;
   17228                 :           0 :     default:
   17229                 :           0 :       gcc_unreachable ();
   17230                 :             :     }
   17231                 :             : 
   17232                 :             :   /* In case of anonymous name, xref_tag is only called to
   17233                 :             :      make type node and push name.  Name lookup is not required.  */
   17234                 :    22100359 :   tree t = NULL_TREE;
   17235                 :    22100359 :   if (!IDENTIFIER_ANON_P (name))
   17236                 :    20511502 :     t = lookup_and_check_tag  (tag_code, name, how, template_header_p);
   17237                 :             : 
   17238                 :    22100359 :   if (t == error_mark_node)
   17239                 :             :     return error_mark_node;
   17240                 :             : 
   17241                 :     2526673 :   if (how != TAG_how::CURRENT_ONLY && t && current_class_type
   17242                 :     1080143 :       && template_class_depth (current_class_type)
   17243                 :    22497656 :       && template_header_p)
   17244                 :             :     {
   17245                 :      280205 :       if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
   17246                 :             :         return t;
   17247                 :             : 
   17248                 :             :       /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
   17249                 :             :          a definition of this tag.  Since, in addition, we are
   17250                 :             :          currently processing a (member) template declaration of a
   17251                 :             :          template class, we must be very careful; consider:
   17252                 :             : 
   17253                 :             :            template <class X> struct S1
   17254                 :             : 
   17255                 :             :            template <class U> struct S2
   17256                 :             :            {
   17257                 :             :              template <class V> friend struct S1;
   17258                 :             :            };
   17259                 :             : 
   17260                 :             :          Here, the S2::S1 declaration should not be confused with the
   17261                 :             :          outer declaration.  In particular, the inner version should
   17262                 :             :          have a template parameter of level 2, not level 1.
   17263                 :             : 
   17264                 :             :          On the other hand, when presented with:
   17265                 :             : 
   17266                 :             :            template <class T> struct S1
   17267                 :             :            {
   17268                 :             :              template <class U> struct S2 {};
   17269                 :             :              template <class U> friend struct S2;
   17270                 :             :            };
   17271                 :             : 
   17272                 :             :          the friend must find S1::S2 eventually.  We accomplish this
   17273                 :             :          by making sure that the new type we create to represent this
   17274                 :             :          declaration has the right TYPE_CONTEXT.  */
   17275                 :      280202 :       context = TYPE_CONTEXT (t);
   17276                 :      280202 :       t = NULL_TREE;
   17277                 :             :     }
   17278                 :             : 
   17279                 :    22100245 :   if (! t)
   17280                 :             :     {
   17281                 :             :       /* If no such tag is yet defined, create a forward-reference node
   17282                 :             :          and record it as the "definition".
   17283                 :             :          When a real declaration of this type is found,
   17284                 :             :          the forward-reference will be altered into a real type.  */
   17285                 :    17373531 :       if (code == ENUMERAL_TYPE)
   17286                 :             :         {
   17287                 :          14 :           error ("use of enum %q#D without previous declaration", name);
   17288                 :          14 :           return error_mark_node;
   17289                 :             :         }
   17290                 :             : 
   17291                 :    17373517 :       t = make_class_type (code);
   17292                 :    17373517 :       TYPE_CONTEXT (t) = context;
   17293                 :    17373517 :       if (IDENTIFIER_LAMBDA_P (name))
   17294                 :             :         /* Mark it as a lambda type right now.  Our caller will
   17295                 :             :            correct the value.  */
   17296                 :      919049 :         SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node);
   17297                 :    17373517 :       t = pushtag (name, t, how);
   17298                 :             :     }
   17299                 :             :   else
   17300                 :             :     {
   17301                 :     4726714 :       if (template_header_p && MAYBE_CLASS_TYPE_P (t))
   17302                 :             :         {
   17303                 :             :           /* Check that we aren't trying to overload a class with different
   17304                 :             :              constraints.  */
   17305                 :     1939744 :           if (!redeclare_class_template (t, current_template_parms,
   17306                 :             :                                          current_template_constraints ()))
   17307                 :          60 :             return error_mark_node;
   17308                 :             :         }
   17309                 :     2786970 :       else if (!processing_template_decl
   17310                 :     2648216 :                && CLASS_TYPE_P (t)
   17311                 :     5409012 :                && CLASSTYPE_IS_TEMPLATE (t))
   17312                 :             :         {
   17313                 :           0 :           auto_diagnostic_group d;
   17314                 :           0 :           error ("redeclaration of %qT as a non-template", t);
   17315                 :           0 :           inform (location_of (t), "previous declaration %qD", t);
   17316                 :           0 :           return error_mark_node;
   17317                 :           0 :         }
   17318                 :             : 
   17319                 :     4726654 :       if (modules_p ()
   17320                 :     4726654 :           && how == TAG_how::CURRENT_ONLY)
   17321                 :             :         {
   17322                 :        8475 :           tree decl = TYPE_NAME (t);
   17323                 :        8475 :           if (!module_may_redeclare (decl))
   17324                 :          15 :             return error_mark_node;
   17325                 :             : 
   17326                 :        8460 :           tree not_tmpl = STRIP_TEMPLATE (decl);
   17327                 :        8460 :           if (DECL_LANG_SPECIFIC (not_tmpl)
   17328                 :        3941 :               && DECL_MODULE_ATTACH_P (not_tmpl)
   17329                 :          39 :               && !DECL_MODULE_EXPORT_P (not_tmpl)
   17330                 :        8493 :               && module_exporting_p ())
   17331                 :             :             {
   17332                 :           6 :               auto_diagnostic_group d;
   17333                 :           6 :               error ("conflicting exporting for declaration %qD", decl);
   17334                 :           6 :               inform (DECL_SOURCE_LOCATION (decl),
   17335                 :             :                       "previously declared here without exporting");
   17336                 :           6 :             }
   17337                 :             : 
   17338                 :        8460 :           tree maybe_tmpl = decl;
   17339                 :        8460 :           if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
   17340                 :        6148 :             maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
   17341                 :             : 
   17342                 :             :           /* FIXME: we should do a more precise check for redefinitions
   17343                 :             :              of a conflicting using-declaration here, as these diagnostics
   17344                 :             :              are not ideal.  */
   17345                 :        8460 :           if (DECL_LANG_SPECIFIC (decl)
   17346                 :        3941 :               && DECL_MODULE_IMPORT_P (decl)
   17347                 :        8507 :               && CP_DECL_CONTEXT (decl) == current_namespace)
   17348                 :             :             {
   17349                 :             :               /* Push it into this TU's symbol slot.  */
   17350                 :          44 :               if (maybe_tmpl != decl)
   17351                 :             :                 /* We're in the template parm binding level.
   17352                 :             :                    Pushtag has logic to slide under that, but we're
   17353                 :             :                    not pushing a *new* type.  */
   17354                 :          18 :                 push_nested_namespace (CP_DECL_CONTEXT (decl));
   17355                 :             : 
   17356                 :          44 :               pushdecl (maybe_tmpl);
   17357                 :          44 :               if (maybe_tmpl != decl)
   17358                 :          18 :                 pop_nested_namespace (CP_DECL_CONTEXT (decl));
   17359                 :             :             }
   17360                 :             : 
   17361                 :        8460 :           set_instantiating_module (maybe_tmpl);
   17362                 :             :         }
   17363                 :             :     }
   17364                 :             : 
   17365                 :             :   return t;
   17366                 :    22100359 : }
   17367                 :             : 
   17368                 :             : /* Create the binfo hierarchy for REF with (possibly NULL) base list
   17369                 :             :    BASE_LIST.  For each element on BASE_LIST the TREE_PURPOSE is an
   17370                 :             :    access_* node, and the TREE_VALUE is the type of the base-class.
   17371                 :             :    Non-NULL TREE_TYPE indicates virtual inheritance.  */
   17372                 :             : 
   17373                 :             : void
   17374                 :    55964572 : xref_basetypes (tree ref, tree base_list)
   17375                 :             : {
   17376                 :    55964572 :   tree *basep;
   17377                 :    55964572 :   tree binfo, base_binfo;
   17378                 :    55964572 :   unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases.  */
   17379                 :    55964572 :   unsigned max_bases = 0;  /* Maximum direct bases.  */
   17380                 :    55964572 :   unsigned max_dvbases = 0; /* Maximum direct virtual bases.  */
   17381                 :    55964572 :   int i;
   17382                 :    55964572 :   tree default_access;
   17383                 :    55964572 :   tree igo_prev; /* Track Inheritance Graph Order.  */
   17384                 :             : 
   17385                 :    55964572 :   if (ref == error_mark_node)
   17386                 :          12 :     return;
   17387                 :             : 
   17388                 :             :   /* The base of a derived class is private by default, all others are
   17389                 :             :      public.  */
   17390                 :    55964572 :   default_access = (TREE_CODE (ref) == RECORD_TYPE
   17391                 :    55436505 :                     && CLASSTYPE_DECLARED_CLASS (ref)
   17392                 :    55964572 :                     ? access_private_node : access_public_node);
   17393                 :             : 
   17394                 :             :   /* First, make sure that any templates in base-classes are
   17395                 :             :      instantiated.  This ensures that if we call ourselves recursively
   17396                 :             :      we do not get confused about which classes are marked and which
   17397                 :             :      are not.  */
   17398                 :    55964572 :   basep = &base_list;
   17399                 :    85116527 :   while (*basep)
   17400                 :             :     {
   17401                 :    29151955 :       tree basetype = TREE_VALUE (*basep);
   17402                 :             : 
   17403                 :             :       /* The dependent_type_p call below should really be dependent_scope_p
   17404                 :             :          so that we give a hard error about using an incomplete type as a
   17405                 :             :          base, but we allow it with a pedwarn for backward
   17406                 :             :          compatibility.  */
   17407                 :    29151955 :       if (processing_template_decl
   17408                 :    29151955 :           && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
   17409                 :           3 :         cxx_incomplete_type_diagnostic (NULL_TREE, basetype,
   17410                 :             :                                         diagnostics::kind::pedwarn);
   17411                 :    29151955 :       if (!dependent_type_p (basetype)
   17412                 :    29151955 :           && !complete_type_or_else (basetype, NULL))
   17413                 :             :         /* An incomplete type.  Remove it from the list.  */
   17414                 :          15 :         *basep = TREE_CHAIN (*basep);
   17415                 :             :       else
   17416                 :             :         {
   17417                 :    29151940 :           max_bases++;
   17418                 :    29151940 :           if (TREE_TYPE (*basep))
   17419                 :       71856 :             max_dvbases++;
   17420                 :    29151940 :           if (CLASS_TYPE_P (basetype))
   17421                 :    28307266 :             max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   17422                 :    29151940 :           basep = &TREE_CHAIN (*basep);
   17423                 :             :         }
   17424                 :             :     }
   17425                 :    55964572 :   max_vbases += max_dvbases;
   17426                 :             : 
   17427                 :    55964572 :   TYPE_MARKED_P (ref) = 1;
   17428                 :             : 
   17429                 :             :   /* The binfo slot should be empty, unless this is an (ill-formed)
   17430                 :             :      redefinition.  */
   17431                 :    55964572 :   gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
   17432                 :             : 
   17433                 :    55964572 :   gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
   17434                 :             : 
   17435                 :    55964572 :   binfo = make_tree_binfo (max_bases);
   17436                 :             : 
   17437                 :    55964572 :   TYPE_BINFO (ref) = binfo;
   17438                 :    55964572 :   BINFO_OFFSET (binfo) = size_zero_node;
   17439                 :    55964572 :   BINFO_TYPE (binfo) = ref;
   17440                 :             : 
   17441                 :             :   /* Apply base-class info set up to the variants of this type.  */
   17442                 :    55964572 :   fixup_type_variants (ref);
   17443                 :             : 
   17444                 :    55964572 :   if (max_bases)
   17445                 :             :     {
   17446                 :    28250970 :       vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases);
   17447                 :             :       /* A C++98 POD cannot have base classes.  */
   17448                 :    28250970 :       CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
   17449                 :             : 
   17450                 :    28250970 :       if (TREE_CODE (ref) == UNION_TYPE)
   17451                 :             :         {
   17452                 :          12 :           error ("derived union %qT invalid", ref);
   17453                 :          12 :           return;
   17454                 :             :         }
   17455                 :             :     }
   17456                 :             : 
   17457                 :    28250958 :   if (max_bases > 1)
   17458                 :      700093 :     warning (OPT_Wmultiple_inheritance,
   17459                 :             :              "%qT defined with multiple direct bases", ref);
   17460                 :             : 
   17461                 :    55964560 :   if (max_vbases)
   17462                 :             :     {
   17463                 :             :       /* An aggregate can't have virtual base classes.  */
   17464                 :      215865 :       CLASSTYPE_NON_AGGREGATE (ref) = true;
   17465                 :             : 
   17466                 :      215865 :       vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
   17467                 :             : 
   17468                 :      215865 :       if (max_dvbases)
   17469                 :       70661 :         warning (OPT_Wvirtual_inheritance,
   17470                 :             :                  "%qT defined with direct virtual base", ref);
   17471                 :             :     }
   17472                 :             : 
   17473                 :    85116488 :   for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
   17474                 :             :     {
   17475                 :    29151928 :       tree access = TREE_PURPOSE (base_list);
   17476                 :    29151928 :       int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
   17477                 :    29151928 :       tree basetype = TREE_VALUE (base_list);
   17478                 :             : 
   17479                 :    29151928 :       if (access == access_default_node)
   17480                 :     4559002 :         access = default_access;
   17481                 :             : 
   17482                 :             :       /* Before C++17, an aggregate cannot have base classes.  In C++17, an
   17483                 :             :          aggregate can't have virtual, private, or protected base classes.  */
   17484                 :    29151928 :       if (cxx_dialect < cxx17
   17485                 :    28930272 :           || access != access_public_node
   17486                 :    28000540 :           || via_virtual)
   17487                 :     1219902 :         CLASSTYPE_NON_AGGREGATE (ref) = true;
   17488                 :             : 
   17489                 :    29151928 :       if (PACK_EXPANSION_P (basetype))
   17490                 :       21247 :         basetype = PACK_EXPANSION_PATTERN (basetype);
   17491                 :    29151928 :       if (TREE_CODE (basetype) == TYPE_DECL)
   17492                 :           0 :         basetype = TREE_TYPE (basetype);
   17493                 :    29151928 :       if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
   17494                 :             :         {
   17495                 :          24 :           error ("base type %qT fails to be a struct or class type",
   17496                 :             :                  basetype);
   17497                 :          24 :           goto dropped_base;
   17498                 :             :         }
   17499                 :             : 
   17500                 :    29151904 :       base_binfo = NULL_TREE;
   17501                 :    29151904 :       if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
   17502                 :             :         {
   17503                 :    22382554 :           base_binfo = TYPE_BINFO (basetype);
   17504                 :             :           /* The original basetype could have been a typedef'd type.  */
   17505                 :    22382554 :           basetype = BINFO_TYPE (base_binfo);
   17506                 :             : 
   17507                 :             :           /* Inherit flags from the base.  */
   17508                 :    67147662 :           TYPE_HAS_NEW_OPERATOR (ref)
   17509                 :    22382554 :             |= TYPE_HAS_NEW_OPERATOR (basetype);
   17510                 :    67147662 :           TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
   17511                 :    22382554 :             |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
   17512                 :    22382554 :           TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
   17513                 :    22382554 :           TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
   17514                 :    67147662 :           CLASSTYPE_DIAMOND_SHAPED_P (ref)
   17515                 :    22382554 :             |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
   17516                 :    67147662 :           CLASSTYPE_REPEATED_BASE_P (ref)
   17517                 :    22382554 :             |= CLASSTYPE_REPEATED_BASE_P (basetype);
   17518                 :             :         }
   17519                 :             : 
   17520                 :             :       /* We must do this test after we've seen through a typedef
   17521                 :             :          type.  */
   17522                 :    29151904 :       if (TYPE_MARKED_P (basetype))
   17523                 :             :         {
   17524                 :          18 :           if (basetype == ref)
   17525                 :           0 :             error ("recursive type %qT undefined", basetype);
   17526                 :             :           else
   17527                 :          18 :             error ("duplicate base type %qT invalid", basetype);
   17528                 :          18 :           goto dropped_base;
   17529                 :             :         }
   17530                 :             : 
   17531                 :    29151886 :       if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
   17532                 :             :         /* Regenerate the pack expansion for the bases. */
   17533                 :       21247 :         basetype = make_pack_expansion (basetype);
   17534                 :             : 
   17535                 :    29151886 :       TYPE_MARKED_P (basetype) = 1;
   17536                 :             : 
   17537                 :    29151886 :       base_binfo = copy_binfo (base_binfo, basetype, ref,
   17538                 :             :                                &igo_prev, via_virtual);
   17539                 :    29151886 :       if (!BINFO_INHERITANCE_CHAIN (base_binfo))
   17540                 :    29080045 :         BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
   17541                 :             : 
   17542                 :    29151886 :       BINFO_BASE_APPEND (binfo, base_binfo);
   17543                 :    29151886 :       BINFO_BASE_ACCESS_APPEND (binfo, access);
   17544                 :    29151886 :       continue;
   17545                 :             : 
   17546                 :          42 :     dropped_base:
   17547                 :             :       /* Update max_vbases to reflect the reality that we are dropping
   17548                 :             :          this base:  if it reaches zero we want to undo the vec_alloc
   17549                 :             :          above to avoid inconsistencies during error-recovery: eg, in
   17550                 :             :          build_special_member_call, CLASSTYPE_VBASECLASSES non null
   17551                 :             :          and vtt null (c++/27952).  */
   17552                 :          42 :       if (via_virtual)
   17553                 :          12 :         max_vbases--;
   17554                 :          42 :       if (CLASS_TYPE_P (basetype))
   17555                 :          30 :         max_vbases
   17556                 :          33 :           -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   17557                 :    29151886 :     }
   17558                 :             : 
   17559                 :    55964560 :   if (CLASSTYPE_VBASECLASSES (ref)
   17560                 :    55964560 :       && max_vbases == 0)
   17561                 :          24 :     vec_free (CLASSTYPE_VBASECLASSES (ref));
   17562                 :             : 
   17563                 :    56180413 :   if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
   17564                 :             :     /* If we didn't get max_vbases vbases, we must have shared at
   17565                 :             :        least one of them, and are therefore diamond shaped.  */
   17566                 :       23311 :     CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
   17567                 :             : 
   17568                 :             :   /* Unmark all the types.  */
   17569                 :    85116446 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   17570                 :    29151886 :     TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   17571                 :    55964560 :   TYPE_MARKED_P (ref) = 0;
   17572                 :             : 
   17573                 :             :   /* Now see if we have a repeated base type.  */
   17574                 :    55964560 :   if (!CLASSTYPE_REPEATED_BASE_P (ref))
   17575                 :             :     {
   17576                 :   144704828 :       for (base_binfo = binfo; base_binfo;
   17577                 :    88740700 :            base_binfo = TREE_CHAIN (base_binfo))
   17578                 :             :         {
   17579                 :    88741411 :           if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   17580                 :             :             {
   17581                 :         711 :               CLASSTYPE_REPEATED_BASE_P (ref) = 1;
   17582                 :         711 :               break;
   17583                 :             :             }
   17584                 :    88740700 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
   17585                 :             :         }
   17586                 :   144704828 :       for (base_binfo = binfo; base_binfo;
   17587                 :    88740700 :            base_binfo = TREE_CHAIN (base_binfo))
   17588                 :    88741411 :         if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   17589                 :    88740700 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   17590                 :             :         else
   17591                 :             :           break;
   17592                 :             :     }
   17593                 :             : }
   17594                 :             : 
   17595                 :             : 
   17596                 :             : /* Copies the enum-related properties from type SRC to type DST.
   17597                 :             :    Used with the underlying type of an enum and the enum itself.  */
   17598                 :             : static void
   17599                 :     1805834 : copy_type_enum (tree dst, tree src)
   17600                 :             : {
   17601                 :     1805834 :   tree t;
   17602                 :     3611686 :   for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
   17603                 :             :     {
   17604                 :     1805852 :       TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
   17605                 :     1805852 :       TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
   17606                 :     1805852 :       TYPE_SIZE (t) = TYPE_SIZE (src);
   17607                 :     1805852 :       TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
   17608                 :     1805852 :       SET_TYPE_MODE (dst, TYPE_MODE (src));
   17609                 :     1805852 :       TYPE_PRECISION (t) = TYPE_PRECISION (src);
   17610                 :     1805852 :       unsigned valign = TYPE_ALIGN (src);
   17611                 :     1805852 :       if (TYPE_USER_ALIGN (t))
   17612                 :          12 :         valign = MAX (valign, TYPE_ALIGN (t));
   17613                 :             :       else
   17614                 :     1805840 :         TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
   17615                 :     1805852 :       SET_TYPE_ALIGN (t, valign);
   17616                 :     1805852 :       TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
   17617                 :             :     }
   17618                 :     1805834 : }
   17619                 :             : 
   17620                 :             : /* Begin compiling the definition of an enumeration type.
   17621                 :             :    NAME is its name,
   17622                 :             : 
   17623                 :             :    if ENUMTYPE is not NULL_TREE then the type has alredy been found.
   17624                 :             : 
   17625                 :             :    UNDERLYING_TYPE is the type that will be used as the storage for
   17626                 :             :    the enumeration type. This should be NULL_TREE if no storage type
   17627                 :             :    was specified.
   17628                 :             : 
   17629                 :             :    ATTRIBUTES are any attributes specified after the enum-key.
   17630                 :             : 
   17631                 :             :    SCOPED_ENUM_P is true if this is a scoped enumeration type.
   17632                 :             : 
   17633                 :             :    if IS_NEW is not NULL, gets TRUE iff a new type is created.
   17634                 :             : 
   17635                 :             :    Returns the type object, as yet incomplete.
   17636                 :             :    Also records info about it so that build_enumerator
   17637                 :             :    may be used to declare the individual values as they are read.  */
   17638                 :             : 
   17639                 :             : tree
   17640                 :     2138926 : start_enum (tree name, tree enumtype, tree underlying_type,
   17641                 :             :             tree attributes, bool scoped_enum_p, bool *is_new)
   17642                 :             : {
   17643                 :     2138926 :   tree prevtype = NULL_TREE;
   17644                 :     2138926 :   gcc_assert (identifier_p (name));
   17645                 :             : 
   17646                 :     2138926 :   if (is_new)
   17647                 :     1708078 :     *is_new = false;
   17648                 :             :   /* [C++0x dcl.enum]p5:
   17649                 :             : 
   17650                 :             :     If not explicitly specified, the underlying type of a scoped
   17651                 :             :     enumeration type is int.  */
   17652                 :     2138926 :   if (!underlying_type && scoped_enum_p)
   17653                 :      121056 :     underlying_type = integer_type_node;
   17654                 :             : 
   17655                 :     2138926 :   if (underlying_type)
   17656                 :      442831 :     underlying_type = cv_unqualified (underlying_type);
   17657                 :             : 
   17658                 :             :   /* If this is the real definition for a previous forward reference,
   17659                 :             :      fill in the contents in the same object that used to be the
   17660                 :             :      forward reference.  */
   17661                 :     2138926 :   if (!enumtype)
   17662                 :     2138795 :     enumtype = lookup_and_check_tag (enum_type, name,
   17663                 :             :                                      /*tag_scope=*/TAG_how::CURRENT_ONLY,
   17664                 :             :                                      /*template_header_p=*/false);
   17665                 :             : 
   17666                 :             :   /* In case of a template_decl, the only check that should be deferred
   17667                 :             :      to instantiation time is the comparison of underlying types.  */
   17668                 :     2138926 :   if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   17669                 :             :     {
   17670                 :             :       /* Attempt to set the declaring module.  */
   17671                 :       35678 :       if (modules_p ())
   17672                 :             :         {
   17673                 :         160 :           tree decl = TYPE_NAME (enumtype);
   17674                 :         160 :           if (!module_may_redeclare (decl))
   17675                 :           3 :             enumtype = error_mark_node;
   17676                 :             :           else
   17677                 :         157 :             set_instantiating_module (decl);
   17678                 :             :         }
   17679                 :             : 
   17680                 :       35678 :       if (enumtype == error_mark_node)
   17681                 :             :         ;
   17682                 :       35865 :       else if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
   17683                 :             :         {
   17684                 :           6 :           auto_diagnostic_group d;
   17685                 :           6 :           error_at (input_location, "scoped/unscoped mismatch "
   17686                 :             :                     "in enum %q#T", enumtype);
   17687                 :           6 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   17688                 :             :                   "previous definition here");
   17689                 :           6 :           enumtype = error_mark_node;
   17690                 :           6 :         }
   17691                 :       35669 :       else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
   17692                 :             :         {
   17693                 :           0 :           auto_diagnostic_group d;
   17694                 :           0 :           error_at (input_location, "underlying type mismatch "
   17695                 :             :                     "in enum %q#T", enumtype);
   17696                 :           0 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   17697                 :             :                   "previous definition here");
   17698                 :           0 :           enumtype = error_mark_node;
   17699                 :           0 :         }
   17700                 :       35653 :       else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
   17701                 :       71322 :                && !same_type_p (underlying_type,
   17702                 :             :                                 ENUM_UNDERLYING_TYPE (enumtype)))
   17703                 :             :         {
   17704                 :          26 :           auto_diagnostic_group d;
   17705                 :          26 :           error_at (input_location, "different underlying type "
   17706                 :             :                     "in enum %q#T", enumtype);
   17707                 :          26 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   17708                 :             :                   "previous definition here");
   17709                 :          26 :           underlying_type = NULL_TREE;
   17710                 :          26 :         }
   17711                 :             :     }
   17712                 :             : 
   17713                 :     2138926 :   if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
   17714                 :       35669 :       || processing_template_decl)
   17715                 :             :     {
   17716                 :             :       /* In case of error, make a dummy enum to allow parsing to
   17717                 :             :          continue.  */
   17718                 :     2103345 :       if (enumtype == error_mark_node)
   17719                 :             :         {
   17720                 :           9 :           name = make_anon_name ();
   17721                 :           9 :           enumtype = NULL_TREE;
   17722                 :             :         }
   17723                 :             : 
   17724                 :             :       /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
   17725                 :             :          of an opaque enum, or an opaque enum of an already defined
   17726                 :             :          enumeration (C++11).
   17727                 :             :          In any other case, it'll be NULL_TREE. */
   17728                 :     2103345 :       if (!enumtype)
   17729                 :             :         {
   17730                 :     2103254 :           if (is_new)
   17731                 :     1672409 :             *is_new = true;
   17732                 :             :         }
   17733                 :     2103345 :       prevtype = enumtype;
   17734                 :             : 
   17735                 :             :       /* Do not push the decl more than once.  */
   17736                 :     2103345 :       if (!enumtype
   17737                 :          91 :           || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   17738                 :             :         {
   17739                 :     2103257 :           enumtype = cxx_make_type (ENUMERAL_TYPE);
   17740                 :     2103257 :           enumtype = pushtag (name, enumtype);
   17741                 :             : 
   17742                 :     2103257 :           if (enumtype != error_mark_node)
   17743                 :             :             {
   17744                 :             :               /* The enum is considered opaque until the opening '{' of the
   17745                 :             :                  enumerator list.  */
   17746                 :     2103239 :               SET_OPAQUE_ENUM_P (enumtype, true);
   17747                 :     2103239 :               ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
   17748                 :             : 
   17749                 :             :               /* std::byte aliases anything.  */
   17750                 :     2103239 :               if (TYPE_CONTEXT (enumtype) == std_node
   17751                 :     2430426 :                   && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
   17752                 :       13227 :                 TYPE_ALIAS_SET (enumtype) = 0;
   17753                 :             :             }
   17754                 :             :         }
   17755                 :             :       else
   17756                 :          88 :           enumtype = xref_tag (enum_type, name);
   17757                 :             : 
   17758                 :     2103345 :       if (enumtype == error_mark_node)
   17759                 :             :         return error_mark_node;
   17760                 :             :     }
   17761                 :             : 
   17762                 :     2138908 :   SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
   17763                 :             : 
   17764                 :     2138908 :   cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
   17765                 :             : 
   17766                 :     2138908 :   if (underlying_type)
   17767                 :             :     {
   17768                 :      442802 :       if (ENUM_UNDERLYING_TYPE (enumtype))
   17769                 :             :         /* We already checked that it matches, don't change it to a different
   17770                 :             :            typedef variant.  */;
   17771                 :      407175 :       else if (CP_INTEGRAL_TYPE_P (underlying_type))
   17772                 :             :         {
   17773                 :      407111 :           copy_type_enum (enumtype, underlying_type);
   17774                 :      407111 :           ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   17775                 :             :         }
   17776                 :          64 :       else if (dependent_type_p (underlying_type))
   17777                 :          51 :         ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   17778                 :             :       else
   17779                 :             :         {
   17780                 :          13 :           error ("underlying type %qT of %qT must be an integral type",
   17781                 :             :                  underlying_type, enumtype);
   17782                 :          13 :           ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
   17783                 :             :         }
   17784                 :             :     }
   17785                 :             : 
   17786                 :             :   /* If into a template class, the returned enum is always the first
   17787                 :             :      declaration (opaque or not) seen. This way all the references to
   17788                 :             :      this type will be to the same declaration. The following ones are used
   17789                 :             :      only to check for definition errors.  */
   17790                 :     2138908 :   if (prevtype && processing_template_decl)
   17791                 :             :     return prevtype;
   17792                 :             :   else
   17793                 :     2138820 :     return enumtype;
   17794                 :             : }
   17795                 :             : 
   17796                 :             : /* After processing and defining all the values of an enumeration type,
   17797                 :             :    install their decls in the enumeration type.
   17798                 :             :    ENUMTYPE is the type object.  */
   17799                 :             : 
   17800                 :             : void
   17801                 :     2038392 : finish_enum_value_list (tree enumtype)
   17802                 :             : {
   17803                 :     2038392 :   tree values;
   17804                 :     2038392 :   tree underlying_type;
   17805                 :     2038392 :   tree decl;
   17806                 :     2038392 :   tree value;
   17807                 :     2038392 :   tree minnode, maxnode;
   17808                 :     2038392 :   tree t;
   17809                 :             : 
   17810                 :     2038392 :   bool fixed_underlying_type_p
   17811                 :     2038392 :     = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
   17812                 :             : 
   17813                 :             :   /* We built up the VALUES in reverse order.  */
   17814                 :     2038392 :   TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
   17815                 :             : 
   17816                 :             :   /* For an enum defined in a template, just set the type of the values;
   17817                 :             :      all further processing is postponed until the template is
   17818                 :             :      instantiated.  We need to set the type so that tsubst of a CONST_DECL
   17819                 :             :      works.  */
   17820                 :     2038392 :   if (processing_template_decl)
   17821                 :             :     {
   17822                 :      372716 :       for (values = TYPE_VALUES (enumtype);
   17823                 :      690782 :            values;
   17824                 :      372716 :            values = TREE_CHAIN (values))
   17825                 :      372716 :         TREE_TYPE (TREE_VALUE (values)) = enumtype;
   17826                 :             :       return;
   17827                 :             :     }
   17828                 :             : 
   17829                 :             :   /* Determine the minimum and maximum values of the enumerators.  */
   17830                 :     1720326 :   if (TYPE_VALUES (enumtype))
   17831                 :             :     {
   17832                 :             :       minnode = maxnode = NULL_TREE;
   17833                 :             : 
   17834                 :    10786268 :       for (values = TYPE_VALUES (enumtype);
   17835                 :    12477667 :            values;
   17836                 :    10786268 :            values = TREE_CHAIN (values))
   17837                 :             :         {
   17838                 :    10786268 :           decl = TREE_VALUE (values);
   17839                 :             : 
   17840                 :             :           /* [dcl.enum]: Following the closing brace of an enum-specifier,
   17841                 :             :              each enumerator has the type of its enumeration.  Prior to the
   17842                 :             :              closing brace, the type of each enumerator is the type of its
   17843                 :             :              initializing value.  */
   17844                 :    10786268 :           TREE_TYPE (decl) = enumtype;
   17845                 :             : 
   17846                 :             :           /* Update the minimum and maximum values, if appropriate.  */
   17847                 :    10786268 :           value = DECL_INITIAL (decl);
   17848                 :    10786268 :           if (TREE_CODE (value) != INTEGER_CST)
   17849                 :           4 :             value = integer_zero_node;
   17850                 :             :           /* Figure out what the minimum and maximum values of the
   17851                 :             :              enumerators are.  */
   17852                 :    10786268 :           if (!minnode)
   17853                 :             :             minnode = maxnode = value;
   17854                 :     9094869 :           else if (tree_int_cst_lt (maxnode, value))
   17855                 :             :             maxnode = value;
   17856                 :     1386687 :           else if (tree_int_cst_lt (value, minnode))
   17857                 :      146968 :             minnode = value;
   17858                 :             :         }
   17859                 :             :     }
   17860                 :             :   else
   17861                 :             :     /* [dcl.enum]
   17862                 :             : 
   17863                 :             :        If the enumerator-list is empty, the underlying type is as if
   17864                 :             :        the enumeration had a single enumerator with value 0.  */
   17865                 :       28927 :     minnode = maxnode = integer_zero_node;
   17866                 :             : 
   17867                 :     1720326 :   if (!fixed_underlying_type_p)
   17868                 :             :     {
   17869                 :             :       /* Compute the number of bits require to represent all values of the
   17870                 :             :          enumeration.  We must do this before the type of MINNODE and
   17871                 :             :          MAXNODE are transformed, since tree_int_cst_min_precision relies
   17872                 :             :          on the TREE_TYPE of the value it is passed.  */
   17873                 :     1398723 :       signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
   17874                 :     1398723 :       int lowprec = tree_int_cst_min_precision (minnode, sgn);
   17875                 :     1398723 :       int highprec = tree_int_cst_min_precision (maxnode, sgn);
   17876                 :     1398723 :       int precision = MAX (lowprec, highprec);
   17877                 :     1398723 :       unsigned int itk;
   17878                 :     1398723 :       bool use_short_enum;
   17879                 :             : 
   17880                 :             :       /* Determine the underlying type of the enumeration.
   17881                 :             : 
   17882                 :             :          [dcl.enum]
   17883                 :             : 
   17884                 :             :          The underlying type of an enumeration is an integral type that
   17885                 :             :          can represent all the enumerator values defined in the
   17886                 :             :          enumeration.  It is implementation-defined which integral type is
   17887                 :             :          used as the underlying type for an enumeration except that the
   17888                 :             :          underlying type shall not be larger than int unless the value of
   17889                 :             :          an enumerator cannot fit in an int or unsigned int.
   17890                 :             : 
   17891                 :             :          We use "int" or an "unsigned int" as the underlying type, even if
   17892                 :             :          a smaller integral type would work, unless the user has
   17893                 :             :          explicitly requested that we use the smallest possible type.  The
   17894                 :             :          user can request that for all enumerations with a command line
   17895                 :             :          flag, or for just one enumeration with an attribute.  */
   17896                 :             : 
   17897                 :     2797446 :       use_short_enum = flag_short_enums
   17898                 :     1398723 :         || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
   17899                 :             : 
   17900                 :             :       /* If the precision of the type was specified with an attribute and it
   17901                 :             :          was too small, give an error.  Otherwise, use it.  */
   17902                 :     1398723 :       if (TYPE_PRECISION (enumtype))
   17903                 :             :         {
   17904                 :          11 :           if (precision > TYPE_PRECISION (enumtype))
   17905                 :           0 :             error ("specified mode too small for enumerated values");
   17906                 :             :           else
   17907                 :             :             {
   17908                 :          11 :               use_short_enum = true;
   17909                 :          11 :               precision = TYPE_PRECISION (enumtype);
   17910                 :             :             }
   17911                 :             :         }
   17912                 :             : 
   17913                 :     2717803 :       for (itk = (use_short_enum ? itk_char : itk_int);
   17914                 :     2717803 :            itk != itk_none;
   17915                 :             :            itk++)
   17916                 :             :         {
   17917                 :     2717800 :           underlying_type = integer_types[itk];
   17918                 :     2717800 :           if (underlying_type != NULL_TREE
   17919                 :     2717782 :               && TYPE_PRECISION (underlying_type) >= precision
   17920                 :     5433641 :               && TYPE_SIGN (underlying_type) == sgn)
   17921                 :             :             break;
   17922                 :             :         }
   17923                 :     1398723 :       if (itk == itk_none)
   17924                 :             :         {
   17925                 :             :           /* DR 377
   17926                 :             : 
   17927                 :             :              IF no integral type can represent all the enumerator values, the
   17928                 :             :              enumeration is ill-formed.  */
   17929                 :           3 :           error ("no integral type can represent all of the enumerator values "
   17930                 :             :                  "for %qT", enumtype);
   17931                 :           3 :           precision = TYPE_PRECISION (long_long_integer_type_node);
   17932                 :           3 :           underlying_type = integer_types[itk_unsigned_long_long];
   17933                 :             :         }
   17934                 :             : 
   17935                 :             :       /* [dcl.enum]
   17936                 :             : 
   17937                 :             :          The value of sizeof() applied to an enumeration type, an object
   17938                 :             :          of an enumeration type, or an enumerator, is the value of sizeof()
   17939                 :             :          applied to the underlying type.  */
   17940                 :     1398723 :       copy_type_enum (enumtype, underlying_type);
   17941                 :             : 
   17942                 :             :       /* Compute the minimum and maximum values for the type.
   17943                 :             : 
   17944                 :             :          [dcl.enum]
   17945                 :             : 
   17946                 :             :          For an enumeration where emin is the smallest enumerator and emax
   17947                 :             :          is the largest, the values of the enumeration are the values of the
   17948                 :             :          underlying type in the range bmin to bmax, where bmin and bmax are,
   17949                 :             :          respectively, the smallest and largest values of the smallest bit-
   17950                 :             :          field that can store emin and emax.  */
   17951                 :             : 
   17952                 :             :       /* The middle-end currently assumes that types with TYPE_PRECISION
   17953                 :             :          narrower than their underlying type are suitably zero or sign
   17954                 :             :          extended to fill their mode.  Similarly, it assumes that the front
   17955                 :             :          end assures that a value of a particular type must be within
   17956                 :             :          TYPE_MIN_VALUE and TYPE_MAX_VALUE.
   17957                 :             : 
   17958                 :             :          We used to set these fields based on bmin and bmax, but that led
   17959                 :             :          to invalid assumptions like optimizing away bounds checking.  So
   17960                 :             :          now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
   17961                 :             :          TYPE_MAX_VALUE to the values for the mode above and only restrict
   17962                 :             :          the ENUM_UNDERLYING_TYPE for the benefit of diagnostics.  */
   17963                 :     1398723 :       ENUM_UNDERLYING_TYPE (enumtype)
   17964                 :     1398723 :         = build_distinct_type_copy (underlying_type);
   17965                 :     1398723 :       TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
   17966                 :     1398723 :       set_min_and_max_values_for_integral_type
   17967                 :     1398723 :         (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
   17968                 :             : 
   17969                 :             :       /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
   17970                 :     1398723 :       if (flag_strict_enums)
   17971                 :          38 :         set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
   17972                 :             : 
   17973                 :     1398723 :       if (use_short_enum)
   17974                 :             :         {
   17975                 :          79 :           TYPE_PACKED (enumtype) = use_short_enum;
   17976                 :          79 :           fixup_attribute_variants (enumtype);
   17977                 :             :         }
   17978                 :             :     }
   17979                 :             :   else
   17980                 :      321603 :     underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
   17981                 :             : 
   17982                 :             :   /* If the enum is exported, mark the consts too.  */
   17983                 :     1720326 :   bool export_p = (UNSCOPED_ENUM_P (enumtype)
   17984                 :     1468886 :                    && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
   17985                 :     1720847 :                    && at_namespace_scope_p ());
   17986                 :             : 
   17987                 :             :   /* Convert each of the enumerators to the type of the underlying
   17988                 :             :      type of the enumeration.  */
   17989                 :    12506594 :   for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
   17990                 :             :     {
   17991                 :    10786268 :       decl = TREE_VALUE (values);
   17992                 :    10786268 :       iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
   17993                 :    10786268 :       if (fixed_underlying_type_p)
   17994                 :             :         /* If the enumeration type has a fixed underlying type, we
   17995                 :             :            already checked all of the enumerator values.  */
   17996                 :     3126500 :         value = DECL_INITIAL (decl);
   17997                 :             :       else
   17998                 :     7659768 :         value = perform_implicit_conversion (underlying_type,
   17999                 :     7659768 :                                              DECL_INITIAL (decl),
   18000                 :             :                                              tf_warning_or_error);
   18001                 :             :       /* Do not clobber shared ints.  */
   18002                 :    10786268 :       if (value != error_mark_node)
   18003                 :             :         {
   18004                 :    10786266 :           value = copy_node (value);
   18005                 :             : 
   18006                 :    10786266 :           TREE_TYPE (value) = enumtype;
   18007                 :             :         }
   18008                 :    10786268 :       DECL_INITIAL (decl) = value;
   18009                 :    10786268 :       if (export_p)
   18010                 :        2890 :         DECL_MODULE_EXPORT_P (decl) = true;
   18011                 :    10786268 :     }
   18012                 :             : 
   18013                 :             :   /* Fix up all variant types of this enum type.  */
   18014                 :     3440670 :   for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
   18015                 :     1720344 :     TYPE_VALUES (t) = TYPE_VALUES (enumtype);
   18016                 :             : 
   18017                 :     1720326 :   if (at_class_scope_p ()
   18018                 :      957993 :       && COMPLETE_TYPE_P (current_class_type)
   18019                 :     1720387 :       && UNSCOPED_ENUM_P (enumtype))
   18020                 :             :     {
   18021                 :          42 :       insert_late_enum_def_bindings (current_class_type, enumtype);
   18022                 :             :       /* TYPE_FIELDS needs fixup.  */
   18023                 :          42 :       fixup_type_variants (current_class_type);
   18024                 :             :     }
   18025                 :             : 
   18026                 :             :   /* Finish debugging output for this type.  */
   18027                 :     1720326 :   rest_of_type_compilation (enumtype, namespace_bindings_p ());
   18028                 :             : 
   18029                 :             :   /* Each enumerator now has the type of its enumeration.  Clear the cache
   18030                 :             :      so that this change in types doesn't confuse us later on.  */
   18031                 :     1720326 :   clear_cv_and_fold_caches ();
   18032                 :             : }
   18033                 :             : 
   18034                 :             : /* Finishes the enum type. This is called only the first time an
   18035                 :             :    enumeration is seen, be it opaque or odinary.
   18036                 :             :    ENUMTYPE is the type object.  */
   18037                 :             : 
   18038                 :             : void
   18039                 :     2027559 : finish_enum (tree enumtype)
   18040                 :             : {
   18041                 :     2027559 :   if (processing_template_decl)
   18042                 :             :     {
   18043                 :      318094 :       if (at_function_scope_p ())
   18044                 :        2480 :         add_stmt (build_min (TAG_DEFN, enumtype));
   18045                 :      318094 :       return;
   18046                 :             :     }
   18047                 :             : 
   18048                 :             :   /* If this is a forward declaration, there should not be any variants,
   18049                 :             :      though we can get a variant in the middle of an enum-specifier with
   18050                 :             :      wacky code like 'enum E { e = sizeof(const E*) };'  */
   18051                 :     3418930 :   gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
   18052                 :             :               && (TYPE_VALUES (enumtype)
   18053                 :             :                   || !TYPE_NEXT_VARIANT (enumtype)));
   18054                 :             : }
   18055                 :             : 
   18056                 :             : /* Build and install a CONST_DECL for an enumeration constant of the
   18057                 :             :    enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
   18058                 :             :    Apply ATTRIBUTES if available.  LOC is the location of NAME.
   18059                 :             :    Assignment of sequential values by default is handled here.  */
   18060                 :             : 
   18061                 :             : tree
   18062                 :    11158961 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
   18063                 :             :                   location_t loc)
   18064                 :             : {
   18065                 :    11158961 :   tree decl;
   18066                 :    11158961 :   tree context;
   18067                 :    11158961 :   tree type;
   18068                 :             : 
   18069                 :             :   /* scalar_constant_value will pull out this expression, so make sure
   18070                 :             :      it's folded as appropriate.
   18071                 :             : 
   18072                 :             :      Creating a TARGET_EXPR in a template breaks when substituting, and
   18073                 :             :      here we would create it for instance when using a class prvalue with
   18074                 :             :      a user-defined conversion function.  So don't use such a tree.  We
   18075                 :             :      instantiate VALUE here to get errors about bad enumerators even in
   18076                 :             :      a template that does not get instantiated.  */
   18077                 :    11158961 :   if (processing_template_decl)
   18078                 :      372716 :     value = maybe_fold_non_dependent_expr (value);
   18079                 :             : 
   18080                 :             :   /* If the VALUE was erroneous, pretend it wasn't there; that will
   18081                 :             :      result in the enum being assigned the next value in sequence.  */
   18082                 :    11158961 :   if (value == error_mark_node)
   18083                 :             :     value = NULL_TREE;
   18084                 :             : 
   18085                 :             :   /* Remove no-op casts from the value.  */
   18086                 :    11158923 :   if (value)
   18087                 :     8513581 :     STRIP_TYPE_NOPS (value);
   18088                 :             : 
   18089                 :    11158961 :   if (! processing_template_decl)
   18090                 :             :     {
   18091                 :             :       /* Validate and default VALUE.  */
   18092                 :    10786245 :       if (value != NULL_TREE)
   18093                 :             :         {
   18094                 :     4849862 :           if (!ENUM_UNDERLYING_TYPE (enumtype))
   18095                 :             :             {
   18096                 :     2628303 :               tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   18097                 :             :                                                            value, true);
   18098                 :     2628303 :               if (tmp_value)
   18099                 :     4849862 :                 value = tmp_value;
   18100                 :             :             }
   18101                 :     2221559 :           else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   18102                 :             :                    (TREE_TYPE (value)))
   18103                 :          39 :             value = perform_implicit_conversion_flags
   18104                 :          39 :               (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
   18105                 :             :                LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
   18106                 :             : 
   18107                 :     4849862 :           if (value == error_mark_node)
   18108                 :             :             value = NULL_TREE;
   18109                 :             : 
   18110                 :     4849841 :           if (value != NULL_TREE)
   18111                 :             :             {
   18112                 :     4849841 :               if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   18113                 :             :                   (TREE_TYPE (value)))
   18114                 :             :                 {
   18115                 :          17 :                   error_at (cp_expr_loc_or_input_loc (value),
   18116                 :             :                             "enumerator value for %qD must have integral or "
   18117                 :             :                             "unscoped enumeration type", name);
   18118                 :          17 :                   value = NULL_TREE;
   18119                 :             :                 }
   18120                 :             :               else
   18121                 :             :                 {
   18122                 :     4849824 :                   value = cxx_constant_value (value);
   18123                 :             : 
   18124                 :     4849824 :                   if (TREE_CODE (value) != INTEGER_CST)
   18125                 :             :                     {
   18126                 :          50 :                       error ("enumerator value for %qD is not an integer "
   18127                 :             :                              "constant", name);
   18128                 :          50 :                       value = NULL_TREE;
   18129                 :             :                     }
   18130                 :             :                 }
   18131                 :             :             }
   18132                 :             :         }
   18133                 :             : 
   18134                 :             :       /* Default based on previous value.  */
   18135                 :          67 :       if (value == NULL_TREE)
   18136                 :             :         {
   18137                 :     5936471 :           if (TYPE_VALUES (enumtype))
   18138                 :             :             {
   18139                 :     5481460 :               tree prev_value;
   18140                 :             : 
   18141                 :             :               /* C++03 7.2/4: If no initializer is specified for the first
   18142                 :             :                  enumerator, the type is an unspecified integral
   18143                 :             :                  type. Otherwise the type is the same as the type of the
   18144                 :             :                  initializing value of the preceding enumerator unless the
   18145                 :             :                  incremented value is not representable in that type, in
   18146                 :             :                  which case the type is an unspecified integral type
   18147                 :             :                  sufficient to contain the incremented value.  */
   18148                 :     5481460 :               prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
   18149                 :     5481460 :               if (TREE_CODE (prev_value) != INTEGER_CST)
   18150                 :           2 :                 value = error_mark_node;
   18151                 :             :               else
   18152                 :             :                 {
   18153                 :     5481458 :                   wi::overflow_type overflowed;
   18154                 :     5481458 :                   tree type = TREE_TYPE (prev_value);
   18155                 :     5481458 :                   signop sgn = TYPE_SIGN (type);
   18156                 :     5481458 :                   widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
   18157                 :     5481458 :                                            &overflowed);
   18158                 :     5481458 :                   if (!overflowed)
   18159                 :             :                     {
   18160                 :     5481458 :                       bool pos = !wi::neg_p (wi, sgn);
   18161                 :     5481458 :                       if (!wi::fits_to_tree_p (wi, type))
   18162                 :             :                         {
   18163                 :             :                           unsigned int itk;
   18164                 :          53 :                           for (itk = itk_int; itk != itk_none; itk++)
   18165                 :             :                             {
   18166                 :          53 :                               type = integer_types[itk];
   18167                 :          53 :                               if (type != NULL_TREE
   18168                 :          53 :                                   && (pos || !TYPE_UNSIGNED (type))
   18169                 :         106 :                                   && wi::fits_to_tree_p (wi, type))
   18170                 :             :                                 break;
   18171                 :             :                             }
   18172                 :          17 :                           if (type && cxx_dialect < cxx11
   18173                 :           6 :                               && itk > itk_unsigned_long)
   18174                 :           3 :                             pedwarn (input_location, OPT_Wlong_long,
   18175                 :             :                                      pos ? G_("\
   18176                 :             : incremented enumerator value is too large for %<unsigned long%>") : G_("\
   18177                 :             : incremented enumerator value is too large for %<long%>"));
   18178                 :             :                         }
   18179                 :     5481458 :                       if (type == NULL_TREE)
   18180                 :           0 :                         overflowed = wi::OVF_UNKNOWN;
   18181                 :             :                       else
   18182                 :     5481458 :                         value = wide_int_to_tree (type, wi);
   18183                 :             :                     }
   18184                 :             : 
   18185                 :     5481458 :                   if (overflowed)
   18186                 :             :                     {
   18187                 :           0 :                       error ("overflow in enumeration values at %qD", name);
   18188                 :           0 :                       value = error_mark_node;
   18189                 :             :                     }
   18190                 :     5481458 :                 }
   18191                 :             :             }
   18192                 :             :           else
   18193                 :      455011 :             value = integer_zero_node;
   18194                 :             :         }
   18195                 :             : 
   18196                 :             :       /* Remove no-op casts from the value.  */
   18197                 :    10786245 :       STRIP_TYPE_NOPS (value);
   18198                 :             : 
   18199                 :             :       /* If the underlying type of the enum is fixed, check whether
   18200                 :             :          the enumerator values fits in the underlying type.  If it
   18201                 :             :          does not fit, the program is ill-formed [C++0x dcl.enum].  */
   18202                 :    10786245 :       if (ENUM_UNDERLYING_TYPE (enumtype)
   18203                 :             :           && value
   18204                 :    10786245 :           && TREE_CODE (value) == INTEGER_CST)
   18205                 :             :         {
   18206                 :     3126475 :           if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
   18207                 :           9 :             error ("enumerator value %qE is outside the range of underlying "
   18208                 :           9 :                    "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
   18209                 :             : 
   18210                 :             :           /* Convert the value to the appropriate type.  */
   18211                 :     3126475 :           value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
   18212                 :             :         }
   18213                 :             :     }
   18214                 :             : 
   18215                 :             :   /* C++ associates enums with global, function, or class declarations.  */
   18216                 :    11158961 :   context = current_scope ();
   18217                 :             : 
   18218                 :             :   /* Build the actual enumeration constant.  Note that the enumeration
   18219                 :             :      constants have the underlying type of the enum (if it is fixed)
   18220                 :             :      or the type of their initializer (if the underlying type of the
   18221                 :             :      enum is not fixed):
   18222                 :             : 
   18223                 :             :       [ C++0x dcl.enum ]
   18224                 :             : 
   18225                 :             :         If the underlying type is fixed, the type of each enumerator
   18226                 :             :         prior to the closing brace is the underlying type; if the
   18227                 :             :         initializing value of an enumerator cannot be represented by
   18228                 :             :         the underlying type, the program is ill-formed. If the
   18229                 :             :         underlying type is not fixed, the type of each enumerator is
   18230                 :             :         the type of its initializing value.
   18231                 :             : 
   18232                 :             :     If the underlying type is not fixed, it will be computed by
   18233                 :             :     finish_enum and we will reset the type of this enumerator.  Of
   18234                 :             :     course, if we're processing a template, there may be no value.  */
   18235                 :    11158961 :   type = value ? TREE_TYPE (value) : NULL_TREE;
   18236                 :             : 
   18237                 :    11158961 :   decl = build_decl (loc, CONST_DECL, name, type);
   18238                 :             : 
   18239                 :    11158961 :   DECL_CONTEXT (decl) = enumtype;
   18240                 :    11158961 :   TREE_CONSTANT (decl) = 1;
   18241                 :    11158961 :   TREE_READONLY (decl) = 1;
   18242                 :    11158961 :   DECL_INITIAL (decl) = value;
   18243                 :             : 
   18244                 :    11158961 :   if (attributes)
   18245                 :       45384 :     cplus_decl_attributes (&decl, attributes, 0);
   18246                 :             : 
   18247                 :    11158961 :   if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
   18248                 :             :     {
   18249                 :             :       /* In something like `struct S { enum E { i = 7 }; };' we put `i'
   18250                 :             :          on the TYPE_FIELDS list for `S'.  (That's so that you can say
   18251                 :             :          things like `S::i' later.)  */
   18252                 :             : 
   18253                 :             :       /* The enumerator may be getting declared outside of its enclosing
   18254                 :             :          class, like so:
   18255                 :             : 
   18256                 :             :            class S { public: enum E : int; }; enum S::E : int { i = 7; };
   18257                 :             : 
   18258                 :             :          For which case we need to make sure that the access of `S::i'
   18259                 :             :          matches the access of `S::E'.  */
   18260                 :     2002626 :       auto cas = make_temp_override (current_access_specifier);
   18261                 :     2002626 :       set_current_access_from_decl (TYPE_NAME (enumtype));
   18262                 :     2002626 :       finish_member_declaration (decl);
   18263                 :     2002626 :     }
   18264                 :             :   else
   18265                 :     9156335 :     pushdecl (decl);
   18266                 :             : 
   18267                 :             :   /* Add this enumeration constant to the list for this type.  */
   18268                 :    11158961 :   TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
   18269                 :             : 
   18270                 :    11158961 :   return decl;
   18271                 :             : }
   18272                 :             : 
   18273                 :             : /* Look for an enumerator with the given NAME within the enumeration
   18274                 :             :    type ENUMTYPE.  This routine is used primarily for qualified name
   18275                 :             :    lookup into an enumerator in C++0x, e.g.,
   18276                 :             : 
   18277                 :             :      enum class Color { Red, Green, Blue };
   18278                 :             : 
   18279                 :             :      Color color = Color::Red;
   18280                 :             : 
   18281                 :             :    Returns the value corresponding to the enumerator, or
   18282                 :             :    NULL_TREE if no such enumerator was found.  */
   18283                 :             : tree
   18284                 :    11082743 : lookup_enumerator (tree enumtype, tree name)
   18285                 :             : {
   18286                 :    11082743 :   tree e;
   18287                 :    11082743 :   gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
   18288                 :             : 
   18289                 :    11082743 :   e = purpose_member (name, TYPE_VALUES (enumtype));
   18290                 :    22165390 :   return e? TREE_VALUE (e) : NULL_TREE;
   18291                 :             : }
   18292                 :             : 
   18293                 :             : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   18294                 :             : 
   18295                 :             : tree
   18296                 :           0 : cxx_simulate_enum_decl (location_t loc, const char *name,
   18297                 :             :                         vec<string_int_pair> *values)
   18298                 :             : {
   18299                 :           0 :   location_t saved_loc = input_location;
   18300                 :           0 :   input_location = loc;
   18301                 :             : 
   18302                 :           0 :   tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
   18303                 :             :                               NULL_TREE, false, NULL);
   18304                 :           0 :   if (!OPAQUE_ENUM_P (enumtype))
   18305                 :             :     {
   18306                 :           0 :       auto_diagnostic_group d;
   18307                 :           0 :       error_at (loc, "multiple definition of %q#T", enumtype);
   18308                 :           0 :       inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   18309                 :             :               "previous definition here");
   18310                 :           0 :       return enumtype;
   18311                 :           0 :     }
   18312                 :           0 :   SET_OPAQUE_ENUM_P (enumtype, false);
   18313                 :           0 :   DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
   18314                 :             : 
   18315                 :           0 :   for (const string_int_pair &value : values)
   18316                 :           0 :     build_enumerator (get_identifier (value.first),
   18317                 :           0 :                       build_int_cst (integer_type_node, value.second),
   18318                 :             :                       enumtype, NULL_TREE, loc);
   18319                 :             : 
   18320                 :           0 :   finish_enum_value_list (enumtype);
   18321                 :           0 :   finish_enum (enumtype);
   18322                 :             : 
   18323                 :           0 :   input_location = saved_loc;
   18324                 :           0 :   return enumtype;
   18325                 :             : }
   18326                 :             : 
   18327                 :             : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   18328                 :             : 
   18329                 :             : tree
   18330                 :           0 : cxx_simulate_record_decl (location_t loc, const char *name,
   18331                 :             :                           array_slice<const tree> fields)
   18332                 :             : {
   18333                 :           0 :   iloc_sentinel ils (loc);
   18334                 :             : 
   18335                 :           0 :   tree ident = get_identifier (name);
   18336                 :           0 :   tree type = xref_tag (/*tag_code=*/record_type, ident);
   18337                 :           0 :   if (type != error_mark_node
   18338                 :           0 :       && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
   18339                 :             :     {
   18340                 :           0 :       error ("redefinition of %q#T", type);
   18341                 :           0 :       type = error_mark_node;
   18342                 :             :     }
   18343                 :           0 :   if (type == error_mark_node)
   18344                 :           0 :     return lhd_simulate_record_decl (loc, name, fields);
   18345                 :             : 
   18346                 :           0 :   xref_basetypes (type, NULL_TREE);
   18347                 :           0 :   type = begin_class_definition (type);
   18348                 :           0 :   if (type == error_mark_node)
   18349                 :           0 :     return lhd_simulate_record_decl (loc, name, fields);
   18350                 :             : 
   18351                 :           0 :   for (tree field : fields)
   18352                 :           0 :     finish_member_declaration (field);
   18353                 :             : 
   18354                 :           0 :   type = finish_struct (type, NULL_TREE);
   18355                 :             : 
   18356                 :           0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   18357                 :           0 :   set_underlying_type (decl);
   18358                 :           0 :   lang_hooks.decls.pushdecl (decl);
   18359                 :             : 
   18360                 :           0 :   return type;
   18361                 :           0 : }
   18362                 :             : 
   18363                 :             : /* We're defining DECL.  Make sure that its type is OK.  */
   18364                 :             : 
   18365                 :             : static void
   18366                 :   143956593 : check_function_type (tree decl, tree current_function_parms)
   18367                 :             : {
   18368                 :   143956593 :   tree fntype = TREE_TYPE (decl);
   18369                 :   143956593 :   tree return_type = complete_type (TREE_TYPE (fntype));
   18370                 :             : 
   18371                 :             :   /* In a function definition, arg types must be complete.  */
   18372                 :   143956593 :   require_complete_types_for_parms (current_function_parms);
   18373                 :             : 
   18374                 :   143956593 :   if (dependent_type_p (return_type)
   18375                 :   143956593 :       || type_uses_auto (return_type))
   18376                 :    43422060 :     return;
   18377                 :   100534533 :   if (!COMPLETE_OR_VOID_TYPE_P (return_type))
   18378                 :             :     {
   18379                 :          12 :       tree args = TYPE_ARG_TYPES (fntype);
   18380                 :             : 
   18381                 :          12 :       error ("return type %q#T is incomplete", return_type);
   18382                 :             : 
   18383                 :             :       /* Make it return void instead.  */
   18384                 :          12 :       if (TREE_CODE (fntype) == METHOD_TYPE)
   18385                 :           3 :         fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
   18386                 :             :                                              void_type_node,
   18387                 :           3 :                                              TREE_CHAIN (args));
   18388                 :             :       else
   18389                 :           9 :         fntype = build_function_type (void_type_node, args);
   18390                 :          12 :       fntype = (cp_build_type_attribute_variant
   18391                 :          12 :                 (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
   18392                 :          12 :       fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
   18393                 :          12 :       TREE_TYPE (decl) = fntype;
   18394                 :             :     }
   18395                 :             :   else
   18396                 :             :     {
   18397                 :   100534521 :       abstract_virtuals_error (decl, TREE_TYPE (fntype));
   18398                 :   100534521 :       maybe_warn_parm_abi (TREE_TYPE (fntype),
   18399                 :   100534521 :                            DECL_SOURCE_LOCATION (decl));
   18400                 :             :     }
   18401                 :             : }
   18402                 :             : 
   18403                 :             : /* True iff FN is an implicitly-defined default constructor.  */
   18404                 :             : 
   18405                 :             : static bool
   18406                 :     4793933 : implicit_default_ctor_p (tree fn)
   18407                 :             : {
   18408                 :     4793933 :   return (DECL_CONSTRUCTOR_P (fn)
   18409                 :     4793933 :           && !user_provided_p (fn)
   18410                 :     5455498 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
   18411                 :             : }
   18412                 :             : 
   18413                 :             : /* Clobber the contents of *this to let the back end know that the object
   18414                 :             :    storage is dead when we enter the constructor or leave the destructor.  */
   18415                 :             : 
   18416                 :             : static tree
   18417                 :     5687521 : build_clobber_this (clobber_kind kind)
   18418                 :             : {
   18419                 :             :   /* Clobbering an empty base is pointless, and harmful if its one byte
   18420                 :             :      TYPE_SIZE overlays real data.  */
   18421                 :     5687521 :   if (is_empty_class (current_class_type))
   18422                 :           0 :     return void_node;
   18423                 :             : 
   18424                 :             :   /* If we have virtual bases, clobber the whole object, but only if we're in
   18425                 :             :      charge.  If we don't have virtual bases, clobber the as-base type so we
   18426                 :             :      don't mess with tail padding.  */
   18427                 :     5687521 :   bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
   18428                 :             : 
   18429                 :     5687521 :   tree ctype = current_class_type;
   18430                 :     5687521 :   if (!vbases)
   18431                 :     5668963 :     ctype = CLASSTYPE_AS_BASE (ctype);
   18432                 :             : 
   18433                 :     5687521 :   tree clobber = build_clobber (ctype, kind);
   18434                 :             : 
   18435                 :     5687521 :   tree thisref = current_class_ref;
   18436                 :     5687521 :   if (ctype != current_class_type)
   18437                 :             :     {
   18438                 :      631661 :       thisref = build_nop (build_reference_type (ctype), current_class_ptr);
   18439                 :      631661 :       thisref = convert_from_reference (thisref);
   18440                 :             :     }
   18441                 :             : 
   18442                 :     5687521 :   tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
   18443                 :     5687521 :   if (vbases)
   18444                 :       18558 :     exprstmt = build_if_in_charge (exprstmt);
   18445                 :             : 
   18446                 :             :   return exprstmt;
   18447                 :             : }
   18448                 :             : 
   18449                 :             : /* Create the FUNCTION_DECL for a function definition.
   18450                 :             :    DECLSPECS and DECLARATOR are the parts of the declaration;
   18451                 :             :    they describe the function's name and the type it returns,
   18452                 :             :    but twisted together in a fashion that parallels the syntax of C.
   18453                 :             : 
   18454                 :             :    FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
   18455                 :             :    DECLARATOR is really the DECL for the function we are about to
   18456                 :             :    process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
   18457                 :             :    indicating that the function is an inline defined in-class.
   18458                 :             : 
   18459                 :             :    This function creates a binding context for the function body
   18460                 :             :    as well as setting up the FUNCTION_DECL in current_function_decl.
   18461                 :             : 
   18462                 :             :    For C++, we must first check whether that datum makes any sense.
   18463                 :             :    For example, "class A local_a(1,2);" means that variable local_a
   18464                 :             :    is an aggregate of type A, which should have a constructor
   18465                 :             :    applied to it with the argument list [1, 2].
   18466                 :             : 
   18467                 :             :    On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
   18468                 :             :    or may be a BLOCK if the function has been defined previously
   18469                 :             :    in this translation unit.  On exit, DECL_INITIAL (decl1) will be
   18470                 :             :    error_mark_node if the function has never been defined, or
   18471                 :             :    a BLOCK if the function has been defined somewhere.  */
   18472                 :             : 
   18473                 :             : bool
   18474                 :   143956629 : start_preparsed_function (tree decl1, tree attrs, int flags)
   18475                 :             : {
   18476                 :   143956629 :   tree ctype = NULL_TREE;
   18477                 :   143956629 :   bool doing_friend = false;
   18478                 :             : 
   18479                 :             :   /* Sanity check.  */
   18480                 :   143956629 :   gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
   18481                 :   143956629 :   gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
   18482                 :             : 
   18483                 :   143956629 :   tree fntype = TREE_TYPE (decl1);
   18484                 :   143956629 :   if (DECL_CLASS_SCOPE_P (decl1))
   18485                 :   104098111 :     ctype = DECL_CONTEXT (decl1);
   18486                 :             :   else
   18487                 :             :     {
   18488                 :    79717036 :       ctype = DECL_FRIEND_CONTEXT (decl1);
   18489                 :             : 
   18490                 :    39858517 :       if (ctype)
   18491                 :   143956629 :         doing_friend = true;
   18492                 :             :     }
   18493                 :             : 
   18494                 :             :   /* Adjust for #pragma target/optimize if this is an artificial function that
   18495                 :             :      (probably) didn't go through grokfndecl.  We particularly don't want this
   18496                 :             :      for deferred instantiations, which should match their template.  */
   18497                 :   143956629 :   if (DECL_ARTIFICIAL (decl1))
   18498                 :     2962926 :     decl_attributes (&decl1, NULL_TREE, 0);
   18499                 :             : 
   18500                 :   143956629 :   if (DECL_DECLARED_INLINE_P (decl1)
   18501                 :   143956629 :       && lookup_attribute ("noinline", attrs))
   18502                 :             :     {
   18503                 :           0 :       auto_urlify_attributes sentinel;
   18504                 :           0 :       warning_at (DECL_SOURCE_LOCATION (decl1), 0,
   18505                 :             :                   "inline function %qD given attribute %qs", decl1, "noinline");
   18506                 :           0 :     }
   18507                 :             : 
   18508                 :             :   /* Handle gnu_inline attribute.  */
   18509                 :   143956629 :   if (GNU_INLINE_P (decl1))
   18510                 :             :     {
   18511                 :     1584967 :       DECL_EXTERNAL (decl1) = 1;
   18512                 :     1584967 :       DECL_NOT_REALLY_EXTERN (decl1) = 0;
   18513                 :     1584967 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   18514                 :     1584967 :       DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
   18515                 :             :     }
   18516                 :             : 
   18517                 :   143956629 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
   18518                 :             :     /* This is a constructor, we must ensure that any default args
   18519                 :             :        introduced by this definition are propagated to the clones
   18520                 :             :        now. The clones are used directly in overload resolution.  */
   18521                 :    18914811 :     adjust_clone_args (decl1);
   18522                 :             : 
   18523                 :             :   /* Sometimes we don't notice that a function is a static member, and
   18524                 :             :      build a METHOD_TYPE for it.  Fix that up now.  */
   18525                 :   143956629 :   gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
   18526                 :             :                 && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
   18527                 :             : 
   18528                 :             :   /* Set up current_class_type, and enter the scope of the class, if
   18529                 :             :      appropriate.  */
   18530                 :   143956629 :   if (ctype)
   18531                 :   107028118 :     push_nested_class (ctype);
   18532                 :             : 
   18533                 :             :   /* Now that we have entered the scope of the class, we must restore
   18534                 :             :      the bindings for any template parameters surrounding DECL1, if it
   18535                 :             :      is an inline member template.  (Order is important; consider the
   18536                 :             :      case where a template parameter has the same name as a field of
   18537                 :             :      the class.)  It is not until after this point that
   18538                 :             :      PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly.  */
   18539                 :   143956629 :   if (flags & SF_INCLASS_INLINE)
   18540                 :    70649500 :     maybe_begin_member_template_processing (decl1);
   18541                 :             : 
   18542                 :             :   /* Effective C++ rule 15.  */
   18543                 :   143956629 :   if (warn_ecpp
   18544                 :         123 :       && DECL_ASSIGNMENT_OPERATOR_P (decl1)
   18545                 :          30 :       && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
   18546                 :   143956659 :       && VOID_TYPE_P (TREE_TYPE (fntype)))
   18547                 :           0 :     warning (OPT_Weffc__,
   18548                 :             :              "%<operator=%> should return a reference to %<*this%>");
   18549                 :             : 
   18550                 :             :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   18551                 :             :      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
   18552                 :   143956629 :   if (!DECL_INITIAL (decl1))
   18553                 :    29918249 :     DECL_INITIAL (decl1) = error_mark_node;
   18554                 :             : 
   18555                 :             :   /* This function exists in static storage.
   18556                 :             :      (This does not mean `static' in the C sense!)  */
   18557                 :   143956629 :   TREE_STATIC (decl1) = 1;
   18558                 :             : 
   18559                 :             :   /* We must call push_template_decl after current_class_type is set
   18560                 :             :      up.  (If we are processing inline definitions after exiting a
   18561                 :             :      class scope, current_class_type will be NULL_TREE until set above
   18562                 :             :      by push_nested_class.)  */
   18563                 :   143956629 :   if (processing_template_decl)
   18564                 :             :     {
   18565                 :    86820268 :       tree newdecl1 = push_template_decl (decl1, doing_friend);
   18566                 :    86820268 :       if (newdecl1 == error_mark_node)
   18567                 :             :         {
   18568                 :          36 :           if (ctype)
   18569                 :           9 :             pop_nested_class ();
   18570                 :          36 :           return false;
   18571                 :             :         }
   18572                 :    86820232 :       decl1 = newdecl1;
   18573                 :             :     }
   18574                 :             : 
   18575                 :             :   /* Make sure the parameter and return types are reasonable.  When
   18576                 :             :      you declare a function, these types can be incomplete, but they
   18577                 :             :      must be complete when you define the function.  */
   18578                 :   143956593 :   check_function_type (decl1, DECL_ARGUMENTS (decl1));
   18579                 :             : 
   18580                 :             :   /* Build the return declaration for the function.  */
   18581                 :   143956593 :   tree restype = TREE_TYPE (fntype);
   18582                 :             : 
   18583                 :   143956593 :   if (DECL_RESULT (decl1) == NULL_TREE)
   18584                 :             :     {
   18585                 :             :       /* In a template instantiation, copy the return type location.  When
   18586                 :             :          parsing, the location will be set in grokdeclarator.  */
   18587                 :    57132099 :       location_t loc = input_location;
   18588                 :    57132099 :       if (DECL_TEMPLATE_INSTANTIATION (decl1))
   18589                 :             :         {
   18590                 :    26843631 :           tree tmpl = template_for_substitution (decl1);
   18591                 :    26843631 :           if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
   18592                 :    25760842 :             loc = DECL_SOURCE_LOCATION (res);
   18593                 :             :         }
   18594                 :             : 
   18595                 :    57132099 :       tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   18596                 :    57132099 :       DECL_ARTIFICIAL (resdecl) = 1;
   18597                 :    57132099 :       DECL_IGNORED_P (resdecl) = 1;
   18598                 :    57132099 :       DECL_RESULT (decl1) = resdecl;
   18599                 :             : 
   18600                 :    57132099 :       cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
   18601                 :             :     }
   18602                 :             : 
   18603                 :             :   /* Record the decl so that the function name is defined.
   18604                 :             :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   18605                 :             :      use the old decl.  */
   18606                 :   143956593 :   if (!processing_template_decl && !(flags & SF_PRE_PARSED))
   18607                 :             :     {
   18608                 :             :       /* A specialization is not used to guide overload resolution.  */
   18609                 :    20325208 :       if (!DECL_FUNCTION_MEMBER_P (decl1)
   18610                 :    20311968 :           && !(DECL_USE_TEMPLATE (decl1) &&
   18611                 :        3597 :                PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
   18612                 :             :         {
   18613                 :     9750355 :           tree olddecl = pushdecl (decl1);
   18614                 :             : 
   18615                 :     9750355 :           if (olddecl == error_mark_node)
   18616                 :             :             /* If something went wrong when registering the declaration,
   18617                 :             :                use DECL1; we have to have a FUNCTION_DECL to use when
   18618                 :             :                parsing the body of the function.  */
   18619                 :             :             ;
   18620                 :             :           else
   18621                 :             :             {
   18622                 :             :               /* Otherwise, OLDDECL is either a previous declaration
   18623                 :             :                  of the same function or DECL1 itself.  */
   18624                 :             : 
   18625                 :     9750142 :               if (warn_missing_declarations
   18626                 :          21 :                   && olddecl == decl1
   18627                 :          15 :                   && !DECL_MAIN_P (decl1)
   18628                 :          15 :                   && TREE_PUBLIC (decl1)
   18629                 :     9750154 :                   && !DECL_DECLARED_INLINE_P (decl1))
   18630                 :             :                 {
   18631                 :           9 :                   tree context;
   18632                 :             : 
   18633                 :             :                   /* Check whether DECL1 is in an anonymous
   18634                 :             :                      namespace.  */
   18635                 :           9 :                   for (context = DECL_CONTEXT (decl1);
   18636                 :          18 :                        context;
   18637                 :           9 :                        context = DECL_CONTEXT (context))
   18638                 :             :                     {
   18639                 :          12 :                       if (TREE_CODE (context) == NAMESPACE_DECL
   18640                 :          12 :                           && DECL_NAME (context) == NULL_TREE)
   18641                 :             :                         break;
   18642                 :             :                     }
   18643                 :             : 
   18644                 :           9 :                   if (context == NULL)
   18645                 :           6 :                     warning_at (DECL_SOURCE_LOCATION (decl1),
   18646                 :           6 :                                 OPT_Wmissing_declarations,
   18647                 :             :                                 "no previous declaration for %qD", decl1);
   18648                 :             :                 }
   18649                 :             : 
   18650                 :     9750142 :               decl1 = olddecl;
   18651                 :             :             }
   18652                 :             :         }
   18653                 :             :       else
   18654                 :             :         {
   18655                 :             :           /* We need to set the DECL_CONTEXT.  */
   18656                 :      807661 :           if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
   18657                 :           0 :             DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
   18658                 :             :         }
   18659                 :    10558016 :       fntype = TREE_TYPE (decl1);
   18660                 :    10558016 :       restype = TREE_TYPE (fntype);
   18661                 :             : 
   18662                 :             :       /* If #pragma weak applies, mark the decl appropriately now.
   18663                 :             :          The pragma only applies to global functions.  Because
   18664                 :             :          determining whether or not the #pragma applies involves
   18665                 :             :          computing the mangled name for the declaration, we cannot
   18666                 :             :          apply the pragma until after we have merged this declaration
   18667                 :             :          with any previous declarations; if the original declaration
   18668                 :             :          has a linkage specification, that specification applies to
   18669                 :             :          the definition as well, and may affect the mangled name.  */
   18670                 :    10558016 :       if (DECL_FILE_SCOPE_P (decl1))
   18671                 :     2376538 :         maybe_apply_pragma_weak (decl1);
   18672                 :             :     }
   18673                 :             : 
   18674                 :             :   /* We are now in the scope of the function being defined.  */
   18675                 :   143956593 :   current_function_decl = decl1;
   18676                 :             : 
   18677                 :             :   /* Save the parm names or decls from this function's declarator
   18678                 :             :      where store_parm_decls will find them.  */
   18679                 :   143956593 :   tree current_function_parms = DECL_ARGUMENTS (decl1);
   18680                 :             : 
   18681                 :             :   /* Let the user know we're compiling this function.  */
   18682                 :   143956593 :   announce_function (decl1);
   18683                 :             : 
   18684                 :   143956593 :   gcc_assert (DECL_INITIAL (decl1));
   18685                 :             : 
   18686                 :             :   /* This function may already have been parsed, in which case just
   18687                 :             :      return; our caller will skip over the body without parsing.  */
   18688                 :   143956593 :   if (DECL_INITIAL (decl1) != error_mark_node)
   18689                 :             :     return true;
   18690                 :             : 
   18691                 :             :   /* Initialize RTL machinery.  We cannot do this until
   18692                 :             :      CURRENT_FUNCTION_DECL and DECL_RESULT are set up.  We do this
   18693                 :             :      even when processing a template; this is how we get
   18694                 :             :      CFUN set up, and our per-function variables initialized.
   18695                 :             :      FIXME factor out the non-RTL stuff.  */
   18696                 :   143956593 :   cp_binding_level *bl = current_binding_level;
   18697                 :   143956593 :   allocate_struct_function (decl1, processing_template_decl);
   18698                 :             : 
   18699                 :             :   /* Initialize the language data structures.  Whenever we start
   18700                 :             :      a new function, we destroy temporaries in the usual way.  */
   18701                 :   143956593 :   cfun->language = ggc_cleared_alloc<language_function> ();
   18702                 :   143956593 :   current_stmt_tree ()->stmts_are_full_exprs_p = 1;
   18703                 :   143956593 :   current_binding_level = bl;
   18704                 :             : 
   18705                 :             :   /* If we are (erroneously) defining a function that we have already
   18706                 :             :      defined before, wipe out what we knew before.  */
   18707                 :   143956593 :   gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
   18708                 :   143956593 :   FNDECL_USED_AUTO (decl1) = false;
   18709                 :   143956593 :   DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
   18710                 :             : 
   18711                 :   143956593 :   if (!processing_template_decl && type_uses_auto (restype))
   18712                 :             :     {
   18713                 :      802509 :       FNDECL_USED_AUTO (decl1) = true;
   18714                 :      802509 :       DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
   18715                 :             :     }
   18716                 :             : 
   18717                 :             :   /* Start the statement-tree, start the tree now.  */
   18718                 :   143956593 :   DECL_SAVED_TREE (decl1) = push_stmt_list ();
   18719                 :             : 
   18720                 :   143956593 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (decl1))
   18721                 :             :     {
   18722                 :             :       /* We know that this was set up by `grokclassfn'.  We do not
   18723                 :             :          wait until `store_parm_decls', since evil parse errors may
   18724                 :             :          never get us to that point.  Here we keep the consistency
   18725                 :             :          between `current_class_type' and `current_class_ptr'.  */
   18726                 :    92924540 :       tree t = DECL_ARGUMENTS (decl1);
   18727                 :             : 
   18728                 :    92924540 :       gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
   18729                 :    92924540 :       gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
   18730                 :             : 
   18731                 :    92924540 :       cp_function_chain->x_current_class_ref
   18732                 :    92924540 :         = cp_build_fold_indirect_ref (t);
   18733                 :             :       /* Set this second to avoid shortcut in cp_build_indirect_ref.  */
   18734                 :    92924540 :       cp_function_chain->x_current_class_ptr = t;
   18735                 :             : 
   18736                 :             :       /* Constructors and destructors need to know whether they're "in
   18737                 :             :          charge" of initializing virtual base classes.  */
   18738                 :    92924540 :       t = DECL_CHAIN (t);
   18739                 :    92924540 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
   18740                 :             :         {
   18741                 :       20653 :           current_in_charge_parm = t;
   18742                 :       20653 :           t = DECL_CHAIN (t);
   18743                 :             :         }
   18744                 :    92924540 :       if (DECL_HAS_VTT_PARM_P (decl1))
   18745                 :             :         {
   18746                 :       41319 :           gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
   18747                 :       41319 :           current_vtt_parm = t;
   18748                 :             :         }
   18749                 :             :     }
   18750                 :             : 
   18751                 :   143956593 :   bool honor_interface = (!DECL_TEMPLATE_INSTANTIATION (decl1)
   18752                 :             :                           /* Implicitly-defined methods (like the
   18753                 :             :                              destructor for a class in which no destructor
   18754                 :             :                              is explicitly declared) must not be defined
   18755                 :             :                              until their definition is needed.  So, we
   18756                 :             :                              ignore interface specifications for
   18757                 :             :                              compiler-generated functions.  */
   18758                 :   143956593 :                           && !DECL_ARTIFICIAL (decl1));
   18759                 :   143956593 :   struct c_fileinfo *finfo
   18760                 :   143956593 :     = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
   18761                 :             : 
   18762                 :   143956593 :   if (processing_template_decl)
   18763                 :             :     /* Don't mess with interface flags.  */;
   18764                 :    57136361 :   else if (DECL_INTERFACE_KNOWN (decl1))
   18765                 :             :     {
   18766                 :    17740778 :       tree ctx = decl_function_context (decl1);
   18767                 :             : 
   18768                 :    17740778 :       if (DECL_NOT_REALLY_EXTERN (decl1))
   18769                 :    14196009 :         DECL_EXTERNAL (decl1) = 0;
   18770                 :             : 
   18771                 :    17740778 :       if (ctx != NULL_TREE && vague_linkage_p (ctx))
   18772                 :             :         /* This is a function in a local class in an extern inline
   18773                 :             :            or template function.  */
   18774                 :     2859701 :         comdat_linkage (decl1);
   18775                 :             :     }
   18776                 :             :   /* If this function belongs to an interface, it is public.
   18777                 :             :      If it belongs to someone else's interface, it is also external.
   18778                 :             :      This only affects inlines and template instantiations.  */
   18779                 :    39395583 :   else if (!finfo->interface_unknown && honor_interface)
   18780                 :             :     {
   18781                 :         112 :       if (DECL_DECLARED_INLINE_P (decl1)
   18782                 :         112 :           || DECL_TEMPLATE_INSTANTIATION (decl1))
   18783                 :             :         {
   18784                 :          88 :           DECL_EXTERNAL (decl1)
   18785                 :         176 :             = (finfo->interface_only
   18786                 :          88 :                || (DECL_DECLARED_INLINE_P (decl1)
   18787                 :          42 :                    && ! flag_implement_inlines
   18788                 :           0 :                    && !DECL_VINDEX (decl1)));
   18789                 :             : 
   18790                 :             :           /* For WIN32 we also want to put these in linkonce sections.  */
   18791                 :          88 :           maybe_make_one_only (decl1);
   18792                 :             :         }
   18793                 :             :       else
   18794                 :          24 :         DECL_EXTERNAL (decl1) = 0;
   18795                 :         112 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   18796                 :             :       /* If this function is in an interface implemented in this file,
   18797                 :             :          make sure that the back end knows to emit this function
   18798                 :             :          here.  */
   18799                 :         112 :       if (!DECL_EXTERNAL (decl1))
   18800                 :          66 :         mark_needed (decl1);
   18801                 :             :     }
   18802                 :    39395471 :   else if (finfo->interface_unknown && finfo->interface_only
   18803                 :           0 :            && honor_interface)
   18804                 :             :     {
   18805                 :             :       /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
   18806                 :             :          interface, we will have both finfo->interface_unknown and
   18807                 :             :          finfo->interface_only set.  In that case, we don't want to
   18808                 :             :          use the normal heuristics because someone will supply a
   18809                 :             :          #pragma implementation elsewhere, and deducing it here would
   18810                 :             :          produce a conflict.  */
   18811                 :           0 :       comdat_linkage (decl1);
   18812                 :           0 :       DECL_EXTERNAL (decl1) = 0;
   18813                 :           0 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   18814                 :           0 :       DECL_DEFER_OUTPUT (decl1) = 1;
   18815                 :             :     }
   18816                 :             :   else
   18817                 :             :     {
   18818                 :             :       /* This is a definition, not a reference.
   18819                 :             :          So clear DECL_EXTERNAL, unless this is a GNU extern inline.  */
   18820                 :    39395471 :       if (!GNU_INLINE_P (decl1))
   18821                 :    39395468 :         DECL_EXTERNAL (decl1) = 0;
   18822                 :             : 
   18823                 :    39395471 :       if ((DECL_DECLARED_INLINE_P (decl1)
   18824                 :     2094004 :            || DECL_TEMPLATE_INSTANTIATION (decl1))
   18825                 :    41253595 :           && ! DECL_INTERFACE_KNOWN (decl1))
   18826                 :    39159591 :         DECL_DEFER_OUTPUT (decl1) = 1;
   18827                 :             :       else
   18828                 :      235880 :         DECL_INTERFACE_KNOWN (decl1) = 1;
   18829                 :             :     }
   18830                 :             : 
   18831                 :             :   /* Determine the ELF visibility attribute for the function.  We must not
   18832                 :             :      do this before calling "pushdecl", as we must allow "duplicate_decls"
   18833                 :             :      to merge any attributes appropriately.  We also need to wait until
   18834                 :             :      linkage is set.  */
   18835                 :   143956593 :   if (!DECL_CLONED_FUNCTION_P (decl1))
   18836                 :   129887849 :     determine_visibility (decl1);
   18837                 :             : 
   18838                 :   143956593 :   if (!processing_template_decl)
   18839                 :    57136361 :     maybe_instantiate_noexcept (decl1);
   18840                 :             : 
   18841                 :   143956593 :   begin_scope (sk_function_parms, decl1);
   18842                 :             : 
   18843                 :   143956593 :   ++function_depth;
   18844                 :             : 
   18845                 :   143956593 :   start_fname_decls ();
   18846                 :             : 
   18847                 :   143956593 :   store_parm_decls (current_function_parms);
   18848                 :             : 
   18849                 :   143956593 :   start_function_contracts (decl1);
   18850                 :             : 
   18851                 :   143956593 :   if (!processing_template_decl
   18852                 :    57136361 :       && (flag_lifetime_dse > 1)
   18853                 :   114253058 :       && DECL_CONSTRUCTOR_P (decl1)
   18854                 :    16103032 :       && !DECL_CLONED_FUNCTION_P (decl1)
   18855                 :             :       /* Clobbering an empty base is harmful if it overlays real data.  */
   18856                 :     5364966 :       && !is_empty_class (current_class_type)
   18857                 :             :       /* We can't clobber safely for an implicitly-defined default constructor
   18858                 :             :          because part of the initialization might happen before we enter the
   18859                 :             :          constructor, via AGGR_INIT_ZERO_FIRST (c++/68006).  */
   18860                 :   148749928 :       && !implicit_default_ctor_p (decl1))
   18861                 :     4362770 :     finish_expr_stmt (build_clobber_this (CLOBBER_OBJECT_BEGIN));
   18862                 :             : 
   18863                 :   143956593 :   if (!processing_template_decl
   18864                 :   114272722 :       && DECL_CONSTRUCTOR_P (decl1)
   18865                 :    16105564 :       && sanitize_flags_p (SANITIZE_VPTR)
   18866                 :        1794 :       && !DECL_CLONED_FUNCTION_P (decl1)
   18867                 :   143957191 :       && !implicit_default_ctor_p (decl1))
   18868                 :         442 :     cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
   18869                 :             : 
   18870                 :   143956593 :   if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
   18871                 :   143956025 :     start_lambda_scope (decl1);
   18872                 :             : 
   18873                 :             :   return true;
   18874                 :             : }
   18875                 :             : 
   18876                 :             : 
   18877                 :             : /* Like start_preparsed_function, except that instead of a
   18878                 :             :    FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
   18879                 :             : 
   18880                 :             :    Returns true on success.  If the DECLARATOR is not suitable
   18881                 :             :    for a function, we return false, which tells the parser to
   18882                 :             :    skip the entire function.  */
   18883                 :             : 
   18884                 :             : bool
   18885                 :    39327923 : start_function (cp_decl_specifier_seq *declspecs,
   18886                 :             :                 const cp_declarator *declarator,
   18887                 :             :                 tree attrs)
   18888                 :             : {
   18889                 :    39327923 :   tree decl1;
   18890                 :             : 
   18891                 :    39327923 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
   18892                 :    39327923 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   18893                 :    39327923 :   if (decl1 == error_mark_node)
   18894                 :             :     return false;
   18895                 :             : 
   18896                 :    39327634 :   if (DECL_MAIN_P (decl1))
   18897                 :             :     /* main must return int.  grokfndecl should have corrected it
   18898                 :             :        (and issued a diagnostic) if the user got it wrong.  */
   18899                 :       33150 :     gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
   18900                 :             :                              integer_type_node));
   18901                 :             : 
   18902                 :    39327634 :   return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
   18903                 :             : }
   18904                 :             : 
   18905                 :             : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
   18906                 :             :    FN.  */
   18907                 :             : 
   18908                 :             : bool
   18909                 :   275367423 : use_eh_spec_block (tree fn)
   18910                 :             : {
   18911                 :   273460039 :   return (flag_exceptions && flag_enforce_eh_specs
   18912                 :   273460039 :           && !processing_template_decl
   18913                 :             :           /* We insert the EH_SPEC_BLOCK only in the original
   18914                 :             :              function; then, it is copied automatically to the
   18915                 :             :              clones.  */
   18916                 :    99385188 :           && !DECL_CLONED_FUNCTION_P (fn)
   18917                 :             :           /* Implicitly-generated constructors and destructors have
   18918                 :             :              exception specifications.  However, those specifications
   18919                 :             :              are the union of the possible exceptions specified by the
   18920                 :             :              constructors/destructors for bases and members, so no
   18921                 :             :              unallowed exception will ever reach this function.  By
   18922                 :             :              not creating the EH_SPEC_BLOCK we save a little memory,
   18923                 :             :              and we avoid spurious warnings about unreachable
   18924                 :             :              code.  */
   18925                 :    85356328 :           && !DECL_DEFAULTED_FN (fn)
   18926                 :   358380705 :           && !type_throw_all_p (TREE_TYPE (fn)));
   18927                 :             : }
   18928                 :             : 
   18929                 :             : /* Helper function to push ARGS into the current lexical scope.  DECL
   18930                 :             :    is the function declaration.  NONPARMS is used to handle enum
   18931                 :             :    constants.  */
   18932                 :             : 
   18933                 :             : void
   18934                 :   140533342 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
   18935                 :             : {
   18936                 :             :   /* If we're doing semantic analysis, then we'll call pushdecl
   18937                 :             :      for each of these.  We must do them in reverse order so that
   18938                 :             :      they end in the correct forward order.  */
   18939                 :   140533342 :   args = nreverse (args);
   18940                 :             : 
   18941                 :   140533342 :   tree next;
   18942                 :   429770891 :   for (tree parm = args; parm; parm = next)
   18943                 :             :     {
   18944                 :   289237549 :       next = DECL_CHAIN (parm);
   18945                 :   289237549 :       if (TREE_CODE (parm) == PARM_DECL)
   18946                 :   289237549 :         pushdecl (parm);
   18947                 :           0 :       else if (nonparms)
   18948                 :             :         {
   18949                 :             :           /* If we find an enum constant or a type tag, put it aside for
   18950                 :             :              the moment.  */
   18951                 :           0 :           TREE_CHAIN (parm) = NULL_TREE;
   18952                 :           0 :           *nonparms = chainon (*nonparms, parm);
   18953                 :             :         }
   18954                 :             :     }
   18955                 :             : 
   18956                 :             :   /* Get the decls in their original chain order and record in the
   18957                 :             :      function.  This is all and only the PARM_DECLs that were
   18958                 :             :      pushed into scope by the loop above.  */
   18959                 :   140533342 :   DECL_ARGUMENTS (decl) = get_local_decls ();
   18960                 :   140533342 : }
   18961                 :             : 
   18962                 :             : /* Store the parameter declarations into the current function declaration.
   18963                 :             :    This is called after parsing the parameter declarations, before
   18964                 :             :    digesting the body of the function.
   18965                 :             : 
   18966                 :             :    Also install to binding contour return value identifier, if any.  */
   18967                 :             : 
   18968                 :             : static void
   18969                 :   143956593 : store_parm_decls (tree current_function_parms)
   18970                 :             : {
   18971                 :   143956593 :   tree fndecl = current_function_decl;
   18972                 :             : 
   18973                 :             :   /* This is a chain of any other decls that came in among the parm
   18974                 :             :      declarations.  If a parm is declared with  enum {foo, bar} x;
   18975                 :             :      then CONST_DECLs for foo and bar are put here.  */
   18976                 :   143956593 :   tree nonparms = NULL_TREE;
   18977                 :             : 
   18978                 :   143956593 :   if (current_function_parms)
   18979                 :             :     {
   18980                 :             :       /* This case is when the function was defined with an ANSI prototype.
   18981                 :             :          The parms already have decls, so we need not do anything here
   18982                 :             :          except record them as in effect
   18983                 :             :          and complain if any redundant old-style parm decls were written.  */
   18984                 :             : 
   18985                 :   137905549 :       tree specparms = current_function_parms;
   18986                 :             : 
   18987                 :             :       /* Must clear this because it might contain TYPE_DECLs declared
   18988                 :             :              at class level.  */
   18989                 :   137905549 :       current_binding_level->names = NULL;
   18990                 :             : 
   18991                 :   137905549 :       do_push_parm_decls (fndecl, specparms, &nonparms);
   18992                 :             :     }
   18993                 :             :   else
   18994                 :     6051044 :     DECL_ARGUMENTS (fndecl) = NULL_TREE;
   18995                 :             : 
   18996                 :             :   /* Now store the final chain of decls for the arguments
   18997                 :             :      as the decl-chain of the current lexical scope.
   18998                 :             :      Put the enumerators in as well, at the front so that
   18999                 :             :      DECL_ARGUMENTS is not modified.  */
   19000                 :   143956593 :   current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
   19001                 :             : 
   19002                 :   143956593 :   if (use_eh_spec_block (current_function_decl))
   19003                 :    18929460 :     current_eh_spec_block = begin_eh_spec_block ();
   19004                 :   143956593 : }
   19005                 :             : 
   19006                 :             : 
   19007                 :             : /* Mark CDTOR's implicit THIS argument for returning, if required by
   19008                 :             :    the ABI..  Return the decl for THIS, if it is to be returned, and
   19009                 :             :    NULL otherwise.  */
   19010                 :             : 
   19011                 :             : tree
   19012                 :   113791991 : maybe_prepare_return_this (tree cdtor)
   19013                 :             : {
   19014                 :   113791991 :   if (targetm.cxx.cdtor_returns_this ())
   19015                 :           0 :     if (tree val = DECL_ARGUMENTS (cdtor))
   19016                 :             :       {
   19017                 :           0 :         suppress_warning (val, OPT_Wuse_after_free);
   19018                 :           0 :         return val;
   19019                 :             :       }
   19020                 :             : 
   19021                 :             :   return NULL_TREE;
   19022                 :             : }
   19023                 :             : 
   19024                 :             : /* Set the return value of the [cd]tor if the ABI wants that.  */
   19025                 :             : 
   19026                 :             : void
   19027                 :     7167177 : maybe_return_this ()
   19028                 :             : {
   19029                 :     7167177 :   if (tree val = maybe_prepare_return_this (current_function_decl))
   19030                 :             :     {
   19031                 :             :       /* Return the address of the object.  */
   19032                 :           0 :       val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
   19033                 :           0 :       val = build2 (MODIFY_EXPR, TREE_TYPE (val),
   19034                 :           0 :                     DECL_RESULT (current_function_decl), val);
   19035                 :           0 :       tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
   19036                 :           0 :       add_stmt (exprstmt);
   19037                 :             :     }
   19038                 :     7167177 : }
   19039                 :             : 
   19040                 :             : /* Do all the processing for the beginning of a destructor; set up the
   19041                 :             :    vtable pointers and cleanups for bases and members.  */
   19042                 :             : 
   19043                 :             : static void
   19044                 :     1524961 : begin_destructor_body (void)
   19045                 :             : {
   19046                 :     1524961 :   tree compound_stmt;
   19047                 :             : 
   19048                 :             :   /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
   19049                 :             :      issued an error message.  We still want to try to process the
   19050                 :             :      body of the function, but initialize_vtbl_ptrs will crash if
   19051                 :             :      TYPE_BINFO is NULL.  */
   19052                 :     1524961 :   if (COMPLETE_TYPE_P (current_class_type))
   19053                 :             :     {
   19054                 :     1524961 :       compound_stmt = begin_compound_stmt (0);
   19055                 :             :       /* Make all virtual function table pointers in non-virtual base
   19056                 :             :          classes point to CURRENT_CLASS_TYPE's virtual function
   19057                 :             :          tables.  */
   19058                 :     1524961 :       initialize_vtbl_ptrs (current_class_ptr);
   19059                 :     1524961 :       finish_compound_stmt (compound_stmt);
   19060                 :             : 
   19061                 :     1524961 :       if (flag_lifetime_dse
   19062                 :             :           /* Clobbering an empty base is harmful if it overlays real data.  */
   19063                 :     1524961 :           && !is_empty_class (current_class_type))
   19064                 :             :       {
   19065                 :     1324814 :         if (sanitize_flags_p (SANITIZE_VPTR)
   19066                 :         223 :             && (flag_sanitize_recover & SANITIZE_VPTR) == 0
   19067                 :     1324877 :             && TYPE_CONTAINS_VPTR_P (current_class_type))
   19068                 :             :           {
   19069                 :          63 :             tree binfo = TYPE_BINFO (current_class_type);
   19070                 :          63 :             tree ref
   19071                 :          63 :               = cp_build_fold_indirect_ref (current_class_ptr);
   19072                 :             : 
   19073                 :          63 :             tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
   19074                 :          63 :             tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
   19075                 :          63 :             tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
   19076                 :             :                                               NOP_EXPR, vtbl,
   19077                 :             :                                               tf_warning_or_error);
   19078                 :             :             /* If the vptr is shared with some virtual nearly empty base,
   19079                 :             :                don't clear it if not in charge, the dtor of the virtual
   19080                 :             :                nearly empty base will do that later.  */
   19081                 :          63 :             if (CLASSTYPE_VBASECLASSES (current_class_type))
   19082                 :             :               {
   19083                 :             :                 tree c = current_class_type;
   19084                 :          66 :                 while (CLASSTYPE_PRIMARY_BINFO (c))
   19085                 :             :                   {
   19086                 :          63 :                     if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
   19087                 :             :                       {
   19088                 :          36 :                         stmt = convert_to_void (stmt, ICV_STATEMENT,
   19089                 :             :                                                 tf_warning_or_error);
   19090                 :          36 :                         stmt = build_if_in_charge (stmt);
   19091                 :          36 :                         break;
   19092                 :             :                       }
   19093                 :          27 :                     c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
   19094                 :             :                   }
   19095                 :             :               }
   19096                 :          63 :             finish_decl_cleanup (NULL_TREE, stmt);
   19097                 :             :           }
   19098                 :             :         else
   19099                 :     1324751 :           finish_decl_cleanup (NULL_TREE,
   19100                 :             :                                build_clobber_this (CLOBBER_OBJECT_END));
   19101                 :             :       }
   19102                 :             : 
   19103                 :             :       /* And insert cleanups for our bases and members so that they
   19104                 :             :          will be properly destroyed if we throw.  */
   19105                 :     1524961 :       push_base_cleanups ();
   19106                 :             :     }
   19107                 :     1524961 : }
   19108                 :             : 
   19109                 :             : /* Do the necessary processing for the beginning of a function body, which
   19110                 :             :    in this case includes member-initializers, but not the catch clauses of
   19111                 :             :    a function-try-block.  Currently, this means opening a binding level
   19112                 :             :    for the member-initializers (in a ctor), member cleanups (in a dtor),
   19113                 :             :    and capture proxies (in a lambda operator()).  */
   19114                 :             : 
   19115                 :             : tree
   19116                 :   114826387 : begin_function_body (void)
   19117                 :             : {
   19118                 :   234694776 :   if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
   19119                 :             :     return NULL_TREE;
   19120                 :             : 
   19121                 :    22903404 :   if (processing_template_decl)
   19122                 :             :     /* Do nothing now.  */;
   19123                 :             :   else
   19124                 :             :     /* Always keep the BLOCK node associated with the outermost pair of
   19125                 :             :        curly braces of a function.  These are needed for correct
   19126                 :             :        operation of dwarfout.c.  */
   19127                 :     7342934 :     keep_next_level (true);
   19128                 :             : 
   19129                 :    22903404 :   tree stmt = begin_compound_stmt (BCS_FN_BODY);
   19130                 :    22903404 :   current_binding_level->artificial = 1;
   19131                 :             : 
   19132                 :    22903404 :   if (processing_template_decl)
   19133                 :             :     /* Do nothing now.  */;
   19134                 :    14685868 :   else if (DECL_DESTRUCTOR_P (current_function_decl))
   19135                 :     1524961 :     begin_destructor_body ();
   19136                 :             : 
   19137                 :             :   return stmt;
   19138                 :             : }
   19139                 :             : 
   19140                 :             : /* Do the processing for the end of a function body.  Currently, this means
   19141                 :             :    closing out the cleanups for fully-constructed bases and members, and in
   19142                 :             :    the case of the destructor, deleting the object if desired.  Again, this
   19143                 :             :    is only meaningful for [cd]tors, since they are the only functions where
   19144                 :             :    there is a significant distinction between the main body and any
   19145                 :             :    function catch clauses.  Handling, say, main() return semantics here
   19146                 :             :    would be wrong, as flowing off the end of a function catch clause for
   19147                 :             :    main() would also need to return 0.  */
   19148                 :             : 
   19149                 :             : void
   19150                 :   114826363 : finish_function_body (tree compstmt)
   19151                 :             : {
   19152                 :   114826363 :   if (compstmt == NULL_TREE)
   19153                 :             :     return;
   19154                 :             : 
   19155                 :             :   /* Close the block.  */
   19156                 :    22903404 :   finish_compound_stmt (compstmt);
   19157                 :             : 
   19158                 :    22903404 :   if (processing_template_decl)
   19159                 :             :     /* Do nothing now.  */;
   19160                 :     7342934 :   else if (DECL_CONSTRUCTOR_P (current_function_decl)
   19161                 :     7342934 :            || DECL_DESTRUCTOR_P (current_function_decl))
   19162                 :     6890771 :     maybe_return_this ();
   19163                 :             : }
   19164                 :             : 
   19165                 :             : /* Given a function, returns the BLOCK corresponding to the outermost level
   19166                 :             :    of curly braces, skipping the artificial block created for constructor
   19167                 :             :    initializers.  */
   19168                 :             : 
   19169                 :             : tree
   19170                 :      311966 : outer_curly_brace_block (tree fndecl)
   19171                 :             : {
   19172                 :      311966 :   tree block = DECL_INITIAL (fndecl);
   19173                 :      311966 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   19174                 :             :     return block;
   19175                 :        1038 :   block = BLOCK_SUBBLOCKS (block);
   19176                 :        1038 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   19177                 :             :     return block;
   19178                 :           0 :   block = BLOCK_SUBBLOCKS (block);
   19179                 :           0 :   gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
   19180                 :             :   return block;
   19181                 :             : }
   19182                 :             : 
   19183                 :             : /* If FNDECL is a class's key method, add the class to the list of
   19184                 :             :    keyed classes that should be emitted.  */
   19185                 :             : 
   19186                 :             : static void
   19187                 :   143960420 : record_key_method_defined (tree fndecl)
   19188                 :             : {
   19189                 :   194996276 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   19190                 :    92951845 :       && DECL_VIRTUAL_P (fndecl)
   19191                 :   146627808 :       && !processing_template_decl)
   19192                 :             :     {
   19193                 :     1311495 :       tree fnclass = DECL_CONTEXT (fndecl);
   19194                 :     1311495 :       if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
   19195                 :             :         {
   19196                 :        1609 :           tree classdecl = TYPE_NAME (fnclass);
   19197                 :             :           /* Classes attached to a named module are already handled.  */
   19198                 :        1609 :           if (!DECL_LANG_SPECIFIC (classdecl)
   19199                 :        1657 :               || !DECL_MODULE_ATTACH_P (classdecl))
   19200                 :        1564 :             vec_safe_push (keyed_classes, fnclass);
   19201                 :             :         }
   19202                 :             :     }
   19203                 :   143960420 : }
   19204                 :             : 
   19205                 :             : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
   19206                 :             :    of "return *this;" immediately before its location, using FNDECL's
   19207                 :             :    first statement (if any) to give the indentation, if appropriate.  */
   19208                 :             : 
   19209                 :             : static void
   19210                 :          18 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
   19211                 :             : {
   19212                 :          18 :   location_t indent = UNKNOWN_LOCATION;
   19213                 :          18 :   tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
   19214                 :          18 :   if (stmts)
   19215                 :           9 :     indent = EXPR_LOCATION (stmts);
   19216                 :          18 :   richloc->add_fixit_insert_formatted ("return *this;",
   19217                 :             :                                        richloc->get_loc (),
   19218                 :             :                                        indent);
   19219                 :          18 : }
   19220                 :             : 
   19221                 :             : /* Finish up a function declaration and compile that function
   19222                 :             :    all the way to assembler language output.  The free the storage
   19223                 :             :    for the function definition. INLINE_P is TRUE if we just
   19224                 :             :    finished processing the body of an in-class inline function
   19225                 :             :    definition.  (This processing will have taken place after the
   19226                 :             :    class definition is complete.)  */
   19227                 :             : 
   19228                 :             : tree
   19229                 :   143956557 : finish_function (bool inline_p)
   19230                 :             : {
   19231                 :   143956557 :   tree fndecl = current_function_decl;
   19232                 :   143956557 :   tree fntype, ctype = NULL_TREE;
   19233                 :   143956557 :   tree resumer = NULL_TREE, destroyer = NULL_TREE;
   19234                 :             : 
   19235                 :             :   /* When we get some parse errors, we can end up without a
   19236                 :             :      current_function_decl, so cope.  */
   19237                 :   143956557 :   if (fndecl == NULL_TREE || fndecl == error_mark_node)
   19238                 :           0 :     return error_mark_node;
   19239                 :             : 
   19240                 :   143956557 :   bool do_contracts = (DECL_HAS_CONTRACTS_P (fndecl)
   19241                 :   143956557 :                        && !processing_template_decl);
   19242                 :             : 
   19243                 :   143956557 :   if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   19244                 :   143955989 :     finish_lambda_scope ();
   19245                 :             : 
   19246                 :   143956557 :   if (c_dialect_objc ())
   19247                 :           0 :     objc_finish_function ();
   19248                 :             : 
   19249                 :   143956557 :   record_key_method_defined (fndecl);
   19250                 :             : 
   19251                 :   143956557 :   fntype = TREE_TYPE (fndecl);
   19252                 :             : 
   19253                 :             :   /*  TREE_READONLY (fndecl) = 1;
   19254                 :             :       This caused &foo to be of type ptr-to-const-function
   19255                 :             :       which then got a warning when stored in a ptr-to-function variable.  */
   19256                 :             : 
   19257                 :   143956557 :   gcc_assert (building_stmt_list_p ());
   19258                 :             :   /* The current function is being defined, so its DECL_INITIAL should
   19259                 :             :      be set, and unless there's a multiple definition, it should be
   19260                 :             :      error_mark_node.  */
   19261                 :   143956557 :   gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
   19262                 :             : 
   19263                 :   143956557 :   cp_coroutine_transform *coroutine = nullptr;
   19264                 :   143956557 :   if (flag_coroutines
   19265                 :    46718598 :       && !processing_template_decl
   19266                 :    20378350 :       && DECL_COROUTINE_P (fndecl)
   19267                 :   143958222 :       && !DECL_RAMP_FN (fndecl))
   19268                 :             :     {
   19269                 :        1665 :       gcc_checking_assert (!DECL_CLONED_FUNCTION_P (fndecl)
   19270                 :             :                            && !DECL_DEFAULTED_FN (fndecl));
   19271                 :        1665 :       coroutine = new cp_coroutine_transform (fndecl, inline_p);
   19272                 :        1665 :       if (coroutine && coroutine->cp_valid_coroutine ())
   19273                 :        1665 :         coroutine->apply_transforms ();
   19274                 :             : 
   19275                 :             :       /* We should handle coroutine IFNs in middle end lowering.  */
   19276                 :        1665 :       cfun->coroutine_component = true;
   19277                 :             : 
   19278                 :             :       /* Do not try to process the ramp's EH unless outlining succeeded.  */
   19279                 :        1665 :       if (coroutine->cp_valid_coroutine () && use_eh_spec_block (fndecl))
   19280                 :         360 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   19281                 :             :                               (TREE_TYPE (fndecl)),
   19282                 :         360 :                               current_eh_spec_block);
   19283                 :             : 
   19284                 :             :      /* If outlining succeeded, then add contracts handling if needed.  */
   19285                 :        1665 :      if (coroutine->cp_valid_coroutine () && do_contracts)
   19286                 :           6 :         maybe_apply_function_contracts (fndecl);
   19287                 :             :     }
   19288                 :             :   else
   19289                 :             :   /* For a cloned function, we've already got all the code we need;
   19290                 :             :      there's no need to add any extra bits.  */
   19291                 :   143954892 :   if (!DECL_CLONED_FUNCTION_P (fndecl))
   19292                 :             :     {
   19293                 :             :       /* Make it so that `main' always returns 0 by default.  */
   19294                 :   129886148 :       if (DECL_MAIN_FREESTANDING_P (current_function_decl)
   19295                 :   129919283 :           && !TREE_THIS_VOLATILE (current_function_decl))
   19296                 :       33135 :         finish_return_stmt (integer_zero_node);
   19297                 :             : 
   19298                 :   129886148 :       if (use_eh_spec_block (current_function_decl))
   19299                 :    18929097 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   19300                 :             :                               (TREE_TYPE (current_function_decl)),
   19301                 :    18929097 :                               current_eh_spec_block);
   19302                 :             : 
   19303                 :   129886148 :      if (do_contracts)
   19304                 :         420 :         maybe_apply_function_contracts (current_function_decl);
   19305                 :             : 
   19306                 :             :     }
   19307                 :             : 
   19308                 :             :   /* If we're saving up tree structure, tie off the function now.  */
   19309                 :   143956557 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   19310                 :             : 
   19311                 :   143956557 :   finish_fname_decls ();
   19312                 :             : 
   19313                 :             :   /* This must come after expand_function_end because cleanups might
   19314                 :             :      have declarations (from inline functions) that need to go into
   19315                 :             :      this function's blocks.  */
   19316                 :             : 
   19317                 :             :   /* If the current binding level isn't the outermost binding level
   19318                 :             :      for this function, either there is a bug, or we have experienced
   19319                 :             :      syntax errors and the statement tree is malformed.  */
   19320                 :   143956557 :   if (current_binding_level->kind != sk_function_parms)
   19321                 :             :     {
   19322                 :             :       /* Make sure we have already experienced errors.  */
   19323                 :           6 :       gcc_assert (errorcount);
   19324                 :             : 
   19325                 :             :       /* Throw away the broken statement tree and extra binding
   19326                 :             :          levels.  */
   19327                 :           6 :       DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
   19328                 :             : 
   19329                 :          12 :       while (current_binding_level->kind != sk_function_parms)
   19330                 :             :         {
   19331                 :           6 :           if (current_binding_level->kind == sk_class)
   19332                 :           0 :             pop_nested_class ();
   19333                 :             :           else
   19334                 :           6 :             poplevel (0, 0, 0);
   19335                 :             :         }
   19336                 :             :     }
   19337                 :   143956557 :   poplevel (1, 0, 1);
   19338                 :             : 
   19339                 :             :   /* Statements should always be full-expressions at the outermost set
   19340                 :             :      of curly braces for a function.  */
   19341                 :   143956557 :   gcc_assert (stmts_are_full_exprs_p ());
   19342                 :             : 
   19343                 :             :   /* If there are no return statements in a function with auto return type,
   19344                 :             :      the return type is void.  But if the declared type is something like
   19345                 :             :      auto*, this is an error.  */
   19346                 :    57136325 :   if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
   19347                 :   144759066 :       && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   19348                 :             :     {
   19349                 :      225372 :       if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   19350                 :      225357 :           && !current_function_returns_value
   19351                 :      450542 :           && !current_function_returns_null)
   19352                 :             :         {
   19353                 :             :           /* We haven't applied return type deduction because we haven't
   19354                 :             :              seen any return statements. Do that now.  */
   19355                 :      225170 :           tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   19356                 :      225170 :           do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
   19357                 :             :                              void_node, node, tf_warning_or_error,
   19358                 :             :                              adc_return_type);
   19359                 :             : 
   19360                 :      225170 :           apply_deduced_return_type (fndecl, void_type_node);
   19361                 :      225170 :           fntype = TREE_TYPE (fndecl);
   19362                 :             :         }
   19363                 :         202 :       else if (!current_function_returns_value
   19364                 :           6 :                && !current_function_returns_null)
   19365                 :             :         {
   19366                 :           6 :           auto_diagnostic_group d;
   19367                 :          12 :           error ("no return statements in function returning %qT",
   19368                 :           6 :                  DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   19369                 :           6 :           inform (input_location, "only plain %<auto%> return type can be "
   19370                 :             :                   "deduced to %<void%>");
   19371                 :           6 :         }
   19372                 :             :     }
   19373                 :             : 
   19374                 :   143956557 :   if (FNDECL_USED_AUTO (fndecl)
   19375                 :   143956557 :       && TREE_TYPE (fntype) != DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   19376                 :      802307 :     if (location_t fcloc = failed_completion_location (fndecl))
   19377                 :             :       {
   19378                 :           6 :         auto_diagnostic_group adg;
   19379                 :           6 :         if (warning (OPT_Wsfinae_incomplete_,
   19380                 :             :                      "defining %qD, which previously failed to be deduced "
   19381                 :             :                      "in a SFINAE context", fndecl)
   19382                 :           6 :             && warn_sfinae_incomplete == 1)
   19383                 :           6 :           inform (fcloc, "here.  Use %qs for a diagnostic at that point",
   19384                 :             :                   "-Wsfinae-incomplete=2");
   19385                 :           6 :       }
   19386                 :             : 
   19387                 :             :   /* Remember that we were in class scope.  */
   19388                 :   143956557 :   if (current_class_name)
   19389                 :   107028106 :     ctype = current_class_type;
   19390                 :             : 
   19391                 :   143956557 :   if (DECL_DELETED_FN (fndecl))
   19392                 :             :     {
   19393                 :          87 :       DECL_INITIAL (fndecl) = error_mark_node;
   19394                 :          87 :       DECL_SAVED_TREE (fndecl) = NULL_TREE;
   19395                 :          87 :       goto cleanup;
   19396                 :             :     }
   19397                 :             : 
   19398                 :   143956470 :   if (flag_openmp)
   19399                 :      290899 :     if (tree attr = lookup_attribute ("omp declare variant base",
   19400                 :      290899 :                                       DECL_ATTRIBUTES (fndecl)))
   19401                 :         157 :       omp_declare_variant_finalize (fndecl, attr);
   19402                 :             : 
   19403                 :             :   /* Complain if there's just no return statement.  */
   19404                 :   143956470 :   if ((warn_return_type
   19405                 :       42052 :        || (cxx_dialect >= cxx14
   19406                 :       34000 :            && DECL_DECLARED_CONSTEXPR_P (fndecl)))
   19407                 :   143925050 :       && !VOID_TYPE_P (TREE_TYPE (fntype))
   19408                 :    88517446 :       && !dependent_type_p (TREE_TYPE (fntype))
   19409                 :    45903420 :       && !current_function_returns_value && !current_function_returns_null
   19410                 :             :       /* Don't complain if we abort or throw.  */
   19411                 :       63495 :       && !current_function_returns_abnormally
   19412                 :             :       /* Don't complain if there's an infinite loop.  */
   19413                 :         922 :       && !current_function_infinite_loop
   19414                 :             :       /* Don't complain if we are declared noreturn.  */
   19415                 :         854 :       && !TREE_THIS_VOLATILE (fndecl)
   19416                 :         848 :       && !DECL_NAME (DECL_RESULT (fndecl))
   19417                 :         848 :       && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
   19418                 :             :       /* Structor return values (if any) are set by the compiler.  */
   19419                 :        1226 :       && !DECL_CONSTRUCTOR_P (fndecl)
   19420                 :         613 :       && !DECL_DESTRUCTOR_P (fndecl)
   19421                 :   143957083 :       && targetm.warn_func_return (fndecl))
   19422                 :             :     {
   19423                 :         607 :       gcc_rich_location richloc (input_location);
   19424                 :             :       /* Potentially add a "return *this;" fix-it hint for
   19425                 :             :          assignment operators.  */
   19426                 :         607 :       if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
   19427                 :             :         {
   19428                 :          39 :           tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
   19429                 :          39 :           if (TREE_CODE (valtype) == REFERENCE_TYPE
   19430                 :          32 :               && current_class_ref
   19431                 :          26 :               && same_type_ignoring_top_level_qualifiers_p
   19432                 :          26 :                   (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
   19433                 :          71 :               && global_dc->option_enabled_p (OPT_Wreturn_type))
   19434                 :          18 :             add_return_star_this_fixit (&richloc, fndecl);
   19435                 :             :         }
   19436                 :         607 :       if (cxx_dialect >= cxx14
   19437                 :         607 :           && DECL_DECLARED_CONSTEXPR_P (fndecl))
   19438                 :           2 :         error_at (&richloc, "no return statement in %<constexpr%> function "
   19439                 :             :                             "returning non-void");
   19440                 :         605 :       else if (warning_at (&richloc, OPT_Wreturn_type,
   19441                 :             :                            "no return statement in function returning "
   19442                 :             :                            "non-void"))
   19443                 :         159 :         suppress_warning (fndecl, OPT_Wreturn_type);
   19444                 :         607 :     }
   19445                 :             : 
   19446                 :             :   /* Lambda closure members are implicitly constexpr if possible.  */
   19447                 :   143956470 :   if (cxx_dialect >= cxx17
   19448                 :   246802510 :       && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
   19449                 :     1204788 :     DECL_DECLARED_CONSTEXPR_P (fndecl)
   19450                 :     1204788 :       = ((processing_template_decl
   19451                 :      536333 :           || is_valid_constexpr_fn (fndecl, /*complain*/false))
   19452                 :     2408547 :          && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
   19453                 :             : 
   19454                 :             :   /* Save constexpr function body before it gets munged by
   19455                 :             :      the NRV transformation.   */
   19456                 :   143956470 :   maybe_save_constexpr_fundef (fndecl);
   19457                 :             : 
   19458                 :             :   /* Invoke the pre-genericize plugin before we start munging things.  */
   19459                 :   143956470 :   if (!processing_template_decl)
   19460                 :    57136238 :     invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   19461                 :             : 
   19462                 :             :   /* Perform delayed folding before NRV transformation.  */
   19463                 :   143956470 :   if (!processing_template_decl
   19464                 :   114272476 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   19465                 :   200833747 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   19466                 :    56876839 :     cp_fold_function (fndecl);
   19467                 :             : 
   19468                 :             :   /* Set up the named return value optimization, if we can.  Candidate
   19469                 :             :      variables are selected in check_return_expr.  */
   19470                 :   143956470 :   if (tree r = current_function_return_value)
   19471                 :             :     {
   19472                 :    35687683 :       if (r != error_mark_node)
   19473                 :      182121 :         finalize_nrv (fndecl, r);
   19474                 :    35687683 :       current_function_return_value = NULL_TREE;
   19475                 :             :     }
   19476                 :             : 
   19477                 :             :   /* Must mark the RESULT_DECL as being in this function.  */
   19478                 :   143956470 :   DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   19479                 :             : 
   19480                 :             :   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
   19481                 :             :      to the FUNCTION_DECL node itself.  */
   19482                 :   143956470 :   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   19483                 :             : 
   19484                 :             :   /* Store the end of the function, so that we get good line number
   19485                 :             :      info for the epilogue.  */
   19486                 :   143956470 :   cfun->function_end_locus = input_location;
   19487                 :             : 
   19488                 :             :   /* Complain about parameters that are only set, but never otherwise used.  */
   19489                 :   143956470 :   if (warn_unused_but_set_parameter
   19490                 :      899826 :       && !processing_template_decl
   19491                 :      460979 :       && errorcount == unused_but_set_errorcount
   19492                 :   144417446 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   19493                 :             :     {
   19494                 :      360772 :       tree decl;
   19495                 :             : 
   19496                 :      360772 :       for (decl = DECL_ARGUMENTS (fndecl);
   19497                 :      961953 :            decl;
   19498                 :      601181 :            decl = DECL_CHAIN (decl))
   19499                 :      601181 :         if (TREE_USED (decl)
   19500                 :      496283 :             && TREE_CODE (decl) == PARM_DECL
   19501                 :      496283 :             && !DECL_READ_P (decl)
   19502                 :         225 :             && DECL_NAME (decl)
   19503                 :         225 :             && !DECL_ARTIFICIAL (decl)
   19504                 :         225 :             && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_)
   19505                 :         225 :             && !DECL_IN_SYSTEM_HEADER (decl)
   19506                 :         225 :             && TREE_TYPE (decl) != error_mark_node
   19507                 :         225 :             && !TYPE_REF_P (TREE_TYPE (decl))
   19508                 :      601406 :             && (!CLASS_TYPE_P (TREE_TYPE (decl))
   19509                 :           0 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
   19510                 :         225 :           warning_at (DECL_SOURCE_LOCATION (decl),
   19511                 :         225 :                       OPT_Wunused_but_set_parameter_,
   19512                 :             :                       "parameter %qD set but not used", decl);
   19513                 :      360772 :       unused_but_set_errorcount = errorcount;
   19514                 :             :     }
   19515                 :             : 
   19516                 :             :   /* Complain about locally defined typedefs that are not used in this
   19517                 :             :      function.  */
   19518                 :   143956470 :   maybe_warn_unused_local_typedefs ();
   19519                 :             : 
   19520                 :             :   /* Possibly warn about unused parameters.  */
   19521                 :   143956470 :   if (warn_unused_parameter
   19522                 :      630510 :       && !processing_template_decl
   19523                 :   144259940 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   19524                 :      233020 :     do_warn_unused_parameter (fndecl);
   19525                 :             : 
   19526                 :             :   /* Genericize before inlining.  */
   19527                 :   143956470 :   if (!processing_template_decl
   19528                 :   114272476 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   19529                 :   200833455 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   19530                 :    56876547 :     cp_genericize (fndecl);
   19531                 :             : 
   19532                 :             :   /* If this function can't throw any exceptions, remember that.  */
   19533                 :   143956470 :   if (!processing_template_decl
   19534                 :    57136238 :       && !cp_function_chain->can_throw
   19535                 :    43140001 :       && !flag_non_call_exceptions
   19536                 :    43135192 :       && !decl_replaceable_p (fndecl,
   19537                 :    43135192 :                               opt_for_fn (fndecl, flag_semantic_interposition))
   19538                 :   186835976 :       && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
   19539                 :    42877145 :     TREE_NOTHROW (fndecl) = 1;
   19540                 :             : 
   19541                 :   143956557 :  cleanup:
   19542                 :             : 
   19543                 :             :   /* We're leaving the context of this function, so zap cfun.  It's still in
   19544                 :             :      DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation.  */
   19545                 :   143956557 :   set_cfun (NULL);
   19546                 :   143956557 :   current_function_decl = NULL;
   19547                 :             : 
   19548                 :             :   /* If this is an in-class inline definition, we may have to pop the
   19549                 :             :      bindings for the template parameters that we added in
   19550                 :             :      maybe_begin_member_template_processing when start_function was
   19551                 :             :      called.  */
   19552                 :   143956557 :   if (inline_p)
   19553                 :    70649928 :     maybe_end_member_template_processing ();
   19554                 :             : 
   19555                 :             :   /* Leave the scope of the class.  */
   19556                 :   143956557 :   if (ctype)
   19557                 :   107028106 :     pop_nested_class ();
   19558                 :             : 
   19559                 :   143956557 :   --function_depth;
   19560                 :             : 
   19561                 :             :   /* Clean up.  */
   19562                 :   143956557 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
   19563                 :             : 
   19564                 :             :   /* Build outlined functions for coroutines and contracts.  */
   19565                 :             : 
   19566                 :   143956557 :   if (coroutine)
   19567                 :             :     {
   19568                 :             :       /* Emit the resumer and destroyer functions now, providing that we have
   19569                 :             :          not encountered some fatal error.  */
   19570                 :        1665 :       if (coroutine->cp_valid_coroutine ())
   19571                 :             :         {
   19572                 :        1581 :           coroutine->finish_transforms ();
   19573                 :        1581 :           resumer = coroutine->get_resumer ();
   19574                 :        1581 :           destroyer = coroutine->get_destroyer ();
   19575                 :        1581 :           expand_or_defer_fn (resumer);
   19576                 :        1581 :           expand_or_defer_fn (destroyer);
   19577                 :             :         }
   19578                 :        1665 :       delete coroutine;
   19579                 :             :     }
   19580                 :             : 
   19581                 :             :   /* If we have used outlined contracts checking functions, build and emit
   19582                 :             :      them here.  */
   19583                 :   143956557 :   finish_function_contracts (fndecl);
   19584                 :             : 
   19585                 :   143956557 :   return fndecl;
   19586                 :             : }
   19587                 :             : 
   19588                 :             : /* Create the FUNCTION_DECL for a function definition.
   19589                 :             :    DECLSPECS and DECLARATOR are the parts of the declaration;
   19590                 :             :    they describe the return type and the name of the function,
   19591                 :             :    but twisted together in a fashion that parallels the syntax of C.
   19592                 :             : 
   19593                 :             :    This function creates a binding context for the function body
   19594                 :             :    as well as setting up the FUNCTION_DECL in current_function_decl.
   19595                 :             : 
   19596                 :             :    Returns a FUNCTION_DECL on success.
   19597                 :             : 
   19598                 :             :    If the DECLARATOR is not suitable for a function (it defines a datum
   19599                 :             :    instead), we return 0, which tells yyparse to report a parse error.
   19600                 :             : 
   19601                 :             :    May return void_type_node indicating that this method is actually
   19602                 :             :    a friend.  See grokfield for more details.
   19603                 :             : 
   19604                 :             :    Came here with a `.pushlevel' .
   19605                 :             : 
   19606                 :             :    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
   19607                 :             :    CHANGES TO CODE IN `grokfield'.  */
   19608                 :             : 
   19609                 :             : tree
   19610                 :    70351731 : grokmethod (cp_decl_specifier_seq *declspecs,
   19611                 :             :             const cp_declarator *declarator, tree attrlist)
   19612                 :             : {
   19613                 :    70351731 :   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
   19614                 :    70351731 :                                 &attrlist);
   19615                 :             : 
   19616                 :    70351731 :   if (fndecl == error_mark_node)
   19617                 :             :     return error_mark_node;
   19618                 :             : 
   19619                 :    70351628 :   if (attrlist)
   19620                 :           0 :     cplus_decl_attributes (&fndecl, attrlist, 0);
   19621                 :             : 
   19622                 :             :   /* Pass friends other than inline friend functions back.  */
   19623                 :    70351628 :   if (fndecl == void_type_node)
   19624                 :             :     return fndecl;
   19625                 :             : 
   19626                 :    70351628 :   if (DECL_IN_AGGR_P (fndecl))
   19627                 :             :     {
   19628                 :           0 :       if (DECL_CLASS_SCOPE_P (fndecl))
   19629                 :           0 :         error ("%qD is already defined in class %qT", fndecl,
   19630                 :           0 :                DECL_CONTEXT (fndecl));
   19631                 :           0 :       return error_mark_node;
   19632                 :             :     }
   19633                 :             : 
   19634                 :    70351628 :   check_template_shadow (fndecl);
   19635                 :             : 
   19636                 :             :   /* p1779 ABI-Isolation makes inline not a default for in-class
   19637                 :             :      definitions attached to a named module.  If the user explicitly
   19638                 :             :      made it inline, grokdeclarator will already have done the right
   19639                 :             :      things.  */
   19640                 :    70351628 :   if ((!named_module_attach_p ()
   19641                 :         390 :        || flag_module_implicit_inline
   19642                 :             :       /* Lambda's operator function remains inline.  */
   19643                 :         765 :        || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
   19644                 :             :       /* If the user explicitly asked for this to be inline, we don't
   19645                 :             :          need to do more, but more importantly we want to warn if we
   19646                 :             :          can't inline it.  */
   19647                 :    70351288 :       && !DECL_DECLARED_INLINE_P (fndecl))
   19648                 :             :     {
   19649                 :    51097637 :       if (TREE_PUBLIC (fndecl))
   19650                 :    50073223 :         DECL_COMDAT (fndecl) = 1;
   19651                 :    51097637 :       DECL_DECLARED_INLINE_P (fndecl) = 1;
   19652                 :             :       /* It's ok if we can't inline this.  */
   19653                 :    51097637 :       DECL_NO_INLINE_WARNING_P (fndecl) = 1;
   19654                 :             :     }
   19655                 :             : 
   19656                 :             :   /* We process method specializations in finish_struct_1.  */
   19657                 :    70351628 :   if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
   19658                 :             :     {
   19659                 :             :       /* Avoid calling decl_spec_seq... until we have to.  */
   19660                 :    58002058 :       bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   19661                 :    58002058 :       fndecl = push_template_decl (fndecl, friendp);
   19662                 :    58002058 :       if (fndecl == error_mark_node)
   19663                 :             :         return fndecl;
   19664                 :             :     }
   19665                 :             : 
   19666                 :    70351621 :   if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
   19667                 :             :     {
   19668                 :           0 :       fndecl = copy_node (fndecl);
   19669                 :           0 :       TREE_CHAIN (fndecl) = NULL_TREE;
   19670                 :             :     }
   19671                 :             : 
   19672                 :    70351621 :   cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
   19673                 :             : 
   19674                 :    70351621 :   DECL_IN_AGGR_P (fndecl) = 1;
   19675                 :    70351621 :   return fndecl;
   19676                 :             : }
   19677                 :             : 
   19678                 :             : 
   19679                 :             : /* VAR is a VAR_DECL.  If its type is incomplete, remember VAR so that
   19680                 :             :    we can lay it out later, when and if its type becomes complete.
   19681                 :             : 
   19682                 :             :    Also handle constexpr variables where the initializer involves
   19683                 :             :    an unlowered PTRMEM_CST because the class isn't complete yet.  */
   19684                 :             : 
   19685                 :             : void
   19686                 :    88225405 : maybe_register_incomplete_var (tree var)
   19687                 :             : {
   19688                 :    88225405 :   gcc_assert (VAR_P (var));
   19689                 :             : 
   19690                 :             :   /* Keep track of variables with incomplete types.  */
   19691                 :    39198442 :   if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
   19692                 :   127422246 :       && DECL_EXTERNAL (var))
   19693                 :             :     {
   19694                 :     5657516 :       tree inner_type = TREE_TYPE (var);
   19695                 :             : 
   19696                 :     5819108 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   19697                 :      161592 :         inner_type = TREE_TYPE (inner_type);
   19698                 :     5657516 :       inner_type = TYPE_MAIN_VARIANT (inner_type);
   19699                 :             : 
   19700                 :     5700156 :       if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
   19701                 :             :           /* RTTI TD entries are created while defining the type_info.  */
   19702                 :     5657516 :           || (TYPE_LANG_SPECIFIC (inner_type)
   19703                 :     2291245 :               && TYPE_BEING_DEFINED (inner_type)))
   19704                 :             :         {
   19705                 :       42640 :           incomplete_var iv = {var, inner_type};
   19706                 :       42640 :           vec_safe_push (incomplete_vars, iv);
   19707                 :             :         }
   19708                 :    10922270 :       else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
   19709                 :     3496151 :                && DECL_CLASS_SCOPE_P (var)
   19710                 :     1107388 :                && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
   19711                 :     1107388 :                && decl_constant_var_p (var)
   19712                 :     6335735 :                && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
   19713                 :             :         {
   19714                 :             :           /* When the outermost open class is complete we can resolve any
   19715                 :             :              pointers-to-members.  */
   19716                 :          13 :           tree context = outermost_open_class ();
   19717                 :          13 :           incomplete_var iv = {var, context};
   19718                 :          13 :           vec_safe_push (incomplete_vars, iv);
   19719                 :             :         }
   19720                 :             :     }
   19721                 :    88225405 : }
   19722                 :             : 
   19723                 :             : /* Called when a class type (given by TYPE) is defined.  If there are
   19724                 :             :    any existing VAR_DECLs whose type has been completed by this
   19725                 :             :    declaration, update them now.  */
   19726                 :             : 
   19727                 :             : void
   19728                 :    55851440 : complete_vars (tree type)
   19729                 :             : {
   19730                 :    55851440 :   unsigned ix;
   19731                 :    55851440 :   incomplete_var *iv;
   19732                 :             : 
   19733                 :    56274851 :   for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
   19734                 :             :     {
   19735                 :      423411 :       if (same_type_p (type, iv->incomplete_type))
   19736                 :             :         {
   19737                 :       41507 :           tree var = iv->decl;
   19738                 :       41507 :           tree type = TREE_TYPE (var);
   19739                 :             : 
   19740                 :       41507 :           if (type != error_mark_node
   19741                 :       41507 :               && (TYPE_MAIN_VARIANT (strip_array_types (type))
   19742                 :       41504 :                   == iv->incomplete_type))
   19743                 :             :             {
   19744                 :             :               /* Complete the type of the variable.  */
   19745                 :       41491 :               complete_type (type);
   19746                 :       41491 :               cp_apply_type_quals_to_decl (cp_type_quals (type), var);
   19747                 :       41491 :               if (COMPLETE_TYPE_P (type))
   19748                 :       41476 :                 layout_var_decl (var);
   19749                 :             :             }
   19750                 :             : 
   19751                 :             :           /* Remove this entry from the list.  */
   19752                 :       41507 :           incomplete_vars->unordered_remove (ix);
   19753                 :             :         }
   19754                 :             :       else
   19755                 :      381904 :         ix++;
   19756                 :             :     }
   19757                 :    55851440 : }
   19758                 :             : 
   19759                 :             : /* If DECL is of a type which needs a cleanup, build and return an
   19760                 :             :    expression to perform that cleanup here.  Return NULL_TREE if no
   19761                 :             :    cleanup need be done.  DECL can also be a _REF when called from
   19762                 :             :    split_nonconstant_init_1.  */
   19763                 :             : 
   19764                 :             : tree
   19765                 :    65084963 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
   19766                 :             : {
   19767                 :    65084963 :   tree type;
   19768                 :    65084963 :   tree attr;
   19769                 :    65084963 :   tree cleanup;
   19770                 :             : 
   19771                 :             :   /* Assume no cleanup is required.  */
   19772                 :    65084963 :   cleanup = NULL_TREE;
   19773                 :             : 
   19774                 :    65084963 :   if (!decl || error_operand_p (decl))
   19775                 :             :     return cleanup;
   19776                 :             : 
   19777                 :             :   /* Handle "__attribute__((cleanup))".  We run the cleanup function
   19778                 :             :      before the destructor since the destructor is what actually
   19779                 :             :      terminates the lifetime of the object.  */
   19780                 :    65084963 :   if (DECL_P (decl))
   19781                 :    64718804 :     attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
   19782                 :             :   else
   19783                 :             :     attr = NULL_TREE;
   19784                 :    64718804 :   if (attr)
   19785                 :             :     {
   19786                 :         157 :       tree id;
   19787                 :         157 :       tree fn;
   19788                 :         157 :       tree arg;
   19789                 :             : 
   19790                 :             :       /* Get the name specified by the user for the cleanup function.  */
   19791                 :         157 :       id = TREE_VALUE (TREE_VALUE (attr));
   19792                 :             :       /* Look up the name to find the cleanup function to call.  It is
   19793                 :             :          important to use lookup_name here because that is what is
   19794                 :             :          used in c-common.cc:handle_cleanup_attribute when performing
   19795                 :             :          initial checks on the attribute.  Note that those checks
   19796                 :             :          include ensuring that the function found is not an overloaded
   19797                 :             :          function, or an object with an overloaded call operator,
   19798                 :             :          etc.; we can rely on the fact that the function found is an
   19799                 :             :          ordinary FUNCTION_DECL.  */
   19800                 :         157 :       fn = lookup_name (id);
   19801                 :         157 :       arg = build_address (decl);
   19802                 :         157 :       if (!mark_used (decl, complain) && !(complain & tf_error))
   19803                 :           0 :         return error_mark_node;
   19804                 :         157 :       cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
   19805                 :         157 :       if (cleanup == error_mark_node)
   19806                 :             :         return error_mark_node;
   19807                 :             :     }
   19808                 :             :   /* Handle ordinary C++ destructors.  */
   19809                 :    65084951 :   type = TREE_TYPE (decl);
   19810                 :    65084951 :   if (type_build_dtor_call (type))
   19811                 :             :     {
   19812                 :     5288463 :       int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
   19813                 :     5288463 :       tree addr;
   19814                 :     5288463 :       tree call;
   19815                 :             : 
   19816                 :     5288463 :       if (TREE_CODE (type) == ARRAY_TYPE)
   19817                 :             :         addr = decl;
   19818                 :             :       else
   19819                 :     5286721 :         addr = build_address (decl);
   19820                 :             : 
   19821                 :     5288463 :       call = build_delete (input_location, TREE_TYPE (addr), addr,
   19822                 :             :                            sfk_complete_destructor, flags, 0, complain);
   19823                 :     5288463 :       if (call == error_mark_node)
   19824                 :             :         cleanup = error_mark_node;
   19825                 :     5288424 :       else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   19826                 :             :         /* Discard the call.  */;
   19827                 :     3949903 :       else if (decl_maybe_constant_destruction (decl, type)
   19828                 :     3950050 :                && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   19829                 :         147 :         cxx_constant_dtor (call, decl);
   19830                 :     3949756 :       else if (cleanup)
   19831                 :           3 :         cleanup = cp_build_compound_expr (cleanup, call, complain);
   19832                 :             :       else
   19833                 :             :         cleanup = call;
   19834                 :             :     }
   19835                 :             : 
   19836                 :             :   /* build_delete sets the location of the destructor call to the
   19837                 :             :      current location, even though the destructor is going to be
   19838                 :             :      called later, at the end of the current scope.  This can lead to
   19839                 :             :      a "jumpy" behavior for users of debuggers when they step around
   19840                 :             :      the end of the block.  So let's unset the location of the
   19841                 :             :      destructor call instead.  */
   19842                 :    65084951 :   protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
   19843                 :    65084951 :   if (cleanup && CONVERT_EXPR_P (cleanup))
   19844                 :           0 :     protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
   19845                 :             : 
   19846                 :           0 :   if (cleanup
   19847                 :     3949937 :       && DECL_P (decl)
   19848                 :     3949466 :       && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
   19849                 :             :       /* Treat objects with destructors as used; the destructor may do
   19850                 :             :          something substantive.  */
   19851                 :     3949460 :       && !mark_used (decl, complain) && !(complain & tf_error))
   19852                 :           0 :     return error_mark_node;
   19853                 :             : 
   19854                 :     3949937 :   if (cleanup && cfun && !processing_template_decl
   19855                 :    68592353 :       && !expr_noexcept_p (cleanup, tf_none))
   19856                 :        4794 :     cp_function_chain->throwing_cleanup = true;
   19857                 :             : 
   19858                 :             :   return cleanup;
   19859                 :             : }
   19860                 :             : 
   19861                 :             : 
   19862                 :             : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
   19863                 :             :    FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
   19864                 :             :    METHOD_TYPE or FUNCTION_TYPE, or pointer to member function.  */
   19865                 :             : 
   19866                 :             : tree
   19867                 :     2744935 : static_fn_type (tree memfntype)
   19868                 :             : {
   19869                 :     2744935 :   tree fntype;
   19870                 :     2744935 :   tree args;
   19871                 :             : 
   19872                 :     2744935 :   if (TYPE_PTRMEMFUNC_P (memfntype))
   19873                 :       21514 :     memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
   19874                 :     2744935 :   if (INDIRECT_TYPE_P (memfntype)
   19875                 :     2405429 :       || TREE_CODE (memfntype) == FUNCTION_DECL)
   19876                 :     2566066 :     memfntype = TREE_TYPE (memfntype);
   19877                 :     2744935 :   if (TREE_CODE (memfntype) == FUNCTION_TYPE)
   19878                 :             :     return memfntype;
   19879                 :      556295 :   gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
   19880                 :      556295 :   args = TYPE_ARG_TYPES (memfntype);
   19881                 :      556295 :   fntype = build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
   19882                 :      556295 :   fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
   19883                 :      556295 :   fntype = (cp_build_type_attribute_variant
   19884                 :      556295 :             (fntype, TYPE_ATTRIBUTES (memfntype)));
   19885                 :      556295 :   fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
   19886                 :      556295 :   return fntype;
   19887                 :             : }
   19888                 :             : 
   19889                 :             : /* DECL was originally constructed as a non-static member function,
   19890                 :             :    but turned out to be static.  Update it accordingly.  */
   19891                 :             : 
   19892                 :             : void
   19893                 :      164584 : revert_static_member_fn (tree decl)
   19894                 :             : {
   19895                 :      164584 :   tree stype = static_fn_type (decl);
   19896                 :      164584 :   cp_cv_quals quals = type_memfn_quals (stype);
   19897                 :      164584 :   cp_ref_qualifier rqual = type_memfn_rqual (stype);
   19898                 :             : 
   19899                 :      164584 :   if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
   19900                 :           9 :     stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
   19901                 :             : 
   19902                 :      164584 :   TREE_TYPE (decl) = stype;
   19903                 :             : 
   19904                 :      164584 :   if (DECL_ARGUMENTS (decl))
   19905                 :      164584 :     DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
   19906                 :      164584 :   DECL_STATIC_FUNCTION_P (decl) = 1;
   19907                 :      164584 : }
   19908                 :             : 
   19909                 :             : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
   19910                 :             :    one of the language-independent trees.  */
   19911                 :             : 
   19912                 :             : enum cp_tree_node_structure_enum
   19913                 : 32518695701 : cp_tree_node_structure (union lang_tree_node * t)
   19914                 :             : {
   19915                 : 32518695701 :   switch (TREE_CODE (&t->generic))
   19916                 :             :     {
   19917                 :             :     case ARGUMENT_PACK_SELECT:  return TS_CP_ARGUMENT_PACK_SELECT;
   19918                 :   141515279 :     case BASELINK:              return TS_CP_BASELINK;
   19919                 :    32836812 :     case CONSTRAINT_INFO:       return TS_CP_CONSTRAINT_INFO;
   19920                 :    10724671 :     case DEFERRED_NOEXCEPT:     return TS_CP_DEFERRED_NOEXCEPT;
   19921                 :     3329284 :     case DEFERRED_PARSE:        return TS_CP_DEFERRED_PARSE;
   19922                 :  1955282828 :     case IDENTIFIER_NODE:       return TS_CP_IDENTIFIER;
   19923                 :     2078802 :     case LAMBDA_EXPR:           return TS_CP_LAMBDA_EXPR;
   19924                 :      162899 :     case BINDING_VECTOR:        return TS_CP_BINDING_VECTOR;
   19925                 :   623067376 :     case OVERLOAD:              return TS_CP_OVERLOAD;
   19926                 :         763 :     case PTRMEM_CST:            return TS_CP_PTRMEM;
   19927                 :    14007922 :     case STATIC_ASSERT:         return TS_CP_STATIC_ASSERT;
   19928                 :   602416047 :     case TEMPLATE_DECL:         return TS_CP_TEMPLATE_DECL;
   19929                 :  1377532083 :     case TEMPLATE_INFO:         return TS_CP_TEMPLATE_INFO;
   19930                 :   596805807 :     case TEMPLATE_PARM_INDEX:   return TS_CP_TPI;
   19931                 :    14566079 :     case TRAIT_EXPR:            return TS_CP_TRAIT_EXPR;
   19932                 :           3 :     case TU_LOCAL_ENTITY:       return TS_CP_TU_LOCAL_ENTITY;
   19933                 :     2481187 :     case USERDEF_LITERAL:       return TS_CP_USERDEF_LITERAL;
   19934                 : 27141887859 :     default:                    return TS_CP_GENERIC;
   19935                 :             :     }
   19936                 :             : }
   19937                 :             : 
   19938                 :             : bool
   19939                 :       10039 : cp_missing_noreturn_ok_p (tree decl)
   19940                 :             : {
   19941                 :             :   /* A missing noreturn is ok for the `main' function.  */
   19942                 :       10039 :   return DECL_MAIN_P (decl);
   19943                 :             : }
   19944                 :             : 
   19945                 :             : /* Return the decl used to identify the COMDAT group into which DECL should
   19946                 :             :    be placed.  */
   19947                 :             : 
   19948                 :             : tree
   19949                 :    83988317 : cxx_comdat_group (tree decl)
   19950                 :             : {
   19951                 :             :   /* Virtual tables, construction virtual tables, and virtual table
   19952                 :             :      tables all go in a single COMDAT group, named after the primary
   19953                 :             :      virtual table.  */
   19954                 :    83988317 :   if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
   19955                 :      451699 :     decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
   19956                 :             :   /* For all other DECLs, the COMDAT group is the mangled name of the
   19957                 :             :      declaration itself.  */
   19958                 :             :   else
   19959                 :             :     {
   19960                 :    83536618 :       while (DECL_THUNK_P (decl))
   19961                 :             :         {
   19962                 :             :           /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
   19963                 :             :              into the same section as the target function.  In that case
   19964                 :             :              we must return target's name.  */
   19965                 :           0 :           tree target = THUNK_TARGET (decl);
   19966                 :           0 :           if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
   19967                 :           0 :               && DECL_SECTION_NAME (target) != NULL
   19968                 :           0 :               && DECL_ONE_ONLY (target))
   19969                 :             :             decl = target;
   19970                 :             :           else
   19971                 :             :             break;
   19972                 :             :         }
   19973                 :             :       /* If a ctor/dtor has already set the comdat group by
   19974                 :             :          maybe_clone_body, don't override it.  */
   19975                 :    83536618 :       if (SUPPORTS_ONE_ONLY
   19976                 :    83536618 :           && TREE_CODE (decl) == FUNCTION_DECL
   19977                 :    83536618 :           && DECL_CLONED_FUNCTION_P (decl))
   19978                 :    15391875 :         if (tree comdat = DECL_COMDAT_GROUP (decl))
   19979                 :             :           return comdat;
   19980                 :             :     }
   19981                 :             : 
   19982                 :             :   return decl;
   19983                 :             : }
   19984                 :             : 
   19985                 :             : /* Returns the return type for FN as written by the user, which may include
   19986                 :             :    a placeholder for a deduced return type.  */
   19987                 :             : 
   19988                 :             : tree
   19989                 :   486695840 : fndecl_declared_return_type (tree fn)
   19990                 :             : {
   19991                 :   486695840 :   fn = STRIP_TEMPLATE (fn);
   19992                 :   486695840 :   if (FNDECL_USED_AUTO (fn))
   19993                 :        4618 :     return DECL_SAVED_AUTO_RETURN_TYPE (fn);
   19994                 :             : 
   19995                 :   486691222 :   return TREE_TYPE (TREE_TYPE (fn));
   19996                 :             : }
   19997                 :             : 
   19998                 :             : /* Returns true iff DECL is a variable or function declared with an auto type
   19999                 :             :    that has not yet been deduced to a real type.  */
   20000                 :             : 
   20001                 :             : bool
   20002                 :   763819413 : undeduced_auto_decl (tree decl)
   20003                 :             : {
   20004                 :   763819413 :   if (cxx_dialect < cxx11)
   20005                 :             :     return false;
   20006                 :   761475220 :   STRIP_ANY_LOCATION_WRAPPER (decl);
   20007                 :   321935929 :   return ((VAR_OR_FUNCTION_DECL_P (decl)
   20008                 :    74806853 :            || TREE_CODE (decl) == TEMPLATE_DECL)
   20009                 :  1008745547 :           && type_uses_auto (TREE_TYPE (decl)));
   20010                 :             : }
   20011                 :             : 
   20012                 :             : /* Complain if DECL has an undeduced return type.  */
   20013                 :             : 
   20014                 :             : bool
   20015                 :   242789038 : require_deduced_type (tree decl, tsubst_flags_t complain)
   20016                 :             : {
   20017                 :   242789038 :   if (undeduced_auto_decl (decl))
   20018                 :             :     {
   20019                 :        2991 :       if (TREE_CODE (decl) == FUNCTION_DECL
   20020                 :        2964 :           && fndecl_built_in_p (decl, BUILT_IN_FRONTEND)
   20021                 :        5371 :           && DECL_FE_FUNCTION_CODE (decl) == CP_BUILT_IN_SOURCE_LOCATION)
   20022                 :             :         {
   20023                 :             :           /* Set the return type of __builtin_source_location.  */
   20024                 :        2380 :           tree type = get_source_location_impl_type ();
   20025                 :        2380 :           if (type == error_mark_node)
   20026                 :             :             {
   20027                 :          33 :               inform (input_location, "using %qs", "__builtin_source_location");
   20028                 :          33 :               return false;
   20029                 :             :             }
   20030                 :        2347 :           type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
   20031                 :        2347 :           type = build_pointer_type (type);
   20032                 :        2347 :           apply_deduced_return_type (decl, type);
   20033                 :        2347 :           return true;
   20034                 :             :         }
   20035                 :             : 
   20036                 :         611 :       if (warning_suppressed_p (decl) && seen_error ())
   20037                 :             :         /* We probably already complained about deduction failure.  */;
   20038                 :         477 :       else if (complain & tf_error)
   20039                 :          72 :         error ("use of %qD before deduction of %<auto%>", decl);
   20040                 :         611 :       note_failed_type_completion (decl, complain);
   20041                 :         611 :       return false;
   20042                 :             :     }
   20043                 :             :   return true;
   20044                 :             : }
   20045                 :             : 
   20046                 :             : /* Create a representation of the explicit-specifier with
   20047                 :             :    constant-expression of EXPR.  COMPLAIN is as for tsubst.  */
   20048                 :             : 
   20049                 :             : tree
   20050                 :     6411834 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
   20051                 :             : {
   20052                 :     6411834 :   if (check_for_bare_parameter_packs (expr))
   20053                 :           3 :     return error_mark_node;
   20054                 :             : 
   20055                 :     6411831 :   if (instantiation_dependent_expression_p (expr))
   20056                 :             :     /* Wait for instantiation, tsubst_function_decl will handle it.  */
   20057                 :             :     return expr;
   20058                 :             : 
   20059                 :     5804938 :   expr = build_converted_constant_bool_expr (expr, complain);
   20060                 :     5804938 :   expr = instantiate_non_dependent_expr (expr, complain);
   20061                 :     5804938 :   expr = cxx_constant_value (expr, complain);
   20062                 :     5804938 :   return expr;
   20063                 :             : }
   20064                 :             : 
   20065                 :             : #include "gt-cp-decl.h"
        

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