LCOV - code coverage report
Current view: top level - gcc/cp - decl.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 7190 7656 93.9 %
Date: 2020-03-28 11:57:23 Functions: 202 213 94.8 %
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-2020 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 "debug.h"
      50                 :            : #include "plugin.h"
      51                 :            : #include "builtins.h"
      52                 :            : #include "gimplify.h"
      53                 :            : #include "asan.h"
      54                 :            : #include "gcc-rich-location.h"
      55                 :            : #include "langhooks.h"
      56                 :            : #include "omp-general.h"
      57                 :            : 
      58                 :            : /* Possible cases of bad specifiers type used by bad_specifiers. */
      59                 :            : enum bad_spec_place {
      60                 :            :   BSP_VAR,    /* variable */
      61                 :            :   BSP_PARM,   /* parameter */
      62                 :            :   BSP_TYPE,   /* type */
      63                 :            :   BSP_FIELD   /* field */
      64                 :            : };
      65                 :            : 
      66                 :            : static const char *redeclaration_error_message (tree, tree);
      67                 :            : 
      68                 :            : static int decl_jump_unsafe (tree);
      69                 :            : static void require_complete_types_for_parms (tree);
      70                 :            : static tree grok_reference_init (tree, tree, tree, int);
      71                 :            : static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
      72                 :            :                          int, int, int, bool, int, tree, location_t);
      73                 :            : static void check_static_variable_definition (tree, tree);
      74                 :            : static void record_unknown_type (tree, const char *);
      75                 :            : static int member_function_or_else (tree, tree, enum overload_flags);
      76                 :            : static tree local_variable_p_walkfn (tree *, int *, void *);
      77                 :            : static const char *tag_name (enum tag_types);
      78                 :            : static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool);
      79                 :            : static void maybe_deduce_size_from_array_init (tree, tree);
      80                 :            : static void layout_var_decl (tree);
      81                 :            : static tree check_initializer (tree, tree, int, vec<tree, va_gc> **);
      82                 :            : static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
      83                 :            : static void copy_type_enum (tree , tree);
      84                 :            : static void check_function_type (tree, tree);
      85                 :            : static void finish_constructor_body (void);
      86                 :            : static void begin_destructor_body (void);
      87                 :            : static void finish_destructor_body (void);
      88                 :            : static void record_key_method_defined (tree);
      89                 :            : static tree create_array_type_for_decl (tree, tree, tree, location_t);
      90                 :            : static tree get_atexit_node (void);
      91                 :            : static tree get_dso_handle_node (void);
      92                 :            : static tree start_cleanup_fn (void);
      93                 :            : static void end_cleanup_fn (void);
      94                 :            : static tree cp_make_fname_decl (location_t, tree, int);
      95                 :            : static void initialize_predefined_identifiers (void);
      96                 :            : static tree check_special_function_return_type
      97                 :            :        (special_function_kind, tree, tree, int, const location_t*);
      98                 :            : static tree push_cp_library_fn (enum tree_code, tree, int);
      99                 :            : static tree build_cp_library_fn (tree, enum tree_code, tree, int);
     100                 :            : static void store_parm_decls (tree);
     101                 :            : static void initialize_local_var (tree, tree);
     102                 :            : static void expand_static_init (tree, tree);
     103                 :            : static location_t smallest_type_location (const cp_decl_specifier_seq*);
     104                 :            : 
     105                 :            : /* The following symbols are subsumed in the cp_global_trees array, and
     106                 :            :    listed here individually for documentation purposes.
     107                 :            : 
     108                 :            :    C++ extensions
     109                 :            :         tree wchar_decl_node;
     110                 :            : 
     111                 :            :         tree vtable_entry_type;
     112                 :            :         tree delta_type_node;
     113                 :            :         tree __t_desc_type_node;
     114                 :            : 
     115                 :            :         tree class_type_node;
     116                 :            :         tree unknown_type_node;
     117                 :            : 
     118                 :            :    Array type `vtable_entry_type[]'
     119                 :            : 
     120                 :            :         tree vtbl_type_node;
     121                 :            :         tree vtbl_ptr_type_node;
     122                 :            : 
     123                 :            :    Namespaces,
     124                 :            : 
     125                 :            :         tree std_node;
     126                 :            :         tree abi_node;
     127                 :            : 
     128                 :            :    A FUNCTION_DECL which can call `abort'.  Not necessarily the
     129                 :            :    one that the user will declare, but sufficient to be called
     130                 :            :    by routines that want to abort the program.
     131                 :            : 
     132                 :            :         tree abort_fndecl;
     133                 :            : 
     134                 :            :    Used by RTTI
     135                 :            :         tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
     136                 :            :         tree tinfo_var_id;  */
     137                 :            : 
     138                 :            : tree cp_global_trees[CPTI_MAX];
     139                 :            : 
     140                 :            : /* A list of objects which have constructors or destructors
     141                 :            :    which reside in the global scope.  The decl is stored in
     142                 :            :    the TREE_VALUE slot and the initializer is stored
     143                 :            :    in the TREE_PURPOSE slot.  */
     144                 :            : tree static_aggregates;
     145                 :            : 
     146                 :            : /* Like static_aggregates, but for thread_local variables.  */
     147                 :            : tree tls_aggregates;
     148                 :            : 
     149                 :            : /* -- end of C++ */
     150                 :            : 
     151                 :            : /* A node for the integer constant 2.  */
     152                 :            : 
     153                 :            : tree integer_two_node;
     154                 :            : 
     155                 :            : /* vector of static decls.  */
     156                 :            : vec<tree, va_gc> *static_decls;
     157                 :            : 
     158                 :            : /* vector of keyed classes.  */
     159                 :            : vec<tree, va_gc> *keyed_classes;
     160                 :            : 
     161                 :            : /* Used only for jumps to as-yet undefined labels, since jumps to
     162                 :            :    defined labels can have their validity checked immediately.  */
     163                 :            : 
     164                 :            : struct GTY((chain_next ("%h.next"))) named_label_use_entry {
     165                 :            :   struct named_label_use_entry *next;
     166                 :            :   /* The binding level to which this entry is *currently* attached.
     167                 :            :      This is initially the binding level in which the goto appeared,
     168                 :            :      but is modified as scopes are closed.  */
     169                 :            :   cp_binding_level *binding_level;
     170                 :            :   /* The head of the names list that was current when the goto appeared,
     171                 :            :      or the inner scope popped.  These are the decls that will *not* be
     172                 :            :      skipped when jumping to the label.  */
     173                 :            :   tree names_in_scope;
     174                 :            :   /* The location of the goto, for error reporting.  */
     175                 :            :   location_t o_goto_locus;
     176                 :            :   /* True if an OpenMP structured block scope has been closed since
     177                 :            :      the goto appeared.  This means that the branch from the label will
     178                 :            :      illegally exit an OpenMP scope.  */
     179                 :            :   bool in_omp_scope;
     180                 :            : };
     181                 :            : 
     182                 :            : /* A list of all LABEL_DECLs in the function that have names.  Here so
     183                 :            :    we can clear out their names' definitions at the end of the
     184                 :            :    function, and so we can check the validity of jumps to these labels.  */
     185                 :            : 
     186                 :            : struct GTY((for_user)) named_label_entry {
     187                 :            : 
     188                 :            :   tree name;  /* Name of decl. */
     189                 :            : 
     190                 :            :   tree label_decl; /* LABEL_DECL, unless deleted local label. */
     191                 :            : 
     192                 :            :   named_label_entry *outer; /* Outer shadowed chain.  */
     193                 :            : 
     194                 :            :   /* The binding level to which the label is *currently* attached.
     195                 :            :      This is initially set to the binding level in which the label
     196                 :            :      is defined, but is modified as scopes are closed.  */
     197                 :            :   cp_binding_level *binding_level;
     198                 :            : 
     199                 :            :   /* The head of the names list that was current when the label was
     200                 :            :      defined, or the inner scope popped.  These are the decls that will
     201                 :            :      be skipped when jumping to the label.  */
     202                 :            :   tree names_in_scope;
     203                 :            : 
     204                 :            :   /* A vector of all decls from all binding levels that would be
     205                 :            :      crossed by a backward branch to the label.  */
     206                 :            :   vec<tree, va_gc> *bad_decls;
     207                 :            : 
     208                 :            :   /* A list of uses of the label, before the label is defined.  */
     209                 :            :   named_label_use_entry *uses;
     210                 :            : 
     211                 :            :   /* The following bits are set after the label is defined, and are
     212                 :            :      updated as scopes are popped.  They indicate that a jump to the
     213                 :            :      label will illegally enter a scope of the given flavor.  */
     214                 :            :   bool in_try_scope;
     215                 :            :   bool in_catch_scope;
     216                 :            :   bool in_omp_scope;
     217                 :            :   bool in_transaction_scope;
     218                 :            :   bool in_constexpr_if;
     219                 :            : };
     220                 :            : 
     221                 :            : #define named_labels cp_function_chain->x_named_labels
     222                 :            : 
     223                 :            : /* The number of function bodies which we are currently processing.
     224                 :            :    (Zero if we are at namespace scope, one inside the body of a
     225                 :            :    function, two inside the body of a function in a local class, etc.)  */
     226                 :            : int function_depth;
     227                 :            : 
     228                 :            : /* Whether the exception-specifier is part of a function type (i.e. C++17).  */
     229                 :            : bool flag_noexcept_type;
     230                 :            : 
     231                 :            : /* States indicating how grokdeclarator() should handle declspecs marked
     232                 :            :    with __attribute__((deprecated)).  An object declared as
     233                 :            :    __attribute__((deprecated)) suppresses warnings of uses of other
     234                 :            :    deprecated items.  */
     235                 :            : enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
     236                 :            : 
     237                 :            : 
     238                 :            : /* A list of VAR_DECLs whose type was incomplete at the time the
     239                 :            :    variable was declared.  */
     240                 :            : 
     241                 :            : struct GTY(()) incomplete_var {
     242                 :            :   tree decl;
     243                 :            :   tree incomplete_type;
     244                 :            : };
     245                 :            : 
     246                 :            : 
     247                 :            : static GTY(()) vec<incomplete_var, va_gc> *incomplete_vars;
     248                 :            : 
     249                 :            : /* Returns the kind of template specialization we are currently
     250                 :            :    processing, given that it's declaration contained N_CLASS_SCOPES
     251                 :            :    explicit scope qualifications.  */
     252                 :            : 
     253                 :            : tmpl_spec_kind
     254                 :   18406800 : current_tmpl_spec_kind (int n_class_scopes)
     255                 :            : {
     256                 :   18406800 :   int n_template_parm_scopes = 0;
     257                 :   18406800 :   int seen_specialization_p = 0;
     258                 :   18406800 :   int innermost_specialization_p = 0;
     259                 :   18406800 :   cp_binding_level *b;
     260                 :            : 
     261                 :            :   /* Scan through the template parameter scopes.  */
     262                 :   18406800 :   for (b = current_binding_level;
     263                 :   22468400 :        b->kind == sk_template_parms;
     264                 :    4061590 :        b = b->level_chain)
     265                 :            :     {
     266                 :            :       /* If we see a specialization scope inside a parameter scope,
     267                 :            :          then something is wrong.  That corresponds to a declaration
     268                 :            :          like:
     269                 :            : 
     270                 :            :             template <class T> template <> ...
     271                 :            : 
     272                 :            :          which is always invalid since [temp.expl.spec] forbids the
     273                 :            :          specialization of a class member template if the enclosing
     274                 :            :          class templates are not explicitly specialized as well.  */
     275                 :    4061590 :       if (b->explicit_spec_p)
     276                 :            :         {
     277                 :      61670 :           if (n_template_parm_scopes == 0)
     278                 :            :             innermost_specialization_p = 1;
     279                 :            :           else
     280                 :        905 :             seen_specialization_p = 1;
     281                 :            :         }
     282                 :    3999920 :       else if (seen_specialization_p == 1)
     283                 :            :         return tsk_invalid_member_spec;
     284                 :            : 
     285                 :    4061590 :       ++n_template_parm_scopes;
     286                 :            :     }
     287                 :            : 
     288                 :            :   /* Handle explicit instantiations.  */
     289                 :   18406800 :   if (processing_explicit_instantiation)
     290                 :            :     {
     291                 :     135395 :       if (n_template_parm_scopes != 0)
     292                 :            :         /* We've seen a template parameter list during an explicit
     293                 :            :            instantiation.  For example:
     294                 :            : 
     295                 :            :              template <class T> template void f(int);
     296                 :            : 
     297                 :            :            This is erroneous.  */
     298                 :            :         return tsk_invalid_expl_inst;
     299                 :            :       else
     300                 :     135395 :         return tsk_expl_inst;
     301                 :            :     }
     302                 :            : 
     303                 :   18271400 :   if (n_template_parm_scopes < n_class_scopes)
     304                 :            :     /* We've not seen enough template headers to match all the
     305                 :            :        specialized classes present.  For example:
     306                 :            : 
     307                 :            :          template <class T> void R<T>::S<T>::f(int);
     308                 :            : 
     309                 :            :        This is invalid; there needs to be one set of template
     310                 :            :        parameters for each class.  */
     311                 :            :     return tsk_insufficient_parms;
     312                 :   18271400 :   else if (n_template_parm_scopes == n_class_scopes)
     313                 :            :     /* We're processing a non-template declaration (even though it may
     314                 :            :        be a member of a template class.)  For example:
     315                 :            : 
     316                 :            :          template <class T> void S<T>::f(int);
     317                 :            : 
     318                 :            :        The `class T' matches the `S<T>', leaving no template headers
     319                 :            :        corresponding to the `f'.  */
     320                 :            :     return tsk_none;
     321                 :    3556630 :   else if (n_template_parm_scopes > n_class_scopes + 1)
     322                 :            :     /* We've got too many template headers.  For example:
     323                 :            : 
     324                 :            :          template <> template <class T> void f (T);
     325                 :            : 
     326                 :            :        There need to be more enclosing classes.  */
     327                 :            :     return tsk_excessive_parms;
     328                 :            :   else
     329                 :            :     /* This must be a template.  It's of the form:
     330                 :            : 
     331                 :            :          template <class T> template <class U> void S<T>::f(U);
     332                 :            : 
     333                 :            :        This is a specialization if the innermost level was a
     334                 :            :        specialization; otherwise it's just a definition of the
     335                 :            :        template.  */
     336                 :    7096070 :     return innermost_specialization_p ? tsk_expl_spec : tsk_template;
     337                 :            : }
     338                 :            : 
     339                 :            : /* Exit the current scope.  */
     340                 :            : 
     341                 :            : void
     342                 :    8320470 : finish_scope (void)
     343                 :            : {
     344                 :    8320470 :   poplevel (0, 0, 0);
     345                 :    8320470 : }
     346                 :            : 
     347                 :            : /* When a label goes out of scope, check to see if that label was used
     348                 :            :    in a valid manner, and issue any appropriate warnings or errors.  */
     349                 :            : 
     350                 :            : static void
     351                 :      10677 : check_label_used (tree label)
     352                 :            : {
     353                 :      10677 :   if (!processing_template_decl)
     354                 :            :     {
     355                 :      10467 :       if (DECL_INITIAL (label) == NULL_TREE)
     356                 :            :         {
     357                 :          8 :           location_t location;
     358                 :            : 
     359                 :          8 :           error ("label %q+D used but not defined", label);
     360                 :          8 :           location = input_location;
     361                 :            :             /* FIXME want (LOCATION_FILE (input_location), (line)0) */
     362                 :            :           /* Avoid crashing later.  */
     363                 :          8 :           define_label (location, DECL_NAME (label));
     364                 :            :         }
     365                 :            :       else 
     366                 :      10459 :         warn_for_unused_label (label);
     367                 :            :     }
     368                 :      10677 : }
     369                 :            : 
     370                 :            : /* Helper function to sort named label entries in a vector by DECL_UID.  */
     371                 :            : 
     372                 :            : static int
     373                 :     139388 : sort_labels (const void *a, const void *b)
     374                 :            : {
     375                 :     139388 :   tree label1 = *(tree const *) a;
     376                 :     139388 :   tree label2 = *(tree const *) b;
     377                 :            : 
     378                 :            :   /* DECL_UIDs can never be equal.  */
     379                 :     139388 :   return DECL_UID (label1) > DECL_UID (label2) ? -1 : +1;
     380                 :            : }
     381                 :            : 
     382                 :            : /* At the end of a function, all labels declared within the function
     383                 :            :    go out of scope.  BLOCK is the top-level block for the
     384                 :            :    function.  */
     385                 :            : 
     386                 :            : static void
     387                 :   19823700 : pop_labels (tree block)
     388                 :            : {
     389                 :   19823700 :   if (!named_labels)
     390                 :   19822000 :     return;
     391                 :            : 
     392                 :            :   /* We need to add the labels to the block chain, so debug
     393                 :            :      information is emitted.  But, we want the order to be stable so
     394                 :            :      need to sort them first.  Otherwise the debug output could be
     395                 :            :      randomly ordered.  I guess it's mostly stable, unless the hash
     396                 :            :      table implementation changes.  */
     397                 :       3532 :   auto_vec<tree, 32> labels (named_labels->elements ());
     398                 :       1766 :   hash_table<named_label_hash>::iterator end (named_labels->end ());
     399                 :      10649 :   for (hash_table<named_label_hash>::iterator iter
     400                 :      14181 :          (named_labels->begin ()); iter != end; ++iter)
     401                 :            :     {
     402                 :      10649 :       named_label_entry *ent = *iter;
     403                 :            : 
     404                 :      10649 :       gcc_checking_assert (!ent->outer);
     405                 :      10649 :       if (ent->label_decl)
     406                 :      10593 :         labels.quick_push (ent->label_decl);
     407                 :      10649 :       ggc_free (ent);
     408                 :            :     }
     409                 :       1766 :   named_labels = NULL;
     410                 :       1766 :   labels.qsort (sort_labels);
     411                 :            : 
     412                 :      12359 :   while (labels.length ())
     413                 :            :     {
     414                 :      10593 :       tree label = labels.pop ();
     415                 :            : 
     416                 :      10593 :       DECL_CHAIN (label) = BLOCK_VARS (block);
     417                 :      10593 :       BLOCK_VARS (block) = label;
     418                 :            : 
     419                 :      10593 :       check_label_used (label);
     420                 :            :     }
     421                 :            : }
     422                 :            : 
     423                 :            : /* At the end of a block with local labels, restore the outer definition.  */
     424                 :            : 
     425                 :            : static void
     426                 :         84 : pop_local_label (tree id, tree label)
     427                 :            : {
     428                 :         84 :   check_label_used (label);
     429                 :         84 :   named_label_entry **slot = named_labels->find_slot_with_hash
     430                 :         84 :     (id, IDENTIFIER_HASH_VALUE (id), NO_INSERT);
     431                 :         84 :   named_label_entry *ent = *slot;
     432                 :            : 
     433                 :         84 :   if (ent->outer)
     434                 :            :     ent = ent->outer;
     435                 :            :   else
     436                 :            :     {
     437                 :         72 :       ent = ggc_cleared_alloc<named_label_entry> ();
     438                 :         72 :       ent->name = id;
     439                 :            :     }
     440                 :         84 :   *slot = ent;
     441                 :         84 : }
     442                 :            : 
     443                 :            : /* The following two routines are used to interface to Objective-C++.
     444                 :            :    The binding level is purposely treated as an opaque type.  */
     445                 :            : 
     446                 :            : void *
     447                 :          0 : objc_get_current_scope (void)
     448                 :            : {
     449                 :          0 :   return current_binding_level;
     450                 :            : }
     451                 :            : 
     452                 :            : /* The following routine is used by the NeXT-style SJLJ exceptions;
     453                 :            :    variables get marked 'volatile' so as to not be clobbered by
     454                 :            :    _setjmp()/_longjmp() calls.  All variables in the current scope,
     455                 :            :    as well as parent scopes up to (but not including) ENCLOSING_BLK
     456                 :            :    shall be thusly marked.  */
     457                 :            : 
     458                 :            : void
     459                 :          0 : objc_mark_locals_volatile (void *enclosing_blk)
     460                 :            : {
     461                 :          0 :   cp_binding_level *scope;
     462                 :            : 
     463                 :          0 :   for (scope = current_binding_level;
     464                 :          0 :        scope && scope != enclosing_blk;
     465                 :          0 :        scope = scope->level_chain)
     466                 :            :     {
     467                 :          0 :       tree decl;
     468                 :            : 
     469                 :          0 :       for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
     470                 :          0 :         objc_volatilize_decl (decl);
     471                 :            : 
     472                 :            :       /* Do not climb up past the current function.  */
     473                 :          0 :       if (scope->kind == sk_function_parms)
     474                 :            :         break;
     475                 :            :     }
     476                 :          0 : }
     477                 :            : 
     478                 :            : /* True if B is the level for the condition of a constexpr if.  */
     479                 :            : 
     480                 :            : static bool
     481                 :     193489 : level_for_constexpr_if (cp_binding_level *b)
     482                 :            : {
     483                 :     182448 :   return (b->kind == sk_cond && b->this_entity
     484                 :        185 :           && TREE_CODE (b->this_entity) == IF_STMT
     485                 :        185 :           && IF_STMT_CONSTEXPR_P (b->this_entity));
     486                 :            : }
     487                 :            : 
     488                 :            : /* Update data for defined and undefined labels when leaving a scope.  */
     489                 :            : 
     490                 :            : int
     491                 :      82052 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
     492                 :            : {
     493                 :      82052 :   named_label_entry *ent = *slot;
     494                 :      82052 :   cp_binding_level *obl = bl->level_chain;
     495                 :            : 
     496                 :      82052 :   if (ent->binding_level == bl)
     497                 :            :     {
     498                 :      11822 :       tree decl;
     499                 :            : 
     500                 :            :       /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
     501                 :            :          TREE_LISTs representing OVERLOADs, so be careful.  */
     502                 :      14128 :       for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
     503                 :       2306 :                                                      ? DECL_CHAIN (decl)
     504                 :        109 :                                                      : TREE_CHAIN (decl)))
     505                 :       2306 :         if (decl_jump_unsafe (decl))
     506                 :        782 :           vec_safe_push (ent->bad_decls, decl);
     507                 :            : 
     508                 :      11822 :       ent->binding_level = obl;
     509                 :      11822 :       ent->names_in_scope = obl->names;
     510                 :      11822 :       switch (bl->kind)
     511                 :            :         {
     512                 :         37 :         case sk_try:
     513                 :         37 :           ent->in_try_scope = true;
     514                 :         37 :           break;
     515                 :         22 :         case sk_catch:
     516                 :         22 :           ent->in_catch_scope = true;
     517                 :         22 :           break;
     518                 :        116 :         case sk_omp:
     519                 :        116 :           ent->in_omp_scope = true;
     520                 :        116 :           break;
     521                 :          4 :         case sk_transaction:
     522                 :          4 :           ent->in_transaction_scope = true;
     523                 :          4 :           break;
     524                 :      11227 :         case sk_block:
     525                 :      12188 :           if (level_for_constexpr_if (bl->level_chain))
     526                 :         15 :             ent->in_constexpr_if = true;
     527                 :            :           break;
     528                 :            :         default:
     529                 :            :           break;
     530                 :            :         }
     531                 :            :     }
     532                 :      70230 :   else if (ent->uses)
     533                 :            :     {
     534                 :            :       struct named_label_use_entry *use;
     535                 :            : 
     536                 :       7712 :       for (use = ent->uses; use ; use = use->next)
     537                 :       4614 :         if (use->binding_level == bl)
     538                 :            :           {
     539                 :       1493 :             use->binding_level = obl;
     540                 :       1493 :             use->names_in_scope = obl->names;
     541                 :       1493 :             if (bl->kind == sk_omp)
     542                 :         12 :               use->in_omp_scope = true;
     543                 :            :           }
     544                 :            :     }
     545                 :            : 
     546                 :      82052 :   return 1;
     547                 :            : }
     548                 :            : 
     549                 :            : /* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
     550                 :            :    when errors were reported, except for -Werror-unused-but-set-*.  */
     551                 :            : static int unused_but_set_errorcount;
     552                 :            : 
     553                 :            : /* Exit a binding level.
     554                 :            :    Pop the level off, and restore the state of the identifier-decl mappings
     555                 :            :    that were in effect when this level was entered.
     556                 :            : 
     557                 :            :    If KEEP == 1, this level had explicit declarations, so
     558                 :            :    and create a "block" (a BLOCK node) for the level
     559                 :            :    to record its declarations and subblocks for symbol table output.
     560                 :            : 
     561                 :            :    If FUNCTIONBODY is nonzero, this level is the body of a function,
     562                 :            :    so create a block as if KEEP were set and also clear out all
     563                 :            :    label names.
     564                 :            : 
     565                 :            :    If REVERSE is nonzero, reverse the order of decls before putting
     566                 :            :    them into the BLOCK.  */
     567                 :            : 
     568                 :            : tree
     569                 :   60164300 : poplevel (int keep, int reverse, int functionbody)
     570                 :            : {
     571                 :   60164300 :   tree link;
     572                 :            :   /* The chain of decls was accumulated in reverse order.
     573                 :            :      Put it into forward order, just for cleanliness.  */
     574                 :   60164300 :   tree decls;
     575                 :   60164300 :   tree subblocks;
     576                 :   60164300 :   tree block;
     577                 :   60164300 :   tree decl;
     578                 :   60164300 :   scope_kind kind;
     579                 :            : 
     580                 :   60164300 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
     581                 :   60164400 :  restart:
     582                 :            : 
     583                 :   60164400 :   block = NULL_TREE;
     584                 :            : 
     585                 :   60164400 :   gcc_assert (current_binding_level->kind != sk_class
     586                 :            :               && current_binding_level->kind != sk_namespace);
     587                 :            : 
     588                 :   60164400 :   if (current_binding_level->kind == sk_cleanup)
     589                 :            :     functionbody = 0;
     590                 :   60164400 :   subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
     591                 :            : 
     592                 :   60164400 :   gcc_assert (!vec_safe_length (current_binding_level->class_shadowed));
     593                 :            : 
     594                 :            :   /* We used to use KEEP == 2 to indicate that the new block should go
     595                 :            :      at the beginning of the list of blocks at this binding level,
     596                 :            :      rather than the end.  This hack is no longer used.  */
     597                 :   60164400 :   gcc_assert (keep == 0 || keep == 1);
     598                 :            : 
     599                 :   60164400 :   if (current_binding_level->keep)
     600                 :    2270300 :     keep = 1;
     601                 :            : 
     602                 :            :   /* Any uses of undefined labels, and any defined labels, now operate
     603                 :            :      under constraints of next binding contour.  */
     604                 :   60164400 :   if (cfun && !functionbody && named_labels)
     605                 :      30040 :     named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
     606                 :      30040 :                    (current_binding_level);
     607                 :            : 
     608                 :            :   /* Get the decls in the order they were written.
     609                 :            :      Usually current_binding_level->names is in reverse order.
     610                 :            :      But parameter decls were previously put in forward order.  */
     611                 :            : 
     612                 :   60164400 :   decls = current_binding_level->names;
     613                 :   60164400 :   if (reverse)
     614                 :            :     {
     615                 :   29573300 :       decls = nreverse (decls);
     616                 :   29573300 :       current_binding_level->names = decls;
     617                 :            :     }
     618                 :            : 
     619                 :            :   /* If there were any declarations or structure tags in that level,
     620                 :            :      or if this level is a function body,
     621                 :            :      create a BLOCK to record them for the life of this function.  */
     622                 :   60164400 :   block = NULL_TREE;
     623                 :            :   /* Avoid function body block if possible.  */
     624                 :   64604600 :   if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
     625                 :            :     keep = 0;
     626                 :   55724500 :   else if (keep == 1 || functionbody)
     627                 :   21709700 :     block = make_node (BLOCK);
     628                 :   21709700 :   if (block != NULL_TREE)
     629                 :            :     {
     630                 :   21709700 :       BLOCK_VARS (block) = decls;
     631                 :   21709700 :       BLOCK_SUBBLOCKS (block) = subblocks;
     632                 :            :     }
     633                 :            : 
     634                 :            :   /* In each subblock, record that this is its superior.  */
     635                 :   60164400 :   if (keep >= 0)
     636                 :   66490300 :     for (link = subblocks; link; link = BLOCK_CHAIN (link))
     637                 :    6325860 :       BLOCK_SUPERCONTEXT (link) = block;
     638                 :            : 
     639                 :            :   /* Before we remove the declarations first check for unused variables.  */
     640                 :   60164400 :   if ((warn_unused_variable || warn_unused_but_set_variable)
     641                 :    4279600 :       && current_binding_level->kind != sk_template_parms
     642                 :    3612280 :       && !processing_template_decl)
     643                 :    4299850 :     for (tree d = get_local_decls (); d; d = TREE_CHAIN (d))
     644                 :            :       {
     645                 :            :         /* There are cases where D itself is a TREE_LIST.  See in
     646                 :            :            push_local_binding where the list of decls returned by
     647                 :            :            getdecls is built.  */
     648                 :    2207920 :         decl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
     649                 :            : 
     650                 :    2207920 :         tree type = TREE_TYPE (decl);
     651                 :    2207920 :         if (VAR_P (decl)
     652                 :     208550 :             && (! TREE_USED (decl) || !DECL_READ_P (decl))
     653                 :        927 :             && ! DECL_IN_SYSTEM_HEADER (decl)
     654                 :            :             /* For structured bindings, consider only real variables, not
     655                 :            :                subobjects.  */
     656                 :        701 :             && (DECL_DECOMPOSITION_P (decl) ? !DECL_DECOMP_BASE (decl)
     657                 :       1251 :                 : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
     658                 :        616 :             && type != error_mark_node
     659                 :    2209250 :             && (!CLASS_TYPE_P (type)
     660                 :         45 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
     661                 :          4 :                 || lookup_attribute ("warn_unused",
     662                 :          4 :                                      TYPE_ATTRIBUTES (TREE_TYPE (decl)))))
     663                 :            :           {
     664                 :        580 :             if (! TREE_USED (decl))
     665                 :            :               {
     666                 :        399 :                 if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     667                 :          2 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     668                 :            :                               OPT_Wunused_variable,
     669                 :            :                               "unused structured binding declaration");
     670                 :            :                 else
     671                 :        395 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     672                 :            :                               OPT_Wunused_variable, "unused variable %qD", decl);
     673                 :            :               }
     674                 :        183 :             else if (DECL_CONTEXT (decl) == current_function_decl
     675                 :            :                      // For -Wunused-but-set-variable leave references alone.
     676                 :        159 :                      && !TYPE_REF_P (TREE_TYPE (decl))
     677                 :        342 :                      && errorcount == unused_but_set_errorcount)
     678                 :            :               {
     679                 :        155 :                 if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     680                 :          8 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     681                 :            :                               OPT_Wunused_but_set_variable, "structured "
     682                 :            :                               "binding declaration set but not used");
     683                 :            :                 else
     684                 :        139 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     685                 :            :                               OPT_Wunused_but_set_variable,
     686                 :            :                               "variable %qD set but not used", decl);
     687                 :        147 :                 unused_but_set_errorcount = errorcount;
     688                 :            :               }
     689                 :            :           }
     690                 :            :       }
     691                 :            : 
     692                 :            :   /* Remove declarations for all the DECLs in this level.  */
     693                 :  122584000 :   for (link = decls; link; link = TREE_CHAIN (link))
     694                 :            :     {
     695                 :   62419900 :       decl = TREE_CODE (link) == TREE_LIST ? TREE_VALUE (link) : link;
     696                 :  124840000 :       tree name = OVL_NAME (decl);
     697                 :            : 
     698                 :            :       /* Remove the binding.  */
     699                 :   62419900 :       if (TREE_CODE (decl) == LABEL_DECL)
     700                 :         84 :         pop_local_label (name, decl);
     701                 :            :       else
     702                 :   62419800 :         pop_local_binding (name, decl);
     703                 :            :     }
     704                 :            : 
     705                 :            :   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
     706                 :   60164400 :   for (link = current_binding_level->type_shadowed;
     707                 :   80154200 :        link; link = TREE_CHAIN (link))
     708                 :   19989700 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
     709                 :            : 
     710                 :            :   /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
     711                 :            :      list if a `using' declaration put them there.  The debugging
     712                 :            :      back ends won't understand OVERLOAD, so we remove them here.
     713                 :            :      Because the BLOCK_VARS are (temporarily) shared with
     714                 :            :      CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
     715                 :            :      popped all the bindings.  Also remove undeduced 'auto' decls,
     716                 :            :      which LTO doesn't understand, and can't have been used by anything.  */
     717                 :   60164400 :   if (block)
     718                 :            :     {
     719                 :   21709700 :       tree* d;
     720                 :            : 
     721                 :   54762500 :       for (d = &BLOCK_VARS (block); *d; )
     722                 :            :         {
     723                 :   33052800 :           if (TREE_CODE (*d) == TREE_LIST
     724                 :   33052800 :               || (!processing_template_decl
     725                 :   20422500 :                   && undeduced_auto_decl (*d)))
     726                 :      39871 :             *d = TREE_CHAIN (*d);
     727                 :            :           else
     728                 :   33013000 :             d = &DECL_CHAIN (*d);
     729                 :            :         }
     730                 :            :     }
     731                 :            : 
     732                 :            :   /* If the level being exited is the top level of a function,
     733                 :            :      check over all the labels.  */
     734                 :   60164400 :   if (functionbody)
     735                 :            :     {
     736                 :   19823700 :       if (block)
     737                 :            :         {
     738                 :            :           /* Since this is the top level block of a function, the vars are
     739                 :            :              the function's parameters.  Don't leave them in the BLOCK
     740                 :            :              because they are found in the FUNCTION_DECL instead.  */
     741                 :   15383800 :           BLOCK_VARS (block) = 0;
     742                 :   15383800 :           pop_labels (block);
     743                 :            :         }
     744                 :            :       else
     745                 :    4439890 :         pop_labels (subblocks);
     746                 :            :     }
     747                 :            : 
     748                 :   60164400 :   kind = current_binding_level->kind;
     749                 :   60164400 :   if (kind == sk_cleanup)
     750                 :            :     {
     751                 :        113 :       tree stmt;
     752                 :            : 
     753                 :            :       /* If this is a temporary binding created for a cleanup, then we'll
     754                 :            :          have pushed a statement list level.  Pop that, create a new
     755                 :            :          BIND_EXPR for the block, and insert it into the stream.  */
     756                 :        113 :       stmt = pop_stmt_list (current_binding_level->statement_list);
     757                 :        113 :       stmt = c_build_bind_expr (input_location, block, stmt);
     758                 :        113 :       add_stmt (stmt);
     759                 :            :     }
     760                 :            : 
     761                 :   60164400 :   leave_scope ();
     762                 :   60164400 :   if (functionbody)
     763                 :            :     {
     764                 :            :       /* The current function is being defined, so its DECL_INITIAL
     765                 :            :          should be error_mark_node.  */
     766                 :   19823700 :       gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
     767                 :   24263600 :       DECL_INITIAL (current_function_decl) = block ? block : subblocks;
     768                 :   19823700 :       if (subblocks)
     769                 :            :         {
     770                 :    8968310 :           if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
     771                 :            :             {
     772                 :    2246170 :               if (BLOCK_SUBBLOCKS (subblocks))
     773                 :     110944 :                 BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
     774                 :            :             }
     775                 :            :           else
     776                 :    2194020 :             BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
     777                 :            :         }
     778                 :            :     }
     779                 :   40340700 :   else if (block)
     780                 :    6325860 :     current_binding_level->blocks
     781                 :   12651700 :       = block_chainon (current_binding_level->blocks, block);
     782                 :            : 
     783                 :            :   /* If we did not make a block for the level just exited,
     784                 :            :      any blocks made for inner levels
     785                 :            :      (since they cannot be recorded as subblocks in that level)
     786                 :            :      must be carried forward so they will later become subblocks
     787                 :            :      of something else.  */
     788                 :   34014800 :   else if (subblocks)
     789                 :          4 :     current_binding_level->blocks
     790                 :          8 :       = block_chainon (current_binding_level->blocks, subblocks);
     791                 :            : 
     792                 :            :   /* Each and every BLOCK node created here in `poplevel' is important
     793                 :            :      (e.g. for proper debugging information) so if we created one
     794                 :            :      earlier, mark it as "used".  */
     795                 :   60164400 :   if (block)
     796                 :   21709700 :     TREE_USED (block) = 1;
     797                 :            : 
     798                 :            :   /* All temporary bindings created for cleanups are popped silently.  */
     799                 :   60164400 :   if (kind == sk_cleanup)
     800                 :        113 :     goto restart;
     801                 :            : 
     802                 :   60164300 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
     803                 :   60164300 :   return block;
     804                 :            : }
     805                 :            : 
     806                 :            : /* Call wrapup_globals_declarations for the globals in NAMESPACE.  */
     807                 :            : /* Diagnose odr-used extern inline variables without definitions
     808                 :            :    in the current TU.  */
     809                 :            : 
     810                 :            : int
     811                 :     105698 : wrapup_namespace_globals ()
     812                 :            : {
     813                 :     105698 :   if (vec<tree, va_gc> *statics = static_decls)
     814                 :            :     {
     815                 :            :       tree decl;
     816                 :            :       unsigned int i;
     817                 :    7491020 :       FOR_EACH_VEC_ELT (*statics, i, decl)
     818                 :            :         {
     819                 :    7404820 :           if (warn_unused_function
     820                 :     753191 :               && TREE_CODE (decl) == FUNCTION_DECL
     821                 :     539038 :               && DECL_INITIAL (decl) == 0
     822                 :       2246 :               && DECL_EXTERNAL (decl)
     823                 :       2246 :               && !TREE_PUBLIC (decl)
     824                 :          8 :               && !DECL_ARTIFICIAL (decl)
     825                 :          8 :               && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
     826                 :    7404820 :               && !TREE_NO_WARNING (decl))
     827                 :          4 :             warning_at (DECL_SOURCE_LOCATION (decl),
     828                 :            :                         OPT_Wunused_function,
     829                 :            :                         "%qF declared %<static%> but never defined", decl);
     830                 :            : 
     831                 :    7404820 :           if (VAR_P (decl)
     832                 :    2316130 :               && DECL_EXTERNAL (decl)
     833                 :    1645380 :               && DECL_INLINE_VAR_P (decl)
     834                 :    7404840 :               && DECL_ODR_USED (decl))
     835                 :          3 :             error_at (DECL_SOURCE_LOCATION (decl),
     836                 :            :                       "odr-used inline variable %qD is not defined", decl);
     837                 :            :         }
     838                 :            : 
     839                 :            :       /* Clear out the list, so we don't rescan next time.  */
     840                 :      86202 :       static_decls = NULL;
     841                 :            : 
     842                 :            :       /* Write out any globals that need to be output.  */
     843                 :      86202 :       return wrapup_global_declarations (statics->address (),
     844                 :      86202 :                                          statics->length ());
     845                 :            :     }
     846                 :            :   return 0;
     847                 :            : }
     848                 :            : 
     849                 :            : /* In C++, you don't have to write `struct S' to refer to `S'; you
     850                 :            :    can just use `S'.  We accomplish this by creating a TYPE_DECL as
     851                 :            :    if the user had written `typedef struct S S'.  Create and return
     852                 :            :    the TYPE_DECL for TYPE.  */
     853                 :            : 
     854                 :            : tree
     855                 :   20404300 : create_implicit_typedef (tree name, tree type)
     856                 :            : {
     857                 :   20404300 :   tree decl;
     858                 :            : 
     859                 :   20404300 :   decl = build_decl (input_location, TYPE_DECL, name, type);
     860                 :   20404300 :   DECL_ARTIFICIAL (decl) = 1;
     861                 :            :   /* There are other implicit type declarations, like the one *within*
     862                 :            :      a class that allows you to write `S::S'.  We must distinguish
     863                 :            :      amongst these.  */
     864                 :   20404300 :   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
     865                 :   20404300 :   TYPE_NAME (type) = decl;
     866                 :   20404300 :   TYPE_STUB_DECL (type) = decl;
     867                 :            : 
     868                 :   20404300 :   return decl;
     869                 :            : }
     870                 :            : 
     871                 :            : /* Function-scope local entities that need discriminators.  Each entry
     872                 :            :    is a {decl,name} pair.  VAR_DECLs for anon unions get their name
     873                 :            :    smashed, so we cannot rely on DECL_NAME.  */
     874                 :            : 
     875                 :            : static GTY((deletable)) vec<tree, va_gc> *local_entities;
     876                 :            : 
     877                 :            : /* Determine the mangling discriminator of local DECL.  There are
     878                 :            :    generally very few of these in any particular function.  */
     879                 :            : 
     880                 :            : void
     881                 :     299239 : determine_local_discriminator (tree decl)
     882                 :            : {
     883                 :     299239 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
     884                 :     299239 :   retrofit_lang_decl (decl);
     885                 :     299239 :   tree ctx = DECL_CONTEXT (decl);
     886                 :     299239 :   tree name = (TREE_CODE (decl) == TYPE_DECL
     887                 :     262085 :                && TYPE_UNNAMED_P (TREE_TYPE (decl))
     888                 :     560106 :                ? NULL_TREE : DECL_NAME (decl));
     889                 :     299239 :   size_t nelts = vec_safe_length (local_entities);
     890                 :    5345640 :   for (size_t i = 0; i < nelts; i += 2)
     891                 :            :     {
     892                 :    5046730 :       tree *pair = &(*local_entities)[i];
     893                 :    5046730 :       tree d = pair[0];
     894                 :    5046730 :       tree n = pair[1];
     895                 :    5046730 :       gcc_checking_assert (d != decl);
     896                 :    5046730 :       if (name == n
     897                 :    1962390 :           && TREE_CODE (decl) == TREE_CODE (d)
     898                 :    7009110 :           && ctx == DECL_CONTEXT (d))
     899                 :            :         {
     900                 :        325 :           tree disc = integer_one_node;
     901                 :        325 :           if (DECL_DISCRIMINATOR (d))
     902                 :        190 :             disc = build_int_cst (TREE_TYPE (disc),
     903                 :        190 :                                   TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
     904                 :        325 :           DECL_DISCRIMINATOR (decl) = disc;
     905                 :            :           /* Replace the saved decl.  */
     906                 :        325 :           pair[0] = decl;
     907                 :        325 :           decl = NULL_TREE;
     908                 :        325 :           break;
     909                 :            :         }
     910                 :            :     }
     911                 :            : 
     912                 :        325 :   if (decl)
     913                 :            :     {
     914                 :     298914 :       vec_safe_reserve (local_entities, 2);
     915                 :     298914 :       local_entities->quick_push (decl);
     916                 :     298914 :       local_entities->quick_push (name);
     917                 :            :     }
     918                 :            : 
     919                 :     299239 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
     920                 :     299239 : }
     921                 :            : 
     922                 :            : 
     923                 :            : 
     924                 :            : /* Returns true if functions FN1 and FN2 have equivalent trailing
     925                 :            :    requires clauses.  */
     926                 :            : 
     927                 :            : static bool
     928                 :     386097 : function_requirements_equivalent_p (tree newfn, tree oldfn)
     929                 :            : {
     930                 :            :   /* In the concepts TS, the combined constraints are compared.  */
     931                 :     386097 :   if (cxx_dialect < cxx2a)
     932                 :            :     {
     933                 :        535 :       tree ci1 = get_constraints (oldfn);
     934                 :        535 :       tree ci2 = get_constraints (newfn);
     935                 :        569 :       tree req1 = ci1 ? CI_ASSOCIATED_CONSTRAINTS (ci1) : NULL_TREE;
     936                 :        578 :       tree req2 = ci2 ? CI_ASSOCIATED_CONSTRAINTS (ci2) : NULL_TREE;
     937                 :        535 :       return cp_tree_equal (req1, req2);
     938                 :            :     }
     939                 :            : 
     940                 :            :   /* Compare only trailing requirements.  */
     941                 :     385562 :   tree reqs1 = get_trailing_function_requirements (newfn);
     942                 :     385562 :   tree reqs2 = get_trailing_function_requirements (oldfn);
     943                 :     385562 :   if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
     944                 :            :     return false;
     945                 :     385539 :   reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
     946                 :     385539 :   reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
     947                 :     385539 :   return cp_tree_equal (reqs1, reqs2);
     948                 :            : }
     949                 :            : 
     950                 :            : /* Subroutine of duplicate_decls: return truthvalue of whether
     951                 :            :    or not types of these decls match.
     952                 :            : 
     953                 :            :    For C++, we must compare the parameter list so that `int' can match
     954                 :            :    `int&' in a parameter position, but `int&' is not confused with
     955                 :            :    `const int&'.  */
     956                 :            : 
     957                 :            : int
     958                 :   40791900 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
     959                 :            : {
     960                 :   40791900 :   int types_match;
     961                 :            : 
     962                 :   40791900 :   if (newdecl == olddecl)
     963                 :            :     return 1;
     964                 :            : 
     965                 :   40715800 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
     966                 :            :     /* If the two DECLs are not even the same kind of thing, we're not
     967                 :            :        interested in their types.  */
     968                 :            :     return 0;
     969                 :            : 
     970                 :   22544300 :   gcc_assert (DECL_P (newdecl));
     971                 :            : 
     972                 :   22544300 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
     973                 :            :     {
     974                 :   15942000 :       tree f1 = TREE_TYPE (newdecl);
     975                 :   15942000 :       tree f2 = TREE_TYPE (olddecl);
     976                 :   15942000 :       tree p1 = TYPE_ARG_TYPES (f1);
     977                 :   15942000 :       tree p2 = TYPE_ARG_TYPES (f2);
     978                 :   15942000 :       tree r2;
     979                 :            : 
     980                 :            :       /* Specializations of different templates are different functions
     981                 :            :          even if they have the same type.  */
     982                 :   15942000 :       tree t1 = (DECL_USE_TEMPLATE (newdecl)
     983                 :     196528 :                  ? DECL_TI_TEMPLATE (newdecl)
     984                 :   15942000 :                  : NULL_TREE);
     985                 :   15942000 :       tree t2 = (DECL_USE_TEMPLATE (olddecl)
     986                 :     247535 :                  ? DECL_TI_TEMPLATE (olddecl)
     987                 :   15942000 :                  : NULL_TREE);
     988                 :   15942000 :       if (t1 != t2)
     989                 :            :         return 0;
     990                 :            : 
     991                 :   15751300 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
     992                 :   15751300 :           && ! (DECL_EXTERN_C_P (newdecl)
     993                 :     114863 :                 && DECL_EXTERN_C_P (olddecl)))
     994                 :            :         return 0;
     995                 :            : 
     996                 :            :       /* A new declaration doesn't match a built-in one unless it
     997                 :            :          is also extern "C".  */
     998                 :   15071200 :       if (DECL_IS_BUILTIN (olddecl)
     999                 :   16584100 :           && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
    1000                 :            :         return 0;
    1001                 :            : 
    1002                 :   15043000 :       if (TREE_CODE (f1) != TREE_CODE (f2))
    1003                 :            :         return 0;
    1004                 :            : 
    1005                 :            :       /* A declaration with deduced return type should use its pre-deduction
    1006                 :            :          type for declaration matching.  */
    1007                 :   15015700 :       r2 = fndecl_declared_return_type (olddecl);
    1008                 :            : 
    1009                 :   15015700 :       if (same_type_p (TREE_TYPE (f1), r2))
    1010                 :            :         {
    1011                 :   12558000 :           if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
    1012                 :   12558000 :               && fndecl_built_in_p (olddecl))
    1013                 :            :             {
    1014                 :         57 :               types_match = self_promoting_args_p (p1);
    1015                 :         57 :               if (p1 == void_list_node)
    1016                 :          4 :                 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
    1017                 :            :             }
    1018                 :            :           else
    1019                 :   12557800 :             types_match =
    1020                 :   12557800 :               compparms (p1, p2)
    1021                 :    1925130 :               && type_memfn_rqual (f1) == type_memfn_rqual (f2)
    1022                 :   14482900 :               && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
    1023                 :     104627 :                   || comp_type_attributes (TREE_TYPE (newdecl),
    1024                 :     104627 :                                            TREE_TYPE (olddecl)) != 0);
    1025                 :            :         }
    1026                 :            :       else
    1027                 :            :         types_match = 0;
    1028                 :            : 
    1029                 :            :       /* Two function declarations match if either has a requires-clause
    1030                 :            :          then both have a requires-clause and their constraints-expressions
    1031                 :            :          are equivalent.  */
    1032                 :   12557900 :       if (types_match && flag_concepts)
    1033                 :     386083 :         types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1034                 :            : 
    1035                 :            :       /* The decls dont match if they correspond to two different versions
    1036                 :            :          of the same function.   Disallow extern "C" functions to be
    1037                 :            :          versions for now.  */
    1038                 :   15015700 :       if (types_match
    1039                 :    1925060 :           && !DECL_EXTERN_C_P (newdecl)
    1040                 :    1284980 :           && !DECL_EXTERN_C_P (olddecl)
    1041                 :    1281940 :           && record_versions
    1042                 :   15840200 :           && maybe_version_functions (newdecl, olddecl,
    1043                 :     824440 :                                       (!DECL_FUNCTION_VERSIONED (newdecl)
    1044                 :     833824 :                                        || !DECL_FUNCTION_VERSIONED (olddecl))))
    1045                 :      10076 :         return 0;
    1046                 :            :     }
    1047                 :    6602390 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1048                 :            :     {
    1049                 :    6379490 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1050                 :            :         return 0;
    1051                 :            : 
    1052                 :    2812810 :       tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1053                 :    2812810 :       tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1054                 :            : 
    1055                 :    2812810 :       if (TREE_CODE (newres) != TREE_CODE (oldres))
    1056                 :            :         return 0;
    1057                 :            : 
    1058                 :            :       /* Two template types match if they are the same. Otherwise, compare
    1059                 :            :          the underlying declarations.  */
    1060                 :    2812800 :       if (TREE_CODE (newres) == TYPE_DECL)
    1061                 :         25 :         types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
    1062                 :            :       else
    1063                 :    2812780 :         types_match = decls_match (newres, oldres);
    1064                 :            :     }
    1065                 :            :   else
    1066                 :            :     {
    1067                 :            :       /* Need to check scope for variable declaration (VAR_DECL).
    1068                 :            :          For typedef (TYPE_DECL), scope is ignored.  */
    1069                 :     222904 :       if (VAR_P (newdecl)
    1070                 :     182580 :           && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1071                 :            :           /* [dcl.link]
    1072                 :            :              Two declarations for an object with C language linkage
    1073                 :            :              with the same name (ignoring the namespace that qualify
    1074                 :            :              it) that appear in different namespace scopes refer to
    1075                 :            :              the same object.  */
    1076                 :     233483 :           && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
    1077                 :            :         return 0;
    1078                 :            : 
    1079                 :     212453 :       if (TREE_TYPE (newdecl) == error_mark_node)
    1080                 :          0 :         types_match = TREE_TYPE (olddecl) == error_mark_node;
    1081                 :     212453 :       else if (TREE_TYPE (olddecl) == NULL_TREE)
    1082                 :          0 :         types_match = TREE_TYPE (newdecl) == NULL_TREE;
    1083                 :     212453 :       else if (TREE_TYPE (newdecl) == NULL_TREE)
    1084                 :            :         types_match = 0;
    1085                 :            :       else
    1086                 :     212453 :         types_match = comptypes (TREE_TYPE (newdecl),
    1087                 :     212453 :                                  TREE_TYPE (olddecl),
    1088                 :            :                                  COMPARE_REDECLARATION);
    1089                 :            :     }
    1090                 :            : 
    1091                 :            :   return types_match;
    1092                 :            : }
    1093                 :            : 
    1094                 :            : /* NEWDECL and OLDDECL have identical signatures.  If they are
    1095                 :            :    different versions adjust them and return true.
    1096                 :            :    If RECORD is set to true, record function versions.  */
    1097                 :            : 
    1098                 :            : bool
    1099                 :     829190 : maybe_version_functions (tree newdecl, tree olddecl, bool record)
    1100                 :            : {
    1101                 :     829190 :   if (!targetm.target_option.function_versions (newdecl, olddecl))
    1102                 :            :     return false;
    1103                 :            : 
    1104                 :      10112 :   if (!DECL_FUNCTION_VERSIONED (olddecl))
    1105                 :            :     {
    1106                 :        144 :       DECL_FUNCTION_VERSIONED (olddecl) = 1;
    1107                 :        144 :       if (DECL_ASSEMBLER_NAME_SET_P (olddecl))
    1108                 :         28 :         mangle_decl (olddecl);
    1109                 :            :     }
    1110                 :            : 
    1111                 :      10112 :   if (!DECL_FUNCTION_VERSIONED (newdecl))
    1112                 :            :     {
    1113                 :        980 :       DECL_FUNCTION_VERSIONED (newdecl) = 1;
    1114                 :        980 :       if (DECL_ASSEMBLER_NAME_SET_P (newdecl))
    1115                 :          0 :         mangle_decl (newdecl);
    1116                 :            :     }
    1117                 :            : 
    1118                 :      10112 :   if (record)
    1119                 :       1000 :     cgraph_node::record_function_versions (olddecl, newdecl);
    1120                 :            : 
    1121                 :            :   return true;
    1122                 :            : }
    1123                 :            : 
    1124                 :            : /* If NEWDECL is `static' and an `extern' was seen previously,
    1125                 :            :    warn about it.  OLDDECL is the previous declaration.
    1126                 :            : 
    1127                 :            :    Note that this does not apply to the C++ case of declaring
    1128                 :            :    a variable `extern const' and then later `const'.
    1129                 :            : 
    1130                 :            :    Don't complain about built-in functions, since they are beyond
    1131                 :            :    the user's control.  */
    1132                 :            : 
    1133                 :            : void
    1134                 :    1350060 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
    1135                 :            : {
    1136                 :    1350060 :   if (TREE_CODE (newdecl) == TYPE_DECL
    1137                 :    1343560 :       || TREE_CODE (newdecl) == TEMPLATE_DECL
    1138                 :    1102400 :       || TREE_CODE (newdecl) == CONST_DECL
    1139                 :    1102400 :       || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1140                 :    1350050 :     return;
    1141                 :            : 
    1142                 :            :   /* Don't get confused by static member functions; that's a different
    1143                 :            :      use of `static'.  */
    1144                 :    1102400 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    1145                 :    1102400 :       && DECL_STATIC_FUNCTION_P (newdecl))
    1146                 :            :     return;
    1147                 :            : 
    1148                 :            :   /* If the old declaration was `static', or the new one isn't, then
    1149                 :            :      everything is OK.  */
    1150                 :    3075830 :   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
    1151                 :            :     return;
    1152                 :            : 
    1153                 :            :   /* It's OK to declare a builtin function as `static'.  */
    1154                 :          8 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1155                 :          8 :       && DECL_ARTIFICIAL (olddecl))
    1156                 :            :     return;
    1157                 :            : 
    1158                 :         16 :   auto_diagnostic_group d;
    1159                 :          8 :   if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1160                 :            :                  "%qD was declared %<extern%> and later %<static%>", newdecl))
    1161                 :          8 :     inform (DECL_SOURCE_LOCATION (olddecl),
    1162                 :            :             "previous declaration of %qD", olddecl);
    1163                 :            : }
    1164                 :            : 
    1165                 :            : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
    1166                 :            :    function templates.  If their exception specifications do not
    1167                 :            :    match, issue a diagnostic.  */
    1168                 :            : 
    1169                 :            : static void
    1170                 :    1257510 : check_redeclaration_exception_specification (tree new_decl,
    1171                 :            :                                              tree old_decl)
    1172                 :            : {
    1173                 :    1708490 :   tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1174                 :    1708490 :   tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1175                 :            : 
    1176                 :            :   /* Two default specs are equivalent, don't force evaluation.  */
    1177                 :     472444 :   if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
    1178                 :    1267210 :       && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
    1179                 :            :     return;
    1180                 :            : 
    1181                 :    1256800 :   if (!type_dependent_expression_p (old_decl))
    1182                 :            :     {
    1183                 :     860171 :       maybe_instantiate_noexcept (new_decl);
    1184                 :     860171 :       maybe_instantiate_noexcept (old_decl);
    1185                 :            :     }
    1186                 :    1707060 :   new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1187                 :    1707060 :   old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1188                 :            : 
    1189                 :            :   /* [except.spec]
    1190                 :            : 
    1191                 :            :      If any declaration of a function has an exception-specification,
    1192                 :            :      all declarations, including the definition and an explicit
    1193                 :            :      specialization, of that function shall have an
    1194                 :            :      exception-specification with the same set of type-ids.  */
    1195                 :    1256800 :   if (! DECL_IS_BUILTIN (old_decl)
    1196                 :    1256800 :       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
    1197                 :            :     {
    1198                 :        308 :       const char *const msg
    1199                 :            :         = G_("declaration of %qF has a different exception specifier");
    1200                 :        308 :       bool complained = true;
    1201                 :        308 :       location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
    1202                 :        616 :       auto_diagnostic_group d;
    1203                 :        308 :       if (DECL_IN_SYSTEM_HEADER (old_decl))
    1204                 :        204 :         complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
    1205                 :        104 :       else if (!flag_exceptions)
    1206                 :            :         /* We used to silently permit mismatched eh specs with
    1207                 :            :            -fno-exceptions, so make them a pedwarn now.  */
    1208                 :          3 :         complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
    1209                 :            :       else
    1210                 :        101 :         error_at (new_loc, msg, new_decl);
    1211                 :        308 :       if (complained)
    1212                 :        108 :         inform (DECL_SOURCE_LOCATION (old_decl),
    1213                 :            :                 "from previous declaration %qF", old_decl);
    1214                 :            :     }
    1215                 :            : }
    1216                 :            : 
    1217                 :            : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
    1218                 :            :    Otherwise issue diagnostics.  */
    1219                 :            : 
    1220                 :            : static bool
    1221                 :    1350060 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
    1222                 :            : {
    1223                 :    1350060 :   old_decl = STRIP_TEMPLATE (old_decl);
    1224                 :    1350060 :   new_decl = STRIP_TEMPLATE (new_decl);
    1225                 :    1350060 :   if (!VAR_OR_FUNCTION_DECL_P (old_decl)
    1226                 :    1343550 :       || !VAR_OR_FUNCTION_DECL_P (new_decl))
    1227                 :            :     return true;
    1228                 :    2687100 :   if (DECL_DECLARED_CONSTEXPR_P (old_decl)
    1229                 :    2687100 :       == DECL_DECLARED_CONSTEXPR_P (new_decl))
    1230                 :            :     {
    1231                 :    1335400 :       if (TREE_CODE (old_decl) != FUNCTION_DECL)
    1232                 :            :         return true;
    1233                 :    2515610 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1234                 :    1257810 :           == DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1235                 :            :         return true;
    1236                 :            :     }
    1237                 :       8152 :   if (TREE_CODE (old_decl) == FUNCTION_DECL)
    1238                 :            :     {
    1239                 :         17 :       if (fndecl_built_in_p (old_decl))
    1240                 :            :         {
    1241                 :            :           /* Hide a built-in declaration.  */
    1242                 :          0 :           DECL_DECLARED_CONSTEXPR_P (old_decl)
    1243                 :          0 :             = DECL_DECLARED_CONSTEXPR_P (new_decl);
    1244                 :          0 :           if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1245                 :          0 :             SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
    1246                 :          0 :           return true;
    1247                 :            :         }
    1248                 :            :       /* 7.1.5 [dcl.constexpr]
    1249                 :            :          Note: An explicit specialization can differ from the template
    1250                 :            :          declaration with respect to the constexpr specifier.  */
    1251                 :         17 :       if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
    1252                 :         28 :           && DECL_TEMPLATE_SPECIALIZATION (new_decl))
    1253                 :            :         return true;
    1254                 :            : 
    1255                 :         10 :       const char *kind = "constexpr";
    1256                 :         10 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1257                 :         18 :           || DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1258                 :            :         kind = "consteval";
    1259                 :         10 :       error_at (DECL_SOURCE_LOCATION (new_decl),
    1260                 :            :                 "redeclaration %qD differs in %qs "
    1261                 :            :                 "from previous declaration", new_decl,
    1262                 :            :                 kind);
    1263                 :         10 :       inform (DECL_SOURCE_LOCATION (old_decl),
    1264                 :            :               "previous declaration %qD", old_decl);
    1265                 :         10 :       return false;
    1266                 :            :     }
    1267                 :            :   return true;
    1268                 :            : }
    1269                 :            : 
    1270                 :            : // If OLDDECL and NEWDECL are concept declarations with the same type
    1271                 :            : // (i.e., and template parameters), but different requirements,
    1272                 :            : // emit diagnostics and return true. Otherwise, return false.
    1273                 :            : static inline bool
    1274                 :          5 : check_concept_refinement (tree olddecl, tree newdecl)
    1275                 :            : {
    1276                 :          5 :   if (!DECL_DECLARED_CONCEPT_P (olddecl) || !DECL_DECLARED_CONCEPT_P (newdecl))
    1277                 :            :     return false;
    1278                 :            : 
    1279                 :          0 :   tree d1 = DECL_TEMPLATE_RESULT (olddecl);
    1280                 :          0 :   tree d2 = DECL_TEMPLATE_RESULT (newdecl);
    1281                 :          0 :   if (TREE_CODE (d1) != TREE_CODE (d2))
    1282                 :            :     return false;
    1283                 :            : 
    1284                 :          0 :   tree t1 = TREE_TYPE (d1);
    1285                 :          0 :   tree t2 = TREE_TYPE (d2);
    1286                 :          0 :   if (TREE_CODE (d1) == FUNCTION_DECL)
    1287                 :            :     {
    1288                 :          0 :       if (compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2))
    1289                 :          0 :           && comp_template_parms (DECL_TEMPLATE_PARMS (olddecl),
    1290                 :          0 :                                   DECL_TEMPLATE_PARMS (newdecl))
    1291                 :          0 :           && !equivalently_constrained (olddecl, newdecl))
    1292                 :            :         {
    1293                 :          0 :           error ("cannot specialize concept %q#D", olddecl);
    1294                 :          0 :           return true;
    1295                 :            :         }
    1296                 :            :     }
    1297                 :            :   return false;
    1298                 :            : }
    1299                 :            : 
    1300                 :            : /* DECL is a redeclaration of a function or function template.  If
    1301                 :            :    it does have default arguments issue a diagnostic.  Note: this
    1302                 :            :    function is used to enforce the requirements in C++11 8.3.6 about
    1303                 :            :    no default arguments in redeclarations.  */
    1304                 :            : 
    1305                 :            : static void
    1306                 :     638673 : check_redeclaration_no_default_args (tree decl)
    1307                 :            : {
    1308                 :     638673 :   gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
    1309                 :            : 
    1310                 :    2469640 :   for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
    1311                 :    2087490 :        t && t != void_list_node; t = TREE_CHAIN (t))
    1312                 :    1448890 :     if (TREE_PURPOSE (t))
    1313                 :            :       {
    1314                 :         72 :         permerror (DECL_SOURCE_LOCATION (decl),
    1315                 :            :                    "redeclaration of %q#D may not have default "
    1316                 :            :                    "arguments", decl);
    1317                 :         72 :         return;
    1318                 :            :       }
    1319                 :            : }
    1320                 :            : 
    1321                 :            : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
    1322                 :            :    in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
    1323                 :            :    the TEMPLATE_DECLs in case of function templates).  This function is used
    1324                 :            :    to enforce the final part of C++17 11.3.6/4, about a single declaration:
    1325                 :            :    "If a friend declaration specifies a default argument expression, that
    1326                 :            :    declaration shall be a definition and shall be the only declaration of
    1327                 :            :    the function or function template in the translation unit."  */
    1328                 :            : 
    1329                 :            : static void
    1330                 :     446832 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl,
    1331                 :            :                                             bool olddecl_hidden_friend_p)
    1332                 :            : {
    1333                 :     882876 :   if (!olddecl_hidden_friend_p && !DECL_FRIEND_P (newdecl))
    1334                 :            :     return;
    1335                 :            : 
    1336                 :      53437 :   tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    1337                 :      53437 :   tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1338                 :            : 
    1339                 :     232237 :   for (; t1 && t1 != void_list_node;
    1340                 :      89400 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1341                 :      21217 :     if ((olddecl_hidden_friend_p && TREE_PURPOSE (t1))
    1342                 :     247091 :         || (DECL_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
    1343                 :            :       {
    1344                 :         28 :         auto_diagnostic_group d;
    1345                 :         28 :         if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1346                 :            :                        "friend declaration of %q#D specifies default "
    1347                 :            :                        "arguments and isn%'t the only declaration", newdecl))
    1348                 :         28 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1349                 :            :                   "previous declaration of %q#D", olddecl);
    1350                 :         28 :         return;
    1351                 :            :       }
    1352                 :            : }
    1353                 :            : 
    1354                 :            : /* Merge tree bits that correspond to attributes noreturn, nothrow,
    1355                 :            :    const,  malloc, and pure from NEWDECL with those of OLDDECL.  */
    1356                 :            : 
    1357                 :            : static void
    1358                 :    1200650 : merge_attribute_bits (tree newdecl, tree olddecl)
    1359                 :            : {
    1360                 :    1200650 :   TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    1361                 :    1200650 :   TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
    1362                 :    1200650 :   TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
    1363                 :    1200650 :   TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
    1364                 :    1200650 :   TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    1365                 :    1200650 :   TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
    1366                 :    1200650 :   DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    1367                 :    1200650 :   DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
    1368                 :    1200650 :   DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    1369                 :    1200650 :   DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
    1370                 :    1200650 :   DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
    1371                 :    1200650 :   DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
    1372                 :    1200650 : }
    1373                 :            : 
    1374                 :            : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)                   \
    1375                 :            :                           && lookup_attribute ("gnu_inline",          \
    1376                 :            :                                                DECL_ATTRIBUTES (fn)))
    1377                 :            : 
    1378                 :            : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
    1379                 :            :    ambiguates olddecl.  Returns true if an error occurs.  */
    1380                 :            : 
    1381                 :            : static bool
    1382                 :    6138270 : duplicate_function_template_decls (tree newdecl, tree olddecl)
    1383                 :            : {
    1384                 :            : 
    1385                 :    6138270 :   tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1386                 :    6138270 :   tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1387                 :            :   /* Function template declarations can be differentiated by parameter
    1388                 :            :      and return type.  */
    1389                 :   12276500 :   if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
    1390                 :    6138270 :                  TYPE_ARG_TYPES (TREE_TYPE (newres)))
    1391                 :    6159380 :        && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
    1392                 :            :                        TREE_TYPE (TREE_TYPE (olddecl))))
    1393                 :            :     {
    1394                 :            :       /* ... and also by their template-heads and requires-clauses.  */
    1395                 :        320 :       if (template_heads_equivalent_p (newdecl, olddecl)
    1396                 :        320 :           && function_requirements_equivalent_p (newres, oldres))
    1397                 :            :         {
    1398                 :          0 :           error ("ambiguating new declaration %q+#D", newdecl);
    1399                 :          0 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1400                 :            :                   "old declaration %q#D", olddecl);
    1401                 :          0 :           return true;
    1402                 :            :         }
    1403                 :            : 
    1404                 :            :       /* FIXME: The types are the same but the are differences
    1405                 :            :          in either the template heads or function requirements.
    1406                 :            :          We should be able to diagnose a set of common errors
    1407                 :            :          stemming from these declarations. For example:
    1408                 :            : 
    1409                 :            :            template<typename T> requires C void f(...);
    1410                 :            :            template<typename T> void f(...) requires C;
    1411                 :            : 
    1412                 :            :          These are functionally equivalent but not equivalent.  */
    1413                 :            :     }
    1414                 :            : 
    1415                 :            :   return false;
    1416                 :            : }
    1417                 :            : 
    1418                 :            : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
    1419                 :            :    If the redeclaration is invalid, a diagnostic is issued, and the
    1420                 :            :    error_mark_node is returned.  Otherwise, OLDDECL is returned.
    1421                 :            : 
    1422                 :            :    If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
    1423                 :            :    returned.
    1424                 :            : 
    1425                 :            :    NEWDECL_IS_FRIEND is true if NEWDECL was declared as a friend.  */
    1426                 :            : 
    1427                 :            : tree
    1428                 :   18001200 : duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
    1429                 :            : {
    1430                 :   18001200 :   unsigned olddecl_uid = DECL_UID (olddecl);
    1431                 :   18001200 :   int olddecl_friend = 0, types_match = 0, hidden_friend = 0;
    1432                 :   18001200 :   int olddecl_hidden_friend = 0;
    1433                 :   18001200 :   int new_defines_function = 0;
    1434                 :   18001200 :   tree new_template_info;
    1435                 :   18001200 :   location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
    1436                 :   18001200 :   location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
    1437                 :            : 
    1438                 :   18001200 :   if (newdecl == olddecl)
    1439                 :            :     return olddecl;
    1440                 :            : 
    1441                 :   17928400 :   types_match = decls_match (newdecl, olddecl);
    1442                 :            : 
    1443                 :            :   /* If either the type of the new decl or the type of the old decl is an
    1444                 :            :      error_mark_node, then that implies that we have already issued an
    1445                 :            :      error (earlier) for some bogus type specification, and in that case,
    1446                 :            :      it is rather pointless to harass the user with yet more error message
    1447                 :            :      about the same declaration, so just pretend the types match here.  */
    1448                 :   17928400 :   if (TREE_TYPE (newdecl) == error_mark_node
    1449                 :   35856700 :       || TREE_TYPE (olddecl) == error_mark_node)
    1450                 :            :     return error_mark_node;
    1451                 :            : 
    1452                 :            :   /* Check for redeclaration and other discrepancies.  */
    1453                 :   17928300 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1454                 :   24080300 :       && DECL_ARTIFICIAL (olddecl))
    1455                 :            :     {
    1456                 :     986307 :       gcc_assert (!DECL_HIDDEN_FRIEND_P (olddecl));
    1457                 :     986307 :       if (TREE_CODE (newdecl) != FUNCTION_DECL)
    1458                 :            :         {
    1459                 :            :           /* Avoid warnings redeclaring built-ins which have not been
    1460                 :            :              explicitly declared.  */
    1461                 :      30249 :           if (DECL_ANTICIPATED (olddecl))
    1462                 :            :             {
    1463                 :      30215 :               if (TREE_PUBLIC (newdecl)
    1464                 :      30693 :                   && CP_DECL_CONTEXT (newdecl) == global_namespace)
    1465                 :         16 :                 warning_at (newdecl_loc,
    1466                 :            :                             OPT_Wbuiltin_declaration_mismatch,
    1467                 :            :                             "built-in function %qD declared as non-function",
    1468                 :            :                             newdecl);
    1469                 :      30215 :               return NULL_TREE;
    1470                 :            :             }
    1471                 :            : 
    1472                 :            :           /* If you declare a built-in or predefined function name as static,
    1473                 :            :              the old definition is overridden, but optionally warn this was a
    1474                 :            :              bad choice of name.  */
    1475                 :         34 :           if (! TREE_PUBLIC (newdecl))
    1476                 :            :             {
    1477                 :         34 :               warning_at (newdecl_loc,
    1478                 :            :                           OPT_Wshadow, 
    1479                 :         34 :                           fndecl_built_in_p (olddecl)
    1480                 :            :                           ? G_("shadowing built-in function %q#D")
    1481                 :            :                           : G_("shadowing library function %q#D"), olddecl);
    1482                 :            :               /* Discard the old built-in function.  */
    1483                 :         34 :               return NULL_TREE;
    1484                 :            :             }
    1485                 :            :           /* If the built-in is not ansi, then programs can override
    1486                 :            :              it even globally without an error.  */
    1487                 :          0 :           else if (! fndecl_built_in_p (olddecl))
    1488                 :          0 :             warning_at (newdecl_loc, 0,
    1489                 :            :                         "library function %q#D redeclared as non-function %q#D",
    1490                 :            :                         olddecl, newdecl);
    1491                 :            :           else
    1492                 :          0 :             error_at (newdecl_loc,
    1493                 :            :                       "declaration of %q#D conflicts with built-in "
    1494                 :            :                       "declaration %q#D", newdecl, olddecl);
    1495                 :          0 :           return NULL_TREE;
    1496                 :            :         }
    1497                 :     956058 :       else if (DECL_OMP_DECLARE_REDUCTION_P (olddecl))
    1498                 :            :         {
    1499                 :         36 :           gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (newdecl));
    1500                 :         36 :           error_at (newdecl_loc,
    1501                 :            :                     "redeclaration of %<pragma omp declare reduction%>");
    1502                 :         36 :           inform (olddecl_loc,
    1503                 :            :                   "previous %<pragma omp declare reduction%> declaration");
    1504                 :         36 :           return error_mark_node;
    1505                 :            :         }
    1506                 :     956022 :       else if (!types_match)
    1507                 :            :         {
    1508                 :            :           /* Avoid warnings redeclaring built-ins which have not been
    1509                 :            :              explicitly declared.  */
    1510                 :     609275 :           if (DECL_ANTICIPATED (olddecl))
    1511                 :            :             {
    1512                 :      53340 :               tree t1, t2;
    1513                 :            : 
    1514                 :            :               /* A new declaration doesn't match a built-in one unless it
    1515                 :            :                  is also extern "C".  */
    1516                 :      53340 :               gcc_assert (DECL_IS_BUILTIN (olddecl));
    1517                 :      53340 :               gcc_assert (DECL_EXTERN_C_P (olddecl));
    1518                 :      53340 :               if (!DECL_EXTERN_C_P (newdecl))
    1519                 :            :                 return NULL_TREE;
    1520                 :            : 
    1521                 :      25148 :               for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1522                 :      25148 :                    t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1523                 :      49367 :                    t1 || t2;
    1524                 :      24219 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1525                 :            :                 {
    1526                 :      49343 :                   if (!t1 || !t2)
    1527                 :            :                     break;
    1528                 :            :                   /* FILE, tm types are not known at the time
    1529                 :            :                      we create the builtins.  */
    1530                 :     148746 :                   for (unsigned i = 0;
    1531                 :     197873 :                        i < sizeof (builtin_structptr_types)
    1532                 :            :                            / sizeof (builtin_structptr_type);
    1533                 :            :                        ++i)
    1534                 :     173647 :                     if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
    1535                 :            :                       {
    1536                 :      24901 :                         tree t = TREE_VALUE (t1);
    1537                 :            : 
    1538                 :      24901 :                         if (TYPE_PTR_P (t)
    1539                 :      49802 :                             && TYPE_IDENTIFIER (TREE_TYPE (t))
    1540                 :      24901 :                             == get_identifier (builtin_structptr_types[i].str)
    1541                 :      49782 :                             && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
    1542                 :            :                           {
    1543                 :      24881 :                             tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1544                 :            : 
    1545                 :      49762 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl))
    1546                 :      24881 :                               = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
    1547                 :      24881 :                             types_match = decls_match (newdecl, olddecl);
    1548                 :      24881 :                             if (types_match)
    1549                 :      24881 :                               return duplicate_decls (newdecl, olddecl,
    1550                 :      24881 :                                                       newdecl_is_friend);
    1551                 :          0 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
    1552                 :            :                           }
    1553                 :         20 :                         goto next_arg;
    1554                 :            :                       }
    1555                 :            : 
    1556                 :      24226 :                   if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    1557                 :            :                     break;
    1558                 :      24219 :                 next_arg:;
    1559                 :            :                 }
    1560                 :            : 
    1561                 :        267 :               warning_at (newdecl_loc,
    1562                 :            :                           OPT_Wbuiltin_declaration_mismatch,
    1563                 :            :                           "declaration of %q#D conflicts with built-in "
    1564                 :            :                           "declaration %q#D", newdecl, olddecl);
    1565                 :            :             }
    1566                 :     555935 :           else if ((DECL_EXTERN_C_P (newdecl)
    1567                 :         20 :                     && DECL_EXTERN_C_P (olddecl))
    1568                 :    1111850 :                    || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1569                 :     555915 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
    1570                 :            :             {
    1571                 :            :               /* Don't really override olddecl for __* prefixed builtins
    1572                 :            :                  except for __[^b]*_chk, the compiler might be using those
    1573                 :            :                  explicitly.  */
    1574                 :         20 :               if (fndecl_built_in_p (olddecl))
    1575                 :            :                 {
    1576                 :         20 :                   tree id = DECL_NAME (olddecl);
    1577                 :         20 :                   const char *name = IDENTIFIER_POINTER (id);
    1578                 :         20 :                   size_t len;
    1579                 :            : 
    1580                 :         20 :                   if (name[0] == '_'
    1581                 :         20 :                       && name[1] == '_'
    1582                 :         40 :                       && (strncmp (name + 2, "builtin_",
    1583                 :            :                                    strlen ("builtin_")) == 0
    1584                 :          8 :                           || (len = strlen (name)) <= strlen ("___chk")
    1585                 :          8 :                           || memcmp (name + len - strlen ("_chk"),
    1586                 :            :                                      "_chk", strlen ("_chk") + 1) != 0))
    1587                 :            :                     {
    1588                 :         20 :                       if (DECL_INITIAL (newdecl))
    1589                 :            :                         {
    1590                 :          8 :                           error_at (newdecl_loc,
    1591                 :            :                                     "definition of %q#D ambiguates built-in "
    1592                 :            :                                     "declaration %q#D", newdecl, olddecl);
    1593                 :          8 :                           return error_mark_node;
    1594                 :            :                         }
    1595                 :         24 :                       auto_diagnostic_group d;
    1596                 :         12 :                       if (permerror (newdecl_loc,
    1597                 :            :                                      "new declaration %q#D ambiguates built-in"
    1598                 :            :                                      " declaration %q#D", newdecl, olddecl)
    1599                 :         12 :                           && flag_permissive)
    1600                 :          4 :                         inform (newdecl_loc,
    1601                 :            :                                 "ignoring the %q#D declaration", newdecl);
    1602                 :         12 :                       return flag_permissive ? olddecl : error_mark_node;
    1603                 :            :                     }
    1604                 :            :                 }
    1605                 :            : 
    1606                 :            :               /* A near match; override the builtin.  */
    1607                 :            : 
    1608                 :          0 :               if (TREE_PUBLIC (newdecl))
    1609                 :          0 :                 warning_at (newdecl_loc,
    1610                 :            :                             OPT_Wbuiltin_declaration_mismatch,
    1611                 :            :                             "new declaration %q#D ambiguates built-in "
    1612                 :            :                             "declaration %q#D", newdecl, olddecl);
    1613                 :            :               else
    1614                 :          0 :                 warning (OPT_Wshadow, 
    1615                 :            :                          fndecl_built_in_p (olddecl)
    1616                 :            :                          ? G_("shadowing built-in function %q#D")
    1617                 :            :                          : G_("shadowing library function %q#D"), olddecl);
    1618                 :            :             }
    1619                 :            :           else
    1620                 :            :             /* Discard the old built-in function.  */
    1621                 :            :             return NULL_TREE;
    1622                 :            : 
    1623                 :            :           /* Replace the old RTL to avoid problems with inlining.  */
    1624                 :        267 :           COPY_DECL_RTL (newdecl, olddecl);
    1625                 :            :         }
    1626                 :            :       /* Even if the types match, prefer the new declarations type for
    1627                 :            :          built-ins which have not been explicitly declared, for
    1628                 :            :          exception lists, etc...  */
    1629                 :     346747 :       else if (DECL_IS_BUILTIN (olddecl))
    1630                 :            :         {
    1631                 :     346747 :           tree type = TREE_TYPE (newdecl);
    1632                 :     346747 :           tree attribs = (*targetm.merge_type_attributes)
    1633                 :     346747 :             (TREE_TYPE (olddecl), type);
    1634                 :            : 
    1635                 :     346747 :           type = cp_build_type_attribute_variant (type, attribs);
    1636                 :     346747 :           TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
    1637                 :            :         }
    1638                 :            : 
    1639                 :            :       /* If a function is explicitly declared "throw ()", propagate that to
    1640                 :            :          the corresponding builtin.  */
    1641                 :     347014 :       if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
    1642                 :     318109 :           && DECL_ANTICIPATED (olddecl)
    1643                 :     318074 :           && TREE_NOTHROW (newdecl)
    1644                 :     598756 :           && !TREE_NOTHROW (olddecl))
    1645                 :            :         {
    1646                 :        145 :           enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
    1647                 :        145 :           tree tmpdecl = builtin_decl_explicit (fncode);
    1648                 :        145 :           if (tmpdecl && tmpdecl != olddecl && types_match)
    1649                 :        145 :             TREE_NOTHROW (tmpdecl)  = 1;
    1650                 :            :         }
    1651                 :            : 
    1652                 :            :       /* Whether or not the builtin can throw exceptions has no
    1653                 :            :          bearing on this declarator.  */
    1654                 :     347014 :       TREE_NOTHROW (olddecl) = 0;
    1655                 :            : 
    1656                 :     694028 :       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
    1657                 :            :         {
    1658                 :            :           /* If a builtin function is redeclared as `static', merge
    1659                 :            :              the declarations, but make the original one static.  */
    1660                 :          0 :           DECL_THIS_STATIC (olddecl) = 1;
    1661                 :          0 :           TREE_PUBLIC (olddecl) = 0;
    1662                 :            : 
    1663                 :            :           /* Make the old declaration consistent with the new one so
    1664                 :            :              that all remnants of the builtin-ness of this function
    1665                 :            :              will be banished.  */
    1666                 :          0 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    1667                 :          0 :           COPY_DECL_RTL (newdecl, olddecl);
    1668                 :            :         }
    1669                 :            :     }
    1670                 :   16942000 :   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    1671                 :            :     {
    1672                 :            :       /* C++ Standard, 3.3, clause 4:
    1673                 :            :          "[Note: a namespace name or a class template name must be unique
    1674                 :            :          in its declarative region (7.3.2, clause 14). ]"  */
    1675                 :    6118070 :       if (TREE_CODE (olddecl) == NAMESPACE_DECL
    1676                 :    6118050 :           || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1677                 :            :         /* Namespace conflicts with not namespace.  */;
    1678                 :    5281480 :       else if (DECL_TYPE_TEMPLATE_P (olddecl)
    1679                 :   11399500 :                || DECL_TYPE_TEMPLATE_P (newdecl))
    1680                 :            :         /* Class template conflicts.  */;
    1681                 :    6118020 :       else if ((TREE_CODE (newdecl) == FUNCTION_DECL
    1682                 :    5297240 :                 && DECL_FUNCTION_TEMPLATE_P (olddecl))
    1683                 :    6133790 :                || (TREE_CODE (olddecl) == FUNCTION_DECL
    1684                 :     820509 :                    && DECL_FUNCTION_TEMPLATE_P (newdecl)))
    1685                 :            :         {
    1686                 :            :           /* One is a function and the other is a template
    1687                 :            :              function.  */
    1688                 :    6101950 :           if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
    1689                 :            :             return NULL_TREE;
    1690                 :            : 
    1691                 :            :           /* There can only be one!  */
    1692                 :       3432 :           if (TREE_CODE (newdecl) == TEMPLATE_DECL
    1693                 :       3432 :               && check_raw_literal_operator (olddecl))
    1694                 :          3 :             error_at (newdecl_loc,
    1695                 :            :                       "literal operator %q#D conflicts with"
    1696                 :            :                       " raw literal operator", newdecl);
    1697                 :       3429 :           else if (check_raw_literal_operator (newdecl))
    1698                 :          3 :             error_at (newdecl_loc,
    1699                 :            :                       "raw literal operator %q#D conflicts with"
    1700                 :            :                       " literal operator template", newdecl);
    1701                 :            :           else
    1702                 :            :             return NULL_TREE;
    1703                 :            :           
    1704                 :          6 :           inform (olddecl_loc, "previous declaration %q#D", olddecl);
    1705                 :          6 :           return error_mark_node;
    1706                 :            :         }
    1707                 :      15931 :       else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    1708                 :      16198 :                || DECL_IMPLICIT_TYPEDEF_P (newdecl))
    1709                 :            :         /* One is an implicit typedef, that's ok.  */
    1710                 :            :         return NULL_TREE;
    1711                 :            : 
    1712                 :         84 :       error ("%q#D redeclared as different kind of entity", newdecl);
    1713                 :         84 :       inform (olddecl_loc, "previous declaration %q#D", olddecl);
    1714                 :            : 
    1715                 :         84 :       return error_mark_node;
    1716                 :            :     }
    1717                 :   10823900 :   else if (!types_match)
    1718                 :            :     {
    1719                 :    9813310 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
    1720                 :            :         /* These are certainly not duplicate declarations; they're
    1721                 :            :            from different scopes.  */
    1722                 :            :         return NULL_TREE;
    1723                 :            : 
    1724                 :    9813270 :       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1725                 :            :         {
    1726                 :    6138280 :           tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1727                 :    6138280 :           tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1728                 :            : 
    1729                 :            :           /* The name of a class template may not be declared to refer to
    1730                 :            :              any other template, class, function, object, namespace, value,
    1731                 :            :              or type in the same scope.  */
    1732                 :    6138280 :           if (TREE_CODE (oldres) == TYPE_DECL
    1733                 :    6138280 :               || TREE_CODE (newres) == TYPE_DECL)
    1734                 :            :             {
    1735                 :          7 :               error_at (newdecl_loc,
    1736                 :            :                         "conflicting declaration of template %q#D", newdecl);
    1737                 :          7 :               inform (olddecl_loc,
    1738                 :            :                       "previous declaration %q#D", olddecl);
    1739                 :          7 :               return error_mark_node;
    1740                 :            :             }
    1741                 :            : 
    1742                 :    6138280 :           else if (TREE_CODE (oldres) == FUNCTION_DECL
    1743                 :    6138270 :                    && TREE_CODE (newres) == FUNCTION_DECL)
    1744                 :            :             {
    1745                 :    6138270 :               if (duplicate_function_template_decls (newdecl, olddecl))
    1746                 :          0 :                 return error_mark_node;
    1747                 :            :               return NULL_TREE;
    1748                 :            :             }
    1749                 :          5 :           else if (check_concept_refinement (olddecl, newdecl))
    1750                 :          0 :             return error_mark_node;
    1751                 :            :           return NULL_TREE;
    1752                 :            :         }
    1753                 :    3674980 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1754                 :            :         {
    1755                 :    3674930 :           if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
    1756                 :            :             {
    1757                 :         11 :               error_at (newdecl_loc,
    1758                 :            :                         "conflicting declaration of C function %q#D",
    1759                 :            :                         newdecl);
    1760                 :         11 :               inform (olddecl_loc,
    1761                 :            :                       "previous declaration %q#D", olddecl);
    1762                 :         11 :               return NULL_TREE;
    1763                 :            :             }
    1764                 :            :           /* For function versions, params and types match, but they
    1765                 :            :              are not ambiguous.  */
    1766                 :    3674870 :           else if ((!DECL_FUNCTION_VERSIONED (newdecl)
    1767                 :    3665510 :                     && !DECL_FUNCTION_VERSIONED (olddecl))
    1768                 :            :                    // The functions have the same parameter types.
    1769                 :    3665510 :                    && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1770                 :    3665510 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
    1771                 :            :                    // And the same constraints.
    1772                 :    3674910 :                    && equivalently_constrained (newdecl, olddecl))
    1773                 :            :             {
    1774                 :         38 :               error_at (newdecl_loc,
    1775                 :            :                         "ambiguating new declaration of %q#D", newdecl);
    1776                 :         38 :               inform (olddecl_loc,
    1777                 :            :                       "old declaration %q#D", olddecl);
    1778                 :         38 :               return error_mark_node;
    1779                 :            :             }
    1780                 :            :           else
    1781                 :    3674830 :             return NULL_TREE;
    1782                 :            :         }
    1783                 :            :       else
    1784                 :            :         {
    1785                 :        105 :           error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
    1786                 :        105 :           inform (olddecl_loc,
    1787                 :            :                   "previous declaration as %q#D", olddecl);
    1788                 :        105 :           return error_mark_node;
    1789                 :            :         }
    1790                 :            :     }
    1791                 :    1010630 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    1792                 :    1680860 :             && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
    1793                 :        229 :                  && (!DECL_TEMPLATE_INFO (newdecl)
    1794                 :        229 :                      || (DECL_TI_TEMPLATE (newdecl)
    1795                 :        229 :                          != DECL_TI_TEMPLATE (olddecl))))
    1796                 :     670237 :                 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
    1797                 :      57091 :                     && (!DECL_TEMPLATE_INFO (olddecl)
    1798                 :      57091 :                         || (DECL_TI_TEMPLATE (olddecl)
    1799                 :      57091 :                             != DECL_TI_TEMPLATE (newdecl))))))
    1800                 :            :     /* It's OK to have a template specialization and a non-template
    1801                 :            :        with the same type, or to have specializations of two
    1802                 :            :        different templates with the same type.  Note that if one is a
    1803                 :            :        specialization, and the other is an instantiation of the same
    1804                 :            :        template, that we do not exit at this point.  That situation
    1805                 :            :        can occur if we instantiate a template class, and then
    1806                 :            :        specialize one of its methods.  This situation is valid, but
    1807                 :            :        the declarations must be merged in the usual way.  */
    1808                 :            :     return NULL_TREE;
    1809                 :    1010630 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    1810                 :    1680860 :            && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
    1811                 :      56915 :                 && !DECL_USE_TEMPLATE (newdecl))
    1812                 :     670237 :                || (DECL_TEMPLATE_INSTANTIATION (newdecl)
    1813                 :         53 :                    && !DECL_USE_TEMPLATE (olddecl))))
    1814                 :            :     /* One of the declarations is a template instantiation, and the
    1815                 :            :        other is not a template at all.  That's OK.  */
    1816                 :            :     return NULL_TREE;
    1817                 :    1010630 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    1818                 :            :     {
    1819                 :            :       /* In [namespace.alias] we have:
    1820                 :            : 
    1821                 :            :            In a declarative region, a namespace-alias-definition can be
    1822                 :            :            used to redefine a namespace-alias declared in that declarative
    1823                 :            :            region to refer only to the namespace to which it already
    1824                 :            :            refers.
    1825                 :            : 
    1826                 :            :          Therefore, if we encounter a second alias directive for the same
    1827                 :            :          alias, we can just ignore the second directive.  */
    1828                 :         24 :       if (DECL_NAMESPACE_ALIAS (newdecl)
    1829                 :         24 :           && (DECL_NAMESPACE_ALIAS (newdecl)
    1830                 :         20 :               == DECL_NAMESPACE_ALIAS (olddecl)))
    1831                 :         12 :         return olddecl;
    1832                 :            : 
    1833                 :            :       /* Leave it to update_binding to merge or report error.  */
    1834                 :            :       return NULL_TREE;
    1835                 :            :     }
    1836                 :            :   else
    1837                 :            :     {
    1838                 :    1010600 :       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
    1839                 :    1010600 :       if (errmsg)
    1840                 :            :         {
    1841                 :        499 :           auto_diagnostic_group d;
    1842                 :        499 :           error_at (newdecl_loc, errmsg, newdecl);
    1843                 :        499 :           if (DECL_NAME (olddecl) != NULL_TREE)
    1844                 :        998 :             inform (olddecl_loc,
    1845                 :        499 :                     (DECL_INITIAL (olddecl) && namespace_bindings_p ())
    1846                 :            :                     ? G_("%q#D previously defined here")
    1847                 :            :                     : G_("%q#D previously declared here"), olddecl);
    1848                 :        499 :           return error_mark_node;
    1849                 :            :         }
    1850                 :    1010100 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    1851                 :     669957 :                && DECL_INITIAL (olddecl) != NULL_TREE
    1852                 :       2672 :                && !prototype_p (TREE_TYPE (olddecl))
    1853                 :    1010100 :                && prototype_p (TREE_TYPE (newdecl)))
    1854                 :            :         {
    1855                 :            :           /* Prototype decl follows defn w/o prototype.  */
    1856                 :          0 :           auto_diagnostic_group d;
    1857                 :          0 :           if (warning_at (newdecl_loc, 0,
    1858                 :            :                           "prototype specified for %q#D", newdecl))
    1859                 :          0 :             inform (olddecl_loc,
    1860                 :            :                     "previous non-prototype definition here");
    1861                 :            :         }
    1862                 :     924663 :       else if (VAR_OR_FUNCTION_DECL_P (olddecl)
    1863                 :    2520900 :                && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
    1864                 :            :         {
    1865                 :            :           /* [dcl.link]
    1866                 :            :              If two declarations of the same function or object
    1867                 :            :              specify different linkage-specifications ..., the program
    1868                 :            :              is ill-formed.... Except for functions with C++ linkage,
    1869                 :            :              a function declaration without a linkage specification
    1870                 :            :              shall not precede the first linkage specification for
    1871                 :            :              that function.  A function can be declared without a
    1872                 :            :              linkage specification after an explicit linkage
    1873                 :            :              specification has been seen; the linkage explicitly
    1874                 :            :              specified in the earlier declaration is not affected by
    1875                 :            :              such a function declaration.
    1876                 :            : 
    1877                 :            :              DR 563 raises the question why the restrictions on
    1878                 :            :              functions should not also apply to objects.  Older
    1879                 :            :              versions of G++ silently ignore the linkage-specification
    1880                 :            :              for this example:
    1881                 :            : 
    1882                 :            :                namespace N { 
    1883                 :            :                  extern int i;
    1884                 :            :                  extern "C" int i;
    1885                 :            :                }
    1886                 :            : 
    1887                 :            :              which is clearly wrong.  Therefore, we now treat objects
    1888                 :            :              like functions.  */
    1889                 :       1408 :           if (current_lang_depth () == 0)
    1890                 :            :             {
    1891                 :            :               /* There is no explicit linkage-specification, so we use
    1892                 :            :                  the linkage from the previous declaration.  */
    1893                 :       1400 :               retrofit_lang_decl (newdecl);
    1894                 :       2800 :               SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    1895                 :            :             }
    1896                 :            :           else
    1897                 :            :             {
    1898                 :         16 :               auto_diagnostic_group d;
    1899                 :         16 :               error_at (newdecl_loc,
    1900                 :            :                         "conflicting declaration of %q#D with %qL linkage",
    1901                 :          8 :                         newdecl, DECL_LANGUAGE (newdecl));
    1902                 :         16 :               inform (olddecl_loc,
    1903                 :            :                       "previous declaration with %qL linkage",
    1904                 :          8 :                       DECL_LANGUAGE (olddecl));
    1905                 :            :             }
    1906                 :            :         }
    1907                 :            : 
    1908                 :    1010100 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
    1909                 :            :         ;
    1910                 :     951824 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL)
    1911                 :            :         {
    1912                 :            :           /* Note: free functions, as TEMPLATE_DECLs, are handled below.  */
    1913                 :     817266 :           if (DECL_FUNCTION_MEMBER_P (olddecl)
    1914                 :     612823 :               && (/* grokfndecl passes member function templates too
    1915                 :            :                      as FUNCTION_DECLs.  */
    1916                 :     429438 :                   DECL_TEMPLATE_INFO (olddecl)
    1917                 :            :                   /* C++11 8.3.6/6.
    1918                 :            :                      Default arguments for a member function of a class
    1919                 :            :                      template shall be specified on the initial declaration
    1920                 :            :                      of the member function within the class template.  */
    1921                 :      32485 :                   || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
    1922                 :     402332 :             check_redeclaration_no_default_args (newdecl);
    1923                 :            :           else
    1924                 :            :             {
    1925                 :     236722 :               tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    1926                 :     210491 :               tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1927                 :     210491 :               int i = 1;
    1928                 :            : 
    1929                 :     970681 :               for (; t1 && t1 != void_list_node;
    1930                 :     380095 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
    1931                 :     381478 :                 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
    1932                 :            :                   {
    1933                 :         52 :                     if (simple_cst_equal (TREE_PURPOSE (t1),
    1934                 :         52 :                                           TREE_PURPOSE (t2)) == 1)
    1935                 :            :                       {
    1936                 :         32 :                         auto_diagnostic_group d;
    1937                 :         16 :                         if (permerror (newdecl_loc,
    1938                 :            :                                        "default argument given for parameter "
    1939                 :            :                                        "%d of %q#D", i, newdecl))
    1940                 :         16 :                           inform (olddecl_loc,
    1941                 :            :                                   "previous specification in %q#D here",
    1942                 :            :                                   olddecl);
    1943                 :            :                       }
    1944                 :            :                     else
    1945                 :            :                       {
    1946                 :         72 :                         auto_diagnostic_group d;
    1947                 :         36 :                         error_at (newdecl_loc,
    1948                 :            :                                   "default argument given for parameter %d "
    1949                 :            :                                   "of %q#D", i, newdecl);
    1950                 :         36 :                         inform (olddecl_loc,
    1951                 :            :                                 "previous specification in %q#D here",
    1952                 :            :                                 olddecl);
    1953                 :            :                       }
    1954                 :            :                   }
    1955                 :            : 
    1956                 :            :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    1957                 :            :                  argument expression, that declaration... shall be the only
    1958                 :            :                  declaration of the function or function template in the
    1959                 :            :                  translation unit."  */
    1960                 :     210491 :               check_no_redeclaration_friend_default_args
    1961                 :     210491 :                 (olddecl, newdecl, DECL_HIDDEN_FRIEND_P (olddecl));
    1962                 :            :             }
    1963                 :            :         }
    1964                 :            :     }
    1965                 :            : 
    1966                 :            :   /* Do not merge an implicit typedef with an explicit one.  In:
    1967                 :            : 
    1968                 :            :        class A;
    1969                 :            :        ...
    1970                 :            :        typedef class A A __attribute__ ((foo));
    1971                 :            : 
    1972                 :            :      the attribute should apply only to the typedef.  */
    1973                 :    1357120 :   if (TREE_CODE (olddecl) == TYPE_DECL
    1974                 :    1370660 :       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    1975                 :      12984 :           || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
    1976                 :            :     return NULL_TREE;
    1977                 :            : 
    1978                 :    1350060 :   if (!validate_constexpr_redeclaration (olddecl, newdecl))
    1979                 :         10 :     return error_mark_node;
    1980                 :            : 
    1981                 :            :   /* We have committed to returning OLDDECL at this point.  */
    1982                 :            : 
    1983                 :            :   /* If new decl is `static' and an `extern' was seen previously,
    1984                 :            :      warn about it.  */
    1985                 :    1350060 :   warn_extern_redeclared_static (newdecl, olddecl);
    1986                 :            : 
    1987                 :            :   /* True to merge attributes between the declarations, false to
    1988                 :            :      set OLDDECL's attributes to those of NEWDECL (for template
    1989                 :            :      explicit specializations that specify their own attributes
    1990                 :            :      independent of those specified for the primary template).  */
    1991                 :    1350060 :   const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
    1992                 :    1016960 :                            || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
    1993                 :    1407130 :                            || DECL_TEMPLATE_SPECIALIZATION (olddecl));
    1994                 :            : 
    1995                 :    1350060 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1996                 :            :     {
    1997                 :    1016960 :       if (merge_attr)
    1998                 :            :         {
    1999                 :     960099 :           if (diagnose_mismatched_attributes (olddecl, newdecl))
    2000                 :         48 :             inform (olddecl_loc, DECL_INITIAL (olddecl)
    2001                 :            :                     ? G_("previous definition of %qD here")
    2002                 :            :                     : G_("previous declaration of %qD here"), olddecl);
    2003                 :            : 
    2004                 :            :           /* [dcl.attr.noreturn]: The first declaration of a function shall
    2005                 :            :              specify the noreturn attribute if any declaration of that function
    2006                 :            :              specifies the noreturn attribute.  */
    2007                 :     960099 :           tree a;
    2008                 :     960099 :           if (TREE_THIS_VOLATILE (newdecl)
    2009                 :      21344 :               && !TREE_THIS_VOLATILE (olddecl)
    2010                 :            :               /* This applies to [[noreturn]] only, not its GNU variants.  */
    2011                 :         54 :               && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
    2012                 :         54 :               && cxx11_attribute_p (a)
    2013                 :     960120 :               && get_attribute_namespace (a) == NULL_TREE)
    2014                 :            :             {
    2015                 :          9 :               error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
    2016                 :            :                         "but its first declaration was not", newdecl);
    2017                 :          9 :               inform (olddecl_loc, "previous declaration of %qD", olddecl);
    2018                 :            :             }
    2019                 :            :         }
    2020                 :            : 
    2021                 :            :       /* Now that functions must hold information normally held
    2022                 :            :          by field decls, there is extra work to do so that
    2023                 :            :          declaration information does not get destroyed during
    2024                 :            :          definition.  */
    2025                 :    1016960 :       if (DECL_VINDEX (olddecl))
    2026                 :      13157 :         DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
    2027                 :    1016960 :       if (DECL_CONTEXT (olddecl))
    2028                 :    1016960 :         DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    2029                 :    1016960 :       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
    2030                 :    1016960 :       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2031                 :    2033920 :       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
    2032                 :    1016960 :       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
    2033                 :    1016960 :       DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
    2034                 :    1016960 :       DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
    2035                 :    2033920 :       DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
    2036                 :    2033920 :       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
    2037                 :    1016960 :       if (DECL_OVERLOADED_OPERATOR_P (olddecl))
    2038                 :      89340 :         DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
    2039                 :     268020 :           = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
    2040                 :    1016960 :       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
    2041                 :            : 
    2042                 :            :       /* Optionally warn about more than one declaration for the same
    2043                 :            :          name, but don't warn about a function declaration followed by a
    2044                 :            :          definition.  */
    2045                 :         36 :       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
    2046                 :         36 :           && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
    2047                 :            :           /* Don't warn about extern decl followed by definition.  */
    2048                 :         36 :           && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
    2049                 :            :           /* Don't warn about friends, let add_friend take care of it.  */
    2050                 :         56 :           && ! (newdecl_is_friend || DECL_FRIEND_P (olddecl))
    2051                 :            :           /* Don't warn about declaration followed by specialization.  */
    2052                 :    1016980 :           && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2053                 :         12 :               || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
    2054                 :            :         {
    2055                 :         16 :           auto_diagnostic_group d;
    2056                 :          8 :           if (warning_at (newdecl_loc,
    2057                 :            :                           OPT_Wredundant_decls,
    2058                 :            :                           "redundant redeclaration of %qD in same scope",
    2059                 :            :                           newdecl))
    2060                 :          8 :             inform (olddecl_loc,
    2061                 :            :                     "previous declaration of %qD", olddecl);
    2062                 :            :         }
    2063                 :            : 
    2064                 :    1016960 :       if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
    2065                 :      56915 :             && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
    2066                 :            :         {
    2067                 :    1920200 :           if (DECL_DELETED_FN (newdecl))
    2068                 :            :             {
    2069                 :         24 :               auto_diagnostic_group d;
    2070                 :         12 :               error_at (newdecl_loc, "deleted definition of %qD", newdecl);
    2071                 :         12 :               inform (olddecl_loc,
    2072                 :            :                       "previous declaration of %qD", olddecl);
    2073                 :            :             }
    2074                 :    2880300 :           DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
    2075                 :            :         }
    2076                 :            :     }
    2077                 :            : 
    2078                 :            :   /* Deal with C++: must preserve virtual function table size.  */
    2079                 :    1350060 :   if (TREE_CODE (olddecl) == TYPE_DECL)
    2080                 :            :     {
    2081                 :       6492 :       tree newtype = TREE_TYPE (newdecl);
    2082                 :       6492 :       tree oldtype = TREE_TYPE (olddecl);
    2083                 :            : 
    2084                 :       6492 :       if (newtype != error_mark_node && oldtype != error_mark_node
    2085                 :      13389 :           && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
    2086                 :        405 :         CLASSTYPE_FRIEND_CLASSES (newtype)
    2087                 :        405 :           = CLASSTYPE_FRIEND_CLASSES (oldtype);
    2088                 :            : 
    2089                 :       6492 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2090                 :            :     }
    2091                 :            : 
    2092                 :            :   /* Copy all the DECL_... slots specified in the new decl except for
    2093                 :            :      any that we copy here from the old type.  */
    2094                 :    1350060 :   if (merge_attr)
    2095                 :    2586390 :     DECL_ATTRIBUTES (newdecl)
    2096                 :    1293190 :       = (*targetm.merge_decl_attributes) (olddecl, newdecl);
    2097                 :            :   else
    2098                 :      56862 :     DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    2099                 :            : 
    2100                 :    1350060 :   if (DECL_DECLARES_FUNCTION_P (olddecl))
    2101                 :            :     {
    2102                 :    2515620 :       olddecl_friend = DECL_FRIEND_P (olddecl);
    2103                 :    1257810 :       olddecl_hidden_friend = DECL_HIDDEN_FRIEND_P (olddecl);
    2104                 :    2515620 :       hidden_friend = (DECL_ANTICIPATED (olddecl)
    2105                 :     333358 :                        && DECL_HIDDEN_FRIEND_P (olddecl)
    2106                 :    1273100 :                        && newdecl_is_friend);
    2107                 :    1253210 :       if (!hidden_friend)
    2108                 :            :         {
    2109                 :    2506420 :           DECL_ANTICIPATED (olddecl) = 0;
    2110                 :    1253210 :           DECL_HIDDEN_FRIEND_P (olddecl) = 0;
    2111                 :            :         }
    2112                 :            :     }
    2113                 :            : 
    2114                 :    1350060 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2115                 :            :     {
    2116                 :     241161 :       tree old_result = DECL_TEMPLATE_RESULT (olddecl);
    2117                 :     241161 :       tree new_result = DECL_TEMPLATE_RESULT (newdecl);
    2118                 :     241161 :       TREE_TYPE (olddecl) = TREE_TYPE (old_result);
    2119                 :            : 
    2120                 :            :       /* The new decl should not already have gathered any
    2121                 :            :          specializations.  */
    2122                 :     241161 :       gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
    2123                 :            : 
    2124                 :     482322 :       DECL_ATTRIBUTES (old_result)
    2125                 :     241161 :         = (*targetm.merge_decl_attributes) (old_result, new_result);
    2126                 :            : 
    2127                 :     241161 :       if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2128                 :            :         {
    2129                 :     240850 :           if (DECL_SOURCE_LOCATION (newdecl)
    2130                 :     240850 :               != DECL_SOURCE_LOCATION (olddecl))
    2131                 :            :             {
    2132                 :            :               /* Per C++11 8.3.6/4, default arguments cannot be added in
    2133                 :            :                  later declarations of a function template.  */
    2134                 :     236341 :               check_redeclaration_no_default_args (newdecl);
    2135                 :            :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2136                 :            :                  argument expression, that declaration... shall be the only
    2137                 :            :                  declaration of the function or function template in the
    2138                 :            :                  translation unit."  */
    2139                 :     236341 :               check_no_redeclaration_friend_default_args
    2140                 :     236341 :                 (old_result, new_result, olddecl_hidden_friend);
    2141                 :            :             }
    2142                 :            : 
    2143                 :     240850 :           check_default_args (newdecl);
    2144                 :            : 
    2145                 :     591508 :           if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
    2146                 :     240882 :               && DECL_INITIAL (new_result))
    2147                 :            :             {
    2148                 :         32 :               if (DECL_INITIAL (old_result))
    2149                 :         16 :                 DECL_UNINLINABLE (old_result) = 1;
    2150                 :            :               else
    2151                 :         16 :                 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
    2152                 :         32 :               DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
    2153                 :         32 :               DECL_NOT_REALLY_EXTERN (old_result)
    2154                 :         32 :                 = DECL_NOT_REALLY_EXTERN (new_result);
    2155                 :         32 :               DECL_INTERFACE_KNOWN (old_result)
    2156                 :         32 :                 = DECL_INTERFACE_KNOWN (new_result);
    2157                 :         32 :               DECL_DECLARED_INLINE_P (old_result)
    2158                 :         32 :                 = DECL_DECLARED_INLINE_P (new_result);
    2159                 :         32 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2160                 :         32 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2161                 :            : 
    2162                 :            :             }
    2163                 :            :           else
    2164                 :            :             {
    2165                 :     240818 :               DECL_DECLARED_INLINE_P (old_result)
    2166                 :     240818 :                 |= DECL_DECLARED_INLINE_P (new_result);
    2167                 :     240818 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2168                 :     240818 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2169                 :     240818 :               check_redeclaration_exception_specification (newdecl, olddecl);
    2170                 :            : 
    2171                 :     240818 :               merge_attribute_bits (new_result, old_result);
    2172                 :            :             }
    2173                 :            :         }
    2174                 :            : 
    2175                 :            :       /* If the new declaration is a definition, update the file and
    2176                 :            :          line information on the declaration, and also make
    2177                 :            :          the old declaration the same definition.  */
    2178                 :     241161 :       if (DECL_INITIAL (new_result) != NULL_TREE)
    2179                 :            :         {
    2180                 :     181416 :           DECL_SOURCE_LOCATION (olddecl)
    2181                 :     362832 :             = DECL_SOURCE_LOCATION (old_result)
    2182                 :     181416 :             = DECL_SOURCE_LOCATION (newdecl);
    2183                 :     181416 :           DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
    2184                 :     181416 :           if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2185                 :            :             {
    2186                 :     181416 :               tree parm;
    2187                 :     181416 :               DECL_ARGUMENTS (old_result)
    2188                 :     181416 :                 = DECL_ARGUMENTS (new_result);
    2189                 :     688199 :               for (parm = DECL_ARGUMENTS (old_result); parm;
    2190                 :     506783 :                    parm = DECL_CHAIN (parm))
    2191                 :     506783 :                 DECL_CONTEXT (parm) = old_result;
    2192                 :            :             }
    2193                 :            :         }
    2194                 :            : 
    2195                 :     241161 :       return olddecl;
    2196                 :            :     }
    2197                 :            : 
    2198                 :    1108890 :   if (types_match)
    2199                 :            :     {
    2200                 :    1108630 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2201                 :    1016690 :         check_redeclaration_exception_specification (newdecl, olddecl);
    2202                 :            : 
    2203                 :            :       /* Automatically handles default parameters.  */
    2204                 :    1108630 :       tree oldtype = TREE_TYPE (olddecl);
    2205                 :    1108630 :       tree newtype;
    2206                 :            : 
    2207                 :            :       /* For typedefs use the old type, as the new type's DECL_NAME points
    2208                 :            :          at newdecl, which will be ggc_freed.  */
    2209                 :    1108630 :       if (TREE_CODE (newdecl) == TYPE_DECL)
    2210                 :            :         {
    2211                 :            :           /* But NEWTYPE might have an attribute, honor that.  */
    2212                 :       6492 :           tree tem = TREE_TYPE (newdecl);
    2213                 :       6492 :           newtype = oldtype;
    2214                 :            : 
    2215                 :       6492 :           if (TYPE_USER_ALIGN (tem))
    2216                 :            :             {
    2217                 :         50 :               if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2218                 :          6 :                 SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2219                 :         25 :               TYPE_USER_ALIGN (newtype) = true;
    2220                 :            :             }
    2221                 :            : 
    2222                 :            :           /* And remove the new type from the variants list.  */
    2223                 :       6492 :           if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2224                 :            :             {
    2225                 :         29 :               tree remove = TREE_TYPE (newdecl);
    2226                 :         29 :               if (TYPE_MAIN_VARIANT (remove) == remove)
    2227                 :            :                 {
    2228                 :         12 :                   gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2229                 :            :                   /* If remove is the main variant, no need to remove that
    2230                 :            :                      from the list.  One of the DECL_ORIGINAL_TYPE
    2231                 :            :                      variants, e.g. created for aligned attribute, might still
    2232                 :            :                      refer to the newdecl TYPE_DECL though, so remove that one
    2233                 :            :                      in that case.  */
    2234                 :         12 :                   if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
    2235                 :          8 :                     if (orig != remove)
    2236                 :          8 :                       for (tree t = TYPE_MAIN_VARIANT (orig); t;
    2237                 :          0 :                            t = TYPE_MAIN_VARIANT (t))
    2238                 :          8 :                         if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2239                 :            :                           {
    2240                 :          8 :                             TYPE_NEXT_VARIANT (t)
    2241                 :          8 :                               = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2242                 :          8 :                             break;
    2243                 :            :                           }
    2244                 :            :                 }           
    2245                 :            :               else
    2246                 :         17 :                 for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2247                 :         17 :                      t = TYPE_NEXT_VARIANT (t))
    2248                 :         17 :                   if (TYPE_NEXT_VARIANT (t) == remove)
    2249                 :            :                     {
    2250                 :         17 :                       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2251                 :         17 :                       break;
    2252                 :            :                     }
    2253                 :            :             }
    2254                 :            :         }
    2255                 :    1102140 :       else if (merge_attr)
    2256                 :    1045270 :         newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
    2257                 :            :       else
    2258                 :      56862 :         newtype = TREE_TYPE (newdecl);
    2259                 :            : 
    2260                 :    1108630 :       if (VAR_P (newdecl))
    2261                 :            :         {
    2262                 :      85441 :           DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
    2263                 :            :           /* For already initialized vars, TREE_READONLY could have been
    2264                 :            :              cleared in cp_finish_decl, because the var needs runtime
    2265                 :            :              initialization or destruction.  Make sure not to set
    2266                 :            :              TREE_READONLY on it again.  */
    2267                 :      85441 :           if (DECL_INITIALIZED_P (olddecl)
    2268                 :       1200 :               && !DECL_EXTERNAL (olddecl)
    2269                 :      85514 :               && !TREE_READONLY (olddecl))
    2270                 :         30 :             TREE_READONLY (newdecl) = 0;
    2271                 :      85441 :           DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
    2272                 :      85441 :           DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
    2273                 :      85441 :             |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
    2274                 :      85441 :           if (DECL_DEPENDENT_INIT_P (olddecl))
    2275                 :      29716 :             SET_DECL_DEPENDENT_INIT_P (newdecl, true);
    2276                 :     170882 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
    2277                 :      85441 :             |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
    2278                 :      85441 :           DECL_DECLARED_CONSTEXPR_P (newdecl)
    2279                 :     170882 :             |= DECL_DECLARED_CONSTEXPR_P (olddecl);
    2280                 :            : 
    2281                 :            :           /* Merge the threadprivate attribute from OLDDECL into NEWDECL.  */
    2282                 :      85441 :           if (DECL_LANG_SPECIFIC (olddecl)
    2283                 :     167443 :               && CP_DECL_THREADPRIVATE_P (olddecl))
    2284                 :            :             {
    2285                 :            :               /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed.  */
    2286                 :         19 :               retrofit_lang_decl (newdecl);
    2287                 :         19 :               CP_DECL_THREADPRIVATE_P (newdecl) = 1;
    2288                 :            :             }
    2289                 :            :         }
    2290                 :            : 
    2291                 :            :       /* An explicit specialization of a function template or of a member
    2292                 :            :          function of a class template can be declared transaction_safe
    2293                 :            :          independently of whether the corresponding template entity is declared
    2294                 :            :          transaction_safe. */
    2295                 :        931 :       if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
    2296                 :        818 :           && DECL_TEMPLATE_INSTANTIATION (olddecl)
    2297                 :         50 :           && DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2298                 :         50 :           && tx_safe_fn_type_p (newtype)
    2299                 :    1108630 :           && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
    2300                 :          0 :         newtype = tx_unsafe_fn_variant (newtype);
    2301                 :            : 
    2302                 :    1108630 :       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
    2303                 :            : 
    2304                 :    1108630 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2305                 :    1016690 :         check_default_args (newdecl);
    2306                 :            : 
    2307                 :            :       /* Lay the type out, unless already done.  */
    2308                 :    1108630 :       if (! same_type_p (newtype, oldtype)
    2309                 :        219 :           && TREE_TYPE (newdecl) != error_mark_node
    2310                 :    1108850 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2311                 :        123 :         layout_type (TREE_TYPE (newdecl));
    2312                 :            : 
    2313                 :    1108630 :       if ((VAR_P (newdecl)
    2314                 :    1023190 :            || TREE_CODE (newdecl) == PARM_DECL
    2315                 :    1023190 :            || TREE_CODE (newdecl) == RESULT_DECL
    2316                 :    1023190 :            || TREE_CODE (newdecl) == FIELD_DECL
    2317                 :    1023190 :            || TREE_CODE (newdecl) == TYPE_DECL)
    2318                 :    1115120 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2319                 :      39800 :         layout_decl (newdecl, 0);
    2320                 :            : 
    2321                 :            :       /* Merge deprecatedness.  */
    2322                 :    1108630 :       if (TREE_DEPRECATED (newdecl))
    2323                 :          4 :         TREE_DEPRECATED (olddecl) = 1;
    2324                 :            : 
    2325                 :            :       /* Preserve function specific target and optimization options */
    2326                 :    1108630 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2327                 :            :         {
    2328                 :    1016690 :           if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    2329                 :    1016690 :               && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    2330                 :          0 :             DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    2331                 :          0 :               = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    2332                 :            : 
    2333                 :    1016690 :           if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    2334                 :    1016690 :               && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    2335                 :          4 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    2336                 :          4 :               = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    2337                 :            :         }
    2338                 :            :       else
    2339                 :            :         {
    2340                 :            :           /* Merge the const type qualifier.  */
    2341                 :      91933 :           if (TREE_READONLY (newdecl))
    2342                 :       9228 :             TREE_READONLY (olddecl) = 1;
    2343                 :            :           /* Merge the volatile type qualifier.  */
    2344                 :      91933 :           if (TREE_THIS_VOLATILE (newdecl))
    2345                 :          2 :             TREE_THIS_VOLATILE (olddecl) = 1;
    2346                 :            :         }
    2347                 :            : 
    2348                 :            :       /* Merge the initialization information.  */
    2349                 :    1108630 :       if (DECL_INITIAL (newdecl) == NULL_TREE
    2350                 :    1639470 :           && DECL_INITIAL (olddecl) != NULL_TREE)
    2351                 :            :         {
    2352                 :      57389 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2353                 :      57389 :           DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2354                 :      57389 :           if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2355                 :            :             {
    2356                 :       2572 :               DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    2357                 :       2572 :               DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    2358                 :            :             }
    2359                 :            :         }
    2360                 :            : 
    2361                 :    1108630 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2362                 :            :         {
    2363                 :    1016690 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2364                 :    1016690 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2365                 :    1016690 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2366                 :    1016690 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2367                 :      10254 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2368                 :    1016690 :           DECL_LOOPING_CONST_OR_PURE_P (newdecl)
    2369                 :    1016690 :             |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
    2370                 :            : 
    2371                 :    1016690 :           if (merge_attr)
    2372                 :     959832 :             merge_attribute_bits (newdecl, olddecl);
    2373                 :            :           else
    2374                 :            :             {
    2375                 :            :               /* Merge the noreturn bit.  */
    2376                 :      56862 :               TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    2377                 :      56862 :               TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    2378                 :      56862 :               TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    2379                 :      56862 :               DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
    2380                 :      56862 :               DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
    2381                 :            :             }
    2382                 :            :           /* Keep the old RTL.  */
    2383                 :    1016690 :           COPY_DECL_RTL (olddecl, newdecl);
    2384                 :            :         }
    2385                 :      91933 :       else if (VAR_P (newdecl)
    2386                 :     199710 :                && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
    2387                 :            :         {
    2388                 :            :           /* Keep the old RTL.  We cannot keep the old RTL if the old
    2389                 :            :              declaration was for an incomplete object and the new
    2390                 :            :              declaration is not since many attributes of the RTL will
    2391                 :            :              change.  */
    2392                 :      85324 :           COPY_DECL_RTL (olddecl, newdecl);
    2393                 :            :         }
    2394                 :            :     }
    2395                 :            :   /* If cannot merge, then use the new type and qualifiers,
    2396                 :            :      and don't preserve the old rtl.  */
    2397                 :            :   else
    2398                 :            :     {
    2399                 :            :       /* Clean out any memory we had of the old declaration.  */
    2400                 :        267 :       tree oldstatic = value_member (olddecl, static_aggregates);
    2401                 :        267 :       if (oldstatic)
    2402                 :          0 :         TREE_VALUE (oldstatic) = error_mark_node;
    2403                 :            : 
    2404                 :        267 :       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
    2405                 :        267 :       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    2406                 :        267 :       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    2407                 :        267 :       TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    2408                 :        267 :       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
    2409                 :            :     }
    2410                 :            : 
    2411                 :            :   /* Merge the storage class information.  */
    2412                 :    1108890 :   merge_weak (newdecl, olddecl);
    2413                 :            : 
    2414                 :    1108890 :   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
    2415                 :    1108890 :   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    2416                 :    1108890 :   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
    2417                 :    1108890 :   if (! DECL_EXTERNAL (olddecl))
    2418                 :      15408 :     DECL_EXTERNAL (newdecl) = 0;
    2419                 :    1108890 :   if (! DECL_COMDAT (olddecl))
    2420                 :     602094 :     DECL_COMDAT (newdecl) = 0;
    2421                 :            : 
    2422                 :    1108890 :   new_template_info = NULL_TREE;
    2423                 :    2207860 :   if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
    2424                 :            :     {
    2425                 :    1098960 :       bool new_redefines_gnu_inline = false;
    2426                 :            : 
    2427                 :    1098960 :       if (new_defines_function
    2428                 :    1098960 :           && ((DECL_INTERFACE_KNOWN (olddecl)
    2429                 :     577780 :                && TREE_CODE (olddecl) == FUNCTION_DECL)
    2430                 :     576994 :               || (TREE_CODE (olddecl) == TEMPLATE_DECL
    2431                 :          0 :                   && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
    2432                 :            :                       == FUNCTION_DECL))))
    2433                 :            :         {
    2434                 :        786 :           tree fn = olddecl;
    2435                 :            : 
    2436                 :        786 :           if (TREE_CODE (fn) == TEMPLATE_DECL)
    2437                 :          0 :             fn = DECL_TEMPLATE_RESULT (olddecl);
    2438                 :            : 
    2439                 :       1014 :           new_redefines_gnu_inline = GNU_INLINE_P (fn) && DECL_INITIAL (fn);
    2440                 :            :         }
    2441                 :            : 
    2442                 :        786 :       if (!new_redefines_gnu_inline)
    2443                 :            :         {
    2444                 :    1098860 :           DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
    2445                 :    1098860 :           DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
    2446                 :    1098860 :           DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
    2447                 :            :         }
    2448                 :    2197930 :       DECL_TEMPLATE_INSTANTIATED (newdecl)
    2449                 :    1098960 :         |= DECL_TEMPLATE_INSTANTIATED (olddecl);
    2450                 :    3132880 :       DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
    2451                 :            : 
    2452                 :            :       /* If the OLDDECL is an instantiation and/or specialization,
    2453                 :            :          then the NEWDECL must be too.  But, it may not yet be marked
    2454                 :            :          as such if the caller has created NEWDECL, but has not yet
    2455                 :            :          figured out that it is a redeclaration.  */
    2456                 :    1098960 :       if (!DECL_USE_TEMPLATE (newdecl))
    2457                 :    1041840 :         DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
    2458                 :            : 
    2459                 :            :       /* Don't really know how much of the language-specific
    2460                 :            :          values we should copy from old to new.  */
    2461                 :    1098960 :       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
    2462                 :    2197930 :       DECL_INITIALIZED_IN_CLASS_P (newdecl)
    2463                 :    1098960 :         |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
    2464                 :            : 
    2465                 :    1098960 :       if (LANG_DECL_HAS_MIN (newdecl))
    2466                 :            :         {
    2467                 :    1098960 :           DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
    2468                 :    1098960 :           if (DECL_TEMPLATE_INFO (newdecl))
    2469                 :            :             {
    2470                 :      57200 :               new_template_info = DECL_TEMPLATE_INFO (newdecl);
    2471                 :      57200 :               if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    2472                 :     114115 :                   && DECL_TEMPLATE_SPECIALIZATION (newdecl))
    2473                 :            :                 /* Remember the presence of explicit specialization args.  */
    2474                 :      56862 :                 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
    2475                 :     113724 :                   = TINFO_USED_TEMPLATE_ID (new_template_info);
    2476                 :            :             }
    2477                 :    1098960 :           DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
    2478                 :            :         }
    2479                 :            : 
    2480                 :    1098960 :       if (DECL_DECLARES_FUNCTION_P (newdecl))
    2481                 :            :         {
    2482                 :            :           /* Only functions have these fields.  */
    2483                 :    3050880 :           DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
    2484                 :          0 :           DECL_BEFRIENDING_CLASSES (newdecl)
    2485                 :    1016960 :             = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
    2486                 :    2033920 :                        DECL_BEFRIENDING_CLASSES (olddecl));
    2487                 :            :           /* DECL_THUNKS is only valid for virtual functions,
    2488                 :            :              otherwise it is a DECL_FRIEND_CONTEXT.  */
    2489                 :    1016960 :           if (DECL_VIRTUAL_P (newdecl))
    2490                 :     135756 :             SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
    2491                 :            :         }
    2492                 :      82002 :       else if (VAR_P (newdecl))
    2493                 :            :         {
    2494                 :            :           /* Only variables have this field.  */
    2495                 :      82002 :           if (VAR_HAD_UNKNOWN_BOUND (olddecl))
    2496                 :        215 :             SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
    2497                 :            :         }
    2498                 :            :     }
    2499                 :            : 
    2500                 :    1108890 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2501                 :            :     {
    2502                 :    1016960 :       tree parm;
    2503                 :            : 
    2504                 :            :       /* Merge parameter attributes. */
    2505                 :    1016960 :       tree oldarg, newarg;
    2506                 :    1016960 :       for (oldarg = DECL_ARGUMENTS(olddecl),  newarg = DECL_ARGUMENTS(newdecl);
    2507                 :    2771010 :            oldarg && newarg;
    2508                 :    1754050 :            oldarg = DECL_CHAIN(oldarg), newarg = DECL_CHAIN(newarg))
    2509                 :            :         {
    2510                 :    3508100 :           DECL_ATTRIBUTES (newarg)
    2511                 :    1754050 :             = (*targetm.merge_decl_attributes) (oldarg, newarg);
    2512                 :    1754050 :           DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    2513                 :            :         }
    2514                 :            : 
    2515                 :    1016960 :       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    2516                 :    1073880 :           && !DECL_TEMPLATE_INSTANTIATION (newdecl))
    2517                 :            :         {
    2518                 :            :           /* If newdecl is not a specialization, then it is not a
    2519                 :            :              template-related function at all.  And that means that we
    2520                 :            :              should have exited above, returning 0.  */
    2521                 :      56862 :           gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
    2522                 :            : 
    2523                 :     113724 :           if (DECL_ODR_USED (olddecl))
    2524                 :            :             /* From [temp.expl.spec]:
    2525                 :            : 
    2526                 :            :                If a template, a member template or the member of a class
    2527                 :            :                template is explicitly specialized then that
    2528                 :            :                specialization shall be declared before the first use of
    2529                 :            :                that specialization that would cause an implicit
    2530                 :            :                instantiation to take place, in every translation unit in
    2531                 :            :                which such a use occurs.  */
    2532                 :          0 :             error ("explicit specialization of %qD after first use",
    2533                 :            :                       olddecl);
    2534                 :            : 
    2535                 :      56862 :           SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
    2536                 :     113724 :           DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
    2537                 :     113700 :                                    && DECL_DECLARED_INLINE_P (newdecl));
    2538                 :            : 
    2539                 :            :           /* Don't propagate visibility from the template to the
    2540                 :            :              specialization here.  We'll do that in determine_visibility if
    2541                 :            :              appropriate.  */
    2542                 :      56862 :           DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
    2543                 :            : 
    2544                 :            :           /* [temp.expl.spec/14] We don't inline explicit specialization
    2545                 :            :              just because the primary template says so.  */
    2546                 :      56862 :           gcc_assert (!merge_attr);
    2547                 :            : 
    2548                 :      56862 :           DECL_DECLARED_INLINE_P (olddecl)
    2549                 :      56862 :             = DECL_DECLARED_INLINE_P (newdecl);
    2550                 :            : 
    2551                 :      56862 :           DECL_DISREGARD_INLINE_LIMITS (olddecl)
    2552                 :      56862 :             = DECL_DISREGARD_INLINE_LIMITS (newdecl);
    2553                 :            : 
    2554                 :      56862 :           DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
    2555                 :            :         }
    2556                 :     960099 :       else if (new_defines_function && DECL_INITIAL (olddecl))
    2557                 :            :         {
    2558                 :            :           /* Never inline re-defined extern inline functions.
    2559                 :            :              FIXME: this could be better handled by keeping both
    2560                 :            :              function as separate declarations.  */
    2561                 :        100 :           DECL_UNINLINABLE (newdecl) = 1;
    2562                 :            :         }
    2563                 :            :       else
    2564                 :            :         {
    2565                 :    1920000 :           if (DECL_PENDING_INLINE_P (olddecl))
    2566                 :            :             {
    2567                 :         16 :               DECL_PENDING_INLINE_P (newdecl) = 1;
    2568                 :          8 :               DECL_PENDING_INLINE_INFO (newdecl)
    2569                 :         24 :                 = DECL_PENDING_INLINE_INFO (olddecl);
    2570                 :            :             }
    2571                 :    1919980 :           else if (DECL_PENDING_INLINE_P (newdecl))
    2572                 :            :             ;
    2573                 :     959991 :           else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
    2574                 :     959991 :             DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
    2575                 :     959991 :               = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
    2576                 :            : 
    2577                 :     959999 :           DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
    2578                 :            : 
    2579                 :     959999 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    2580                 :    2877180 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    2581                 :            : 
    2582                 :     959999 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    2583                 :     959999 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    2584                 :     959999 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    2585                 :    1815540 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    2586                 :            :         }
    2587                 :            : 
    2588                 :            :       /* Preserve abstractness on cloned [cd]tors.  */
    2589                 :    1016960 :       DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
    2590                 :            : 
    2591                 :            :       /* Update newdecl's parms to point at olddecl.  */
    2592                 :    3329690 :       for (parm = DECL_ARGUMENTS (newdecl); parm;
    2593                 :    2312730 :            parm = DECL_CHAIN (parm))
    2594                 :    2312730 :         DECL_CONTEXT (parm) = olddecl;
    2595                 :            : 
    2596                 :    1016960 :       if (! types_match)
    2597                 :            :         {
    2598                 :        267 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    2599                 :        267 :           COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
    2600                 :        267 :           COPY_DECL_RTL (newdecl, olddecl);
    2601                 :            :         }
    2602                 :    1016960 :       if (! types_match || new_defines_function)
    2603                 :            :         {
    2604                 :            :           /* These need to be copied so that the names are available.
    2605                 :            :              Note that if the types do match, we'll preserve inline
    2606                 :            :              info and other bits, but if not, we won't.  */
    2607                 :     578047 :           DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
    2608                 :     578047 :           DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
    2609                 :            :         }
    2610                 :            :       /* If redeclaring a builtin function, it stays built in
    2611                 :            :          if newdecl is a gnu_inline definition, or if newdecl is just
    2612                 :            :          a declaration.  */
    2613                 :    1016960 :       if (fndecl_built_in_p (olddecl)
    2614                 :    1037450 :           && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
    2615                 :            :         {
    2616                 :     346210 :           copy_decl_built_in_function (newdecl, olddecl);
    2617                 :            :           /* If we're keeping the built-in definition, keep the rtl,
    2618                 :            :              regardless of declaration matches.  */
    2619                 :     346210 :           COPY_DECL_RTL (olddecl, newdecl);
    2620                 :     346210 :           if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    2621                 :            :             {
    2622                 :     346206 :               enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    2623                 :     346206 :               switch (fncode)
    2624                 :            :                 {
    2625                 :            :                   /* If a compatible prototype of these builtin functions
    2626                 :            :                      is seen, assume the runtime implements it with the
    2627                 :            :                      expected semantics.  */
    2628                 :        573 :                 case BUILT_IN_STPCPY:
    2629                 :        573 :                   if (builtin_decl_explicit_p (fncode))
    2630                 :        573 :                     set_builtin_decl_implicit_p (fncode, true);
    2631                 :            :                   break;
    2632                 :     345633 :                 default:
    2633                 :     345633 :                   if (builtin_decl_explicit_p (fncode))
    2634                 :     345633 :                     set_builtin_decl_declared_p (fncode, true);
    2635                 :            :                   break;
    2636                 :            :                 }
    2637                 :            : 
    2638                 :     346206 :               copy_attributes_to_builtin (newdecl);
    2639                 :            :             }
    2640                 :            :         }
    2641                 :    1016960 :       if (new_defines_function)
    2642                 :            :         /* If defining a function declared with other language
    2643                 :            :            linkage, use the previously declared language linkage.  */
    2644                 :    1155560 :         SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    2645                 :     439181 :       else if (types_match)
    2646                 :            :         {
    2647                 :     438914 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    2648                 :            :           /* Don't clear out the arguments if we're just redeclaring a
    2649                 :            :              function.  */
    2650                 :     438914 :           if (DECL_ARGUMENTS (olddecl))
    2651                 :      87854 :             DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
    2652                 :            :         }
    2653                 :            :     }
    2654                 :      91933 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    2655                 :          0 :     NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
    2656                 :            : 
    2657                 :            :   /* Now preserve various other info from the definition.  */
    2658                 :    1108890 :   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
    2659                 :    1108890 :   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
    2660                 :    1108890 :   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    2661                 :    1108890 :   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    2662                 :            : 
    2663                 :            :   /* Warn about conflicting visibility specifications.  */
    2664                 :    1108890 :   if (DECL_VISIBILITY_SPECIFIED (olddecl)
    2665                 :     433840 :       && DECL_VISIBILITY_SPECIFIED (newdecl)
    2666                 :    1109150 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    2667                 :            :     {
    2668                 :         28 :       auto_diagnostic_group d;
    2669                 :         14 :       if (warning_at (newdecl_loc, OPT_Wattributes,
    2670                 :            :                       "%qD: visibility attribute ignored because it "
    2671                 :            :                       "conflicts with previous declaration", newdecl))
    2672                 :         14 :         inform (olddecl_loc,
    2673                 :            :                 "previous declaration of %qD", olddecl);
    2674                 :            :     }
    2675                 :            :   /* Choose the declaration which specified visibility.  */
    2676                 :    1108890 :   if (DECL_VISIBILITY_SPECIFIED (olddecl))
    2677                 :            :     {
    2678                 :     433840 :       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    2679                 :     433840 :       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    2680                 :            :     }
    2681                 :            :   /* Init priority used to be merged from newdecl to olddecl by the memcpy,
    2682                 :            :      so keep this behavior.  */
    2683                 :    1108890 :   if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
    2684                 :            :     {
    2685                 :          4 :       SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
    2686                 :          4 :       DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
    2687                 :            :     }
    2688                 :            :   /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED.  */
    2689                 :    2217790 :   if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    2690                 :            :     {
    2691                 :         59 :       SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    2692                 :         59 :       DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    2693                 :            :     }
    2694                 :    1108890 :   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    2695                 :    2217790 :   if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    2696                 :    1108890 :       > DECL_WARN_IF_NOT_ALIGN (newdecl))
    2697                 :          0 :     SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    2698                 :            :                                 DECL_WARN_IF_NOT_ALIGN (olddecl));
    2699                 :    1108890 :   if (TREE_CODE (newdecl) == FIELD_DECL)
    2700                 :          0 :     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
    2701                 :            : 
    2702                 :            :   /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
    2703                 :            :      with that from NEWDECL below.  */
    2704                 :    1108890 :   if (DECL_LANG_SPECIFIC (olddecl))
    2705                 :            :     {
    2706                 :    1098960 :       gcc_assert (DECL_LANG_SPECIFIC (olddecl)
    2707                 :            :                   != DECL_LANG_SPECIFIC (newdecl));
    2708                 :    1098960 :       ggc_free (DECL_LANG_SPECIFIC (olddecl));
    2709                 :            :     }
    2710                 :            : 
    2711                 :            :   /* Merge the USED information.  */
    2712                 :    1108890 :   if (TREE_USED (olddecl))
    2713                 :      35848 :     TREE_USED (newdecl) = 1;
    2714                 :    1073050 :   else if (TREE_USED (newdecl))
    2715                 :         22 :     TREE_USED (olddecl) = 1;
    2716                 :    1108890 :   if (VAR_P (newdecl))
    2717                 :            :     {
    2718                 :      85441 :       if (DECL_READ_P (olddecl))
    2719                 :       7781 :         DECL_READ_P (newdecl) = 1;
    2720                 :      77660 :       else if (DECL_READ_P (newdecl))
    2721                 :          0 :         DECL_READ_P (olddecl) = 1;
    2722                 :            :     }
    2723                 :    1108890 :   if (DECL_PRESERVE_P (olddecl))
    2724                 :         28 :     DECL_PRESERVE_P (newdecl) = 1;
    2725                 :    1108870 :   else if (DECL_PRESERVE_P (newdecl))
    2726                 :         28 :     DECL_PRESERVE_P (olddecl) = 1;
    2727                 :            : 
    2728                 :            :   /* Merge the DECL_FUNCTION_VERSIONED information.  newdecl will be copied
    2729                 :            :      to olddecl and deleted.  */
    2730                 :    1108890 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    2731                 :    2125860 :       && DECL_FUNCTION_VERSIONED (olddecl))
    2732                 :            :     {
    2733                 :            :       /* Set the flag for newdecl so that it gets copied to olddecl.  */
    2734                 :        344 :       DECL_FUNCTION_VERSIONED (newdecl) = 1;
    2735                 :            :       /* newdecl will be purged after copying to olddecl and is no longer
    2736                 :            :          a version.  */
    2737                 :        344 :       cgraph_node::delete_function_version_by_decl (newdecl);
    2738                 :            :     }
    2739                 :            : 
    2740                 :    1108890 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2741                 :            :     {
    2742                 :    1016960 :       int function_size;
    2743                 :    1016960 :       struct symtab_node *snode = symtab_node::get (olddecl);
    2744                 :            : 
    2745                 :    1016960 :       function_size = sizeof (struct tree_decl_common);
    2746                 :            : 
    2747                 :    1016960 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    2748                 :            :               (char *) newdecl + sizeof (struct tree_common),
    2749                 :            :               function_size - sizeof (struct tree_common));
    2750                 :            : 
    2751                 :    1016960 :       memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    2752                 :            :               (char *) newdecl + sizeof (struct tree_decl_common),
    2753                 :            :               sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
    2754                 :            : 
    2755                 :            :       /* Preserve symtab node mapping.  */
    2756                 :    1016960 :       olddecl->decl_with_vis.symtab_node = snode;
    2757                 :            : 
    2758                 :    1016960 :       if (new_template_info)
    2759                 :            :         /* If newdecl is a template instantiation, it is possible that
    2760                 :            :            the following sequence of events has occurred:
    2761                 :            : 
    2762                 :            :            o A friend function was declared in a class template.  The
    2763                 :            :            class template was instantiated.
    2764                 :            : 
    2765                 :            :            o The instantiation of the friend declaration was
    2766                 :            :            recorded on the instantiation list, and is newdecl.
    2767                 :            : 
    2768                 :            :            o Later, however, instantiate_class_template called pushdecl
    2769                 :            :            on the newdecl to perform name injection.  But, pushdecl in
    2770                 :            :            turn called duplicate_decls when it discovered that another
    2771                 :            :            declaration of a global function with the same name already
    2772                 :            :            existed.
    2773                 :            : 
    2774                 :            :            o Here, in duplicate_decls, we decided to clobber newdecl.
    2775                 :            : 
    2776                 :            :            If we're going to do that, we'd better make sure that
    2777                 :            :            olddecl, and not newdecl, is on the list of
    2778                 :            :            instantiations so that if we try to do the instantiation
    2779                 :            :            again we won't get the clobbered declaration.  */
    2780                 :      57200 :         reregister_specialization (newdecl,
    2781                 :            :                                    new_template_info,
    2782                 :            :                                    olddecl);
    2783                 :            :     }
    2784                 :            :   else
    2785                 :            :     {
    2786                 :      91933 :       size_t size = tree_code_size (TREE_CODE (newdecl));
    2787                 :            : 
    2788                 :      91933 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    2789                 :            :               (char *) newdecl + sizeof (struct tree_common),
    2790                 :            :               sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    2791                 :      91933 :       switch (TREE_CODE (newdecl))
    2792                 :            :         {
    2793                 :      91933 :         case LABEL_DECL:
    2794                 :      91933 :         case VAR_DECL:
    2795                 :      91933 :         case RESULT_DECL:
    2796                 :      91933 :         case PARM_DECL:
    2797                 :      91933 :         case FIELD_DECL:
    2798                 :      91933 :         case TYPE_DECL:
    2799                 :      91933 :         case CONST_DECL:
    2800                 :      91933 :           {
    2801                 :      91933 :             struct symtab_node *snode = NULL;
    2802                 :            : 
    2803                 :      91933 :             if (VAR_P (newdecl)
    2804                 :      91933 :                 && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
    2805                 :          3 :                     || DECL_EXTERNAL (olddecl)))
    2806                 :      85441 :               snode = symtab_node::get (olddecl);
    2807                 :      91933 :             memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    2808                 :            :                     (char *) newdecl + sizeof (struct tree_decl_common),
    2809                 :            :                     size - sizeof (struct tree_decl_common)
    2810                 :      91933 :                     + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    2811                 :      91933 :             if (VAR_P (newdecl))
    2812                 :      85441 :               olddecl->decl_with_vis.symtab_node = snode;
    2813                 :            :           }
    2814                 :            :           break;
    2815                 :          0 :         default:
    2816                 :          0 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    2817                 :            :                   (char *) newdecl + sizeof (struct tree_decl_common),
    2818                 :            :                   sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
    2819                 :          0 :                   + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    2820                 :          0 :           break;
    2821                 :            :         }
    2822                 :            :     }
    2823                 :            : 
    2824                 :    1108890 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    2825                 :            :     {
    2826                 :    1102400 :       if (DECL_EXTERNAL (olddecl)
    2827                 :    1102400 :           || TREE_PUBLIC (olddecl)
    2828                 :    1102400 :           || TREE_STATIC (olddecl))
    2829                 :            :         {
    2830                 :            :           /* Merge the section attribute.
    2831                 :            :              We want to issue an error if the sections conflict but that must be
    2832                 :            :              done later in decl_attributes since we are called before attributes
    2833                 :            :              are assigned.  */
    2834                 :    1102400 :           if (DECL_SECTION_NAME (newdecl) != NULL)
    2835                 :          7 :             set_decl_section_name (olddecl, DECL_SECTION_NAME (newdecl));
    2836                 :            : 
    2837                 :    1102400 :           if (DECL_ONE_ONLY (newdecl))
    2838                 :            :             {
    2839                 :          0 :               struct symtab_node *oldsym, *newsym;
    2840                 :          0 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2841                 :          0 :                 oldsym = cgraph_node::get_create (olddecl);
    2842                 :            :               else
    2843                 :          0 :                 oldsym = varpool_node::get_create (olddecl);
    2844                 :          0 :               newsym = symtab_node::get (newdecl);
    2845                 :          0 :               oldsym->set_comdat_group (newsym->get_comdat_group ());
    2846                 :            :             }
    2847                 :            :         }
    2848                 :            : 
    2849                 :    1102400 :       if (VAR_P (newdecl)
    2850                 :    1102400 :           && CP_DECL_THREAD_LOCAL_P (newdecl))
    2851                 :            :         {
    2852                 :        374 :           CP_DECL_THREAD_LOCAL_P (olddecl) = true;
    2853                 :        374 :           if (!processing_template_decl)
    2854                 :        364 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    2855                 :            :         }
    2856                 :            :     }
    2857                 :            : 
    2858                 :    1108890 :   DECL_UID (olddecl) = olddecl_uid;
    2859                 :    1108890 :   if (olddecl_friend)
    2860                 :      11742 :     DECL_FRIEND_P (olddecl) = 1;
    2861                 :    1108890 :   if (hidden_friend)
    2862                 :            :     {
    2863                 :        164 :       DECL_ANTICIPATED (olddecl) = 1;
    2864                 :         82 :       DECL_HIDDEN_FRIEND_P (olddecl) = 1;
    2865                 :            :     }
    2866                 :            : 
    2867                 :            :   /* NEWDECL contains the merged attribute lists.
    2868                 :            :      Update OLDDECL to be the same.  */
    2869                 :    1108890 :   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    2870                 :            : 
    2871                 :            :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    2872                 :            :     so that encode_section_info has a chance to look at the new decl
    2873                 :            :     flags and attributes.  */
    2874                 :    1108890 :   if (DECL_RTL_SET_P (olddecl)
    2875                 :    1108890 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    2876                 :          0 :           || (VAR_P (olddecl)
    2877                 :          0 :               && TREE_STATIC (olddecl))))
    2878                 :          0 :     make_decl_rtl (olddecl);
    2879                 :            : 
    2880                 :            :   /* The NEWDECL will no longer be needed.  Because every out-of-class
    2881                 :            :      declaration of a member results in a call to duplicate_decls,
    2882                 :            :      freeing these nodes represents in a significant savings.
    2883                 :            : 
    2884                 :            :      Before releasing the node, be sore to remove function from symbol
    2885                 :            :      table that might have been inserted there to record comdat group.
    2886                 :            :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    2887                 :            :      structure is shared in between newdecl and oldecl.  */
    2888                 :    1108890 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2889                 :    1016960 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    2890                 :    1108890 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    2891                 :            :     {
    2892                 :    1102400 :       struct symtab_node *snode = symtab_node::get (newdecl);
    2893                 :    1102400 :       if (snode)
    2894                 :        387 :         snode->remove ();
    2895                 :            :     }
    2896                 :            : 
    2897                 :            :   /* Remove the associated constraints for newdecl, if any, before
    2898                 :            :      reclaiming memory. */
    2899                 :    1108890 :   if (flag_concepts)
    2900                 :     188246 :     remove_constraints (newdecl);
    2901                 :            : 
    2902                 :    1108890 :   ggc_free (newdecl);
    2903                 :            : 
    2904                 :    1108890 :   return olddecl;
    2905                 :            : }
    2906                 :            : 
    2907                 :            : /* Return zero if the declaration NEWDECL is valid
    2908                 :            :    when the declaration OLDDECL (assumed to be for the same name)
    2909                 :            :    has already been seen.
    2910                 :            :    Otherwise return an error message format string with a %s
    2911                 :            :    where the identifier should go.  */
    2912                 :            : 
    2913                 :            : static const char *
    2914                 :    1010920 : redeclaration_error_message (tree newdecl, tree olddecl)
    2915                 :            : {
    2916                 :    1010920 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    2917                 :            :     {
    2918                 :            :       /* Because C++ can put things into name space for free,
    2919                 :            :          constructs like "typedef struct foo { ... } foo"
    2920                 :            :          would look like an erroneous redeclaration.  */
    2921                 :      13566 :       if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
    2922                 :            :         return NULL;
    2923                 :            :       else
    2924                 :          0 :         return G_("redefinition of %q#D");
    2925                 :            :     }
    2926                 :     997354 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2927                 :            :     {
    2928                 :            :       /* If this is a pure function, its olddecl will actually be
    2929                 :            :          the original initialization to `0' (which we force to call
    2930                 :            :          abort()).  Don't complain about redefinition in this case.  */
    2931                 :    2010710 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
    2932                 :     670261 :           && DECL_INITIAL (olddecl) == NULL_TREE)
    2933                 :            :         return NULL;
    2934                 :            : 
    2935                 :            :       /* If both functions come from different namespaces, this is not
    2936                 :            :          a redeclaration - this is a conflict with a used function.  */
    2937                 :    1340430 :       if (DECL_NAMESPACE_SCOPE_P (olddecl)
    2938                 :     198101 :           && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
    2939                 :     670221 :           && ! decls_match (olddecl, newdecl))
    2940                 :            :         return G_("%qD conflicts with used function");
    2941                 :            : 
    2942                 :            :       /* We'll complain about linkage mismatches in
    2943                 :            :          warn_extern_redeclared_static.  */
    2944                 :            : 
    2945                 :            :       /* Defining the same name twice is no good.  */
    2946                 :     670217 :       if (decl_defined_p (olddecl)
    2947                 :     670217 :           && decl_defined_p (newdecl))
    2948                 :            :         {
    2949                 :        368 :           if (DECL_NAME (olddecl) == NULL_TREE)
    2950                 :            :             return G_("%q#D not declared in class");
    2951                 :        532 :           else if (!GNU_INLINE_P (olddecl)
    2952                 :        492 :                    || GNU_INLINE_P (newdecl))
    2953                 :        260 :             return G_("redefinition of %q#D");
    2954                 :            :         }
    2955                 :            : 
    2956                 :     733322 :       if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
    2957                 :            :         {
    2958                 :      57791 :           bool olda = GNU_INLINE_P (olddecl);
    2959                 :     115582 :           bool newa = GNU_INLINE_P (newdecl);
    2960                 :            : 
    2961                 :      57791 :           if (olda != newa)
    2962                 :            :             {
    2963                 :         20 :               if (newa)
    2964                 :            :                 return G_("%q+D redeclared inline with "
    2965                 :            :                           "%<gnu_inline%> attribute");
    2966                 :            :               else
    2967                 :         12 :                 return G_("%q+D redeclared inline without "
    2968                 :            :                           "%<gnu_inline%> attribute");
    2969                 :            :             }
    2970                 :            :         }
    2971                 :            : 
    2972                 :     669937 :       check_abi_tag_redeclaration
    2973                 :     669937 :         (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
    2974                 :     669937 :          lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
    2975                 :            : 
    2976                 :     669937 :       return NULL;
    2977                 :            :     }
    2978                 :     327117 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2979                 :            :     {
    2980                 :     241187 :       tree nt, ot;
    2981                 :            : 
    2982                 :     241187 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
    2983                 :            :         return G_("redefinition of %q#D");
    2984                 :            : 
    2985                 :     241185 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
    2986                 :        317 :         return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
    2987                 :        317 :                                             DECL_TEMPLATE_RESULT (olddecl));
    2988                 :            : 
    2989                 :     240868 :       if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
    2990                 :            :         return NULL;
    2991                 :            : 
    2992                 :     240855 :       nt = DECL_TEMPLATE_RESULT (newdecl);
    2993                 :     240855 :       if (DECL_TEMPLATE_INFO (nt))
    2994                 :      28725 :         nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
    2995                 :     240855 :       ot = DECL_TEMPLATE_RESULT (olddecl);
    2996                 :     240855 :       if (DECL_TEMPLATE_INFO (ot))
    2997                 :     240855 :         ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
    2998                 :     422297 :       if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
    2999                 :     240902 :           && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
    3000                 :         15 :         return G_("redefinition of %q#D");
    3001                 :            : 
    3002                 :     342990 :       if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
    3003                 :            :         {
    3004                 :      87228 :           bool olda = GNU_INLINE_P (ot);
    3005                 :     174456 :           bool newa = GNU_INLINE_P (nt);
    3006                 :            : 
    3007                 :      87228 :           if (olda != newa)
    3008                 :            :             {
    3009                 :          0 :               if (newa)
    3010                 :            :                 return G_("%q+D redeclared inline with "
    3011                 :            :                           "%<gnu_inline%> attribute");
    3012                 :            :               else
    3013                 :          0 :                 return G_("%q+D redeclared inline without "
    3014                 :            :                           "%<gnu_inline%> attribute");
    3015                 :            :             }
    3016                 :            :         }
    3017                 :            : 
    3018                 :            :       /* Core issue #226 (C++0x): 
    3019                 :            :            
    3020                 :            :            If a friend function template declaration specifies a
    3021                 :            :            default template-argument, that declaration shall be a
    3022                 :            :            definition and shall be the only declaration of the
    3023                 :            :            function template in the translation unit.  */
    3024                 :     240840 :       if ((cxx_dialect != cxx98) 
    3025                 :     228512 :           && TREE_CODE (ot) == FUNCTION_DECL && DECL_FRIEND_P (ot)
    3026                 :     262874 :           && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl), 
    3027                 :            :                                        /*is_primary=*/true,
    3028                 :            :                                        /*is_partial=*/false,
    3029                 :            :                                        /*is_friend_decl=*/2))
    3030                 :            :         return G_("redeclaration of friend %q#D "
    3031                 :            :                   "may not have default template arguments");
    3032                 :            : 
    3033                 :     240837 :       return NULL;
    3034                 :            :     }
    3035                 :      85930 :   else if (VAR_P (newdecl)
    3036                 :      85858 :            && CP_DECL_THREAD_LOCAL_P (newdecl) != CP_DECL_THREAD_LOCAL_P (olddecl)
    3037                 :      85957 :            && (! DECL_LANG_SPECIFIC (olddecl)
    3038                 :         23 :                || ! CP_DECL_THREADPRIVATE_P (olddecl)
    3039                 :         19 :                || CP_DECL_THREAD_LOCAL_P (newdecl)))
    3040                 :            :     {
    3041                 :            :       /* Only variables can be thread-local, and all declarations must
    3042                 :            :          agree on this property.  */
    3043                 :          8 :       if (CP_DECL_THREAD_LOCAL_P (newdecl))
    3044                 :            :         return G_("thread-local declaration of %q#D follows "
    3045                 :            :                   "non-thread-local declaration");
    3046                 :            :       else
    3047                 :          4 :         return G_("non-thread-local declaration of %q#D follows "
    3048                 :            :                   "thread-local declaration");
    3049                 :            :     }
    3050                 :      86144 :   else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
    3051                 :            :     {
    3052                 :            :       /* The objects have been declared at namespace scope.  If either
    3053                 :            :          is a member of an anonymous union, then this is an invalid
    3054                 :            :          redeclaration.  For example:
    3055                 :            : 
    3056                 :            :            int i;
    3057                 :            :            union { int i; };
    3058                 :            : 
    3059                 :            :            is invalid.  */
    3060                 :      85813 :       if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
    3061                 :     171683 :           || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
    3062                 :            :         return G_("redeclaration of %q#D");
    3063                 :            :       /* If at least one declaration is a reference, there is no
    3064                 :            :          conflict.  For example:
    3065                 :            : 
    3066                 :            :            int i = 3;
    3067                 :            :            extern int i;
    3068                 :            : 
    3069                 :            :          is valid.  */
    3070                 :     171244 :       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
    3071                 :            :         return NULL;
    3072                 :            : 
    3073                 :            :       /* Static data member declared outside a class definition
    3074                 :            :          if the variable is defined within the class with constexpr
    3075                 :            :          specifier is declaration rather than definition (and
    3076                 :            :          deprecated).  */
    3077                 :       6535 :       if (cxx_dialect >= cxx17
    3078                 :       6476 :           && VAR_P (olddecl)
    3079                 :       6440 :           && DECL_CLASS_SCOPE_P (olddecl)
    3080                 :       6424 :           && DECL_DECLARED_CONSTEXPR_P (olddecl)
    3081                 :      12935 :           && !DECL_INITIAL (newdecl))
    3082                 :            :         {
    3083                 :       6400 :           DECL_EXTERNAL (newdecl) = 1;
    3084                 :            :           /* For now, only warn with explicit -Wdeprecated.  */
    3085                 :       6400 :           if (global_options_set.x_warn_deprecated)
    3086                 :            :             {
    3087                 :         88 :               auto_diagnostic_group d;
    3088                 :         44 :               if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
    3089                 :            :                                 "redundant redeclaration of %<constexpr%> "
    3090                 :            :                                 "static data member %qD", newdecl))
    3091                 :          8 :                 inform (DECL_SOURCE_LOCATION (olddecl),
    3092                 :            :                           "previous declaration of %qD", olddecl);
    3093                 :            :             }
    3094                 :       6400 :           return NULL;
    3095                 :            :         }
    3096                 :            : 
    3097                 :            :       /* Reject two definitions.  */
    3098                 :            :       return G_("redefinition of %q#D");
    3099                 :            :     }
    3100                 :            :   else
    3101                 :            :     {
    3102                 :            :       /* Objects declared with block scope:  */
    3103                 :            :       /* Reject two definitions, and reject a definition
    3104                 :            :          together with an external reference.  */
    3105                 :         40 :       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
    3106                 :         40 :         return G_("redeclaration of %q#D");
    3107                 :            :       return NULL;
    3108                 :            :     }
    3109                 :            : }
    3110                 :            : 
    3111                 :            : 
    3112                 :            : /* Hash and equality functions for the named_label table.  */
    3113                 :            : 
    3114                 :            : hashval_t
    3115                 :      41618 : named_label_hash::hash (const value_type entry)
    3116                 :            : {
    3117                 :      41618 :   return IDENTIFIER_HASH_VALUE (entry->name);
    3118                 :            : }
    3119                 :            : 
    3120                 :            : bool
    3121                 :      41561 : named_label_hash::equal (const value_type entry, compare_type name)
    3122                 :            : {
    3123                 :      41561 :   return name == entry->name;
    3124                 :            : }
    3125                 :            : 
    3126                 :            : /* Look for a label named ID in the current function.  If one cannot
    3127                 :            :    be found, create one.  Return the named_label_entry, or NULL on
    3128                 :            :    failure.  */
    3129                 :            : 
    3130                 :            : static named_label_entry *
    3131                 :      12123 : lookup_label_1 (tree id, bool making_local_p)
    3132                 :            : {
    3133                 :            :   /* You can't use labels at global scope.  */
    3134                 :      12123 :   if (current_function_decl == NULL_TREE)
    3135                 :            :     {
    3136                 :          4 :       error ("label %qE referenced outside of any function", id);
    3137                 :          4 :       return NULL;
    3138                 :            :     }
    3139                 :            : 
    3140                 :      12119 :   if (!named_labels)
    3141                 :       1774 :     named_labels = hash_table<named_label_hash>::create_ggc (13);
    3142                 :            : 
    3143                 :      12119 :   hashval_t hash = IDENTIFIER_HASH_VALUE (id);
    3144                 :      12119 :   named_label_entry **slot
    3145                 :      12119 :     = named_labels->find_slot_with_hash (id, hash, INSERT);
    3146                 :      12119 :   named_label_entry *old = *slot;
    3147                 :            :   
    3148                 :      12119 :   if (old && old->label_decl)
    3149                 :            :     {
    3150                 :       1446 :       if (!making_local_p)
    3151                 :            :         return old;
    3152                 :            : 
    3153                 :         12 :       if (old->binding_level == current_binding_level)
    3154                 :            :         {
    3155                 :          0 :           error ("local label %qE conflicts with existing label", id);
    3156                 :          0 :           inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
    3157                 :          0 :           return NULL;
    3158                 :            :         }
    3159                 :            :     }
    3160                 :            : 
    3161                 :            :   /* We are making a new decl, create or reuse the named_label_entry  */
    3162                 :      10685 :   named_label_entry *ent = NULL;
    3163                 :      10685 :   if (old && !old->label_decl)
    3164                 :            :     ent = old;
    3165                 :            :   else
    3166                 :            :     {
    3167                 :      10669 :       ent = ggc_cleared_alloc<named_label_entry> ();
    3168                 :      10669 :       ent->name = id;
    3169                 :      10669 :       ent->outer = old;
    3170                 :      10669 :       *slot = ent;
    3171                 :            :     }
    3172                 :            : 
    3173                 :            :   /* Now create the LABEL_DECL.  */
    3174                 :      10685 :   tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
    3175                 :            : 
    3176                 :      10685 :   DECL_CONTEXT (decl) = current_function_decl;
    3177                 :      10685 :   SET_DECL_MODE (decl, VOIDmode);
    3178                 :      10685 :   if (making_local_p)
    3179                 :            :     {
    3180                 :         84 :       C_DECLARED_LABEL_FLAG (decl) = true;
    3181                 :         84 :       DECL_CHAIN (decl) = current_binding_level->names;
    3182                 :         84 :       current_binding_level->names = decl;
    3183                 :            :     }
    3184                 :            : 
    3185                 :      10685 :   ent->label_decl = decl;
    3186                 :            : 
    3187                 :      10685 :   return ent;
    3188                 :            : }
    3189                 :            : 
    3190                 :            : /* Wrapper for lookup_label_1.  */
    3191                 :            : 
    3192                 :            : tree
    3193                 :       1354 : lookup_label (tree id)
    3194                 :            : {
    3195                 :       1354 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    3196                 :       1354 :   named_label_entry *ent = lookup_label_1 (id, false);
    3197                 :       1354 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    3198                 :       1354 :   return ent ? ent->label_decl : NULL_TREE;
    3199                 :            : }
    3200                 :            : 
    3201                 :            : tree
    3202                 :         84 : declare_local_label (tree id)
    3203                 :            : {
    3204                 :         84 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    3205                 :         84 :   named_label_entry *ent = lookup_label_1 (id, true);
    3206                 :         84 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    3207                 :         84 :   return ent ? ent->label_decl : NULL_TREE;
    3208                 :            : }
    3209                 :            : 
    3210                 :            : /* Returns nonzero if it is ill-formed to jump past the declaration of
    3211                 :            :    DECL.  Returns 2 if it's also a real problem.  */
    3212                 :            : 
    3213                 :            : static int
    3214                 :      11031 : decl_jump_unsafe (tree decl)
    3215                 :            : {
    3216                 :            :   /* [stmt.dcl]/3: A program that jumps from a point where a local variable
    3217                 :            :      with automatic storage duration is not in scope to a point where it is
    3218                 :            :      in scope is ill-formed unless the variable has scalar type, class type
    3219                 :            :      with a trivial default constructor and a trivial destructor, a
    3220                 :            :      cv-qualified version of one of these types, or an array of one of the
    3221                 :            :      preceding types and is declared without an initializer (8.5).  */
    3222                 :      11031 :   tree type = TREE_TYPE (decl);
    3223                 :            : 
    3224                 :      11031 :   if (!VAR_P (decl) || TREE_STATIC (decl)
    3225                 :      10612 :       || type == error_mark_node)
    3226                 :            :     return 0;
    3227                 :            : 
    3228                 :      10588 :   if (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    3229                 :      10588 :       || variably_modified_type_p (type, NULL_TREE))
    3230                 :        816 :     return 2;
    3231                 :            : 
    3232                 :       9772 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    3233                 :         24 :     return 1;
    3234                 :            : 
    3235                 :            :   return 0;
    3236                 :            : }
    3237                 :            : 
    3238                 :            : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
    3239                 :            :    to the user.  */
    3240                 :            : 
    3241                 :            : static bool
    3242                 :        262 : identify_goto (tree decl, location_t loc, const location_t *locus,
    3243                 :            :                diagnostic_t diag_kind)
    3244                 :            : {
    3245                 :        262 :   bool complained
    3246                 :        365 :     = emit_diagnostic (diag_kind, loc, 0,
    3247                 :            :                        decl ? N_("jump to label %qD")
    3248                 :            :                        : N_("jump to case label"), decl);
    3249                 :        262 :   if (complained && locus)
    3250                 :        159 :     inform (*locus, "  from here");
    3251                 :        262 :   return complained;
    3252                 :            : }
    3253                 :            : 
    3254                 :            : /* Check that a single previously seen jump to a newly defined label
    3255                 :            :    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
    3256                 :            :    the jump context; NAMES are the names in scope in LEVEL at the jump
    3257                 :            :    context; LOCUS is the source position of the jump or 0.  Returns
    3258                 :            :    true if all is well.  */
    3259                 :            : 
    3260                 :            : static bool
    3261                 :     182756 : check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
    3262                 :            :                        bool exited_omp, const location_t *locus)
    3263                 :            : {
    3264                 :     182756 :   cp_binding_level *b;
    3265                 :     182756 :   bool complained = false;
    3266                 :     182756 :   int identified = 0;
    3267                 :     182756 :   bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
    3268                 :            : 
    3269                 :     182756 :   if (exited_omp)
    3270                 :            :     {
    3271                 :         12 :       complained = identify_goto (decl, input_location, locus, DK_ERROR);
    3272                 :         12 :       if (complained)
    3273                 :         12 :         inform (input_location, "  exits OpenMP structured block");
    3274                 :            :       saw_omp = true;
    3275                 :            :       identified = 2;
    3276                 :            :     }
    3277                 :            : 
    3278                 :     365266 :   for (b = current_binding_level; b ; b = b->level_chain)
    3279                 :            :     {
    3280                 :     365266 :       tree new_decls, old_decls = (b == level ? names : NULL_TREE);
    3281                 :            : 
    3282                 :     373983 :       for (new_decls = b->names; new_decls != old_decls;
    3283                 :      17430 :            new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
    3284                 :          4 :                         : TREE_CHAIN (new_decls)))
    3285                 :            :         {
    3286                 :       8717 :           int problem = decl_jump_unsafe (new_decls);
    3287                 :       8717 :           if (! problem)
    3288                 :       8667 :             continue;
    3289                 :            : 
    3290                 :         50 :           if (!identified)
    3291                 :            :             {
    3292                 :         50 :               complained = identify_goto (decl, input_location, locus,
    3293                 :            :                                           problem > 1
    3294                 :            :                                           ? DK_ERROR : DK_PERMERROR);
    3295                 :         50 :               identified = 1;
    3296                 :            :             }
    3297                 :         50 :           if (complained)
    3298                 :            :             {
    3299                 :         50 :               if (problem > 1)
    3300                 :         46 :                 inform (DECL_SOURCE_LOCATION (new_decls),
    3301                 :            :                         "  crosses initialization of %q#D", new_decls);
    3302                 :            :               else
    3303                 :          4 :                 inform (DECL_SOURCE_LOCATION (new_decls),
    3304                 :            :                         "  enters scope of %q#D, which has "
    3305                 :            :                         "non-trivial destructor", new_decls);
    3306                 :            :             }
    3307                 :            :         }
    3308                 :            : 
    3309                 :     365266 :       if (b == level)
    3310                 :            :         break;
    3311                 :            : 
    3312                 :     182510 :       const char *inf = NULL;
    3313                 :     182510 :       location_t loc = input_location;
    3314                 :     182510 :       switch (b->kind)
    3315                 :            :         {
    3316                 :          4 :         case sk_try:
    3317                 :          4 :           if (!saw_eh)
    3318                 :          4 :             inf = G_("  enters %<try%> block");
    3319                 :            :           saw_eh = true;
    3320                 :            :           break;
    3321                 :            : 
    3322                 :         12 :         case sk_catch:
    3323                 :         12 :           if (!saw_eh)
    3324                 :         12 :             inf = G_("  enters %<catch%> block");
    3325                 :            :           saw_eh = true;
    3326                 :            :           break;
    3327                 :            : 
    3328                 :        132 :         case sk_omp:
    3329                 :        132 :           if (!saw_omp)
    3330                 :        108 :             inf = G_("  enters OpenMP structured block");
    3331                 :            :           saw_omp = true;
    3332                 :            :           break;
    3333                 :            : 
    3334                 :          4 :         case sk_transaction:
    3335                 :          4 :           if (!saw_tm)
    3336                 :          4 :             inf = G_("  enters synchronized or atomic statement");
    3337                 :            :           saw_tm = true;
    3338                 :            :           break;
    3339                 :            : 
    3340                 :     182265 :         case sk_block:
    3341                 :     182320 :           if (!saw_cxif && level_for_constexpr_if (b->level_chain))
    3342                 :            :             {
    3343                 :          9 :               inf = G_("  enters %<constexpr if%> statement");
    3344                 :          9 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    3345                 :            :               saw_cxif = true;
    3346                 :            :             }
    3347                 :            :           break;
    3348                 :            : 
    3349                 :            :         default:
    3350                 :            :           break;
    3351                 :            :         }
    3352                 :            : 
    3353                 :     182510 :       if (inf)
    3354                 :            :         {
    3355                 :        137 :           if (identified < 2)
    3356                 :        137 :             complained = identify_goto (decl, input_location, locus, DK_ERROR);
    3357                 :        137 :           identified = 2;
    3358                 :        137 :           if (complained)
    3359                 :        137 :             inform (loc, inf);
    3360                 :            :         }
    3361                 :            :     }
    3362                 :            : 
    3363                 :     182756 :   return !identified;
    3364                 :            : }
    3365                 :            : 
    3366                 :            : static void
    3367                 :        711 : check_previous_goto (tree decl, struct named_label_use_entry *use)
    3368                 :            : {
    3369                 :        711 :   check_previous_goto_1 (decl, use->binding_level,
    3370                 :        711 :                          use->names_in_scope, use->in_omp_scope,
    3371                 :          0 :                          &use->o_goto_locus);
    3372                 :          0 : }
    3373                 :            : 
    3374                 :            : static bool
    3375                 :     182045 : check_switch_goto (cp_binding_level* level)
    3376                 :            : {
    3377                 :          0 :   return check_previous_goto_1 (NULL_TREE, level, level->names, false, NULL);
    3378                 :            : }
    3379                 :            : 
    3380                 :            : /* Check that a new jump to a label DECL is OK.  Called by
    3381                 :            :    finish_goto_stmt.  */
    3382                 :            : 
    3383                 :            : void
    3384                 :       1339 : check_goto (tree decl)
    3385                 :            : {
    3386                 :            :   /* We can't know where a computed goto is jumping.
    3387                 :            :      So we assume that it's OK.  */
    3388                 :       1339 :   if (TREE_CODE (decl) != LABEL_DECL)
    3389                 :       1339 :     return;
    3390                 :            : 
    3391                 :            :   /* We didn't record any information about this label when we created it,
    3392                 :            :      and there's not much point since it's trivial to analyze as a return.  */
    3393                 :       1233 :   if (decl == cdtor_label)
    3394                 :            :     return;
    3395                 :            : 
    3396                 :       1106 :   hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
    3397                 :       1106 :   named_label_entry **slot
    3398                 :       1106 :     = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
    3399                 :       1106 :   named_label_entry *ent = *slot;
    3400                 :            : 
    3401                 :            :   /* If the label hasn't been defined yet, defer checking.  */
    3402                 :       1106 :   if (! DECL_INITIAL (decl))
    3403                 :            :     {
    3404                 :            :       /* Don't bother creating another use if the last goto had the
    3405                 :            :          same data, and will therefore create the same set of errors.  */
    3406                 :        837 :       if (ent->uses
    3407                 :        150 :           && ent->uses->names_in_scope == current_binding_level->names)
    3408                 :            :         return;
    3409                 :            : 
    3410                 :        719 :       named_label_use_entry *new_use
    3411                 :        719 :         = ggc_alloc<named_label_use_entry> ();
    3412                 :        719 :       new_use->binding_level = current_binding_level;
    3413                 :        719 :       new_use->names_in_scope = current_binding_level->names;
    3414                 :        719 :       new_use->o_goto_locus = input_location;
    3415                 :        719 :       new_use->in_omp_scope = false;
    3416                 :            : 
    3417                 :        719 :       new_use->next = ent->uses;
    3418                 :        719 :       ent->uses = new_use;
    3419                 :        719 :       return;
    3420                 :            :     }
    3421                 :            : 
    3422                 :        269 :   bool saw_catch = false, complained = false;
    3423                 :        269 :   int identified = 0;
    3424                 :        269 :   tree bad;
    3425                 :        269 :   unsigned ix;
    3426                 :            : 
    3427                 :        257 :   if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
    3428                 :        249 :       || ent->in_constexpr_if
    3429                 :        515 :       || ent->in_omp_scope || !vec_safe_is_empty (ent->bad_decls))
    3430                 :            :     {
    3431                 :         35 :       diagnostic_t diag_kind = DK_PERMERROR;
    3432                 :         35 :       if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
    3433                 :         16 :           || ent->in_transaction_scope || ent->in_omp_scope)
    3434                 :         27 :         diag_kind = DK_ERROR;
    3435                 :         35 :       complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    3436                 :            :                                   &input_location, diag_kind);
    3437                 :         35 :       identified = 1 + (diag_kind == DK_ERROR);
    3438                 :            :     }
    3439                 :            : 
    3440                 :        277 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
    3441                 :            :     {
    3442                 :          8 :       int u = decl_jump_unsafe (bad);
    3443                 :            : 
    3444                 :          8 :       if (u > 1 && DECL_ARTIFICIAL (bad))
    3445                 :            :         {
    3446                 :            :           /* Can't skip init of __exception_info.  */
    3447                 :          0 :           if (identified == 1)
    3448                 :            :             {
    3449                 :          0 :               complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    3450                 :            :                                           &input_location, DK_ERROR);
    3451                 :          0 :               identified = 2;
    3452                 :            :             }
    3453                 :          0 :           if (complained)
    3454                 :          0 :             inform (DECL_SOURCE_LOCATION (bad), "  enters %<catch%> block");
    3455                 :            :           saw_catch = true;
    3456                 :            :         }
    3457                 :          8 :       else if (complained)
    3458                 :            :         {
    3459                 :          8 :           if (u > 1)
    3460                 :          8 :             inform (DECL_SOURCE_LOCATION (bad),
    3461                 :            :                     "  skips initialization of %q#D", bad);
    3462                 :            :           else
    3463                 :          0 :             inform (DECL_SOURCE_LOCATION (bad),
    3464                 :            :                     "  enters scope of %q#D which has "
    3465                 :            :                     "non-trivial destructor", bad);
    3466                 :            :         }
    3467                 :            :     }
    3468                 :            : 
    3469                 :        269 :   if (complained)
    3470                 :            :     {
    3471                 :         35 :       if (ent->in_try_scope)
    3472                 :         12 :         inform (input_location, "  enters %<try%> block");
    3473                 :         23 :       else if (ent->in_catch_scope && !saw_catch)
    3474                 :          4 :         inform (input_location, "  enters %<catch%> block");
    3475                 :         19 :       else if (ent->in_transaction_scope)
    3476                 :          4 :         inform (input_location, "  enters synchronized or atomic statement");
    3477                 :         15 :       else if (ent->in_constexpr_if)
    3478                 :          3 :         inform (input_location, "  enters %<constexpr if%> statement");
    3479                 :            :     }
    3480                 :            : 
    3481                 :        269 :   if (ent->in_omp_scope)
    3482                 :            :     {
    3483                 :          4 :       if (complained)
    3484                 :          4 :         inform (input_location, "  enters OpenMP structured block");
    3485                 :            :     }
    3486                 :        265 :   else if (flag_openmp)
    3487                 :         28 :     for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    3488                 :            :       {
    3489                 :         28 :         if (b == ent->binding_level)
    3490                 :            :           break;
    3491                 :         28 :         if (b->kind == sk_omp)
    3492                 :            :           {
    3493                 :         28 :             if (identified < 2)
    3494                 :            :               {
    3495                 :         28 :                 complained = identify_goto (decl,
    3496                 :         28 :                                             DECL_SOURCE_LOCATION (decl),
    3497                 :            :                                             &input_location, DK_ERROR);
    3498                 :         28 :                 identified = 2;
    3499                 :            :               }
    3500                 :         28 :             if (complained)
    3501                 :         28 :               inform (input_location, "  exits OpenMP structured block");
    3502                 :            :             break;
    3503                 :            :           }
    3504                 :            :       }
    3505                 :            : }
    3506                 :            : 
    3507                 :            : /* Check that a return is ok wrt OpenMP structured blocks.
    3508                 :            :    Called by finish_return_stmt.  Returns true if all is well.  */
    3509                 :            : 
    3510                 :            : bool
    3511                 :      34173 : check_omp_return (void)
    3512                 :            : {
    3513                 :     104236 :   for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    3514                 :     104236 :     if (b->kind == sk_omp)
    3515                 :            :       {
    3516                 :         16 :         error ("invalid exit from OpenMP structured block");
    3517                 :         16 :         return false;
    3518                 :            :       }
    3519                 :     104220 :     else if (b->kind == sk_function_parms)
    3520                 :            :       break;
    3521                 :            :   return true;
    3522                 :            : }
    3523                 :            : 
    3524                 :            : /* Define a label, specifying the location in the source file.
    3525                 :            :    Return the LABEL_DECL node for the label.  */
    3526                 :            : 
    3527                 :            : static tree
    3528                 :      10685 : define_label_1 (location_t location, tree name)
    3529                 :            : {
    3530                 :            :   /* After labels, make any new cleanups in the function go into their
    3531                 :            :      own new (temporary) binding contour.  */
    3532                 :      10685 :   for (cp_binding_level *p = current_binding_level;
    3533                 :      22587 :        p->kind != sk_function_parms;
    3534                 :      11902 :        p = p->level_chain)
    3535                 :      11902 :     p->more_cleanups_ok = 0;
    3536                 :            : 
    3537                 :      10685 :   named_label_entry *ent = lookup_label_1 (name, false);
    3538                 :      10685 :   tree decl = ent->label_decl;
    3539                 :            : 
    3540                 :      10685 :   if (DECL_INITIAL (decl) != NULL_TREE)
    3541                 :            :     {
    3542                 :          8 :       error ("duplicate label %qD", decl);
    3543                 :          8 :       return error_mark_node;
    3544                 :            :     }
    3545                 :            :   else
    3546                 :            :     {
    3547                 :            :       /* Mark label as having been defined.  */
    3548                 :      10677 :       DECL_INITIAL (decl) = error_mark_node;
    3549                 :            :       /* Say where in the source.  */
    3550                 :      10677 :       DECL_SOURCE_LOCATION (decl) = location;
    3551                 :            : 
    3552                 :      10677 :       ent->binding_level = current_binding_level;
    3553                 :      10677 :       ent->names_in_scope = current_binding_level->names;
    3554                 :            : 
    3555                 :      11388 :       for (named_label_use_entry *use = ent->uses; use; use = use->next)
    3556                 :        711 :         check_previous_goto (decl, use);
    3557                 :      10677 :       ent->uses = NULL;
    3558                 :            :     }
    3559                 :            : 
    3560                 :      10677 :   return decl;
    3561                 :            : }
    3562                 :            : 
    3563                 :            : /* Wrapper for define_label_1.  */
    3564                 :            : 
    3565                 :            : tree
    3566                 :      10685 : define_label (location_t location, tree name)
    3567                 :            : {
    3568                 :      10685 :   bool running = timevar_cond_start (TV_NAME_LOOKUP);
    3569                 :      10685 :   tree ret = define_label_1 (location, name);
    3570                 :      10685 :   timevar_cond_stop (TV_NAME_LOOKUP, running);
    3571                 :      10685 :   return ret;
    3572                 :            : }
    3573                 :            : 
    3574                 :            : 
    3575                 :            : struct cp_switch
    3576                 :            : {
    3577                 :            :   cp_binding_level *level;
    3578                 :            :   struct cp_switch *next;
    3579                 :            :   /* The SWITCH_STMT being built.  */
    3580                 :            :   tree switch_stmt;
    3581                 :            :   /* A splay-tree mapping the low element of a case range to the high
    3582                 :            :      element, or NULL_TREE if there is no high element.  Used to
    3583                 :            :      determine whether or not a new case label duplicates an old case
    3584                 :            :      label.  We need a tree, rather than simply a hash table, because
    3585                 :            :      of the GNU case range extension.  */
    3586                 :            :   splay_tree cases;
    3587                 :            :   /* Remember whether a default: case label has been seen.  */
    3588                 :            :   bool has_default_p;
    3589                 :            :   /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT.  */
    3590                 :            :   bool break_stmt_seen_p;
    3591                 :            :   /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
    3592                 :            :      where BREAK_STMT doesn't belong to the SWITCH_STMT.  */
    3593                 :            :   bool in_loop_body_p;
    3594                 :            : };
    3595                 :            : 
    3596                 :            : /* A stack of the currently active switch statements.  The innermost
    3597                 :            :    switch statement is on the top of the stack.  There is no need to
    3598                 :            :    mark the stack for garbage collection because it is only active
    3599                 :            :    during the processing of the body of a function, and we never
    3600                 :            :    collect at that point.  */
    3601                 :            : 
    3602                 :            : static struct cp_switch *switch_stack;
    3603                 :            : 
    3604                 :            : /* Called right after a switch-statement condition is parsed.
    3605                 :            :    SWITCH_STMT is the switch statement being parsed.  */
    3606                 :            : 
    3607                 :            : void
    3608                 :      55386 : push_switch (tree switch_stmt)
    3609                 :            : {
    3610                 :      55386 :   struct cp_switch *p = XNEW (struct cp_switch);
    3611                 :      55386 :   p->level = current_binding_level;
    3612                 :      55386 :   p->next = switch_stack;
    3613                 :      55386 :   p->switch_stmt = switch_stmt;
    3614                 :      55386 :   p->cases = splay_tree_new (case_compare, NULL, NULL);
    3615                 :      55386 :   p->has_default_p = false;
    3616                 :      55386 :   p->break_stmt_seen_p = false;
    3617                 :      55386 :   p->in_loop_body_p = false;
    3618                 :      55386 :   switch_stack = p;
    3619                 :      55386 : }
    3620                 :            : 
    3621                 :            : void
    3622                 :      55386 : pop_switch (void)
    3623                 :            : {
    3624                 :      55386 :   struct cp_switch *cs = switch_stack;
    3625                 :      55386 :   location_t switch_location;
    3626                 :            : 
    3627                 :            :   /* Emit warnings as needed.  */
    3628                 :      55386 :   switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
    3629                 :      55386 :   const bool bool_cond_p
    3630                 :      55386 :     = (SWITCH_STMT_TYPE (cs->switch_stmt)
    3631                 :      55386 :        && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
    3632                 :      55386 :   if (!processing_template_decl)
    3633                 :      43323 :     c_do_switch_warnings (cs->cases, switch_location,
    3634                 :      43323 :                           SWITCH_STMT_TYPE (cs->switch_stmt),
    3635                 :      43323 :                           SWITCH_STMT_COND (cs->switch_stmt), bool_cond_p);
    3636                 :            : 
    3637                 :            :   /* For the benefit of block_may_fallthru remember if the switch body
    3638                 :            :      case labels cover all possible values and if there are break; stmts.  */
    3639                 :      55386 :   if (cs->has_default_p
    3640                 :      55386 :       || (!processing_template_decl
    3641                 :      22257 :           && c_switch_covers_all_cases_p (cs->cases,
    3642                 :      22257 :                                           SWITCH_STMT_TYPE (cs->switch_stmt))))
    3643                 :      29846 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
    3644                 :      55386 :   if (!cs->break_stmt_seen_p)
    3645                 :      12874 :     SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
    3646                 :      55386 :   gcc_assert (!cs->in_loop_body_p);
    3647                 :      55386 :   splay_tree_delete (cs->cases);
    3648                 :      55386 :   switch_stack = switch_stack->next;
    3649                 :      55386 :   free (cs);
    3650                 :      55386 : }
    3651                 :            : 
    3652                 :            : /* Note that a BREAK_STMT is about to be added.  If it is inside of
    3653                 :            :    a SWITCH_STMT and not inside of a loop body inside of it, note
    3654                 :            :    in switch_stack we've seen a BREAK_STMT.  */
    3655                 :            : 
    3656                 :            : void
    3657                 :     259500 : note_break_stmt (void)
    3658                 :            : {
    3659                 :     259500 :   if (switch_stack && !switch_stack->in_loop_body_p)
    3660                 :     148651 :     switch_stack->break_stmt_seen_p = true;
    3661                 :     259500 : }
    3662                 :            : 
    3663                 :            : /* Note the start of processing of an iteration statement's body.
    3664                 :            :    The note_break_stmt function will do nothing while processing it.
    3665                 :            :    Return a flag that should be passed to note_iteration_stmt_body_end.  */
    3666                 :            : 
    3667                 :            : bool
    3668                 :     858773 : note_iteration_stmt_body_start (void)
    3669                 :            : {
    3670                 :     858773 :   if (!switch_stack)
    3671                 :            :     return false;
    3672                 :       2539 :   bool ret = switch_stack->in_loop_body_p;
    3673                 :       2539 :   switch_stack->in_loop_body_p = true;
    3674                 :       2539 :   return ret;
    3675                 :            : }
    3676                 :            : 
    3677                 :            : /* Note the end of processing of an iteration statement's body.  */
    3678                 :            : 
    3679                 :            : void
    3680                 :     858773 : note_iteration_stmt_body_end (bool prev)
    3681                 :            : {
    3682                 :     858773 :   if (switch_stack)
    3683                 :       2539 :     switch_stack->in_loop_body_p = prev;
    3684                 :     858773 : }
    3685                 :            : 
    3686                 :            : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
    3687                 :            :    condition.  Note that if TYPE and VALUE are already integral we don't
    3688                 :            :    really do the conversion because the language-independent
    3689                 :            :    warning/optimization code will work better that way.  */
    3690                 :            : 
    3691                 :            : static tree
    3692                 :     363844 : case_conversion (tree type, tree value)
    3693                 :            : {
    3694                 :     363844 :   if (value == NULL_TREE)
    3695                 :            :     return value;
    3696                 :            : 
    3697                 :     161028 :   value = mark_rvalue_use (value);
    3698                 :            : 
    3699                 :     161028 :   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3700                 :     160718 :     type = type_promotes_to (type);
    3701                 :            : 
    3702                 :     161028 :   tree ovalue = value;
    3703                 :            :   /* The constant-expression VALUE shall be a converted constant expression
    3704                 :            :      of the adjusted type of the switch condition, which doesn't allow
    3705                 :            :      narrowing conversions.  */
    3706                 :     161028 :   value = build_converted_constant_expr (type, value, tf_warning_or_error);
    3707                 :            : 
    3708                 :     161028 :   if (cxx_dialect >= cxx11
    3709                 :     161028 :       && (SCOPED_ENUM_P (type)
    3710                 :     158918 :           || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
    3711                 :            :     /* Use the converted value.  */;
    3712                 :            :   else
    3713                 :            :     /* The already integral case.  */
    3714                 :            :     value = ovalue;
    3715                 :            : 
    3716                 :     161028 :   return cxx_constant_value (value);
    3717                 :            : }
    3718                 :            : 
    3719                 :            : /* Note that we've seen a definition of a case label, and complain if this
    3720                 :            :    is a bad place for one.  */
    3721                 :            : 
    3722                 :            : tree
    3723                 :     247636 : finish_case_label (location_t loc, tree low_value, tree high_value)
    3724                 :            : {
    3725                 :     247636 :   tree cond, r;
    3726                 :     247636 :   cp_binding_level *p;
    3727                 :     247636 :   tree type;
    3728                 :            : 
    3729                 :     247636 :   if (low_value == NULL_TREE && high_value == NULL_TREE)
    3730                 :      29807 :     switch_stack->has_default_p = true;
    3731                 :            : 
    3732                 :     247636 :   if (processing_template_decl)
    3733                 :            :     {
    3734                 :      65591 :       tree label;
    3735                 :            : 
    3736                 :            :       /* For templates, just add the case label; we'll do semantic
    3737                 :            :          analysis at instantiation-time.  */
    3738                 :      65591 :       label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
    3739                 :      65591 :       return add_stmt (build_case_label (low_value, high_value, label));
    3740                 :            :     }
    3741                 :            : 
    3742                 :            :   /* Find the condition on which this switch statement depends.  */
    3743                 :     182045 :   cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
    3744                 :     182045 :   if (cond && TREE_CODE (cond) == TREE_LIST)
    3745                 :          0 :     cond = TREE_VALUE (cond);
    3746                 :            : 
    3747                 :     182045 :   if (!check_switch_goto (switch_stack->level))
    3748                 :        103 :     return error_mark_node;
    3749                 :            : 
    3750                 :     181942 :   type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
    3751                 :     181942 :   if (type == error_mark_node)
    3752                 :            :     return error_mark_node;
    3753                 :            : 
    3754                 :     181922 :   low_value = case_conversion (type, low_value);
    3755                 :     181922 :   high_value = case_conversion (type, high_value);
    3756                 :            : 
    3757                 :     181922 :   r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
    3758                 :            : 
    3759                 :            :   /* After labels, make any new cleanups in the function go into their
    3760                 :            :      own new (temporary) binding contour.  */
    3761                 :     181922 :   for (p = current_binding_level;
    3762                 :     893829 :        p->kind != sk_function_parms;
    3763                 :     711907 :        p = p->level_chain)
    3764                 :     711907 :     p->more_cleanups_ok = 0;
    3765                 :            : 
    3766                 :            :   return r;
    3767                 :            : }
    3768                 :            : 
    3769                 :            : struct typename_info {
    3770                 :            :   tree scope;
    3771                 :            :   tree name;
    3772                 :            :   tree template_id;
    3773                 :            :   bool enum_p;
    3774                 :            :   bool class_p;
    3775                 :            : };
    3776                 :            : 
    3777                 :            : struct typename_hasher : ggc_ptr_hash<tree_node>
    3778                 :            : {
    3779                 :            :   typedef typename_info *compare_type;
    3780                 :            : 
    3781                 :            :   /* Hash a TYPENAME_TYPE.  */
    3782                 :            : 
    3783                 :            :   static hashval_t
    3784                 :   34739700 :   hash (tree t)
    3785                 :            :   {
    3786                 :   34739700 :     hashval_t hash;
    3787                 :            : 
    3788                 :   34739700 :     hash = (htab_hash_pointer (TYPE_CONTEXT (t))
    3789                 :   34739700 :             ^ htab_hash_pointer (TYPE_IDENTIFIER (t)));
    3790                 :            : 
    3791                 :   34739700 :     return hash;
    3792                 :            :   }
    3793                 :            : 
    3794                 :            :   /* Compare two TYPENAME_TYPEs.  */
    3795                 :            : 
    3796                 :            :   static bool
    3797                 :   42324600 :   equal (tree t1, const typename_info *t2)
    3798                 :            :   {
    3799                 :   42324600 :     return (TYPE_IDENTIFIER (t1) == t2->name
    3800                 :   20503700 :             && TYPE_CONTEXT (t1) == t2->scope
    3801                 :    4050520 :             && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
    3802                 :    4008580 :             && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
    3803                 :   46333200 :             && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
    3804                 :            :   }
    3805                 :            : };
    3806                 :            : 
    3807                 :            : /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
    3808                 :            :    the type of `T', NAME is the IDENTIFIER_NODE for `t'.
    3809                 :            : 
    3810                 :            :    Returns the new TYPENAME_TYPE.  */
    3811                 :            : 
    3812                 :            : static GTY (()) hash_table<typename_hasher> *typename_htab;
    3813                 :            : 
    3814                 :            : tree
    3815                 :    6577450 : build_typename_type (tree context, tree name, tree fullname,
    3816                 :            :                      enum tag_types tag_type)
    3817                 :            : {
    3818                 :    6577450 :   tree t;
    3819                 :    6577450 :   tree d;
    3820                 :    6577450 :   typename_info ti;
    3821                 :    6577450 :   tree *e;
    3822                 :    6577450 :   hashval_t hash;
    3823                 :            : 
    3824                 :    6577450 :   if (typename_htab == NULL)
    3825                 :       8033 :     typename_htab = hash_table<typename_hasher>::create_ggc (61);
    3826                 :            : 
    3827                 :    6577450 :   ti.scope = FROB_CONTEXT (context);
    3828                 :    6577450 :   ti.name = name;
    3829                 :    6577450 :   ti.template_id = fullname;
    3830                 :    6577450 :   ti.enum_p = tag_type == enum_type;
    3831                 :    6577450 :   ti.class_p = (tag_type == class_type
    3832                 :            :                 || tag_type == record_type
    3833                 :    6577450 :                 || tag_type == union_type);
    3834                 :    6577450 :   hash =  (htab_hash_pointer (ti.scope)
    3835                 :    6577450 :            ^ htab_hash_pointer (ti.name));
    3836                 :            : 
    3837                 :            :   /* See if we already have this type.  */
    3838                 :    6577450 :   e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
    3839                 :    6577450 :   if (*e)
    3840                 :            :     t = *e;
    3841                 :            :   else
    3842                 :            :     {
    3843                 :            :       /* Build the TYPENAME_TYPE.  */
    3844                 :    2568930 :       t = cxx_make_type (TYPENAME_TYPE);
    3845                 :    2568930 :       TYPE_CONTEXT (t) = ti.scope;
    3846                 :    2568930 :       TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
    3847                 :    2568930 :       TYPENAME_IS_ENUM_P (t) = ti.enum_p;
    3848                 :    2568930 :       TYPENAME_IS_CLASS_P (t) = ti.class_p;
    3849                 :            : 
    3850                 :            :       /* Build the corresponding TYPE_DECL.  */
    3851                 :    2568930 :       d = build_decl (input_location, TYPE_DECL, name, t);
    3852                 :    2568930 :       TYPE_NAME (TREE_TYPE (d)) = d;
    3853                 :    2568930 :       TYPE_STUB_DECL (TREE_TYPE (d)) = d;
    3854                 :    2568930 :       DECL_CONTEXT (d) = FROB_CONTEXT (context);
    3855                 :    2568930 :       DECL_ARTIFICIAL (d) = 1;
    3856                 :            : 
    3857                 :            :       /* Store it in the hash table.  */
    3858                 :    2568930 :       *e = t;
    3859                 :            : 
    3860                 :            :       /* TYPENAME_TYPEs must always be compared structurally, because
    3861                 :            :          they may or may not resolve down to another type depending on
    3862                 :            :          the currently open classes. */
    3863                 :    2568930 :       SET_TYPE_STRUCTURAL_EQUALITY (t);
    3864                 :            :     }
    3865                 :            : 
    3866                 :    6577450 :   return t;
    3867                 :            : }
    3868                 :            : 
    3869                 :            : /* Resolve `typename CONTEXT::NAME'.  TAG_TYPE indicates the tag
    3870                 :            :    provided to name the type.  Returns an appropriate type, unless an
    3871                 :            :    error occurs, in which case error_mark_node is returned.  If we
    3872                 :            :    locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
    3873                 :            :    return that, rather than the _TYPE it corresponds to, in other
    3874                 :            :    cases we look through the type decl.  If TF_ERROR is set, complain
    3875                 :            :    about errors, otherwise be quiet.  */
    3876                 :            : 
    3877                 :            : tree
    3878                 :   35345100 : make_typename_type (tree context, tree name, enum tag_types tag_type,
    3879                 :            :                     tsubst_flags_t complain)
    3880                 :            : {
    3881                 :   35345100 :   tree fullname;
    3882                 :   35345100 :   tree t;
    3883                 :   35345100 :   bool want_template;
    3884                 :            : 
    3885                 :   35345100 :   if (name == error_mark_node
    3886                 :   35345100 :       || context == NULL_TREE
    3887                 :   35345100 :       || context == error_mark_node)
    3888                 :            :     return error_mark_node;
    3889                 :            : 
    3890                 :   35345100 :   if (TYPE_P (name))
    3891                 :            :     {
    3892                 :          0 :       if (!(TYPE_LANG_SPECIFIC (name)
    3893                 :          0 :             && (CLASSTYPE_IS_TEMPLATE (name)
    3894                 :          0 :                 || CLASSTYPE_USE_TEMPLATE (name))))
    3895                 :          0 :         name = TYPE_IDENTIFIER (name);
    3896                 :            :       else
    3897                 :            :         /* Create a TEMPLATE_ID_EXPR for the type.  */
    3898                 :          0 :         name = build_nt (TEMPLATE_ID_EXPR,
    3899                 :          0 :                          CLASSTYPE_TI_TEMPLATE (name),
    3900                 :          0 :                          CLASSTYPE_TI_ARGS (name));
    3901                 :            :     }
    3902                 :   35345100 :   else if (TREE_CODE (name) == TYPE_DECL)
    3903                 :          0 :     name = DECL_NAME (name);
    3904                 :            : 
    3905                 :   35345100 :   fullname = name;
    3906                 :            : 
    3907                 :   35345100 :   if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    3908                 :            :     {
    3909                 :     736525 :       name = TREE_OPERAND (name, 0);
    3910                 :     736525 :       if (DECL_TYPE_TEMPLATE_P (name))
    3911                 :          0 :         name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
    3912                 :     736525 :       if (TREE_CODE (name) != IDENTIFIER_NODE)
    3913                 :            :         {
    3914                 :          0 :           if (complain & tf_error)
    3915                 :          0 :             error ("%qD is not a type", name);
    3916                 :          0 :           return error_mark_node;
    3917                 :            :         }
    3918                 :            :     }
    3919                 :   35345100 :   if (TREE_CODE (name) == TEMPLATE_DECL)
    3920                 :            :     {
    3921                 :          0 :       if (complain & tf_error)
    3922                 :          0 :         error ("%qD used without template arguments", name);
    3923                 :          0 :       return error_mark_node;
    3924                 :            :     }
    3925                 :   35345100 :   gcc_assert (identifier_p (name));
    3926                 :   35345100 :   gcc_assert (TYPE_P (context));
    3927                 :            : 
    3928                 :   35345100 :   if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
    3929                 :            :     /* This can happen for C++17 variadic using (c++/88986).  */;
    3930                 :   35345100 :   else if (!MAYBE_CLASS_TYPE_P (context))
    3931                 :            :     {
    3932                 :          3 :       if (complain & tf_error)
    3933                 :          3 :         error ("%q#T is not a class", context);
    3934                 :          3 :       return error_mark_node;
    3935                 :            :     }
    3936                 :            :   
    3937                 :            :   /* When the CONTEXT is a dependent type,  NAME could refer to a
    3938                 :            :      dependent base class of CONTEXT.  But look inside it anyway
    3939                 :            :      if CONTEXT is a currently open scope, in case it refers to a
    3940                 :            :      member of the current instantiation or a non-dependent base;
    3941                 :            :      lookup will stop when we hit a dependent base.  */
    3942                 :   35345100 :   if (!dependent_scope_p (context))
    3943                 :            :     /* We should only set WANT_TYPE when we're a nested typename type.
    3944                 :            :        Then we can give better diagnostics if we find a non-type.  */
    3945                 :   29597000 :     t = lookup_field (context, name, 2, /*want_type=*/true);
    3946                 :            :   else
    3947                 :            :     t = NULL_TREE;
    3948                 :            : 
    3949                 :   35345100 :   if ((!t || TREE_CODE (t) == TREE_LIST) && dependent_type_p (context))
    3950                 :    5751000 :     return build_typename_type (context, name, fullname, tag_type);
    3951                 :            : 
    3952                 :   29594100 :   want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
    3953                 :            :   
    3954                 :   29594100 :   if (!t)
    3955                 :            :     {
    3956                 :    1300240 :       if (complain & tf_error)
    3957                 :            :         {
    3958                 :        190 :           if (!COMPLETE_TYPE_P (context))
    3959                 :         22 :             cxx_incomplete_type_error (NULL_TREE, context);
    3960                 :            :           else
    3961                 :        329 :             error (want_template ? G_("no class template named %q#T in %q#T")
    3962                 :            :                    : G_("no type named %q#T in %q#T"), name, context);
    3963                 :            :         }
    3964                 :    1300240 :       return error_mark_node;
    3965                 :            :     }
    3966                 :            :   
    3967                 :            :   /* Pull out the template from an injected-class-name (or multiple).  */
    3968                 :   28293900 :   if (want_template)
    3969                 :     682089 :     t = maybe_get_template_decl_from_type_decl (t);
    3970                 :            : 
    3971                 :   28293900 :   if (TREE_CODE (t) == TREE_LIST)
    3972                 :            :     {
    3973                 :          4 :       if (complain & tf_error)
    3974                 :            :         {
    3975                 :          4 :           error ("lookup of %qT in %qT is ambiguous", name, context);
    3976                 :          4 :           print_candidates (t);
    3977                 :            :         }
    3978                 :          4 :       return error_mark_node;
    3979                 :            :     }
    3980                 :            : 
    3981                 :   28293900 :   if (want_template && !DECL_TYPE_TEMPLATE_P (t))
    3982                 :            :     {
    3983                 :          7 :       if (complain & tf_error)
    3984                 :          7 :         error ("%<typename %T::%D%> names %q#T, which is not a class template",
    3985                 :            :                context, name, t);
    3986                 :          7 :       return error_mark_node;
    3987                 :            :     }
    3988                 :   28293800 :   if (!want_template && TREE_CODE (t) != TYPE_DECL)
    3989                 :            :     {
    3990                 :          8 :       if (complain & tf_error)
    3991                 :          4 :         error ("%<typename %T::%D%> names %q#T, which is not a type",
    3992                 :            :                context, name, t);
    3993                 :          8 :       return error_mark_node;
    3994                 :            :     }
    3995                 :            : 
    3996                 :   28293800 :   if (!perform_or_defer_access_check (TYPE_BINFO (context), t, t, complain))
    3997                 :         13 :     return error_mark_node;
    3998                 :            : 
    3999                 :            :   /* If we are currently parsing a template and if T is a typedef accessed
    4000                 :            :      through CONTEXT then we need to remember and check access of T at
    4001                 :            :      template instantiation time.  */
    4002                 :   28293800 :   add_typedef_to_current_template_for_access_check (t, context, input_location);
    4003                 :            : 
    4004                 :   28293800 :   if (want_template)
    4005                 :     682082 :     return lookup_template_class (t, TREE_OPERAND (fullname, 1),
    4006                 :            :                                   NULL_TREE, context,
    4007                 :            :                                   /*entering_scope=*/0,
    4008                 :     682082 :                                   complain | tf_user);
    4009                 :            :   
    4010                 :   27611700 :   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
    4011                 :      57099 :     t = TREE_TYPE (t);
    4012                 :            : 
    4013                 :   27611700 :   maybe_record_typedef_use (t);
    4014                 :            : 
    4015                 :   27611700 :   return t;
    4016                 :            : }
    4017                 :            : 
    4018                 :            : /* Resolve `CONTEXT::template NAME'.  Returns a TEMPLATE_DECL if the name
    4019                 :            :    can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
    4020                 :            :    in which case error_mark_node is returned.
    4021                 :            : 
    4022                 :            :    If PARM_LIST is non-NULL, also make sure that the template parameter
    4023                 :            :    list of TEMPLATE_DECL matches.
    4024                 :            : 
    4025                 :            :    If COMPLAIN zero, don't complain about any errors that occur.  */
    4026                 :            : 
    4027                 :            : tree
    4028                 :       5552 : make_unbound_class_template (tree context, tree name, tree parm_list,
    4029                 :            :                              tsubst_flags_t complain)
    4030                 :            : {
    4031                 :       5552 :   tree t;
    4032                 :       5552 :   tree d;
    4033                 :            : 
    4034                 :       5552 :   if (TYPE_P (name))
    4035                 :          0 :     name = TYPE_IDENTIFIER (name);
    4036                 :       5552 :   else if (DECL_P (name))
    4037                 :          0 :     name = DECL_NAME (name);
    4038                 :       5552 :   gcc_assert (identifier_p (name));
    4039                 :            : 
    4040                 :       5552 :   if (!dependent_type_p (context)
    4041                 :       5552 :       || currently_open_class (context))
    4042                 :            :     {
    4043                 :        790 :       tree tmpl = NULL_TREE;
    4044                 :            : 
    4045                 :       1572 :       if (MAYBE_CLASS_TYPE_P (context))
    4046                 :        782 :         tmpl = lookup_field (context, name, 0, false);
    4047                 :            : 
    4048                 :        782 :       if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
    4049                 :          4 :         tmpl = maybe_get_template_decl_from_type_decl (tmpl);
    4050                 :            : 
    4051                 :        790 :       if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
    4052                 :            :         {
    4053                 :         12 :           if (complain & tf_error)
    4054                 :          8 :             error ("no class template named %q#T in %q#T", name, context);
    4055                 :         12 :           return error_mark_node;
    4056                 :            :         }
    4057                 :            : 
    4058                 :        778 :       if (parm_list
    4059                 :        778 :           && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
    4060                 :            :         {
    4061                 :          0 :           if (complain & tf_error)
    4062                 :            :             {
    4063                 :          0 :               error ("template parameters do not match template %qD", tmpl);
    4064                 :          0 :               inform (DECL_SOURCE_LOCATION (tmpl),
    4065                 :            :                       "%qD declared here", tmpl);
    4066                 :            :             }
    4067                 :          0 :           return error_mark_node;
    4068                 :            :         }
    4069                 :            : 
    4070                 :        778 :       if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
    4071                 :            :                                           complain))
    4072                 :          0 :         return error_mark_node;
    4073                 :            : 
    4074                 :            :       return tmpl;
    4075                 :            :     }
    4076                 :            : 
    4077                 :            :   /* Build the UNBOUND_CLASS_TEMPLATE.  */
    4078                 :       4762 :   t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
    4079                 :       4762 :   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
    4080                 :       4762 :   TREE_TYPE (t) = NULL_TREE;
    4081                 :       4762 :   SET_TYPE_STRUCTURAL_EQUALITY (t);
    4082                 :            : 
    4083                 :            :   /* Build the corresponding TEMPLATE_DECL.  */
    4084                 :       4762 :   d = build_decl (input_location, TEMPLATE_DECL, name, t);
    4085                 :       4762 :   TYPE_NAME (TREE_TYPE (d)) = d;
    4086                 :       4762 :   TYPE_STUB_DECL (TREE_TYPE (d)) = d;
    4087                 :       4762 :   DECL_CONTEXT (d) = FROB_CONTEXT (context);
    4088                 :       4762 :   DECL_ARTIFICIAL (d) = 1;
    4089                 :       4762 :   DECL_TEMPLATE_PARMS (d) = parm_list;
    4090                 :            : 
    4091                 :       4762 :   return t;
    4092                 :            : }
    4093                 :            : 
    4094                 :            : 
    4095                 :            : 
    4096                 :            : /* Push the declarations of builtin types into the global namespace.
    4097                 :            :    RID_INDEX is the index of the builtin type in the array
    4098                 :            :    RID_POINTERS.  NAME is the name used when looking up the builtin
    4099                 :            :    type.  TYPE is the _TYPE node for the builtin type.
    4100                 :            : 
    4101                 :            :    The calls to set_global_binding below should be
    4102                 :            :    eliminated.  Built-in types should not be looked up name; their
    4103                 :            :    names are keywords that the parser can recognize.  However, there
    4104                 :            :    is code in c-common.c that uses identifier_global_value to look up
    4105                 :            :    built-in types by name.  */
    4106                 :            : 
    4107                 :            : void
    4108                 :    2653520 : record_builtin_type (enum rid rid_index,
    4109                 :            :                      const char* name,
    4110                 :            :                      tree type)
    4111                 :            : {
    4112                 :    2653520 :   tree decl = NULL_TREE;
    4113                 :            : 
    4114                 :    2653520 :   if (name)
    4115                 :            :     {
    4116                 :    1871190 :       tree tname = get_identifier (name);
    4117                 :    1871190 :       tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
    4118                 :    1871190 :       DECL_ARTIFICIAL (tdecl) = 1;
    4119                 :    1871190 :       set_global_binding (tdecl);
    4120                 :    1871190 :       decl = tdecl;
    4121                 :            :     }
    4122                 :            : 
    4123                 :    2653520 :   if ((int) rid_index < (int) RID_MAX)
    4124                 :    1401790 :     if (tree rname = ridpointers[(int) rid_index])
    4125                 :    1630090 :       if (!decl || DECL_NAME (decl) != rname)
    4126                 :            :         {
    4127                 :     625864 :           tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
    4128                 :     625864 :           DECL_ARTIFICIAL (rdecl) = 1;
    4129                 :     625864 :           set_global_binding (rdecl);
    4130                 :     625864 :           if (!decl)
    4131                 :     391165 :             decl = rdecl;
    4132                 :            :         }
    4133                 :            : 
    4134                 :    2653520 :   if (decl)
    4135                 :            :     {
    4136                 :    2262360 :       if (!TYPE_NAME (type))
    4137                 :    1792960 :         TYPE_NAME (type) = decl;
    4138                 :    2262360 :       debug_hooks->type_decl (decl, 0);
    4139                 :            :     }
    4140                 :    2653520 : }
    4141                 :            : 
    4142                 :            : /* Push a type into the namespace so that the back ends ignore it.  */
    4143                 :            : 
    4144                 :            : static void
    4145                 :     312932 : record_unknown_type (tree type, const char* name)
    4146                 :            : {
    4147                 :     312932 :   tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
    4148                 :            :                                     TYPE_DECL, get_identifier (name), type));
    4149                 :            :   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
    4150                 :     312932 :   DECL_IGNORED_P (decl) = 1;
    4151                 :     312932 :   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    4152                 :     312932 :   TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
    4153                 :     312932 :   SET_TYPE_ALIGN (type, 1);
    4154                 :     312932 :   TYPE_USER_ALIGN (type) = 0;
    4155                 :     312932 :   SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
    4156                 :     312932 : }
    4157                 :            : 
    4158                 :            : /* Create all the predefined identifiers.  */
    4159                 :            : 
    4160                 :            : static void
    4161                 :      78233 : initialize_predefined_identifiers (void)
    4162                 :            : {
    4163                 :      78233 :   struct predefined_identifier
    4164                 :            :   {
    4165                 :            :     const char *name; /* Name.  */
    4166                 :            :     tree *node;  /* Node to store it in.  */
    4167                 :            :     cp_identifier_kind kind;  /* Kind of identifier.  */
    4168                 :            :   };
    4169                 :            : 
    4170                 :            :   /* A table of identifiers to create at startup.  */
    4171                 :      78233 :   static const predefined_identifier predefined_identifiers[] = {
    4172                 :            :     {"C++", &lang_name_cplusplus, cik_normal},
    4173                 :            :     {"C", &lang_name_c, cik_normal},
    4174                 :            :     /* Some of these names have a trailing space so that it is
    4175                 :            :        impossible for them to conflict with names written by users.  */
    4176                 :            :     {"__ct ", &ctor_identifier, cik_ctor},
    4177                 :            :     {"__ct_base ", &base_ctor_identifier, cik_ctor},
    4178                 :            :     {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
    4179                 :            :     {"__dt ", &dtor_identifier, cik_dtor},
    4180                 :            :     {"__dt_base ", &base_dtor_identifier, cik_dtor},
    4181                 :            :     {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
    4182                 :            :     {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
    4183                 :            :     {"__conv_op ", &conv_op_identifier, cik_conv_op},
    4184                 :            :     {"__in_chrg", &in_charge_identifier, cik_normal},
    4185                 :            :     {"this", &this_identifier, cik_normal},
    4186                 :            :     {"__delta", &delta_identifier, cik_normal},
    4187                 :            :     {"__pfn", &pfn_identifier, cik_normal},
    4188                 :            :     {"_vptr", &vptr_identifier, cik_normal},
    4189                 :            :     {"__vtt_parm", &vtt_parm_identifier, cik_normal},
    4190                 :            :     {"::", &global_identifier, cik_normal},
    4191                 :            :       /* The demangler expects anonymous namespaces to be called
    4192                 :            :          something starting with '_GLOBAL__N_'.  It no longer needs
    4193                 :            :          to be unique to the TU.  */
    4194                 :            :     {"_GLOBAL__N_1", &anon_identifier, cik_normal},
    4195                 :            :     {"auto", &auto_identifier, cik_normal},
    4196                 :            :     {"decltype(auto)", &decltype_auto_identifier, cik_normal},
    4197                 :            :     {"initializer_list", &init_list_identifier, cik_normal},
    4198                 :            :     {"__for_range ", &for_range__identifier, cik_normal},
    4199                 :            :     {"__for_begin ", &for_begin__identifier, cik_normal},
    4200                 :            :     {"__for_end ", &for_end__identifier, cik_normal},
    4201                 :            :     {"__for_range", &for_range_identifier, cik_normal},
    4202                 :            :     {"__for_begin", &for_begin_identifier, cik_normal},
    4203                 :            :     {"__for_end", &for_end_identifier, cik_normal},
    4204                 :            :     {"abi_tag", &abi_tag_identifier, cik_normal},
    4205                 :            :     {"aligned", &aligned_identifier, cik_normal},
    4206                 :            :     {"begin", &begin_identifier, cik_normal},
    4207                 :            :     {"end", &end_identifier, cik_normal},
    4208                 :            :     {"get", &get__identifier, cik_normal},
    4209                 :            :     {"gnu", &gnu_identifier, cik_normal},
    4210                 :            :     {"tuple_element", &tuple_element_identifier, cik_normal},
    4211                 :            :     {"tuple_size", &tuple_size_identifier, cik_normal},
    4212                 :            :     {"type", &type_identifier, cik_normal},
    4213                 :            :     {"value", &value_identifier, cik_normal},
    4214                 :            :     {"_FUN", &fun_identifier, cik_normal},
    4215                 :            :     {"__closure", &closure_identifier, cik_normal},
    4216                 :            :     {"heap uninit", &heap_uninit_identifier, cik_normal},
    4217                 :            :     {"heap ", &heap_identifier, cik_normal},
    4218                 :            :     {"heap deleted", &heap_deleted_identifier, cik_normal},
    4219                 :            :     {NULL, NULL, cik_normal}
    4220                 :            :   };
    4221                 :            : 
    4222                 :    3364020 :   for (const predefined_identifier *pid = predefined_identifiers;
    4223                 :    3364020 :        pid->name; ++pid)
    4224                 :            :     {
    4225                 :    3285790 :       *pid->node = get_identifier (pid->name);
    4226                 :            :       /* Some of these identifiers already have a special kind.  */
    4227                 :    3285790 :       if (pid->kind != cik_normal)
    4228                 :     625864 :         set_identifier_kind (*pid->node, pid->kind);
    4229                 :            :     }
    4230                 :      78233 : }
    4231                 :            : 
    4232                 :            : /* Create the predefined scalar types of C,
    4233                 :            :    and some nodes representing standard constants (0, 1, (void *)0).
    4234                 :            :    Initialize the global binding level.
    4235                 :            :    Make definitions for built-in primitive functions.  */
    4236                 :            : 
    4237                 :            : void
    4238                 :      78233 : cxx_init_decl_processing (void)
    4239                 :            : {
    4240                 :      78233 :   tree void_ftype;
    4241                 :      78233 :   tree void_ftype_ptr;
    4242                 :            : 
    4243                 :            :   /* Create all the identifiers we need.  */
    4244                 :      78233 :   initialize_predefined_identifiers ();
    4245                 :            : 
    4246                 :            :   /* Create the global variables.  */
    4247                 :      78233 :   push_to_top_level ();
    4248                 :            : 
    4249                 :      78233 :   current_function_decl = NULL_TREE;
    4250                 :      78233 :   current_binding_level = NULL;
    4251                 :            :   /* Enter the global namespace.  */
    4252                 :      78233 :   gcc_assert (global_namespace == NULL_TREE);
    4253                 :      78233 :   global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
    4254                 :            :                                       void_type_node);
    4255                 :      78233 :   TREE_PUBLIC (global_namespace) = 1;
    4256                 :      78233 :   DECL_CONTEXT (global_namespace)
    4257                 :     156466 :     = build_translation_unit_decl (get_identifier (main_input_filename));
    4258                 :            :   /* Remember whether we want the empty class passing ABI change warning
    4259                 :            :      in this TU.  */
    4260                 :      78233 :   TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
    4261                 :      78828 :     = warn_abi && abi_version_crosses (12);
    4262                 :      78233 :   debug_hooks->register_main_translation_unit
    4263                 :      78233 :     (DECL_CONTEXT (global_namespace));
    4264                 :      78233 :   begin_scope (sk_namespace, global_namespace);
    4265                 :      78233 :   current_namespace = global_namespace;
    4266                 :            : 
    4267                 :      78233 :   if (flag_visibility_ms_compat)
    4268                 :          8 :     default_visibility = VISIBILITY_HIDDEN;
    4269                 :            : 
    4270                 :            :   /* Initially, C.  */
    4271                 :      78233 :   current_lang_name = lang_name_c;
    4272                 :            : 
    4273                 :            :   /* Create the `std' namespace.  */
    4274                 :      78233 :   push_namespace (get_identifier ("std"));
    4275                 :      78233 :   std_node = current_namespace;
    4276                 :      78233 :   pop_namespace ();
    4277                 :            : 
    4278                 :      78233 :   flag_noexcept_type = (cxx_dialect >= cxx17);
    4279                 :            : 
    4280                 :      78233 :   c_common_nodes_and_builtins ();
    4281                 :            : 
    4282                 :      78233 :   tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
    4283                 :      78233 :   tree decl
    4284                 :      78233 :     = add_builtin_function ("__builtin_is_constant_evaluated",
    4285                 :            :                             bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    4286                 :            :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    4287                 :      78233 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    4288                 :            : 
    4289                 :      78233 :   tree cptr_ftype = build_function_type_list (const_ptr_type_node, NULL_TREE);
    4290                 :      78233 :   decl = add_builtin_function ("__builtin_source_location",
    4291                 :            :                                cptr_ftype, CP_BUILT_IN_SOURCE_LOCATION,
    4292                 :            :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    4293                 :      78233 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    4294                 :            : 
    4295                 :      78233 :   integer_two_node = build_int_cst (NULL_TREE, 2);
    4296                 :            : 
    4297                 :            :   /* Guess at the initial static decls size.  */
    4298                 :      78233 :   vec_alloc (static_decls, 500);
    4299                 :            : 
    4300                 :            :   /* ... and keyed classes.  */
    4301                 :      78233 :   vec_alloc (keyed_classes, 100);
    4302                 :            : 
    4303                 :      78233 :   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
    4304                 :      78233 :   truthvalue_type_node = boolean_type_node;
    4305                 :      78233 :   truthvalue_false_node = boolean_false_node;
    4306                 :      78233 :   truthvalue_true_node = boolean_true_node;
    4307                 :            : 
    4308                 :      78233 :   empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
    4309                 :      78233 :   noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
    4310                 :      78233 :   noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
    4311                 :      78233 :   noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
    4312                 :            :                                             NULL_TREE);
    4313                 :            : 
    4314                 :            : #if 0
    4315                 :            :   record_builtin_type (RID_MAX, NULL, string_type_node);
    4316                 :            : #endif
    4317                 :            : 
    4318                 :      78233 :   delta_type_node = ptrdiff_type_node;
    4319                 :      78233 :   vtable_index_type = ptrdiff_type_node;
    4320                 :            : 
    4321                 :      78233 :   vtt_parm_type = build_pointer_type (const_ptr_type_node);
    4322                 :      78233 :   void_ftype = build_function_type_list (void_type_node, NULL_TREE);
    4323                 :      78233 :   void_ftype_ptr = build_function_type_list (void_type_node,
    4324                 :            :                                              ptr_type_node, NULL_TREE);
    4325                 :      78233 :   void_ftype_ptr
    4326                 :      78233 :     = build_exception_variant (void_ftype_ptr, empty_except_spec);
    4327                 :            : 
    4328                 :            :   /* Create the conversion operator marker.  This operator's DECL_NAME
    4329                 :            :      is in the identifier table, so we can use identifier equality to
    4330                 :            :      find it.  */
    4331                 :      78233 :   conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
    4332                 :            :                                     void_ftype);
    4333                 :            : 
    4334                 :            :   /* C++ extensions */
    4335                 :            : 
    4336                 :      78233 :   unknown_type_node = make_node (LANG_TYPE);
    4337                 :      78233 :   record_unknown_type (unknown_type_node, "unknown type");
    4338                 :            : 
    4339                 :            :   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
    4340                 :      78233 :   TREE_TYPE (unknown_type_node) = unknown_type_node;
    4341                 :            : 
    4342                 :            :   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
    4343                 :            :      result.  */
    4344                 :      78233 :   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
    4345                 :      78233 :   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
    4346                 :            : 
    4347                 :      78233 :   init_list_type_node = make_node (LANG_TYPE);
    4348                 :      78233 :   record_unknown_type (init_list_type_node, "init list");
    4349                 :            : 
    4350                 :      78233 :   {
    4351                 :            :     /* Make sure we get a unique function type, so we can give
    4352                 :            :        its pointer type a name.  (This wins for gdb.) */
    4353                 :      78233 :     tree vfunc_type = make_node (FUNCTION_TYPE);
    4354                 :      78233 :     TREE_TYPE (vfunc_type) = integer_type_node;
    4355                 :      78233 :     TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
    4356                 :      78233 :     layout_type (vfunc_type);
    4357                 :            : 
    4358                 :      78233 :     vtable_entry_type = build_pointer_type (vfunc_type);
    4359                 :            :   }
    4360                 :      78233 :   record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
    4361                 :            : 
    4362                 :      78233 :   vtbl_type_node
    4363                 :      78233 :     = build_cplus_array_type (vtable_entry_type, NULL_TREE);
    4364                 :      78233 :   layout_type (vtbl_type_node);
    4365                 :      78233 :   vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
    4366                 :      78233 :   record_builtin_type (RID_MAX, NULL, vtbl_type_node);
    4367                 :      78233 :   vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
    4368                 :      78233 :   layout_type (vtbl_ptr_type_node);
    4369                 :      78233 :   record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
    4370                 :            : 
    4371                 :      78233 :   push_namespace (get_identifier ("__cxxabiv1"));
    4372                 :      78233 :   abi_node = current_namespace;
    4373                 :      78233 :   pop_namespace ();
    4374                 :            : 
    4375                 :      78233 :   global_type_node = make_node (LANG_TYPE);
    4376                 :      78233 :   record_unknown_type (global_type_node, "global type");
    4377                 :            : 
    4378                 :      78233 :   any_targ_node = make_node (LANG_TYPE);
    4379                 :      78233 :   record_unknown_type (any_targ_node, "any type");
    4380                 :            : 
    4381                 :            :   /* Now, C++.  */
    4382                 :      78233 :   current_lang_name = lang_name_cplusplus;
    4383                 :            : 
    4384                 :      78233 :   if (aligned_new_threshold > 1
    4385                 :      78233 :       && !pow2p_hwi (aligned_new_threshold))
    4386                 :            :     {
    4387                 :          0 :       error ("%<-faligned-new=%d%> is not a power of two",
    4388                 :            :              aligned_new_threshold);
    4389                 :          0 :       aligned_new_threshold = 1;
    4390                 :            :     }
    4391                 :      78233 :   if (aligned_new_threshold == -1)
    4392                 :     124360 :     aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
    4393                 :      78233 :   if (aligned_new_threshold == 1)
    4394                 :      32095 :     aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
    4395                 :            : 
    4396                 :      78233 :   {
    4397                 :      78233 :     tree newattrs, extvisattr;
    4398                 :      78233 :     tree newtype, deltype;
    4399                 :      78233 :     tree ptr_ftype_sizetype;
    4400                 :      78233 :     tree new_eh_spec;
    4401                 :            : 
    4402                 :      78233 :     ptr_ftype_sizetype
    4403                 :      78233 :       = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
    4404                 :      78233 :     if (cxx_dialect == cxx98)
    4405                 :            :       {
    4406                 :      11136 :         tree bad_alloc_id;
    4407                 :      11136 :         tree bad_alloc_type_node;
    4408                 :      11136 :         tree bad_alloc_decl;
    4409                 :            : 
    4410                 :      11136 :         push_nested_namespace (std_node);
    4411                 :      11136 :         bad_alloc_id = get_identifier ("bad_alloc");
    4412                 :      11136 :         bad_alloc_type_node = make_class_type (RECORD_TYPE);
    4413                 :      11136 :         TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
    4414                 :      11136 :         bad_alloc_decl
    4415                 :      11136 :           = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
    4416                 :      11136 :         DECL_CONTEXT (bad_alloc_decl) = current_namespace;
    4417                 :      11136 :         pop_nested_namespace (std_node);
    4418                 :            : 
    4419                 :      11136 :         new_eh_spec
    4420                 :      11136 :           = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
    4421                 :            :       }
    4422                 :            :     else
    4423                 :      67097 :       new_eh_spec = noexcept_false_spec;
    4424                 :            : 
    4425                 :            :     /* Ensure attribs.c is initialized.  */
    4426                 :      78233 :     init_attributes ();
    4427                 :            : 
    4428                 :      78233 :     extvisattr = build_tree_list (get_identifier ("externally_visible"),
    4429                 :            :                                   NULL_TREE);
    4430                 :      78233 :     newattrs = tree_cons (get_identifier ("alloc_size"),
    4431                 :            :                           build_tree_list (NULL_TREE, integer_one_node),
    4432                 :            :                           extvisattr);
    4433                 :      78233 :     newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
    4434                 :      78233 :     newtype = build_exception_variant (newtype, new_eh_spec);
    4435                 :      78233 :     deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
    4436                 :      78233 :     deltype = build_exception_variant (deltype, empty_except_spec);
    4437                 :      78233 :     tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    4438                 :      78233 :     DECL_IS_MALLOC (opnew) = 1;
    4439                 :      78233 :     DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4440                 :      78233 :     opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    4441                 :      78233 :     DECL_IS_MALLOC (opnew) = 1;
    4442                 :      78233 :     DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4443                 :      78233 :     tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4444                 :      78233 :     DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4445                 :      78233 :     opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4446                 :      78233 :     DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4447                 :      78233 :     if (flag_sized_deallocation)
    4448                 :            :       {
    4449                 :            :         /* Also push the sized deallocation variants:
    4450                 :            :              void operator delete(void*, std::size_t) throw();
    4451                 :            :              void operator delete[](void*, std::size_t) throw();  */
    4452                 :      65607 :         tree void_ftype_ptr_size
    4453                 :      65607 :           = build_function_type_list (void_type_node, ptr_type_node,
    4454                 :            :                                       size_type_node, NULL_TREE);
    4455                 :      65607 :         deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
    4456                 :            :                                                    extvisattr);
    4457                 :      65607 :         deltype = build_exception_variant (deltype, empty_except_spec);
    4458                 :      65607 :         opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4459                 :      65607 :         DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4460                 :      65607 :         opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4461                 :      65607 :         DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4462                 :            :       }
    4463                 :            : 
    4464                 :      78233 :     if (aligned_new_threshold)
    4465                 :            :       {
    4466                 :      32095 :         push_nested_namespace (std_node);
    4467                 :      32095 :         tree align_id = get_identifier ("align_val_t");
    4468                 :      32095 :         align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
    4469                 :            :                                       NULL_TREE, /*scoped*/true, NULL);
    4470                 :      32095 :         pop_nested_namespace (std_node);
    4471                 :            : 
    4472                 :            :         /* operator new (size_t, align_val_t); */
    4473                 :      32095 :         newtype = build_function_type_list (ptr_type_node, size_type_node,
    4474                 :            :                                             align_type_node, NULL_TREE);
    4475                 :      32095 :         newtype = cp_build_type_attribute_variant (newtype, newattrs);
    4476                 :      32095 :         newtype = build_exception_variant (newtype, new_eh_spec);
    4477                 :      32095 :         opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    4478                 :      32095 :         DECL_IS_MALLOC (opnew) = 1;
    4479                 :      32095 :         DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4480                 :      32095 :         opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    4481                 :      32095 :         DECL_IS_MALLOC (opnew) = 1;
    4482                 :      32095 :         DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4483                 :            : 
    4484                 :            :         /* operator delete (void *, align_val_t); */
    4485                 :      32095 :         deltype = build_function_type_list (void_type_node, ptr_type_node,
    4486                 :            :                                             align_type_node, NULL_TREE);
    4487                 :      32095 :         deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    4488                 :      32095 :         deltype = build_exception_variant (deltype, empty_except_spec);
    4489                 :      32095 :         opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4490                 :      32095 :         DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4491                 :      32095 :         opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4492                 :      32095 :         DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4493                 :            : 
    4494                 :      32095 :         if (flag_sized_deallocation)
    4495                 :            :           {
    4496                 :            :             /* operator delete (void *, size_t, align_val_t); */
    4497                 :      32092 :             deltype = build_function_type_list (void_type_node, ptr_type_node,
    4498                 :            :                                                 size_type_node, align_type_node,
    4499                 :            :                                                 NULL_TREE);
    4500                 :      32092 :             deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    4501                 :      32092 :             deltype = build_exception_variant (deltype, empty_except_spec);
    4502                 :      32092 :             opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4503                 :      32092 :             DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4504                 :      32092 :             opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4505                 :      32092 :             DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4506                 :            :           }
    4507                 :            :       }
    4508                 :            : 
    4509                 :      78233 :     nullptr_type_node = make_node (NULLPTR_TYPE);
    4510                 :     156466 :     TYPE_SIZE (nullptr_type_node) = bitsize_int (GET_MODE_BITSIZE (ptr_mode));
    4511                 :     156466 :     TYPE_SIZE_UNIT (nullptr_type_node) = size_int (GET_MODE_SIZE (ptr_mode));
    4512                 :      78233 :     TYPE_UNSIGNED (nullptr_type_node) = 1;
    4513                 :     156466 :     TYPE_PRECISION (nullptr_type_node) = GET_MODE_BITSIZE (ptr_mode);
    4514                 :      78233 :     if (abi_version_at_least (9))
    4515                 :      78046 :       SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    4516                 :      78233 :     SET_TYPE_MODE (nullptr_type_node, ptr_mode);
    4517                 :      78233 :     record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
    4518                 :      78233 :     nullptr_node = build_int_cst (nullptr_type_node, 0);
    4519                 :            :   }
    4520                 :            : 
    4521                 :      78233 :   abort_fndecl
    4522                 :      78233 :     = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
    4523                 :            :                             ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
    4524                 :            : 
    4525                 :            :   /* Perform other language dependent initializations.  */
    4526                 :      78233 :   init_class_processing ();
    4527                 :      78233 :   init_rtti_processing ();
    4528                 :      78233 :   init_template_processing ();
    4529                 :            : 
    4530                 :      78233 :   if (flag_exceptions)
    4531                 :      77408 :     init_exception_processing ();
    4532                 :            : 
    4533                 :      78233 :   if (! supports_one_only ())
    4534                 :          0 :     flag_weak = 0;
    4535                 :            : 
    4536                 :      78233 :   make_fname_decl = cp_make_fname_decl;
    4537                 :      78233 :   start_fname_decls ();
    4538                 :            : 
    4539                 :            :   /* Show we use EH for cleanups.  */
    4540                 :      78233 :   if (flag_exceptions)
    4541                 :      77408 :     using_eh_for_cleanups ();
    4542                 :      78233 : }
    4543                 :            : 
    4544                 :            : /* Generate an initializer for a function naming variable from
    4545                 :            :    NAME. NAME may be NULL, to indicate a dependent name.  TYPE_P is
    4546                 :            :    filled in with the type of the init.  */
    4547                 :            : 
    4548                 :            : tree
    4549                 :      34080 : cp_fname_init (const char* name, tree *type_p)
    4550                 :            : {
    4551                 :      34080 :   tree domain = NULL_TREE;
    4552                 :      34080 :   tree type;
    4553                 :      34080 :   tree init = NULL_TREE;
    4554                 :      34080 :   size_t length = 0;
    4555                 :            : 
    4556                 :      34080 :   if (name)
    4557                 :            :     {
    4558                 :      13991 :       length = strlen (name);
    4559                 :      13991 :       domain = build_index_type (size_int (length));
    4560                 :      13991 :       init = build_string (length + 1, name);
    4561                 :            :     }
    4562                 :            : 
    4563                 :      34080 :   type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
    4564                 :      34080 :   type = build_cplus_array_type (type, domain);
    4565                 :            : 
    4566                 :      34080 :   *type_p = type;
    4567                 :            : 
    4568                 :      34080 :   if (init)
    4569                 :      13991 :     TREE_TYPE (init) = type;
    4570                 :            :   else
    4571                 :      20089 :     init = error_mark_node;
    4572                 :            : 
    4573                 :      34080 :   return init;
    4574                 :            : }
    4575                 :            : 
    4576                 :            : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
    4577                 :            :    the decl, LOC is the location to give the decl, NAME is the
    4578                 :            :    initialization string and TYPE_DEP indicates whether NAME depended
    4579                 :            :    on the type of the function. We make use of that to detect
    4580                 :            :    __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
    4581                 :            :    at the point of first use, so we mustn't push the decl now.  */
    4582                 :            : 
    4583                 :            : static tree
    4584                 :      34080 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
    4585                 :            : {
    4586                 :      34080 :   const char * name = NULL;
    4587                 :      34080 :   bool release_name = false;
    4588                 :      34080 :   if (!(type_dep && in_template_function ()))
    4589                 :            :     {
    4590                 :      13991 :       if (current_function_decl == NULL_TREE)
    4591                 :            :         name = "top level";
    4592                 :      13971 :       else if (type_dep == 1) /* __PRETTY_FUNCTION__ */
    4593                 :      13246 :         name = cxx_printable_name (current_function_decl, 2);
    4594                 :        725 :       else if (type_dep == 0) /* __FUNCTION__ */
    4595                 :            :         {
    4596                 :        725 :           name = fname_as_string (type_dep);
    4597                 :        725 :           release_name = true;
    4598                 :            :         }
    4599                 :            :       else
    4600                 :          0 :         gcc_unreachable ();
    4601                 :            :     }
    4602                 :      34080 :   tree type;
    4603                 :      34080 :   tree init = cp_fname_init (name, &type);
    4604                 :      34080 :   tree decl = build_decl (loc, VAR_DECL, id, type);
    4605                 :            : 
    4606                 :      34080 :   if (release_name)
    4607                 :        725 :     free (CONST_CAST (char *, name));
    4608                 :            : 
    4609                 :            :   /* As we're using pushdecl_with_scope, we must set the context.  */
    4610                 :      34080 :   DECL_CONTEXT (decl) = current_function_decl;
    4611                 :            : 
    4612                 :      34080 :   TREE_READONLY (decl) = 1;
    4613                 :      34080 :   DECL_ARTIFICIAL (decl) = 1;
    4614                 :      68160 :   DECL_DECLARED_CONSTEXPR_P (decl) = 1;
    4615                 :      34080 :   TREE_STATIC (decl) = 1;
    4616                 :            : 
    4617                 :      34080 :   TREE_USED (decl) = 1;
    4618                 :            : 
    4619                 :      34080 :   if (init)
    4620                 :            :     {
    4621                 :      34080 :       SET_DECL_VALUE_EXPR (decl, init);
    4622                 :      34080 :       DECL_HAS_VALUE_EXPR_P (decl) = 1;
    4623                 :            :       /* For decl_constant_var_p.  */
    4624                 :      34080 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    4625                 :            :     }
    4626                 :            : 
    4627                 :      34080 :   if (current_function_decl)
    4628                 :            :     {
    4629                 :      34060 :       DECL_CONTEXT (decl) = current_function_decl;
    4630                 :      34060 :       decl = pushdecl_outermost_localscope (decl);
    4631                 :      34060 :       if (decl != error_mark_node)
    4632                 :      34056 :         add_decl_expr (decl);
    4633                 :            :     }
    4634                 :            :   else
    4635                 :            :     {
    4636                 :         20 :       DECL_THIS_STATIC (decl) = true;
    4637                 :         20 :       pushdecl_top_level_and_finish (decl, NULL_TREE);
    4638                 :            :     }
    4639                 :            : 
    4640                 :      34080 :   return decl;
    4641                 :            : }
    4642                 :            : 
    4643                 :            : /* Install DECL as a builtin function at current (global) scope.
    4644                 :            :    Return the new decl (if we found an existing version).  Also
    4645                 :            :    installs it into ::std, if it's not '_*'.  */
    4646                 :            : 
    4647                 :            : tree
    4648                 :  134843000 : cxx_builtin_function (tree decl)
    4649                 :            : {
    4650                 :  134843000 :   retrofit_lang_decl (decl);
    4651                 :            : 
    4652                 :  134843000 :   DECL_ARTIFICIAL (decl) = 1;
    4653                 :  134843000 :   SET_DECL_LANGUAGE (decl, lang_c);
    4654                 :            :   /* Runtime library routines are, by definition, available in an
    4655                 :            :      external shared object.  */
    4656                 :  134843000 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    4657                 :  134843000 :   DECL_VISIBILITY_SPECIFIED (decl) = 1;
    4658                 :            : 
    4659                 :  134843000 :   tree id = DECL_NAME (decl);
    4660                 :  134843000 :   const char *name = IDENTIFIER_POINTER (id);
    4661                 :  134843000 :   if (name[0] != '_' || name[1] != '_')
    4662                 :            :     /* In the user's namespace, it must be declared before use.  */
    4663                 :   56426600 :     DECL_ANTICIPATED (decl) = 1;
    4664                 :  106630000 :   else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
    4665                 :  106630000 :            && 0 != strncmp (name + 2, "builtin_", strlen ("builtin_"))
    4666                 :  124565000 :            && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
    4667                 :            :                            "_chk", strlen ("_chk") + 1))
    4668                 :            :     /* Treat __*_chk fortification functions as anticipated as well,
    4669                 :            :        unless they are __builtin_*_chk.  */
    4670                 :    1354100 :     DECL_ANTICIPATED (decl) = 1;
    4671                 :            : 
    4672                 :            :   /* All builtins that don't begin with an '_' should additionally
    4673                 :            :      go in the 'std' namespace.  */
    4674                 :  134843000 :   if (name[0] != '_')
    4675                 :            :     {
    4676                 :   28105300 :       tree std_decl = copy_decl (decl);
    4677                 :            : 
    4678                 :   28105300 :       push_nested_namespace (std_node);
    4679                 :   28105300 :       DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
    4680                 :   28105300 :       pushdecl (std_decl);
    4681                 :   28105300 :       pop_nested_namespace (std_node);
    4682                 :            :     }
    4683                 :            : 
    4684                 :  134843000 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    4685                 :  134843000 :   decl = pushdecl (decl);
    4686                 :            : 
    4687                 :  134843000 :   return decl;
    4688                 :            : }
    4689                 :            : 
    4690                 :            : /* Like cxx_builtin_function, but guarantee the function is added to the global
    4691                 :            :    scope.  This is to allow function specific options to add new machine
    4692                 :            :    dependent builtins when the target ISA changes via attribute((target(...)))
    4693                 :            :    which saves space on program startup if the program does not use non-generic
    4694                 :            :    ISAs.  */
    4695                 :            : 
    4696                 :            : tree
    4697                 :     499644 : cxx_builtin_function_ext_scope (tree decl)
    4698                 :            : {
    4699                 :     499644 :   push_nested_namespace (global_namespace);
    4700                 :     499644 :   decl = cxx_builtin_function (decl);
    4701                 :     499644 :   pop_nested_namespace (global_namespace);
    4702                 :            : 
    4703                 :     499644 :   return decl;
    4704                 :            : }
    4705                 :            : 
    4706                 :            : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    4707                 :            : 
    4708                 :            : tree
    4709                 :          0 : cxx_simulate_builtin_function_decl (tree decl)
    4710                 :            : {
    4711                 :          0 :   retrofit_lang_decl (decl);
    4712                 :            : 
    4713                 :          0 :   DECL_ARTIFICIAL (decl) = 1;
    4714                 :          0 :   SET_DECL_LANGUAGE (decl, lang_cplusplus);
    4715                 :          0 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    4716                 :          0 :   return pushdecl (decl);
    4717                 :            : }
    4718                 :            : 
    4719                 :            : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
    4720                 :            :    function.  Not called directly.  */
    4721                 :            : 
    4722                 :            : static tree
    4723                 :     978326 : build_library_fn (tree name, enum tree_code operator_code, tree type,
    4724                 :            :                   int ecf_flags)
    4725                 :            : {
    4726                 :     978326 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    4727                 :     978326 :   DECL_EXTERNAL (fn) = 1;
    4728                 :     978326 :   TREE_PUBLIC (fn) = 1;
    4729                 :     978326 :   DECL_ARTIFICIAL (fn) = 1;
    4730                 :     978326 :   DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
    4731                 :     978326 :     = OVL_OP_INFO (false, operator_code)->ovl_op_code;
    4732                 :     978326 :   SET_DECL_LANGUAGE (fn, lang_c);
    4733                 :            :   /* Runtime library routines are, by definition, available in an
    4734                 :            :      external shared object.  */
    4735                 :     978326 :   DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
    4736                 :     978326 :   DECL_VISIBILITY_SPECIFIED (fn) = 1;
    4737                 :     978326 :   set_call_expr_flags (fn, ecf_flags);
    4738                 :     978326 :   return fn;
    4739                 :            : }
    4740                 :            : 
    4741                 :            : /* Returns the _DECL for a library function with C++ linkage.  */
    4742                 :            : 
    4743                 :            : static tree
    4744                 :     714118 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
    4745                 :            :                      int ecf_flags)
    4746                 :            : {
    4747                 :     714118 :   tree fn = build_library_fn (name, operator_code, type, ecf_flags);
    4748                 :     714118 :   DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
    4749                 :     714118 :   SET_DECL_LANGUAGE (fn, lang_cplusplus);
    4750                 :     714118 :   return fn;
    4751                 :            : }
    4752                 :            : 
    4753                 :            : /* Like build_library_fn, but takes a C string instead of an
    4754                 :            :    IDENTIFIER_NODE.  */
    4755                 :            : 
    4756                 :            : tree
    4757                 :      86489 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
    4758                 :            : {
    4759                 :      86489 :   return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
    4760                 :            : }
    4761                 :            : 
    4762                 :            : /* Like build_cp_library_fn, but takes a C string instead of an
    4763                 :            :    IDENTIFIER_NODE.  */
    4764                 :            : 
    4765                 :            : tree
    4766                 :      77408 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
    4767                 :            : {
    4768                 :      77408 :   return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
    4769                 :      77408 :                               ecf_flags);
    4770                 :            : }
    4771                 :            : 
    4772                 :            : /* Like build_library_fn, but also pushes the function so that we will
    4773                 :            :    be able to find it via get_global_binding.  Also, the function
    4774                 :            :    may throw exceptions listed in RAISES.  */
    4775                 :            : 
    4776                 :            : tree
    4777                 :     177719 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
    4778                 :            : {
    4779                 :     177719 :   tree fn;
    4780                 :            : 
    4781                 :     177719 :   if (raises)
    4782                 :      10847 :     type = build_exception_variant (type, raises);
    4783                 :            : 
    4784                 :     177719 :   fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
    4785                 :     177719 :   pushdecl_top_level (fn);
    4786                 :     177719 :   return fn;
    4787                 :            : }
    4788                 :            : 
    4789                 :            : /* Like build_cp_library_fn, but also pushes the function so that it
    4790                 :            :    will be found by normal lookup.  */
    4791                 :            : 
    4792                 :            : static tree
    4793                 :     636710 : push_cp_library_fn (enum tree_code operator_code, tree type,
    4794                 :            :                     int ecf_flags)
    4795                 :            : {
    4796                 :     636710 :   tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
    4797                 :            :                                  operator_code, type, ecf_flags);
    4798                 :     636710 :   pushdecl (fn);
    4799                 :     636710 :   if (flag_tm)
    4800                 :       3164 :     apply_tm_attr (fn, get_identifier ("transaction_safe"));
    4801                 :     636710 :   return fn;
    4802                 :            : }
    4803                 :            : 
    4804                 :            : /* Like push_library_fn, but takes a TREE_LIST of parm types rather than
    4805                 :            :    a FUNCTION_TYPE.  */
    4806                 :            : 
    4807                 :            : tree
    4808                 :          0 : push_void_library_fn (tree name, tree parmtypes, int ecf_flags)
    4809                 :            : {
    4810                 :          0 :   tree type = build_function_type (void_type_node, parmtypes);
    4811                 :          0 :   return push_library_fn (name, type, NULL_TREE, ecf_flags);
    4812                 :            : }
    4813                 :            : 
    4814                 :            : /* Like push_library_fn, but also note that this function throws
    4815                 :            :    and does not return.  Used for __throw_foo and the like.  */
    4816                 :            : 
    4817                 :            : tree
    4818                 :      90991 : push_throw_library_fn (tree name, tree type)
    4819                 :            : {
    4820                 :      90991 :   tree fn = push_library_fn (name, type, NULL_TREE, ECF_NORETURN | ECF_COLD);
    4821                 :      90991 :   return fn;
    4822                 :            : }
    4823                 :            : 
    4824                 :            : /* When we call finish_struct for an anonymous union, we create
    4825                 :            :    default copy constructors and such.  But, an anonymous union
    4826                 :            :    shouldn't have such things; this function undoes the damage to the
    4827                 :            :    anonymous union type T.
    4828                 :            : 
    4829                 :            :    (The reason that we create the synthesized methods is that we don't
    4830                 :            :    distinguish `union { int i; }' from `typedef union { int i; } U'.
    4831                 :            :    The first is an anonymous union; the second is just an ordinary
    4832                 :            :    union type.)  */
    4833                 :            : 
    4834                 :            : void
    4835                 :      18164 : fixup_anonymous_aggr (tree t)
    4836                 :            : {
    4837                 :            :   /* Wipe out memory of synthesized methods.  */
    4838                 :      18164 :   TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
    4839                 :      18164 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
    4840                 :      18164 :   TYPE_HAS_COPY_CTOR (t) = 0;
    4841                 :      18164 :   TYPE_HAS_CONST_COPY_CTOR (t) = 0;
    4842                 :      18164 :   TYPE_HAS_COPY_ASSIGN (t) = 0;
    4843                 :      18164 :   TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
    4844                 :            : 
    4845                 :            :   /* Splice the implicitly generated functions out of TYPE_FIELDS.  */
    4846                 :     105209 :   for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
    4847                 :      69334 :     if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
    4848                 :          0 :       *prev_p = DECL_CHAIN (probe);
    4849                 :            :     else
    4850                 :      69318 :       prev_p = &DECL_CHAIN (probe);
    4851                 :            : 
    4852                 :            :   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
    4853                 :            :      assignment operators (because they cannot have these methods themselves).
    4854                 :            :      For anonymous unions this is already checked because they are not allowed
    4855                 :            :      in any union, otherwise we have to check it.  */
    4856                 :      18164 :   if (TREE_CODE (t) != UNION_TYPE)
    4857                 :            :     {
    4858                 :        437 :       tree field, type;
    4859                 :            : 
    4860                 :       1959 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    4861                 :       1522 :         if (TREE_CODE (field) == FIELD_DECL)
    4862                 :            :           {
    4863                 :        977 :             type = TREE_TYPE (field);
    4864                 :       1032 :             if (CLASS_TYPE_P (type))
    4865                 :            :               {
    4866                 :         55 :                 if (TYPE_NEEDS_CONSTRUCTING (type))
    4867                 :          4 :                   error ("member %q+#D with constructor not allowed "
    4868                 :            :                          "in anonymous aggregate", field);
    4869                 :         55 :                 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    4870                 :          0 :                   error ("member %q+#D with destructor not allowed "
    4871                 :            :                          "in anonymous aggregate", field);
    4872                 :         55 :                 if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    4873                 :          0 :                   error ("member %q+#D with copy assignment operator "
    4874                 :            :                          "not allowed in anonymous aggregate", field);
    4875                 :            :               }
    4876                 :            :           }
    4877                 :            :     }
    4878                 :      18164 : }
    4879                 :            : 
    4880                 :            : /* Warn for an attribute located at LOCATION that appertains to the
    4881                 :            :    class type CLASS_TYPE that has not been properly placed after its
    4882                 :            :    class-key, in it class-specifier.  */
    4883                 :            : 
    4884                 :            : void
    4885                 :         21 : warn_misplaced_attr_for_class_type (location_t location,
    4886                 :            :                                     tree class_type)
    4887                 :            : {
    4888                 :         35 :   gcc_assert (OVERLOAD_TYPE_P (class_type));
    4889                 :            : 
    4890                 :         42 :   auto_diagnostic_group d;
    4891                 :         21 :   if (warning_at (location, OPT_Wattributes,
    4892                 :            :                   "attribute ignored in declaration "
    4893                 :            :                   "of %q#T", class_type))
    4894                 :         21 :     inform (location,
    4895                 :            :             "attribute for %q#T must follow the %qs keyword",
    4896                 :            :             class_type, class_key_or_enum_as_string (class_type));
    4897                 :         21 : }
    4898                 :            : 
    4899                 :            : /* Returns the cv-qualifiers that apply to the type specified
    4900                 :            :    by the DECLSPECS.  */
    4901                 :            : 
    4902                 :            : static int
    4903                 :   80486200 : get_type_quals (const cp_decl_specifier_seq *declspecs)
    4904                 :            : {
    4905                 :   80486200 :   int type_quals = TYPE_UNQUALIFIED;
    4906                 :            : 
    4907                 :   80486200 :   if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    4908                 :    8194320 :     type_quals |= TYPE_QUAL_CONST;
    4909                 :   80486200 :   if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    4910                 :     212891 :     type_quals |= TYPE_QUAL_VOLATILE;
    4911                 :   80486200 :   if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    4912                 :         21 :     type_quals |= TYPE_QUAL_RESTRICT;
    4913                 :            : 
    4914                 :   80486200 :   return type_quals;
    4915                 :            : }
    4916                 :            : 
    4917                 :            : /* Make sure that a declaration with no declarator is well-formed, i.e.
    4918                 :            :    just declares a tagged type or anonymous union.
    4919                 :            : 
    4920                 :            :    Returns the type declared; or NULL_TREE if none.  */
    4921                 :            : 
    4922                 :            : tree
    4923                 :    4766760 : check_tag_decl (cp_decl_specifier_seq *declspecs,
    4924                 :            :                 bool explicit_type_instantiation_p)
    4925                 :            : {
    4926                 :    4766760 :   int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    4927                 :    4766760 :   int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
    4928                 :            :   /* If a class, struct, or enum type is declared by the DECLSPECS
    4929                 :            :      (i.e, if a class-specifier, enum-specifier, or non-typename
    4930                 :            :      elaborated-type-specifier appears in the DECLSPECS),
    4931                 :            :      DECLARED_TYPE is set to the corresponding type.  */
    4932                 :    4766760 :   tree declared_type = NULL_TREE;
    4933                 :    4766760 :   bool error_p = false;
    4934                 :            : 
    4935                 :    4766760 :   if (declspecs->multiple_types_p)
    4936                 :         28 :     error_at (smallest_type_location (declspecs),
    4937                 :            :               "multiple types in one declaration");
    4938                 :    4766730 :   else if (declspecs->redefined_builtin_type)
    4939                 :            :     {
    4940                 :         22 :       location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
    4941                 :         22 :       if (!in_system_header_at (loc))
    4942                 :         10 :         permerror (loc, "redeclaration of C++ built-in type %qT",
    4943                 :            :                    declspecs->redefined_builtin_type);
    4944                 :         22 :       return NULL_TREE;
    4945                 :            :     }
    4946                 :            : 
    4947                 :    4766740 :   if (declspecs->type
    4948                 :    4766720 :       && TYPE_P (declspecs->type)
    4949                 :    9527160 :       && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
    4950                 :    4760330 :            && MAYBE_CLASS_TYPE_P (declspecs->type))
    4951                 :     243950 :           || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
    4952                 :            :     declared_type = declspecs->type;
    4953                 :       6437 :   else if (declspecs->type == error_mark_node)
    4954                 :        802 :     error_p = true;
    4955                 :            : 
    4956                 :    4766740 :   if (type_uses_auto (declared_type))
    4957                 :            :     {
    4958                 :         10 :       error_at (declspecs->locations[ds_type_spec],
    4959                 :            :                 "%<auto%> can only be specified for variables "
    4960                 :            :                 "or function declarations");
    4961                 :         10 :       return error_mark_node;
    4962                 :            :     }
    4963                 :            : 
    4964                 :    9283170 :   if (declared_type && !OVERLOAD_TYPE_P (declared_type))
    4965                 :            :     declared_type = NULL_TREE;
    4966                 :            : 
    4967                 :    4766730 :   if (!declared_type && !saw_friend && !error_p)
    4968                 :        104 :     permerror (input_location, "declaration does not declare anything");
    4969                 :            :   /* Check for an anonymous union.  */
    4970                 :    4760270 :   else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
    4971                 :    9283070 :            && TYPE_UNNAMED_P (declared_type))
    4972                 :            :     {
    4973                 :            :       /* 7/3 In a simple-declaration, the optional init-declarator-list
    4974                 :            :          can be omitted only when declaring a class (clause 9) or
    4975                 :            :          enumeration (7.2), that is, when the decl-specifier-seq contains
    4976                 :            :          either a class-specifier, an elaborated-type-specifier with
    4977                 :            :          a class-key (9.1), or an enum-specifier.  In these cases and
    4978                 :            :          whenever a class-specifier or enum-specifier is present in the
    4979                 :            :          decl-specifier-seq, the identifiers in these specifiers are among
    4980                 :            :          the names being declared by the declaration (as class-name,
    4981                 :            :          enum-names, or enumerators, depending on the syntax).  In such
    4982                 :            :          cases, and except for the declaration of an unnamed bit-field (9.6),
    4983                 :            :          the decl-specifier-seq shall introduce one or more names into the
    4984                 :            :          program, or shall redeclare a name introduced by a previous
    4985                 :            :          declaration.  [Example:
    4986                 :            :              enum { };                  // ill-formed
    4987                 :            :              typedef class { };         // ill-formed
    4988                 :            :          --end example]  */
    4989                 :      18172 :       if (saw_typedef)
    4990                 :            :         {
    4991                 :          8 :           error_at (declspecs->locations[ds_typedef],
    4992                 :            :                     "missing type-name in typedef-declaration");
    4993                 :          8 :           return NULL_TREE;
    4994                 :            :         }
    4995                 :      18164 :       /* Anonymous unions are objects, so they can have specifiers.  */;
    4996                 :      18164 :       SET_ANON_AGGR_TYPE_P (declared_type);
    4997                 :            : 
    4998                 :      18164 :       if (TREE_CODE (declared_type) != UNION_TYPE)
    4999                 :        437 :         pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
    5000                 :            :                  OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
    5001                 :            :     }
    5002                 :            : 
    5003                 :            :   else
    5004                 :            :     {
    5005                 :    4748450 :       if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
    5006                 :         11 :         error_at (declspecs->locations[ds_inline],
    5007                 :            :                   "%<inline%> can only be specified for functions");
    5008                 :    4748440 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
    5009                 :          3 :         error_at (declspecs->locations[ds_virtual],
    5010                 :            :                   "%<virtual%> can only be specified for functions");
    5011                 :    4748440 :       else if (saw_friend
    5012                 :    4748440 :                && (!current_class_type
    5013                 :      79433 :                    || current_scope () != current_class_type))
    5014                 :          0 :         error_at (declspecs->locations[ds_friend],
    5015                 :            :                   "%<friend%> can only be specified inside a class");
    5016                 :    4748440 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
    5017                 :          3 :         error_at (declspecs->locations[ds_explicit],
    5018                 :            :                   "%<explicit%> can only be specified for constructors");
    5019                 :    4748430 :       else if (declspecs->storage_class)
    5020                 :          3 :         error_at (declspecs->locations[ds_storage_class],
    5021                 :            :                   "a storage class can only be specified for objects "
    5022                 :            :                   "and functions");
    5023                 :    4748430 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    5024                 :         11 :         error_at (declspecs->locations[ds_const],
    5025                 :            :                   "%<const%> can only be specified for objects and "
    5026                 :            :                   "functions");
    5027                 :    4748420 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    5028                 :          3 :         error_at (declspecs->locations[ds_volatile],
    5029                 :            :                   "%<volatile%> can only be specified for objects and "
    5030                 :            :                   "functions");
    5031                 :    4748420 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    5032                 :          3 :         error_at (declspecs->locations[ds_restrict],
    5033                 :            :                   "%<__restrict%> can only be specified for objects and "
    5034                 :            :                   "functions");
    5035                 :    4748410 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
    5036                 :          3 :         error_at (declspecs->locations[ds_thread],
    5037                 :            :                   "%<__thread%> can only be specified for objects "
    5038                 :            :                   "and functions");
    5039                 :    4748410 :       else if (saw_typedef)
    5040                 :         31 :         warning_at (declspecs->locations[ds_typedef], 0,
    5041                 :            :                     "%<typedef%> was ignored in this declaration");
    5042                 :    4748380 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
    5043                 :          9 :         error_at (declspecs->locations[ds_constexpr],
    5044                 :            :                   "%qs cannot be used for type declarations", "constexpr");
    5045                 :    4748370 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
    5046                 :          1 :         error_at (declspecs->locations[ds_constinit],
    5047                 :            :                   "%qs cannot be used for type declarations", "constinit");
    5048                 :    4748370 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
    5049                 :          1 :         error_at (declspecs->locations[ds_consteval],
    5050                 :            :                   "%qs cannot be used for type declarations", "consteval");
    5051                 :            :     }
    5052                 :            : 
    5053                 :    4766720 :   if (declspecs->attributes && warn_attributes && declared_type)
    5054                 :            :     {
    5055                 :         22 :       location_t loc;
    5056                 :         15 :       if (!CLASS_TYPE_P (declared_type)
    5057                 :         37 :           || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
    5058                 :            :         /* For a non-template class, use the name location.  */
    5059                 :         15 :         loc = location_of (declared_type);
    5060                 :            :       else
    5061                 :            :         /* For a template class (an explicit instantiation), use the
    5062                 :            :            current location.  */
    5063                 :          7 :         loc = input_location;
    5064                 :            : 
    5065                 :         22 :       if (explicit_type_instantiation_p)
    5066                 :            :         /* [dcl.attr.grammar]/4:
    5067                 :            : 
    5068                 :            :                No attribute-specifier-seq shall appertain to an explicit
    5069                 :            :                instantiation.  */
    5070                 :            :         {
    5071                 :          7 :           if (warning_at (loc, OPT_Wattributes,
    5072                 :            :                           "attribute ignored in explicit instantiation %q#T",
    5073                 :            :                           declared_type))
    5074                 :          7 :             inform (loc,
    5075                 :            :                     "no attribute can be applied to "
    5076                 :            :                     "an explicit instantiation");
    5077                 :            :         }
    5078                 :            :       else
    5079                 :         15 :         warn_misplaced_attr_for_class_type (loc, declared_type);
    5080                 :            :     }
    5081                 :            : 
    5082                 :            :   return declared_type;
    5083                 :            : }
    5084                 :            : 
    5085                 :            : /* Called when a declaration is seen that contains no names to declare.
    5086                 :            :    If its type is a reference to a structure, union or enum inherited
    5087                 :            :    from a containing scope, shadow that tag name for the current scope
    5088                 :            :    with a forward reference.
    5089                 :            :    If its type defines a new named structure or union
    5090                 :            :    or defines an enum, it is valid but we need not do anything here.
    5091                 :            :    Otherwise, it is an error.
    5092                 :            : 
    5093                 :            :    C++: may have to grok the declspecs to learn about static,
    5094                 :            :    complain for anonymous unions.
    5095                 :            : 
    5096                 :            :    Returns the TYPE declared -- or NULL_TREE if none.  */
    5097                 :            : 
    5098                 :            : tree
    5099                 :    4407510 : shadow_tag (cp_decl_specifier_seq *declspecs)
    5100                 :            : {
    5101                 :    4407510 :   tree t = check_tag_decl (declspecs,
    5102                 :            :                            /*explicit_type_instantiation_p=*/false);
    5103                 :            : 
    5104                 :    4407510 :   if (!t)
    5105                 :            :     return NULL_TREE;
    5106                 :            : 
    5107                 :    4406690 :   if (maybe_process_partial_specialization (t) == error_mark_node)
    5108                 :            :     return NULL_TREE;
    5109                 :            : 
    5110                 :            :   /* This is where the variables in an anonymous union are
    5111                 :            :      declared.  An anonymous union declaration looks like:
    5112                 :            :      union { ... } ;
    5113                 :            :      because there is no declarator after the union, the parser
    5114                 :            :      sends that declaration here.  */
    5115                 :    8724610 :   if (ANON_AGGR_TYPE_P (t))
    5116                 :            :     {
    5117                 :        302 :       fixup_anonymous_aggr (t);
    5118                 :            : 
    5119                 :        594 :       if (TYPE_FIELDS (t))
    5120                 :            :         {
    5121                 :        302 :           tree decl = grokdeclarator (/*declarator=*/NULL,
    5122                 :            :                                       declspecs, NORMAL, 0, NULL);
    5123                 :        302 :           finish_anon_union (decl);
    5124                 :            :         }
    5125                 :            :     }
    5126                 :            : 
    5127                 :            :   return t;
    5128                 :            : }
    5129                 :            : 
    5130                 :            : /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
    5131                 :            : 
    5132                 :            : tree
    5133                 :   28659100 : groktypename (cp_decl_specifier_seq *type_specifiers,
    5134                 :            :               const cp_declarator *declarator,
    5135                 :            :               bool is_template_arg)
    5136                 :            : {
    5137                 :   28659100 :   tree attrs;
    5138                 :   28659100 :   tree type;
    5139                 :   57318100 :   enum decl_context context
    5140                 :   28659100 :     = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
    5141                 :   28659100 :   attrs = type_specifiers->attributes;
    5142                 :   28659100 :   type_specifiers->attributes = NULL_TREE;
    5143                 :   28659100 :   type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
    5144                 :   28659100 :   if (attrs && type != error_mark_node)
    5145                 :            :     {
    5146                 :        617 :       if (CLASS_TYPE_P (type))
    5147                 :          7 :         warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
    5148                 :            :                  "outside of definition", type);
    5149                 :        610 :       else if (MAYBE_CLASS_TYPE_P (type))
    5150                 :            :         /* A template type parameter or other dependent type.  */
    5151                 :          4 :         warning (OPT_Wattributes, "ignoring attributes applied to dependent "
    5152                 :            :                  "type %qT without an associated declaration", type);
    5153                 :            :       else
    5154                 :        606 :         cplus_decl_attributes (&type, attrs, 0);
    5155                 :            :     }
    5156                 :   28659100 :   return type;
    5157                 :            : }
    5158                 :            : 
    5159                 :            : /* Process a DECLARATOR for a function-scope variable declaration,
    5160                 :            :    namespace-scope variable declaration, or function declaration.
    5161                 :            :    (Function definitions go through start_function; class member
    5162                 :            :    declarations appearing in the body of the class go through
    5163                 :            :    grokfield.)  The DECL corresponding to the DECLARATOR is returned.
    5164                 :            :    If an error occurs, the error_mark_node is returned instead.
    5165                 :            :    
    5166                 :            :    DECLSPECS are the decl-specifiers for the declaration.  INITIALIZED is
    5167                 :            :    SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
    5168                 :            :    for an explicitly defaulted function, or SD_DELETED for an explicitly
    5169                 :            :    deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
    5170                 :            :    implicitly initialized via a default constructor.  ATTRIBUTES and
    5171                 :            :    PREFIX_ATTRIBUTES are GNU attributes associated with this declaration.
    5172                 :            : 
    5173                 :            :    The scope represented by the context of the returned DECL is pushed
    5174                 :            :    (if it is not the global namespace) and is assigned to
    5175                 :            :    *PUSHED_SCOPE_P.  The caller is then responsible for calling
    5176                 :            :    pop_scope on *PUSHED_SCOPE_P if it is set.  */
    5177                 :            : 
    5178                 :            : tree
    5179                 :   10157900 : start_decl (const cp_declarator *declarator,
    5180                 :            :             cp_decl_specifier_seq *declspecs,
    5181                 :            :             int initialized,
    5182                 :            :             tree attributes,
    5183                 :            :             tree prefix_attributes,
    5184                 :            :             tree *pushed_scope_p)
    5185                 :            : {
    5186                 :   10157900 :   tree decl;
    5187                 :   10157900 :   tree context;
    5188                 :   10157900 :   bool was_public;
    5189                 :   10157900 :   int flags;
    5190                 :   10157900 :   bool alias;
    5191                 :            : 
    5192                 :   10157900 :   *pushed_scope_p = NULL_TREE;
    5193                 :            : 
    5194                 :            :   /* An object declared as __attribute__((deprecated)) suppresses
    5195                 :            :      warnings of uses of other deprecated items.  */
    5196                 :   10157900 :   if (lookup_attribute ("deprecated", attributes))
    5197                 :      11492 :     deprecated_state = DEPRECATED_SUPPRESS;
    5198                 :            : 
    5199                 :   10157900 :   attributes = chainon (attributes, prefix_attributes);
    5200                 :            : 
    5201                 :   10157900 :   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
    5202                 :            :                          &attributes);
    5203                 :            : 
    5204                 :   10157900 :   deprecated_state = DEPRECATED_NORMAL;
    5205                 :            : 
    5206                 :   10157900 :   if (decl == NULL_TREE || VOID_TYPE_P (decl)
    5207                 :   10157900 :       || decl == error_mark_node)
    5208                 :       2573 :     return error_mark_node;
    5209                 :            : 
    5210                 :   10155400 :   context = CP_DECL_CONTEXT (decl);
    5211                 :   10155400 :   if (context != global_namespace)
    5212                 :    1870460 :     *pushed_scope_p = push_scope (context);
    5213                 :            : 
    5214                 :            :   /* Is it valid for this decl to have an initializer at all?
    5215                 :            :      If not, set INITIALIZED to zero, which will indirectly
    5216                 :            :      tell `cp_finish_decl' to ignore the initializer once it is parsed.  */
    5217                 :   10155400 :   if (initialized
    5218                 :    3047240 :       && TREE_CODE (decl) == TYPE_DECL)
    5219                 :            :     {
    5220                 :         12 :       error_at (DECL_SOURCE_LOCATION (decl),
    5221                 :            :                 "typedef %qD is initialized (use %qs instead)",
    5222                 :            :                 decl, "decltype");
    5223                 :         12 :       return error_mark_node;
    5224                 :            :     }
    5225                 :            : 
    5226                 :   10155300 :   if (initialized)
    5227                 :            :     {
    5228                 :    3047220 :       if (! toplevel_bindings_p ()
    5229                 :    3047220 :           && DECL_EXTERNAL (decl))
    5230                 :          4 :         warning (0, "declaration of %q#D has %<extern%> and is initialized",
    5231                 :            :                  decl);
    5232                 :    3047220 :       DECL_EXTERNAL (decl) = 0;
    5233                 :    3047220 :       if (toplevel_bindings_p ())
    5234                 :     442520 :         TREE_STATIC (decl) = 1;
    5235                 :            :     }
    5236                 :   10155300 :   alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
    5237                 :            :   
    5238                 :   10155300 :   if (alias && TREE_CODE (decl) == FUNCTION_DECL)
    5239                 :      66895 :     record_key_method_defined (decl);
    5240                 :            : 
    5241                 :            :   /* If this is a typedef that names the class for linkage purposes
    5242                 :            :      (7.1.3p8), apply any attributes directly to the type.  */
    5243                 :   10155300 :   if (TREE_CODE (decl) == TYPE_DECL
    5244                 :    2035380 :       && OVERLOAD_TYPE_P (TREE_TYPE (decl))
    5245                 :   10735300 :       && decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl))))
    5246                 :            :     flags = ATTR_FLAG_TYPE_IN_PLACE;
    5247                 :            :   else
    5248                 :            :     flags = 0;
    5249                 :            : 
    5250                 :            :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    5251                 :   10155300 :   cplus_decl_attributes (&decl, attributes, flags);
    5252                 :            : 
    5253                 :            :   /* Dllimported symbols cannot be defined.  Static data members (which
    5254                 :            :      can be initialized in-class and dllimported) go through grokfield,
    5255                 :            :      not here, so we don't need to exclude those decls when checking for
    5256                 :            :      a definition.  */
    5257                 :   10155300 :   if (initialized && DECL_DLLIMPORT_P (decl))
    5258                 :            :     {
    5259                 :          0 :       error_at (DECL_SOURCE_LOCATION (decl),
    5260                 :            :                 "definition of %q#D is marked %<dllimport%>", decl);
    5261                 :          0 :       DECL_DLLIMPORT_P (decl) = 0;
    5262                 :            :     }
    5263                 :            : 
    5264                 :            :   /* If #pragma weak was used, mark the decl weak now.  */
    5265                 :   10155300 :   if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
    5266                 :    6244180 :     maybe_apply_pragma_weak (decl);
    5267                 :            : 
    5268                 :   10155300 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5269                 :    4334310 :       && DECL_DECLARED_INLINE_P (decl)
    5270                 :      88095 :       && DECL_UNINLINABLE (decl)
    5271                 :   10155300 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    5272                 :          0 :     warning_at (DECL_SOURCE_LOCATION (decl), 0,
    5273                 :            :                 "inline function %qD given attribute %qs", decl, "noinline");
    5274                 :            : 
    5275                 :   10155300 :   if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
    5276                 :            :     {
    5277                 :     111413 :       bool this_tmpl = (processing_template_decl
    5278                 :     111413 :                         > template_class_depth (context));
    5279                 :     111413 :       if (VAR_P (decl))
    5280                 :            :         {
    5281                 :      82002 :           tree field = lookup_field (context, DECL_NAME (decl), 0, false);
    5282                 :      82002 :           if (field == NULL_TREE
    5283                 :      82002 :               || !(VAR_P (field) || variable_template_p (field)))
    5284                 :          7 :             error ("%q+#D is not a static data member of %q#T", decl, context);
    5285                 :      81995 :           else if (variable_template_p (field)
    5286                 :      81995 :                    && (DECL_LANG_SPECIFIC (decl)
    5287                 :         42 :                        && DECL_TEMPLATE_SPECIALIZATION (decl)))
    5288                 :            :             /* OK, specialization was already checked.  */;
    5289                 :      81980 :           else if (variable_template_p (field) && !this_tmpl)
    5290                 :            :             {
    5291                 :          3 :               error_at (DECL_SOURCE_LOCATION (decl),
    5292                 :            :                         "non-member-template declaration of %qD", decl);
    5293                 :          3 :               inform (DECL_SOURCE_LOCATION (field), "does not match "
    5294                 :            :                       "member template declaration here");
    5295                 :          3 :               return error_mark_node;
    5296                 :            :             }
    5297                 :            :           else
    5298                 :            :             {
    5299                 :      81977 :               if (variable_template_p (field))
    5300                 :         24 :                 field = DECL_TEMPLATE_RESULT (field);
    5301                 :            : 
    5302                 :      81977 :               if (DECL_CONTEXT (field) != context)
    5303                 :            :                 {
    5304                 :          4 :                   if (!same_type_p (DECL_CONTEXT (field), context))
    5305                 :         12 :                     permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
    5306                 :            :                                "to be defined as %<%T::%D%>",
    5307                 :          4 :                                DECL_CONTEXT (field), DECL_NAME (decl),
    5308                 :          4 :                                context, DECL_NAME (decl));
    5309                 :          4 :                   DECL_CONTEXT (decl) = DECL_CONTEXT (field);
    5310                 :            :                 }
    5311                 :            :               /* Static data member are tricky; an in-class initialization
    5312                 :            :                  still doesn't provide a definition, so the in-class
    5313                 :            :                  declaration will have DECL_EXTERNAL set, but will have an
    5314                 :            :                  initialization.  Thus, duplicate_decls won't warn
    5315                 :            :                  about this situation, and so we check here.  */
    5316                 :      92780 :               if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
    5317                 :         12 :                 error ("duplicate initialization of %qD", decl);
    5318                 :      81977 :               field = duplicate_decls (decl, field,
    5319                 :            :                                        /*newdecl_is_friend=*/false);
    5320                 :      81977 :               if (field == error_mark_node)
    5321                 :            :                 return error_mark_node;
    5322                 :      81920 :               else if (field)
    5323                 :      81920 :                 decl = field;
    5324                 :            :             }
    5325                 :            :         }
    5326                 :            :       else
    5327                 :            :         {
    5328                 :      29424 :           tree field = check_classfn (context, decl,
    5329                 :            :                                       this_tmpl
    5330                 :         13 :                                       ? current_template_parms
    5331                 :            :                                       : NULL_TREE);
    5332                 :      29332 :           if (field && field != error_mark_node
    5333                 :      58743 :               && duplicate_decls (decl, field,
    5334                 :            :                                  /*newdecl_is_friend=*/false))
    5335                 :      29332 :             decl = field;
    5336                 :            :         }
    5337                 :            : 
    5338                 :            :       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
    5339                 :     111353 :       DECL_IN_AGGR_P (decl) = 0;
    5340                 :            :       /* Do not mark DECL as an explicit specialization if it was not
    5341                 :            :          already marked as an instantiation; a declaration should
    5342                 :            :          never be marked as a specialization unless we know what
    5343                 :            :          template is being specialized.  */
    5344                 :     111353 :       if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    5345                 :            :         {
    5346                 :      27791 :           SET_DECL_TEMPLATE_SPECIALIZATION (decl);
    5347                 :      27791 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    5348                 :      26643 :             DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
    5349                 :      26643 :                                   && DECL_DECLARED_INLINE_P (decl));
    5350                 :            :           else
    5351                 :       1148 :             DECL_COMDAT (decl) = false;
    5352                 :            : 
    5353                 :            :           /* [temp.expl.spec] An explicit specialization of a static data
    5354                 :            :              member of a template is a definition if the declaration
    5355                 :            :              includes an initializer; otherwise, it is a declaration.
    5356                 :            : 
    5357                 :            :              We check for processing_specialization so this only applies
    5358                 :            :              to the new specialization syntax.  */
    5359                 :      27791 :           if (!initialized && processing_specialization)
    5360                 :      27638 :             DECL_EXTERNAL (decl) = 1;
    5361                 :            :         }
    5362                 :            : 
    5363                 :     139052 :       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
    5364                 :            :           /* Aliases are definitions. */
    5365                 :     111401 :           && !alias)
    5366                 :         12 :         permerror (declarator->id_loc,
    5367                 :            :                    "declaration of %q#D outside of class is not definition",
    5368                 :            :                    decl);
    5369                 :            :     }
    5370                 :            : 
    5371                 :   10155300 :   was_public = TREE_PUBLIC (decl);
    5372                 :            : 
    5373                 :            :   /* Enter this declaration into the symbol table.  Don't push the plain
    5374                 :            :      VAR_DECL for a variable template.  */
    5375                 :   10155300 :   if (!template_parm_scope_p ()
    5376                 :   10155300 :       || !VAR_P (decl))
    5377                 :    9902580 :     decl = maybe_push_decl (decl);
    5378                 :            : 
    5379                 :   10155300 :   if (processing_template_decl)
    5380                 :            :     {
    5381                 :            :       /* Make sure that for a `constinit' decl push_template_decl creates
    5382                 :            :          a DECL_TEMPLATE_INFO info for us, so that cp_finish_decl can then set
    5383                 :            :          TINFO_VAR_DECLARED_CONSTINIT.  */
    5384                 :    3910530 :       if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
    5385                 :         20 :         retrofit_lang_decl (decl);
    5386                 :    3910530 :       decl = push_template_decl (decl);
    5387                 :            :     }
    5388                 :   10155300 :   if (decl == error_mark_node)
    5389                 :            :     return error_mark_node;
    5390                 :            : 
    5391                 :   10155100 :   if (VAR_P (decl)
    5392                 :    3785460 :       && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
    5393                 :   10243500 :       && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl))
    5394                 :            :     {
    5395                 :            :       /* This is a const variable with implicit 'static'.  Set
    5396                 :            :          DECL_THIS_STATIC so we can tell it from variables that are
    5397                 :            :          !TREE_PUBLIC because of the anonymous namespace.  */
    5398                 :      38080 :       gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
    5399                 :      38080 :       DECL_THIS_STATIC (decl) = 1;
    5400                 :            :     }
    5401                 :            : 
    5402                 :    3512480 :   if (current_function_decl && VAR_P (decl)
    5403                 :   16116100 :       && DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    5404                 :            :     {
    5405                 :     217004 :       bool ok = false;
    5406                 :     217004 :       if (CP_DECL_THREAD_LOCAL_P (decl))
    5407                 :         14 :         error_at (DECL_SOURCE_LOCATION (decl),
    5408                 :            :                   "%qD declared %<thread_local%> in %qs function", decl,
    5409                 :          7 :                   DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    5410                 :            :                   ? "consteval" : "constexpr");
    5411                 :     216997 :       else if (TREE_STATIC (decl))
    5412                 :         44 :         error_at (DECL_SOURCE_LOCATION (decl),
    5413                 :            :                   "%qD declared %<static%> in %qs function", decl,
    5414                 :         22 :                   DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    5415                 :            :                   ? "consteval" : "constexpr");
    5416                 :            :       else
    5417                 :            :         ok = true;
    5418                 :         29 :       if (!ok)
    5419                 :         29 :         cp_function_chain->invalid_constexpr = true;
    5420                 :            :     }
    5421                 :            : 
    5422                 :   10155100 :   if (!processing_template_decl && VAR_P (decl))
    5423                 :    1092270 :     start_decl_1 (decl, initialized);
    5424                 :            : 
    5425                 :   10155100 :   return decl;
    5426                 :            : }
    5427                 :            : 
    5428                 :            : /* Process the declaration of a variable DECL.  INITIALIZED is true
    5429                 :            :    iff DECL is explicitly initialized.  (INITIALIZED is false if the
    5430                 :            :    variable is initialized via an implicitly-called constructor.)
    5431                 :            :    This function must be called for ordinary variables (including, for
    5432                 :            :    example, implicit instantiations of templates), but must not be
    5433                 :            :    called for template declarations.  */
    5434                 :            : 
    5435                 :            : void
    5436                 :    1098300 : start_decl_1 (tree decl, bool initialized)
    5437                 :            : {
    5438                 :    1098300 :   tree type;
    5439                 :    1098300 :   bool complete_p;
    5440                 :    1098300 :   bool aggregate_definition_p;
    5441                 :            : 
    5442                 :    1098300 :   gcc_assert (!processing_template_decl);
    5443                 :            : 
    5444                 :    2196590 :   if (error_operand_p (decl))
    5445                 :            :     return;
    5446                 :            : 
    5447                 :    1098280 :   gcc_assert (VAR_P (decl));
    5448                 :            : 
    5449                 :    1098280 :   type = TREE_TYPE (decl);
    5450                 :    1098280 :   complete_p = COMPLETE_TYPE_P (type);
    5451                 :    1354120 :   aggregate_definition_p = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
    5452                 :            : 
    5453                 :            :   /* If an explicit initializer is present, or if this is a definition
    5454                 :            :      of an aggregate, then we need a complete type at this point.
    5455                 :            :      (Scalars are always complete types, so there is nothing to
    5456                 :            :      check.)  This code just sets COMPLETE_P; errors (if necessary)
    5457                 :            :      are issued below.  */
    5458                 :    1098280 :   if ((initialized || aggregate_definition_p) 
    5459                 :     663615 :       && !complete_p
    5460                 :    1190540 :       && COMPLETE_TYPE_P (complete_type (type)))
    5461                 :            :     {
    5462                 :      22272 :       complete_p = true;
    5463                 :            :       /* We will not yet have set TREE_READONLY on DECL if the type
    5464                 :            :          was "const", but incomplete, before this point.  But, now, we
    5465                 :            :          have a complete type, so we can try again.  */
    5466                 :      22272 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    5467                 :            :     }
    5468                 :            : 
    5469                 :    1098270 :   if (is_global_var (decl))
    5470                 :            :     {
    5471                 :     493597 :       type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    5472                 :     493597 :                                    ? TCTX_THREAD_STORAGE
    5473                 :     493597 :                                    : TCTX_STATIC_STORAGE);
    5474                 :     493597 :       verify_type_context (input_location, context, TREE_TYPE (decl));
    5475                 :            :     }
    5476                 :    1098270 :   if (initialized)
    5477                 :            :     /* Is it valid for this decl to have an initializer at all?  */
    5478                 :            :     {
    5479                 :            :       /* Don't allow initializations for incomplete types except for
    5480                 :            :          arrays which might be completed by the initialization.  */
    5481                 :     576977 :       if (complete_p)
    5482                 :            :         ;                       /* A complete type is ok.  */
    5483                 :      69785 :       else if (type_uses_auto (type))
    5484                 :            :         ;                       /* An auto type is ok.  */
    5485                 :      45180 :       else if (TREE_CODE (type) != ARRAY_TYPE)
    5486                 :            :         {
    5487                 :         26 :           error ("variable %q#D has initializer but incomplete type", decl);
    5488                 :         26 :           type = TREE_TYPE (decl) = error_mark_node;
    5489                 :            :         }
    5490                 :      45154 :       else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
    5491                 :            :         {
    5492                 :          0 :           if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    5493                 :          0 :             error ("elements of array %q#D have incomplete type", decl);
    5494                 :            :           /* else we already gave an error in start_decl.  */
    5495                 :            :         }
    5496                 :            :     }
    5497                 :     521295 :   else if (aggregate_definition_p && !complete_p)
    5498                 :            :     {
    5499                 :        204 :       if (type_uses_auto (type))
    5500                 :         51 :         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
    5501                 :            :       else
    5502                 :            :         {
    5503                 :        153 :           error ("aggregate %q#D has incomplete type and cannot be defined",
    5504                 :            :                  decl);
    5505                 :            :           /* Change the type so that assemble_variable will give
    5506                 :            :              DECL an rtl we can live with: (mem (const_int 0)).  */
    5507                 :        153 :           type = TREE_TYPE (decl) = error_mark_node;
    5508                 :            :         }
    5509                 :            :     }
    5510                 :            : 
    5511                 :            :   /* Create a new scope to hold this declaration if necessary.
    5512                 :            :      Whether or not a new scope is necessary cannot be determined
    5513                 :            :      until after the type has been completed; if the type is a
    5514                 :            :      specialization of a class template it is not until after
    5515                 :            :      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    5516                 :            :      will be set correctly.  */
    5517                 :    1098270 :   maybe_push_cleanup_level (type);
    5518                 :            : }
    5519                 :            : 
    5520                 :            : /* Handle initialization of references.  DECL, TYPE, and INIT have the
    5521                 :            :    same meaning as in cp_finish_decl.  *CLEANUP must be NULL on entry,
    5522                 :            :    but will be set to a new CLEANUP_STMT if a temporary is created
    5523                 :            :    that must be destroyed subsequently.
    5524                 :            : 
    5525                 :            :    Returns an initializer expression to use to initialize DECL, or
    5526                 :            :    NULL if the initialization can be performed statically.
    5527                 :            : 
    5528                 :            :    Quotes on semantics can be found in ARM 8.4.3.  */
    5529                 :            : 
    5530                 :            : static tree
    5531                 :      69780 : grok_reference_init (tree decl, tree type, tree init, int flags)
    5532                 :            : {
    5533                 :      69780 :   if (init == NULL_TREE)
    5534                 :            :     {
    5535                 :         16 :       if ((DECL_LANG_SPECIFIC (decl) == 0
    5536                 :          4 :            || DECL_IN_AGGR_P (decl) == 0)
    5537                 :         32 :           && ! DECL_THIS_EXTERN (decl))
    5538                 :         16 :         error_at (DECL_SOURCE_LOCATION (decl),
    5539                 :            :                   "%qD declared as reference but not initialized", decl);
    5540                 :         16 :       return NULL_TREE;
    5541                 :            :     }
    5542                 :            : 
    5543                 :      69764 :   tree ttype = TREE_TYPE (type);
    5544                 :      69764 :   if (TREE_CODE (init) == TREE_LIST)
    5545                 :            :     {
    5546                 :            :       /* This handles (C++20 only) code like
    5547                 :            : 
    5548                 :            :            const A& r(1, 2, 3);
    5549                 :            : 
    5550                 :            :          where we treat the parenthesized list as a CONSTRUCTOR.  */
    5551                 :        955 :       if (TREE_TYPE (init) == NULL_TREE
    5552                 :        955 :           && CP_AGGREGATE_TYPE_P (ttype)
    5553                 :         38 :           && !DECL_DECOMPOSITION_P (decl)
    5554                 :        971 :           && (cxx_dialect >= cxx2a))
    5555                 :            :         {
    5556                 :         11 :           init = build_constructor_from_list (init_list_type_node, init);
    5557                 :         11 :           CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    5558                 :         11 :           CONSTRUCTOR_IS_PAREN_INIT (init) = true;
    5559                 :            :         }
    5560                 :            :       else
    5561                 :        944 :         init = build_x_compound_expr_from_list (init, ELK_INIT,
    5562                 :            :                                                 tf_warning_or_error);
    5563                 :            :     }
    5564                 :            : 
    5565                 :      69764 :   if (TREE_CODE (ttype) != ARRAY_TYPE
    5566                 :     138455 :       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
    5567                 :            :     /* Note: default conversion is only called in very special cases.  */
    5568                 :         15 :     init = decay_conversion (init, tf_warning_or_error);
    5569                 :            : 
    5570                 :            :   /* check_initializer handles this for non-reference variables, but for
    5571                 :            :      references we need to do it here or the initializer will get the
    5572                 :            :      incomplete array type and confuse later calls to
    5573                 :            :      cp_complete_array_type.  */
    5574                 :      69764 :   if (TREE_CODE (ttype) == ARRAY_TYPE
    5575                 :       1073 :       && TYPE_DOMAIN (ttype) == NULL_TREE
    5576                 :      69840 :       && (BRACE_ENCLOSED_INITIALIZER_P (init)
    5577                 :         40 :           || TREE_CODE (init) == STRING_CST))
    5578                 :            :     {
    5579                 :         18 :       cp_complete_array_type (&ttype, init, false);
    5580                 :         18 :       if (ttype != TREE_TYPE (type))
    5581                 :         18 :         type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
    5582                 :            :     }
    5583                 :            : 
    5584                 :            :   /* Convert INIT to the reference type TYPE.  This may involve the
    5585                 :            :      creation of a temporary, whose lifetime must be the same as that
    5586                 :            :      of the reference.  If so, a DECL_EXPR for the temporary will be
    5587                 :            :      added just after the DECL_EXPR for DECL.  That's why we don't set
    5588                 :            :      DECL_INITIAL for local references (instead assigning to them
    5589                 :            :      explicitly); we need to allow the temporary to be initialized
    5590                 :            :      first.  */
    5591                 :      69764 :   return initialize_reference (type, init, flags,
    5592                 :      69764 :                                tf_warning_or_error);
    5593                 :            : }
    5594                 :            : 
    5595                 :            : /* Designated initializers in arrays are not supported in GNU C++.
    5596                 :            :    The parser cannot detect this error since it does not know whether
    5597                 :            :    a given brace-enclosed initializer is for a class type or for an
    5598                 :            :    array.  This function checks that CE does not use a designated
    5599                 :            :    initializer.  If it does, an error is issued.  Returns true if CE
    5600                 :            :    is valid, i.e., does not have a designated initializer.  */
    5601                 :            : 
    5602                 :            : bool
    5603                 :     830898 : check_array_designated_initializer (constructor_elt *ce,
    5604                 :            :                                     unsigned HOST_WIDE_INT index)
    5605                 :            : {
    5606                 :            :   /* Designated initializers for array elements are not supported.  */
    5607                 :     830898 :   if (ce->index)
    5608                 :            :     {
    5609                 :            :       /* The parser only allows identifiers as designated
    5610                 :            :          initializers.  */
    5611                 :     422391 :       if (ce->index == error_mark_node)
    5612                 :            :         {
    5613                 :          0 :           error ("name used in a GNU-style designated "
    5614                 :            :                  "initializer for an array");
    5615                 :          0 :           return false;
    5616                 :            :         }
    5617                 :     422391 :       else if (identifier_p (ce->index))
    5618                 :            :         {
    5619                 :         31 :           error ("name %qD used in a GNU-style designated "
    5620                 :            :                  "initializer for an array", ce->index);
    5621                 :         31 :           return false;
    5622                 :            :         }
    5623                 :            : 
    5624                 :     422360 :       tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
    5625                 :            :                                                   ce->index, true);
    5626                 :     422360 :       if (ce_index
    5627                 :     422356 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
    5628                 :     844713 :           && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
    5629                 :            :               == INTEGER_CST))
    5630                 :            :         {
    5631                 :            :           /* A C99 designator is OK if it matches the current index.  */
    5632                 :     422353 :           if (wi::to_wide (ce_index) == index)
    5633                 :            :             {
    5634                 :     422345 :               ce->index = ce_index;
    5635                 :     422345 :               return true;
    5636                 :            :             }
    5637                 :            :           else
    5638                 :          8 :             sorry ("non-trivial designated initializers not supported");
    5639                 :            :         }
    5640                 :            :       else
    5641                 :         14 :         error_at (cp_expr_loc_or_input_loc (ce->index),
    5642                 :            :                   "C99 designator %qE is not an integral constant-expression",
    5643                 :            :                   ce->index);
    5644                 :            : 
    5645                 :         15 :       return false;
    5646                 :            :     }
    5647                 :            : 
    5648                 :            :   return true;
    5649                 :            : }
    5650                 :            : 
    5651                 :            : /* When parsing `int a[] = {1, 2};' we don't know the size of the
    5652                 :            :    array until we finish parsing the initializer.  If that's the
    5653                 :            :    situation we're in, update DECL accordingly.  */
    5654                 :            : 
    5655                 :            : static void
    5656                 :    4862440 : maybe_deduce_size_from_array_init (tree decl, tree init)
    5657                 :            : {
    5658                 :    4862440 :   tree type = TREE_TYPE (decl);
    5659                 :            : 
    5660                 :    4862440 :   if (TREE_CODE (type) == ARRAY_TYPE
    5661                 :     245804 :       && TYPE_DOMAIN (type) == NULL_TREE
    5662                 :    5067950 :       && TREE_CODE (decl) != TYPE_DECL)
    5663                 :            :     {
    5664                 :            :       /* do_default is really a C-ism to deal with tentative definitions.
    5665                 :            :          But let's leave it here to ease the eventual merge.  */
    5666                 :     205508 :       int do_default = !DECL_EXTERNAL (decl);
    5667                 :     205508 :       tree initializer = init ? init : DECL_INITIAL (decl);
    5668                 :     205508 :       int failure = 0;
    5669                 :            : 
    5670                 :            :       /* Check that there are no designated initializers in INIT, as
    5671                 :            :          those are not supported in GNU C++, and as the middle-end
    5672                 :            :          will crash if presented with a non-numeric designated
    5673                 :            :          initializer.  */
    5674                 :     210205 :       if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
    5675                 :            :         {
    5676                 :       4692 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
    5677                 :       4692 :           constructor_elt *ce;
    5678                 :       4692 :           HOST_WIDE_INT i;
    5679                 :      70684 :           FOR_EACH_VEC_SAFE_ELT (v, i, ce)
    5680                 :            :             {
    5681                 :      66000 :               if (instantiation_dependent_expression_p (ce->index))
    5682                 :    4862440 :                 return;
    5683                 :      65992 :               if (!check_array_designated_initializer (ce, i))
    5684                 :          3 :                 failure = 1;
    5685                 :            :             }
    5686                 :            :         }
    5687                 :            : 
    5688                 :       4684 :       if (failure)
    5689                 :          3 :         TREE_TYPE (decl) = error_mark_node;
    5690                 :            :       else
    5691                 :            :         {
    5692                 :     205497 :           failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
    5693                 :            :                                             do_default);
    5694                 :     205497 :           if (failure == 1)
    5695                 :            :             {
    5696                 :         80 :               error_at (cp_expr_loc_or_loc (initializer,
    5697                 :         40 :                                          DECL_SOURCE_LOCATION (decl)),
    5698                 :            :                         "initializer fails to determine size of %qD", decl);
    5699                 :            :             }
    5700                 :     205457 :           else if (failure == 2)
    5701                 :            :             {
    5702                 :         27 :               if (do_default)
    5703                 :            :                 {
    5704                 :          8 :                   error_at (DECL_SOURCE_LOCATION (decl),
    5705                 :            :                             "array size missing in %qD", decl);
    5706                 :            :                 }
    5707                 :            :               /* If a `static' var's size isn't known, make it extern as
    5708                 :            :                  well as static, so it does not get allocated.  If it's not
    5709                 :            :                  `static', then don't mark it extern; finish_incomplete_decl
    5710                 :            :                  will give it a default size and it will get allocated.  */
    5711                 :         19 :               else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
    5712                 :          0 :                 DECL_EXTERNAL (decl) = 1;
    5713                 :            :             }
    5714                 :     205430 :           else if (failure == 3)
    5715                 :            :             {
    5716                 :          8 :               error_at (DECL_SOURCE_LOCATION (decl),
    5717                 :            :                         "zero-size array %qD", decl);
    5718                 :            :             }
    5719                 :            :         }
    5720                 :            : 
    5721                 :     205500 :       cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
    5722                 :            : 
    5723                 :     205500 :       relayout_decl (decl);
    5724                 :            :     }
    5725                 :            : }
    5726                 :            : 
    5727                 :            : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
    5728                 :            :    any appropriate error messages regarding the layout.  */
    5729                 :            : 
    5730                 :            : static void
    5731                 :    5313540 : layout_var_decl (tree decl)
    5732                 :            : {
    5733                 :    5313540 :   tree type;
    5734                 :            : 
    5735                 :    5313540 :   type = TREE_TYPE (decl);
    5736                 :    5313540 :   if (type == error_mark_node)
    5737                 :            :     return;
    5738                 :            : 
    5739                 :            :   /* If we haven't already laid out this declaration, do so now.
    5740                 :            :      Note that we must not call complete type for an external object
    5741                 :            :      because it's type might involve templates that we are not
    5742                 :            :      supposed to instantiate yet.  (And it's perfectly valid to say
    5743                 :            :      `extern X x' for some incomplete type `X'.)  */
    5744                 :    5313490 :   if (!DECL_EXTERNAL (decl))
    5745                 :    3797680 :     complete_type (type);
    5746                 :    5313490 :   if (!DECL_SIZE (decl)
    5747                 :     252610 :       && TREE_TYPE (decl) != error_mark_node
    5748                 :    5566100 :       && complete_or_array_type_p (type))
    5749                 :     228740 :     layout_decl (decl, 0);
    5750                 :            : 
    5751                 :    5313490 :   if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
    5752                 :            :     {
    5753                 :            :       /* An automatic variable with an incomplete type: that is an error.
    5754                 :            :          Don't talk about array types here, since we took care of that
    5755                 :            :          message in grokdeclarator.  */
    5756                 :         22 :       error_at (DECL_SOURCE_LOCATION (decl),
    5757                 :            :                 "storage size of %qD isn%'t known", decl);
    5758                 :         22 :       TREE_TYPE (decl) = error_mark_node;
    5759                 :            :     }
    5760                 :            : #if 0
    5761                 :            :   /* Keep this code around in case we later want to control debug info
    5762                 :            :      based on whether a type is "used".  (jason 1999-11-11) */
    5763                 :            : 
    5764                 :            :   else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
    5765                 :            :     /* Let debugger know it should output info for this type.  */
    5766                 :            :     note_debug_info_needed (ttype);
    5767                 :            : 
    5768                 :            :   if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
    5769                 :            :     note_debug_info_needed (DECL_CONTEXT (decl));
    5770                 :            : #endif
    5771                 :            : 
    5772                 :    9111170 :   if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
    5773                 :    2833870 :       && DECL_SIZE (decl) != NULL_TREE
    5774                 :    8073800 :       && ! TREE_CONSTANT (DECL_SIZE (decl)))
    5775                 :            :     {
    5776                 :          8 :       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
    5777                 :          0 :         constant_expression_warning (DECL_SIZE (decl));
    5778                 :            :       else
    5779                 :            :         {
    5780                 :          8 :           error_at (DECL_SOURCE_LOCATION (decl),
    5781                 :            :                     "storage size of %qD isn%'t constant", decl);
    5782                 :          8 :           TREE_TYPE (decl) = error_mark_node;
    5783                 :            :         }
    5784                 :            :     }
    5785                 :            : }
    5786                 :            : 
    5787                 :            : /* If a local static variable is declared in an inline function, or if
    5788                 :            :    we have a weak definition, we must endeavor to create only one
    5789                 :            :    instance of the variable at link-time.  */
    5790                 :            : 
    5791                 :            : void
    5792                 :    5313880 : maybe_commonize_var (tree decl)
    5793                 :            : {
    5794                 :            :   /* Don't mess with __FUNCTION__ and similar.  */
    5795                 :    5313880 :   if (DECL_ARTIFICIAL (decl))
    5796                 :            :     return;
    5797                 :            : 
    5798                 :            :   /* Static data in a function with comdat linkage also has comdat
    5799                 :            :      linkage.  */
    5800                 :    4515440 :   if ((TREE_STATIC (decl)
    5801                 :    1771670 :        && DECL_FUNCTION_SCOPE_P (decl)
    5802                 :      37226 :        && vague_linkage_p (DECL_CONTEXT (decl)))
    5803                 :    9452370 :       || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
    5804                 :            :     {
    5805                 :     848520 :       if (flag_weak)
    5806                 :            :         {
    5807                 :            :           /* With weak symbols, we simply make the variable COMDAT;
    5808                 :            :              that will cause copies in multiple translations units to
    5809                 :            :              be merged.  */
    5810                 :     848496 :           comdat_linkage (decl);
    5811                 :            :         }
    5812                 :            :       else
    5813                 :            :         {
    5814                 :         24 :           if (DECL_INITIAL (decl) == NULL_TREE
    5815                 :         24 :               || DECL_INITIAL (decl) == error_mark_node)
    5816                 :            :             {
    5817                 :            :               /* Without weak symbols, we can use COMMON to merge
    5818                 :            :                  uninitialized variables.  */
    5819                 :         22 :               TREE_PUBLIC (decl) = 1;
    5820                 :         22 :               DECL_COMMON (decl) = 1;
    5821                 :            :             }
    5822                 :            :           else
    5823                 :            :             {
    5824                 :            :               /* While for initialized variables, we must use internal
    5825                 :            :                  linkage -- which means that multiple copies will not
    5826                 :            :                  be merged.  */
    5827                 :          2 :               TREE_PUBLIC (decl) = 0;
    5828                 :          2 :               DECL_COMMON (decl) = 0;
    5829                 :          2 :               DECL_INTERFACE_KNOWN (decl) = 1;
    5830                 :          2 :               const char *msg;
    5831                 :          6 :               if (DECL_INLINE_VAR_P (decl))
    5832                 :            :                 msg = G_("sorry: semantics of inline variable "
    5833                 :            :                          "%q#D are wrong (you%'ll wind up with "
    5834                 :            :                          "multiple copies)");
    5835                 :            :               else
    5836                 :            :                 msg = G_("sorry: semantics of inline function "
    5837                 :            :                          "static data %q#D are wrong (you%'ll wind "
    5838                 :            :                          "up with multiple copies)");
    5839                 :          2 :               if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
    5840                 :            :                               msg, decl))
    5841                 :          2 :                 inform (DECL_SOURCE_LOCATION (decl),
    5842                 :            :                         "you can work around this by removing the initializer");
    5843                 :            :             }
    5844                 :            :         }
    5845                 :            :     }
    5846                 :            : }
    5847                 :            : 
    5848                 :            : /* Issue an error message if DECL is an uninitialized const variable.
    5849                 :            :    CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
    5850                 :            :    context from potential_constant_expression.  Returns true if all is well,
    5851                 :            :    false otherwise.  */
    5852                 :            : 
    5853                 :            : bool
    5854                 :     796097 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
    5855                 :            :                                    tsubst_flags_t complain)
    5856                 :            : {
    5857                 :     796097 :   tree type = strip_array_types (TREE_TYPE (decl));
    5858                 :            : 
    5859                 :            :   /* ``Unless explicitly declared extern, a const object does not have
    5860                 :            :      external linkage and must be initialized. ($8.4; $12.1)'' ARM
    5861                 :            :      7.1.6 */
    5862                 :     796097 :   if (VAR_P (decl)
    5863                 :     796097 :       && !TYPE_REF_P (type)
    5864                 :     795293 :       && (CP_TYPE_CONST_P (type)
    5865                 :            :           /* C++20 permits trivial default initialization in constexpr
    5866                 :            :              context (P1331R2).  */
    5867                 :     643952 :           || (cxx_dialect < cxx2a
    5868                 :     584816 :               && (constexpr_context_p
    5869                 :     564801 :                   || var_in_constexpr_fn (decl))))
    5870                 :     969088 :       && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    5871                 :            :     {
    5872                 :     133136 :       tree field = default_init_uninitialized_part (type);
    5873                 :     133136 :       if (!field)
    5874                 :            :         return true;
    5875                 :            : 
    5876                 :        361 :       bool show_notes = true;
    5877                 :            : 
    5878                 :        361 :       if (!constexpr_context_p || cxx_dialect >= cxx2a)
    5879                 :            :         {
    5880                 :         97 :           if (CP_TYPE_CONST_P (type))
    5881                 :            :             {
    5882                 :         76 :               if (complain & tf_error)
    5883                 :         75 :                 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
    5884                 :            :                                         "uninitialized %<const %D%>", decl);
    5885                 :            :             }
    5886                 :            :           else
    5887                 :            :             {
    5888                 :         21 :               if (!is_instantiation_of_constexpr (current_function_decl)
    5889                 :         21 :                   && (complain & tf_error))
    5890                 :         17 :                 error_at (DECL_SOURCE_LOCATION (decl),
    5891                 :            :                           "uninitialized variable %qD in %<constexpr%> "
    5892                 :            :                           "function", decl);
    5893                 :            :               else
    5894                 :            :                 show_notes = false;
    5895                 :         21 :               cp_function_chain->invalid_constexpr = true;
    5896                 :            :             }
    5897                 :            :         }
    5898                 :        264 :       else if (complain & tf_error)
    5899                 :          2 :         error_at (DECL_SOURCE_LOCATION (decl),
    5900                 :            :                   "uninitialized variable %qD in %<constexpr%> context",
    5901                 :            :                   decl);
    5902                 :            : 
    5903                 :        427 :       if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
    5904                 :            :         {
    5905                 :         59 :           tree defaulted_ctor;
    5906                 :            : 
    5907                 :         59 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    5908                 :            :                   "%q#T has no user-provided default constructor", type);
    5909                 :         59 :           defaulted_ctor = in_class_defaulted_default_constructor (type);
    5910                 :         59 :           if (defaulted_ctor)
    5911                 :         23 :             inform (DECL_SOURCE_LOCATION (defaulted_ctor),
    5912                 :            :                     "constructor is not user-provided because it is "
    5913                 :            :                     "explicitly defaulted in the class body");
    5914                 :         59 :           inform (DECL_SOURCE_LOCATION (field),
    5915                 :            :                   "and the implicitly-defined constructor does not "
    5916                 :            :                   "initialize %q#D", field);
    5917                 :            :         }
    5918                 :            : 
    5919                 :        361 :       return false;
    5920                 :            :     }
    5921                 :            : 
    5922                 :            :   return true;
    5923                 :            : }
    5924                 :            : 
    5925                 :            : /* Structure holding the current initializer being processed by reshape_init.
    5926                 :            :    CUR is a pointer to the current element being processed, END is a pointer
    5927                 :            :    after the last element present in the initializer.  */
    5928                 :            : struct reshape_iter
    5929                 :            : {
    5930                 :            :   constructor_elt *cur;
    5931                 :            :   constructor_elt *end;
    5932                 :            : };
    5933                 :            : 
    5934                 :            : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
    5935                 :            : 
    5936                 :            : /* FIELD is a FIELD_DECL or NULL.  In the former case, the value
    5937                 :            :    returned is the next FIELD_DECL (possibly FIELD itself) that can be
    5938                 :            :    initialized.  If there are no more such fields, the return value
    5939                 :            :    will be NULL.  */
    5940                 :            : 
    5941                 :            : tree
    5942                 :    1674810 : next_initializable_field (tree field)
    5943                 :            : {
    5944                 :    4718390 :   while (field
    5945                 :    4718390 :          && (TREE_CODE (field) != FIELD_DECL
    5946                 :    1098170 :              || DECL_UNNAMED_BIT_FIELD (field)
    5947                 :    1097920 :              || (DECL_ARTIFICIAL (field)
    5948                 :            :                  /* In C++17, don't skip base class fields.  */
    5949                 :    1097920 :                  && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field))
    5950                 :            :                  /* Don't skip vptr fields.  We might see them when we're
    5951                 :            :                     called from reduced_constant_expression_p.  */
    5952                 :        492 :                  && !DECL_VIRTUAL_P (field))))
    5953                 :    3043580 :     field = DECL_CHAIN (field);
    5954                 :            : 
    5955                 :    1674810 :   return field;
    5956                 :            : }
    5957                 :            : 
    5958                 :            : /* Return true for [dcl.init.list] direct-list-initialization from
    5959                 :            :    single element of enumeration with a fixed underlying type.  */
    5960                 :            : 
    5961                 :            : bool
    5962                 :   14568200 : is_direct_enum_init (tree type, tree init)
    5963                 :            : {
    5964                 :   14568200 :   if (cxx_dialect >= cxx17
    5965                 :    3474550 :       && TREE_CODE (type) == ENUMERAL_TYPE
    5966                 :     119146 :       && ENUM_FIXED_UNDERLYING_TYPE_P (type)
    5967                 :      22795 :       && TREE_CODE (init) == CONSTRUCTOR
    5968                 :       1256 :       && CONSTRUCTOR_IS_DIRECT_INIT (init)
    5969                 :   14569000 :       && CONSTRUCTOR_NELTS (init) == 1)
    5970                 :        392 :     return true;
    5971                 :            :   return false;
    5972                 :            : }
    5973                 :            : 
    5974                 :            : /* Subroutine of reshape_init_array and reshape_init_vector, which does
    5975                 :            :    the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
    5976                 :            :    INTEGER_CST representing the size of the array minus one (the maximum index),
    5977                 :            :    or NULL_TREE if the array was declared without specifying the size. D is
    5978                 :            :    the iterator within the constructor.  */
    5979                 :            : 
    5980                 :            : static tree
    5981                 :      69252 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
    5982                 :            :                       tree first_initializer_p, tsubst_flags_t complain)
    5983                 :            : {
    5984                 :      69252 :   tree new_init;
    5985                 :     133667 :   bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
    5986                 :      69252 :   unsigned HOST_WIDE_INT max_index_cst = 0;
    5987                 :      69252 :   unsigned HOST_WIDE_INT index;
    5988                 :            : 
    5989                 :            :   /* The initializer for an array is always a CONSTRUCTOR.  If this is the
    5990                 :            :      outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
    5991                 :            :      to build a new one.  */
    5992                 :      69252 :   bool reuse = (first_initializer_p
    5993                 :      62929 :                 && !CP_AGGREGATE_TYPE_P (elt_type)
    5994                 :      84108 :                 && !TREE_SIDE_EFFECTS (first_initializer_p));
    5995                 :      54969 :   if (reuse)
    5996                 :            :     new_init = first_initializer_p;
    5997                 :            :   else
    5998                 :      54969 :     new_init = build_constructor (init_list_type_node, NULL);
    5999                 :            : 
    6000                 :      69252 :   if (sized_array_p)
    6001                 :            :     {
    6002                 :            :       /* Minus 1 is used for zero sized arrays.  */
    6003                 :      64359 :       if (integer_all_onesp (max_index))
    6004                 :            :         return new_init;
    6005                 :            : 
    6006                 :      64331 :       if (tree_fits_uhwi_p (max_index))
    6007                 :      64331 :         max_index_cst = tree_to_uhwi (max_index);
    6008                 :            :       /* sizetype is sign extended, not zero extended.  */
    6009                 :            :       else
    6010                 :          0 :         max_index_cst = tree_to_uhwi (fold_convert (size_type_node, max_index));
    6011                 :            :     }
    6012                 :            : 
    6013                 :            :   /* Set to the index of the last element with a non-zero initializer.
    6014                 :            :      Zero initializers for elements past this one can be dropped.  */
    6015                 :      69224 :   unsigned HOST_WIDE_INT last_nonzero = -1;
    6016                 :            :   /* Loop until there are no more initializers.  */
    6017                 :     471295 :   for (index = 0;
    6018                 :     471295 :        d->cur != d->end && (!sized_array_p || index <= max_index_cst);
    6019                 :            :        ++index)
    6020                 :            :     {
    6021                 :     402118 :       tree elt_init;
    6022                 :     402118 :       constructor_elt *old_cur = d->cur;
    6023                 :            : 
    6024                 :     402118 :       check_array_designated_initializer (d->cur, index);
    6025                 :     402118 :       elt_init = reshape_init_r (elt_type, d,
    6026                 :            :                                  /*first_initializer_p=*/NULL_TREE,
    6027                 :            :                                  complain);
    6028                 :     402118 :       if (elt_init == error_mark_node)
    6029                 :         43 :         return error_mark_node;
    6030                 :     402075 :       tree idx = size_int (index);
    6031                 :     402075 :       if (reuse)
    6032                 :            :         {
    6033                 :     133114 :           old_cur->index = idx;
    6034                 :     133114 :           old_cur->value = elt_init;
    6035                 :            :         }
    6036                 :            :       else
    6037                 :     268961 :         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    6038                 :            :                                 idx, elt_init);
    6039                 :     402075 :       if (!TREE_CONSTANT (elt_init))
    6040                 :      78370 :         TREE_CONSTANT (new_init) = false;
    6041                 :            : 
    6042                 :            :       /* Pointers initialized to strings must be treated as non-zero
    6043                 :            :          even if the string is empty.  */
    6044                 :     402075 :       tree init_type = TREE_TYPE (elt_init);
    6045                 :     402075 :       if (POINTER_TYPE_P (elt_type) != POINTER_TYPE_P (init_type)
    6046                 :     402075 :           || !type_initializer_zero_p (elt_type, elt_init))
    6047                 :            :         last_nonzero = index;
    6048                 :            : 
    6049                 :            :       /* This can happen with an invalid initializer (c++/54501).  */
    6050                 :     402075 :       if (d->cur == old_cur && !sized_array_p)
    6051                 :            :         break;
    6052                 :            :     }
    6053                 :            : 
    6054                 :      69181 :   if (sized_array_p && trivial_type_p (elt_type))
    6055                 :            :     {
    6056                 :            :       /* Strip trailing zero-initializers from an array of a trivial
    6057                 :            :          type of known size.  They are redundant and get in the way
    6058                 :            :          of telling them apart from those with implicit zero value.  */
    6059                 :      43259 :       unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (new_init);
    6060                 :      43259 :       if (last_nonzero > nelts)
    6061                 :            :         nelts = 0;
    6062                 :      35482 :       else if (last_nonzero < nelts - 1)
    6063                 :       4475 :         nelts = last_nonzero + 1;
    6064                 :            : 
    6065                 :            :       /* Sharing a stripped constructor can get in the way of
    6066                 :            :          overload resolution.  E.g., initializing a class from
    6067                 :            :          {{0}} might be invalid while initializing the same class
    6068                 :            :          from {{}} might be valid.  */
    6069                 :      43259 :       if (reuse && nelts < CONSTRUCTOR_NELTS (new_init))
    6070                 :            :         {
    6071                 :       4059 :           vec<constructor_elt, va_gc> *v;
    6072                 :       4059 :           vec_alloc (v, nelts);
    6073                 :       4568 :           for (unsigned int i = 0; i < nelts; i++)
    6074                 :            :             {
    6075                 :        509 :               constructor_elt elt = *CONSTRUCTOR_ELT (new_init, i);
    6076                 :        509 :               if (TREE_CODE (elt.value) == CONSTRUCTOR)
    6077                 :         18 :                 elt.value = unshare_constructor (elt.value);
    6078                 :        509 :               v->quick_push (elt);
    6079                 :            :             }
    6080                 :       4059 :           new_init = build_constructor (TREE_TYPE (new_init), v);
    6081                 :            :         }
    6082                 :            :       else
    6083                 :      39200 :         vec_safe_truncate (CONSTRUCTOR_ELTS (new_init), nelts);
    6084                 :            :     }
    6085                 :            : 
    6086                 :            :   return new_init;
    6087                 :            : }
    6088                 :            : 
    6089                 :            : /* Subroutine of reshape_init_r, processes the initializers for arrays.
    6090                 :            :    Parameters are the same of reshape_init_r.  */
    6091                 :            : 
    6092                 :            : static tree
    6093                 :      39144 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
    6094                 :            :                     tsubst_flags_t complain)
    6095                 :            : {
    6096                 :      39144 :   tree max_index = NULL_TREE;
    6097                 :            : 
    6098                 :      39144 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    6099                 :            : 
    6100                 :      39144 :   if (TYPE_DOMAIN (type))
    6101                 :      34307 :     max_index = array_type_nelts (type);
    6102                 :            : 
    6103                 :      39144 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    6104                 :      39144 :                                first_initializer_p, complain);
    6105                 :            : }
    6106                 :            : 
    6107                 :            : /* Subroutine of reshape_init_r, processes the initializers for vectors.
    6108                 :            :    Parameters are the same of reshape_init_r.  */
    6109                 :            : 
    6110                 :            : static tree
    6111                 :      30132 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
    6112                 :            : {
    6113                 :      30132 :   tree max_index = NULL_TREE;
    6114                 :            : 
    6115                 :      30132 :   gcc_assert (VECTOR_TYPE_P (type));
    6116                 :            : 
    6117                 :      30132 :   if (COMPOUND_LITERAL_P (d->cur->value))
    6118                 :            :     {
    6119                 :         24 :       tree value = d->cur->value;
    6120                 :         24 :       if (!same_type_p (TREE_TYPE (value), type))
    6121                 :            :         {
    6122                 :          0 :           if (complain & tf_error)
    6123                 :          0 :             error ("invalid type %qT as initializer for a vector of type %qT",
    6124                 :          0 :                    TREE_TYPE (d->cur->value), type);
    6125                 :          0 :           value = error_mark_node;
    6126                 :            :         }
    6127                 :         24 :       ++d->cur;
    6128                 :         24 :       return value;
    6129                 :            :     }
    6130                 :            : 
    6131                 :            :   /* For a vector, we initialize it as an array of the appropriate size.  */
    6132                 :      30108 :   if (VECTOR_TYPE_P (type))
    6133                 :      30108 :     max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
    6134                 :            : 
    6135                 :      30108 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    6136                 :      30108 :                                NULL_TREE, complain);
    6137                 :            : }
    6138                 :            : 
    6139                 :            : /* Subroutine of reshape_init_r, processes the initializers for classes
    6140                 :            :    or union. Parameters are the same of reshape_init_r.  */
    6141                 :            : 
    6142                 :            : static tree
    6143                 :     456538 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
    6144                 :            :                     tsubst_flags_t complain)
    6145                 :            : {
    6146                 :     456538 :   tree field;
    6147                 :     456538 :   tree new_init;
    6148                 :            : 
    6149                 :     913076 :   gcc_assert (CLASS_TYPE_P (type));
    6150                 :            : 
    6151                 :            :   /* The initializer for a class is always a CONSTRUCTOR.  */
    6152                 :     456538 :   new_init = build_constructor (init_list_type_node, NULL);
    6153                 :     461685 :   field = next_initializable_field (TYPE_FIELDS (type));
    6154                 :            : 
    6155                 :     456538 :   if (!field)
    6156                 :            :     {
    6157                 :            :       /* [dcl.init.aggr]
    6158                 :            : 
    6159                 :            :         An initializer for an aggregate member that is an
    6160                 :            :         empty class shall have the form of an empty
    6161                 :            :         initializer-list {}.  */
    6162                 :        120 :       if (!first_initializer_p)
    6163                 :            :         {
    6164                 :         99 :           if (complain & tf_error)
    6165                 :         15 :             error ("initializer for %qT must be brace-enclosed", type);
    6166                 :         99 :           return error_mark_node;
    6167                 :            :         }
    6168                 :            :       return new_init;
    6169                 :            :     }
    6170                 :            : 
    6171                 :            :   /* Loop through the initializable fields, gathering initializers.  */
    6172                 :    1441060 :   while (d->cur != d->end)
    6173                 :            :     {
    6174                 :     990153 :       tree field_init;
    6175                 :     990153 :       constructor_elt *old_cur = d->cur;
    6176                 :            : 
    6177                 :            :       /* Handle designated initializers, as an extension.  */
    6178                 :     990153 :       if (d->cur->index)
    6179                 :            :         {
    6180                 :      43943 :           if (d->cur->index == error_mark_node)
    6181                 :          7 :             return error_mark_node;
    6182                 :            : 
    6183                 :      43936 :           if (TREE_CODE (d->cur->index) == FIELD_DECL)
    6184                 :            :             {
    6185                 :            :               /* We already reshaped this.  */
    6186                 :        149 :               if (field != d->cur->index)
    6187                 :            :                 {
    6188                 :         10 :                   tree id = DECL_NAME (d->cur->index);
    6189                 :         10 :                   gcc_assert (id);
    6190                 :         10 :                   gcc_checking_assert (d->cur->index
    6191                 :            :                                        == get_class_binding (type, id));
    6192                 :         10 :                   field = d->cur->index;
    6193                 :            :                 }
    6194                 :            :             }
    6195                 :      43787 :           else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    6196                 :      43779 :             field = get_class_binding (type, d->cur->index);
    6197                 :            :           else
    6198                 :            :             {
    6199                 :          8 :               if (complain & tf_error)
    6200                 :          8 :                 error ("%<[%E] =%> used in a GNU-style designated initializer"
    6201                 :            :                        " for class %qT", d->cur->index, type);
    6202                 :          8 :               return error_mark_node;
    6203                 :            :             }
    6204                 :            : 
    6205                 :      43928 :           if (!field || TREE_CODE (field) != FIELD_DECL)
    6206                 :            :             {
    6207                 :         12 :               if (complain & tf_error)
    6208                 :          4 :                 error ("%qT has no non-static data member named %qD", type,
    6209                 :          4 :                        d->cur->index);
    6210                 :         12 :               return error_mark_node;
    6211                 :            :             }
    6212                 :            :         }
    6213                 :            : 
    6214                 :            :       /* If we processed all the member of the class, we are done.  */
    6215                 :     990126 :       if (!field)
    6216                 :            :         break;
    6217                 :            : 
    6218                 :     989896 :       field_init = reshape_init_r (TREE_TYPE (field), d,
    6219                 :            :                                    /*first_initializer_p=*/NULL_TREE,
    6220                 :            :                                    complain);
    6221                 :     989896 :       if (field_init == error_mark_node)
    6222                 :        114 :         return error_mark_node;
    6223                 :            : 
    6224                 :     989782 :       if (d->cur == old_cur && d->cur->index)
    6225                 :            :         {
    6226                 :            :           /* This can happen with an invalid initializer for a flexible
    6227                 :            :              array member (c++/54441).  */
    6228                 :          0 :           if (complain & tf_error)
    6229                 :          0 :             error ("invalid initializer for %q#D", field);
    6230                 :          0 :           return error_mark_node;
    6231                 :            :         }
    6232                 :            : 
    6233                 :     989782 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
    6234                 :            : 
    6235                 :            :       /* [dcl.init.aggr]
    6236                 :            : 
    6237                 :            :         When a union  is  initialized with a brace-enclosed
    6238                 :            :         initializer, the braces shall only contain an
    6239                 :            :         initializer for the first member of the union.  */
    6240                 :     989782 :       if (TREE_CODE (type) == UNION_TYPE)
    6241                 :            :         break;
    6242                 :            : 
    6243                 :     984646 :       field = next_initializable_field (DECL_CHAIN (field));
    6244                 :            :     }
    6245                 :            : 
    6246                 :            :   return new_init;
    6247                 :            : }
    6248                 :            : 
    6249                 :            : /* Subroutine of reshape_init_r.  We're in a context where C99 initializer
    6250                 :            :    designators are not valid; either complain or return true to indicate
    6251                 :            :    that reshape_init_r should return error_mark_node.  */
    6252                 :            : 
    6253                 :            : static bool
    6254                 :       1274 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
    6255                 :            : {
    6256                 :       1274 :   if (d->cur->index)
    6257                 :            :     {
    6258                 :         28 :       if (complain & tf_error)
    6259                 :         56 :         error_at (cp_expr_loc_or_input_loc (d->cur->index),
    6260                 :            :                   "C99 designator %qE outside aggregate initializer",
    6261                 :            :                   d->cur->index);
    6262                 :            :       else
    6263                 :            :         return true;
    6264                 :            :     }
    6265                 :            :   return false;
    6266                 :            : }
    6267                 :            : 
    6268                 :            : /* Subroutine of reshape_init, which processes a single initializer (part of
    6269                 :            :    a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
    6270                 :            :    iterator within the CONSTRUCTOR which points to the initializer to process.
    6271                 :            :    If this is the first initializer of the outermost CONSTRUCTOR node,
    6272                 :            :    FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE.  */
    6273                 :            : 
    6274                 :            : static tree
    6275                 :    1917450 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
    6276                 :            :                 tsubst_flags_t complain)
    6277                 :            : {
    6278                 :    1917450 :   tree init = d->cur->value;
    6279                 :            : 
    6280                 :    3834800 :   if (error_operand_p (init))
    6281                 :            :     return error_mark_node;
    6282                 :            : 
    6283                 :     981268 :   if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
    6284                 :    1918080 :       && has_designator_problem (d, complain))
    6285                 :          0 :     return error_mark_node;
    6286                 :            : 
    6287                 :    1917360 :   tree stripped_init = tree_strip_any_location_wrapper (init);
    6288                 :            : 
    6289                 :    1917360 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    6290                 :            :     {
    6291                 :            :       /* A complex type can be initialized from one or two initializers,
    6292                 :            :          but braces are not elided.  */
    6293                 :         70 :       d->cur++;
    6294                 :         80 :       if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
    6295                 :            :         {
    6296                 :         10 :           if (CONSTRUCTOR_NELTS (stripped_init) > 2)
    6297                 :            :             {
    6298                 :          0 :               if (complain & tf_error)
    6299                 :          0 :                 error ("too many initializers for %qT", type);
    6300                 :            :               else
    6301                 :          0 :                 return error_mark_node;
    6302                 :            :             }
    6303                 :            :         }
    6304                 :         60 :       else if (first_initializer_p && d->cur != d->end)
    6305                 :            :         {
    6306                 :         28 :           vec<constructor_elt, va_gc> *v = 0;
    6307                 :         28 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    6308                 :         28 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, d->cur->value);
    6309                 :         28 :           if (has_designator_problem (d, complain))
    6310                 :          0 :             return error_mark_node;
    6311                 :         28 :           d->cur++;
    6312                 :         28 :           init = build_constructor (init_list_type_node, v);
    6313                 :            :         }
    6314                 :         70 :       return init;
    6315                 :            :     }
    6316                 :            : 
    6317                 :            :   /* A non-aggregate type is always initialized with a single
    6318                 :            :      initializer.  */
    6319                 :    2624040 :   if (!CP_AGGREGATE_TYPE_P (type))
    6320                 :            :     {
    6321                 :            :       /* It is invalid to initialize a non-aggregate type with a
    6322                 :            :          brace-enclosed initializer before C++0x.
    6323                 :            :          We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
    6324                 :            :          of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
    6325                 :            :          a CONSTRUCTOR (with a record type).  */
    6326                 :    1117850 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR
    6327                 :            :           /* Don't complain about a capture-init.  */
    6328                 :       4459 :           && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
    6329                 :    1122300 :           && BRACE_ENCLOSED_INITIALIZER_P (stripped_init))  /* p7626.C */
    6330                 :            :         {
    6331                 :       4428 :           if (SCALAR_TYPE_P (type))
    6332                 :            :             {
    6333                 :        354 :               if (cxx_dialect < cxx11)
    6334                 :            :                 {
    6335                 :         18 :                   if (complain & tf_error)
    6336                 :         18 :                     error ("braces around scalar initializer for type %qT",
    6337                 :            :                            type);
    6338                 :         18 :                   init = error_mark_node;
    6339                 :            :                 }
    6340                 :        336 :               else if (first_initializer_p
    6341                 :        336 :                        || (CONSTRUCTOR_NELTS (stripped_init) > 0
    6342                 :        290 :                            && (BRACE_ENCLOSED_INITIALIZER_P
    6343                 :            :                                (CONSTRUCTOR_ELT (stripped_init,0)->value))))
    6344                 :            :                 {
    6345                 :         18 :                   if (complain & tf_error)
    6346                 :         18 :                     error ("too many braces around scalar initializer "
    6347                 :            :                            "for type %qT", type);
    6348                 :         18 :                   init = error_mark_node;
    6349                 :            :                 }
    6350                 :            :             }
    6351                 :            :           else
    6352                 :       4074 :             maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    6353                 :            :         }
    6354                 :            : 
    6355                 :    1117850 :       d->cur++;
    6356                 :    1117850 :       return init;
    6357                 :            :     }
    6358                 :            : 
    6359                 :            :   /* "If T is a class type and the initializer list has a single element of
    6360                 :            :      type cv U, where U is T or a class derived from T, the object is
    6361                 :            :      initialized from that element."  Even if T is an aggregate.  */
    6362                 :    1462870 :   if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
    6363                 :     718667 :       && first_initializer_p
    6364                 :     475894 :       && d->end - d->cur == 1
    6365                 :     888977 :       && reference_related_p (type, TREE_TYPE (init)))
    6366                 :            :     {
    6367                 :        105 :       d->cur++;
    6368                 :        105 :       return init;
    6369                 :            :     }
    6370                 :            : 
    6371                 :            :   /* [dcl.init.aggr]
    6372                 :            : 
    6373                 :            :      All implicit type conversions (clause _conv_) are considered when
    6374                 :            :      initializing the aggregate member with an initializer from an
    6375                 :            :      initializer-list.  If the initializer can initialize a member,
    6376                 :            :      the member is initialized.  Otherwise, if the member is itself a
    6377                 :            :      non-empty subaggregate, brace elision is assumed and the
    6378                 :            :      initializer is considered for the initialization of the first
    6379                 :            :      member of the subaggregate.  */
    6380                 :     799332 :   if (TREE_CODE (init) != CONSTRUCTOR
    6381                 :            :       /* But don't try this for the first initializer, since that would be
    6382                 :            :          looking through the outermost braces; A a2 = { a1 }; is not a
    6383                 :            :          valid aggregate initialization.  */
    6384                 :     336880 :       && !first_initializer_p
    6385                 :     801754 :       && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
    6386                 :       1755 :           || can_convert_arg (type, TREE_TYPE (init), init, LOOKUP_NORMAL,
    6387                 :            :                               complain)))
    6388                 :            :     {
    6389                 :        683 :       d->cur++;
    6390                 :        683 :       return init;
    6391                 :            :     }
    6392                 :            : 
    6393                 :            :   /* [dcl.init.string]
    6394                 :            : 
    6395                 :            :       A char array (whether plain char, signed char, or unsigned char)
    6396                 :            :       can be initialized by a string-literal (optionally enclosed in
    6397                 :            :       braces); a wchar_t array can be initialized by a wide
    6398                 :            :       string-literal (optionally enclosed in braces).  */
    6399                 :     798649 :   if (TREE_CODE (type) == ARRAY_TYPE
    6400                 :     863881 :       && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
    6401                 :            :     {
    6402                 :       3444 :       tree str_init = init;
    6403                 :       3444 :       tree stripped_str_init = stripped_init;
    6404                 :            : 
    6405                 :            :       /* Strip one level of braces if and only if they enclose a single
    6406                 :            :          element (as allowed by [dcl.init.string]).  */
    6407                 :       3444 :       if (!first_initializer_p
    6408                 :       1540 :           && TREE_CODE (stripped_str_init) == CONSTRUCTOR
    6409                 :       4440 :           && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
    6410                 :            :         {
    6411                 :        270 :           str_init = (*CONSTRUCTOR_ELTS (stripped_str_init))[0].value;
    6412                 :        270 :           stripped_str_init = tree_strip_any_location_wrapper (str_init);
    6413                 :            :         }
    6414                 :            : 
    6415                 :            :       /* If it's a string literal, then it's the initializer for the array
    6416                 :            :          as a whole. Otherwise, continue with normal initialization for
    6417                 :            :          array types (one value per array element).  */
    6418                 :       3444 :       if (TREE_CODE (stripped_str_init) == STRING_CST)
    6419                 :            :         {
    6420                 :        520 :           if (has_designator_problem (d, complain))
    6421                 :          0 :             return error_mark_node;
    6422                 :        520 :           d->cur++;
    6423                 :        520 :           return str_init;
    6424                 :            :         }
    6425                 :            :     }
    6426                 :            : 
    6427                 :            :   /* The following cases are about aggregates. If we are not within a full
    6428                 :            :      initializer already, and there is not a CONSTRUCTOR, it means that there
    6429                 :            :      is a missing set of braces (that is, we are processing the case for
    6430                 :            :      which reshape_init exists).  */
    6431                 :     798129 :   if (!first_initializer_p)
    6432                 :            :     {
    6433                 :     273642 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR)
    6434                 :            :         {
    6435                 :     272354 :           tree init_type = TREE_TYPE (init);
    6436                 :     272354 :           if (init_type && TYPE_PTRMEMFUNC_P (init_type))
    6437                 :            :             /* There is no need to call reshape_init for pointer-to-member
    6438                 :            :                function initializers, as they are always constructed correctly
    6439                 :            :                by the front end.  Here we have e.g. {.__pfn=0B, .__delta=0},
    6440                 :            :                which is missing outermost braces.  We should warn below, and
    6441                 :            :                one of the routines below will wrap it in additional { }.  */;
    6442                 :            :           /* For a nested compound literal, proceed to specialized routines,
    6443                 :            :              to handle initialization of arrays and similar.  */
    6444                 :     272342 :           else if (COMPOUND_LITERAL_P (stripped_init))
    6445                 :         27 :             gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    6446                 :            :           /* A CONSTRUCTOR of the target's type is a previously
    6447                 :            :              digested initializer.  */
    6448                 :     272315 :           else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
    6449                 :            :             {
    6450                 :         18 :               ++d->cur;
    6451                 :         18 :               return init;
    6452                 :            :             }
    6453                 :            :           else
    6454                 :            :             {
    6455                 :            :               /* Something that hasn't been reshaped yet.  */
    6456                 :     272297 :               ++d->cur;
    6457                 :     544594 :               gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    6458                 :     272297 :               return reshape_init (type, init, complain);
    6459                 :            :             }
    6460                 :            :         }
    6461                 :            : 
    6462                 :       1327 :       if (complain & tf_warning)
    6463                 :       1227 :         warning (OPT_Wmissing_braces,
    6464                 :            :                  "missing braces around initializer for %qT",
    6465                 :            :                  type);
    6466                 :            :     }
    6467                 :            : 
    6468                 :            :   /* Dispatch to specialized routines.  */
    6469                 :     982352 :   if (CLASS_TYPE_P (type))
    6470                 :     456538 :     return reshape_init_class (type, d, first_initializer_p, complain);
    6471                 :      69276 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    6472                 :      39144 :     return reshape_init_array (type, d, first_initializer_p, complain);
    6473                 :      30132 :   else if (VECTOR_TYPE_P (type))
    6474                 :      30132 :     return reshape_init_vector (type, d, complain);
    6475                 :            :   else
    6476                 :          0 :     gcc_unreachable();
    6477                 :            : }
    6478                 :            : 
    6479                 :            : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
    6480                 :            :    brace-enclosed aggregate initializer.
    6481                 :            : 
    6482                 :            :    INIT is the CONSTRUCTOR containing the list of initializers describing
    6483                 :            :    a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
    6484                 :            :    It may not presently match the shape of the TYPE; for example:
    6485                 :            : 
    6486                 :            :      struct S { int a; int b; };
    6487                 :            :      struct S a[] = { 1, 2, 3, 4 };
    6488                 :            : 
    6489                 :            :    Here INIT will hold a vector of four elements, rather than a
    6490                 :            :    vector of two elements, each itself a vector of two elements.  This
    6491                 :            :    routine transforms INIT from the former form into the latter.  The
    6492                 :            :    revised CONSTRUCTOR node is returned.  */
    6493                 :            : 
    6494                 :            : tree
    6495                 :    1433280 : reshape_init (tree type, tree init, tsubst_flags_t complain)
    6496                 :            : {
    6497                 :    1433280 :   vec<constructor_elt, va_gc> *v;
    6498                 :    1433280 :   reshape_iter d;
    6499                 :    1433280 :   tree new_init;
    6500                 :            : 
    6501                 :    2866560 :   gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
    6502                 :            : 
    6503                 :    1433280 :   v = CONSTRUCTOR_ELTS (init);
    6504                 :            : 
    6505                 :            :   /* An empty constructor does not need reshaping, and it is always a valid
    6506                 :            :      initializer.  */
    6507                 :    1433280 :   if (vec_safe_is_empty (v))
    6508                 :            :     return init;
    6509                 :            : 
    6510                 :            :   /* Brace elision is not performed for a CONSTRUCTOR representing
    6511                 :            :      parenthesized aggregate initialization.  */
    6512                 :     525824 :   if (CONSTRUCTOR_IS_PAREN_INIT (init))
    6513                 :            :     return init;
    6514                 :            : 
    6515                 :            :   /* Handle [dcl.init.list] direct-list-initialization from
    6516                 :            :      single element of enumeration with a fixed underlying type.  */
    6517                 :     525782 :   if (is_direct_enum_init (type, init))
    6518                 :            :     {
    6519                 :        350 :       tree elt = CONSTRUCTOR_ELT (init, 0)->value;
    6520                 :        350 :       type = cv_unqualified (type);
    6521                 :        350 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
    6522                 :            :         {
    6523                 :        320 :           warning_sentinel w (warn_useless_cast);
    6524                 :        320 :           warning_sentinel w2 (warn_ignored_qualifiers);
    6525                 :        320 :           return cp_build_c_cast (input_location, type, elt,
    6526                 :            :                                   tf_warning_or_error);
    6527                 :            :         }
    6528                 :            :       else
    6529                 :         30 :         return error_mark_node;
    6530                 :            :     }
    6531                 :            : 
    6532                 :            :   /* Recurse on this CONSTRUCTOR.  */
    6533                 :     525432 :   d.cur = &(*v)[0];
    6534                 :     525432 :   d.end = d.cur + v->length ();
    6535                 :            : 
    6536                 :     525432 :   new_init = reshape_init_r (type, &d, init, complain);
    6537                 :     525432 :   if (new_init == error_mark_node)
    6538                 :            :     return error_mark_node;
    6539                 :            : 
    6540                 :            :   /* Make sure all the element of the constructor were used. Otherwise,
    6541                 :            :      issue an error about exceeding initializers.  */
    6542                 :     525158 :   if (d.cur != d.end)
    6543                 :            :     {
    6544                 :         90 :       if (complain & tf_error)
    6545                 :         57 :         error ("too many initializers for %qT", type);
    6546                 :         90 :       return error_mark_node;
    6547                 :            :     }
    6548                 :            : 
    6549                 :     525068 :   if (CONSTRUCTOR_IS_DIRECT_INIT (init)
    6550                 :     570749 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    6551                 :      45681 :     CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
    6552                 :     525068 :   if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
    6553                 :     525510 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    6554                 :        442 :     CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    6555                 :            : 
    6556                 :            :   return new_init;
    6557                 :            : }
    6558                 :            : 
    6559                 :            : /* Verify array initializer.  Returns true if errors have been reported.  */
    6560                 :            : 
    6561                 :            : bool
    6562                 :     276675 : check_array_initializer (tree decl, tree type, tree init)
    6563                 :            : {
    6564                 :     276675 :   tree element_type = TREE_TYPE (type);
    6565                 :            : 
    6566                 :            :   /* The array type itself need not be complete, because the
    6567                 :            :      initializer may tell us how many elements are in the array.
    6568                 :            :      But, the elements of the array must be complete.  */
    6569                 :     276675 :   if (!COMPLETE_TYPE_P (complete_type (element_type)))
    6570                 :            :     {
    6571                 :         19 :       if (decl)
    6572                 :         11 :         error_at (DECL_SOURCE_LOCATION (decl),
    6573                 :            :                   "elements of array %q#D have incomplete type", decl);
    6574                 :            :       else
    6575                 :          8 :         error ("elements of array %q#T have incomplete type", type);
    6576                 :         19 :       return true;
    6577                 :            :     }
    6578                 :            : 
    6579                 :     276656 :   location_t loc = (decl ? location_of (decl) : input_location);
    6580                 :     276656 :   if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
    6581                 :            :     return true;
    6582                 :            : 
    6583                 :            :   /* A compound literal can't have variable size.  */
    6584                 :     276656 :   if (init && !decl
    6585                 :     278530 :       && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
    6586                 :       1870 :           || !TREE_CONSTANT (TYPE_SIZE (element_type))))
    6587                 :            :     {
    6588                 :          4 :       error ("variable-sized compound literal");
    6589                 :          4 :       return true;
    6590                 :            :     }
    6591                 :            :   return false;
    6592                 :            : }
    6593                 :            : 
    6594                 :            : /* Subroutine of check_initializer; args are passed down from that function.
    6595                 :            :    Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init.  */
    6596                 :            : 
    6597                 :            : static tree
    6598                 :     397597 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
    6599                 :            :      
    6600                 :            : {
    6601                 :     397597 :   gcc_assert (stmts_are_full_exprs_p ());
    6602                 :     397597 :   return build_aggr_init (decl, init, flags, tf_warning_or_error);
    6603                 :            : }
    6604                 :            : 
    6605                 :            : /* Verify INIT (the initializer for DECL), and record the
    6606                 :            :    initialization in DECL_INITIAL, if appropriate.  CLEANUP is as for
    6607                 :            :    grok_reference_init.
    6608                 :            : 
    6609                 :            :    If the return value is non-NULL, it is an expression that must be
    6610                 :            :    evaluated dynamically to initialize DECL.  */
    6611                 :            : 
    6612                 :            : static tree
    6613                 :    4334730 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
    6614                 :            : {
    6615                 :    4334730 :   tree type;
    6616                 :    4334730 :   tree init_code = NULL;
    6617                 :    4334730 :   tree core_type;
    6618                 :            : 
    6619                 :            :   /* Things that are going to be initialized need to have complete
    6620                 :            :      type.  */
    6621                 :    4334730 :   TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
    6622                 :            : 
    6623                 :    4334730 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    6624                 :            :     {
    6625                 :            :       /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
    6626                 :            :          it doesn't have storage to be initialized.  */
    6627                 :        830 :       gcc_assert (init == NULL_TREE);
    6628                 :            :       return NULL_TREE;
    6629                 :            :     }
    6630                 :            : 
    6631                 :    4333900 :   if (type == error_mark_node)
    6632                 :            :     /* We will have already complained.  */
    6633                 :            :     return NULL_TREE;
    6634                 :            : 
    6635                 :    4333900 :   if (TREE_CODE (type) == ARRAY_TYPE)
    6636                 :            :     {
    6637                 :     274793 :       if (check_array_initializer (decl, type, init))
    6638                 :            :         return NULL_TREE;
    6639                 :            :     }
    6640                 :    4059100 :   else if (!COMPLETE_TYPE_P (type))
    6641                 :            :     {
    6642                 :         34 :       error_at (DECL_SOURCE_LOCATION (decl),
    6643                 :            :                 "%q#D has incomplete type", decl);
    6644                 :         34 :       TREE_TYPE (decl) = error_mark_node;
    6645                 :         34 :       return NULL_TREE;
    6646                 :            :     }
    6647                 :            :   else
    6648                 :            :     /* There is no way to make a variable-sized class type in GNU C++.  */
    6649                 :    4059070 :     gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
    6650                 :            : 
    6651                 :    4578020 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
    6652                 :            :     {
    6653                 :     241042 :       int init_len = CONSTRUCTOR_NELTS (init);
    6654                 :     241042 :       if (SCALAR_TYPE_P (type))
    6655                 :            :         {
    6656                 :        770 :           if (init_len == 0)
    6657                 :            :             {
    6658                 :        193 :               maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    6659                 :        193 :               init = build_zero_init (type, NULL_TREE, false);
    6660                 :            :             }
    6661                 :        577 :           else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
    6662                 :            :             {
    6663                 :         16 :               error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    6664                 :            :                         "scalar object %qD requires one element in "
    6665                 :            :                         "initializer", decl);
    6666                 :          8 :               TREE_TYPE (decl) = error_mark_node;
    6667                 :          8 :               return NULL_TREE;
    6668                 :            :             }
    6669                 :            :         }
    6670                 :            :     }
    6671                 :            : 
    6672                 :    4333840 :   if (TREE_CODE (decl) == CONST_DECL)
    6673                 :            :     {
    6674                 :          0 :       gcc_assert (!TYPE_REF_P (type));
    6675                 :            : 
    6676                 :          0 :       DECL_INITIAL (decl) = init;
    6677                 :            : 
    6678                 :          0 :       gcc_assert (init != NULL_TREE);
    6679                 :            :       init = NULL_TREE;
    6680                 :            :     }
    6681                 :    5076260 :   else if (!init && DECL_REALLY_EXTERN (decl))
    6682                 :            :     ;
    6683                 :     742412 :   else if (init || type_build_ctor_call (type)
    6684                 :    4901640 :            || TYPE_REF_P (type))
    6685                 :            :     {
    6686                 :    3766060 :       if (TYPE_REF_P (type))
    6687                 :            :         {
    6688                 :      69780 :           init = grok_reference_init (decl, type, init, flags);
    6689                 :      69780 :           flags |= LOOKUP_ALREADY_DIGESTED;
    6690                 :            :         }
    6691                 :    3696280 :       else if (!init)
    6692                 :     174614 :         check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    6693                 :            :                                            tf_warning_or_error);
    6694                 :            :       /* Do not reshape constructors of vectors (they don't need to be
    6695                 :            :          reshaped.  */
    6696                 :    3765480 :       else if (BRACE_ENCLOSED_INITIALIZER_P (init))
    6697                 :            :         {
    6698                 :     240688 :           if (is_std_init_list (type))
    6699                 :            :             {
    6700                 :        119 :               init = perform_implicit_conversion (type, init,
    6701                 :            :                                                   tf_warning_or_error);
    6702                 :        119 :               flags |= LOOKUP_ALREADY_DIGESTED;
    6703                 :            :             }
    6704                 :     467649 :           else if (TYPE_NON_AGGREGATE_CLASS (type))
    6705                 :            :             {
    6706                 :            :               /* Don't reshape if the class has constructors.  */
    6707                 :      20270 :               if (cxx_dialect == cxx98)
    6708                 :          6 :                 error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    6709                 :            :                           "in C++98 %qD must be initialized by "
    6710                 :            :                           "constructor, not by %<{...}%>",
    6711                 :            :                           decl);
    6712                 :            :             }
    6713                 :     220299 :           else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
    6714                 :            :             {
    6715                 :          0 :               error ("opaque vector types cannot be initialized");
    6716                 :          0 :               init = error_mark_node;
    6717                 :            :             }
    6718                 :            :           else
    6719                 :            :             {
    6720                 :     220299 :               init = reshape_init (type, init, tf_warning_or_error);
    6721                 :     220299 :               flags |= LOOKUP_NO_NARROWING;
    6722                 :            :             }
    6723                 :            :         }
    6724                 :            :       /* [dcl.init] "Otherwise, if the destination type is an array, the object
    6725                 :            :          is initialized as follows..."  So handle things like
    6726                 :            : 
    6727                 :            :           int a[](1, 2, 3);
    6728                 :            : 
    6729                 :            :          which is permitted in C++20 by P0960.  */
    6730                 :    3280980 :       else if (TREE_CODE (init) == TREE_LIST
    6731                 :      94262 :                && TREE_TYPE (init) == NULL_TREE
    6732                 :      94262 :                && TREE_CODE (type) == ARRAY_TYPE
    6733                 :        152 :                && !DECL_DECOMPOSITION_P (decl)
    6734                 :    3281050 :                && (cxx_dialect >= cxx2a))
    6735                 :            :         {
    6736                 :            :           /* [dcl.init.string] "An array of ordinary character type [...]
    6737                 :            :              can be initialized by an ordinary string literal [...] by an
    6738                 :            :              appropriately-typed string literal enclosed in braces" only
    6739                 :            :              talks about braces, but GCC has always accepted
    6740                 :            : 
    6741                 :            :                char a[]("foobar");
    6742                 :            : 
    6743                 :            :              so we continue to do so.  */
    6744                 :         41 :           tree val = TREE_VALUE (init);
    6745                 :         41 :           if (TREE_CHAIN (init) == NULL_TREE
    6746                 :         22 :               && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    6747                 :         52 :               && TREE_CODE (tree_strip_any_location_wrapper (val))
    6748                 :            :                  == STRING_CST)
    6749                 :            :             /* If the list has a single element and it's a string literal,
    6750                 :            :                then it's the initializer for the array as a whole.  */
    6751                 :            :             init = val;
    6752                 :            :           else
    6753                 :            :             {
    6754                 :         32 :               init = build_constructor_from_list (init_list_type_node, init);
    6755                 :         32 :               CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    6756                 :         32 :               CONSTRUCTOR_IS_PAREN_INIT (init) = true;
    6757                 :            :             }
    6758                 :            :         }
    6759                 :    3280940 :       else if (TREE_CODE (init) == TREE_LIST
    6760                 :      94221 :                && TREE_TYPE (init) != unknown_type_node
    6761                 :    3463330 :                && !MAYBE_CLASS_TYPE_P (type))
    6762                 :            :         {
    6763                 :       6061 :           gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    6764                 :            : 
    6765                 :            :           /* We get here with code like `int a (2);' */
    6766                 :       6061 :           init = build_x_compound_expr_from_list (init, ELK_INIT,
    6767                 :            :                                                   tf_warning_or_error);
    6768                 :            :         }
    6769                 :            : 
    6770                 :            :       /* If DECL has an array type without a specific bound, deduce the
    6771                 :            :          array size from the initializer.  */
    6772                 :    3766060 :       maybe_deduce_size_from_array_init (decl, init);
    6773                 :    3766060 :       type = TREE_TYPE (decl);
    6774                 :    3766060 :       if (type == error_mark_node)
    6775                 :            :         return NULL_TREE;
    6776                 :            : 
    6777                 :    7060420 :       if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
    6778                 :     604382 :            && !(flags & LOOKUP_ALREADY_DIGESTED)
    6779                 :     832229 :            && !(init && BRACE_ENCLOSED_INITIALIZER_P (init)
    6780                 :     454746 :                 && CP_AGGREGATE_TYPE_P (type)
    6781                 :     414206 :                 && (CLASS_TYPE_P (type)
    6782                 :        870 :                     || !TYPE_NEEDS_CONSTRUCTING (type)
    6783                 :        834 :                     || type_has_extended_temps (type))))
    6784                 :   10503100 :           || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
    6785                 :            :         {
    6786                 :     397597 :           init_code = build_aggr_init_full_exprs (decl, init, flags);
    6787                 :            : 
    6788                 :            :           /* A constructor call is a non-trivial initializer even if
    6789                 :            :              it isn't explicitly written.  */
    6790                 :     397597 :           if (TREE_SIDE_EFFECTS (init_code))
    6791                 :     395746 :             DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
    6792                 :            : 
    6793                 :            :           /* If this is a constexpr initializer, expand_default_init will
    6794                 :            :              have returned an INIT_EXPR rather than a CALL_EXPR.  In that
    6795                 :            :              case, pull the initializer back out and pass it down into
    6796                 :            :              store_init_value.  */
    6797                 :     926126 :           while (TREE_CODE (init_code) == EXPR_STMT
    6798                 :     926126 :                  || TREE_CODE (init_code) == CONVERT_EXPR)
    6799                 :     528529 :             init_code = TREE_OPERAND (init_code, 0);
    6800                 :     397597 :           if (TREE_CODE (init_code) == INIT_EXPR)
    6801                 :            :             {
    6802                 :            :               /* In C++20, the call to build_aggr_init could have created
    6803                 :            :                  an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
    6804                 :            :                  A(1, 2).  */
    6805                 :     134738 :               init = TREE_OPERAND (init_code, 1);
    6806                 :     134738 :               init_code = NULL_TREE;
    6807                 :            :               /* Don't call digest_init; it's unnecessary and will complain
    6808                 :            :                  about aggregate initialization of non-aggregate classes.  */
    6809                 :     134738 :               flags |= LOOKUP_ALREADY_DIGESTED;
    6810                 :            :             }
    6811                 :     525718 :           else if (DECL_DECLARED_CONSTEXPR_P (decl)
    6812                 :     262859 :                    || (flags & LOOKUP_CONSTINIT))
    6813                 :            :             {
    6814                 :            :               /* Declared constexpr or constinit, but no suitable initializer;
    6815                 :            :                  massage init appropriately so we can pass it into
    6816                 :            :                  store_init_value for the error.  */
    6817                 :        229 :               if (CLASS_TYPE_P (type)
    6818                 :        460 :                   && (!init || TREE_CODE (init) == TREE_LIST))
    6819                 :            :                 {
    6820                 :         74 :                   init = build_functional_cast (input_location, type,
    6821                 :            :                                                 init, tf_none);
    6822                 :         74 :                   if (TREE_CODE (init) == TARGET_EXPR)
    6823                 :         62 :                     TARGET_EXPR_DIRECT_INIT_P (init) = true;
    6824                 :            :                 }
    6825                 :            :               init_code = NULL_TREE;
    6826                 :            :             }
    6827                 :            :           else
    6828                 :            :             init = NULL_TREE;
    6829                 :            :         }
    6830                 :            : 
    6831                 :    3766060 :       if (init && TREE_CODE (init) != TREE_VEC)
    6832                 :            :         {
    6833                 :            :           /* In aggregate initialization of a variable, each element
    6834                 :            :              initialization is a full-expression because there is no
    6835                 :            :              enclosing expression.  */
    6836                 :    3503410 :           gcc_assert (stmts_are_full_exprs_p ());
    6837                 :            : 
    6838                 :    3503410 :           init_code = store_init_value (decl, init, cleanups, flags);
    6839                 :            : 
    6840                 :    3503410 :           if (DECL_INITIAL (decl)
    6841                 :    2133780 :               && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    6842                 :    3750710 :               && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
    6843                 :            :             {
    6844                 :     190719 :               tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
    6845                 :     190719 :               if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
    6846                 :     190719 :                   && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
    6847                 :         51 :                 cp_complete_array_type (&TREE_TYPE (elt), elt, false);
    6848                 :            :             }
    6849                 :            : 
    6850                 :     458473 :           if (pedantic && TREE_CODE (type) == ARRAY_TYPE
    6851                 :      49751 :               && DECL_INITIAL (decl)
    6852                 :      49630 :               && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
    6853                 :    3551870 :               && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
    6854                 :          8 :             warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
    6855                 :          4 :                                          DECL_SOURCE_LOCATION (decl)),
    6856                 :            :                         0, "array %qD initialized by parenthesized "
    6857                 :            :                         "string literal %qE",
    6858                 :          4 :                         decl, DECL_INITIAL (decl));
    6859                 :            :           init = NULL_TREE;
    6860                 :            :         }
    6861                 :            :     }
    6862                 :            :   else
    6863                 :            :     {
    6864                 :    1135560 :       if (CLASS_TYPE_P (core_type = strip_array_types (type))
    6865                 :     624349 :           && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
    6866                 :      56553 :               || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
    6867                 :         21 :         diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
    6868                 :            :                                                   /*complain=*/true);
    6869                 :            : 
    6870                 :     567782 :       check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    6871                 :            :                                          tf_warning_or_error);
    6872                 :            :     }
    6873                 :            : 
    6874                 :    4333840 :   if (init && init != error_mark_node)
    6875                 :          0 :     init_code = build2 (INIT_EXPR, type, decl, init);
    6876                 :            : 
    6877                 :    4333840 :   if (init_code)
    6878                 :            :     {
    6879                 :            :       /* We might have set these in cp_finish_decl.  */
    6880                 :    1633770 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
    6881                 :    1633770 :       TREE_CONSTANT (decl) = false;
    6882                 :            :     }
    6883                 :            : 
    6884                 :    4333840 :   if (init_code
    6885                 :    1633770 :       && DECL_IN_AGGR_P (decl)
    6886                 :    4333840 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    6887                 :            :     {
    6888                 :          0 :       static int explained = 0;
    6889                 :            : 
    6890                 :          0 :       if (cxx_dialect < cxx11)
    6891                 :          0 :         error ("initializer invalid for static member with constructor");
    6892                 :          0 :       else if (cxx_dialect < cxx17)
    6893                 :          0 :         error ("non-constant in-class initialization invalid for static "
    6894                 :            :                "member %qD", decl);
    6895                 :            :       else
    6896                 :          0 :         error ("non-constant in-class initialization invalid for non-inline "
    6897                 :            :                "static member %qD", decl);
    6898                 :          0 :       if (!explained)
    6899                 :            :         {
    6900                 :          0 :           inform (input_location,
    6901                 :            :                   "(an out of class initialization is required)");
    6902                 :          0 :           explained = 1;
    6903                 :            :         }
    6904                 :          0 :       return NULL_TREE;
    6905                 :            :     }
    6906                 :            : 
    6907                 :            :   return init_code;
    6908                 :            : }
    6909                 :            : 
    6910                 :            : /* If DECL is not a local variable, give it RTL.  */
    6911                 :            : 
    6912                 :            : static void
    6913                 :   11131000 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
    6914                 :            : {
    6915                 :   11131000 :   int toplev = toplevel_bindings_p ();
    6916                 :   11131000 :   int defer_p;
    6917                 :            : 
    6918                 :            :   /* Set the DECL_ASSEMBLER_NAME for the object.  */
    6919                 :   11131000 :   if (asmspec)
    6920                 :            :     {
    6921                 :            :       /* The `register' keyword, when used together with an
    6922                 :            :          asm-specification, indicates that the variable should be
    6923                 :            :          placed in a particular register.  */
    6924                 :      85187 :       if (VAR_P (decl) && DECL_REGISTER (decl))
    6925                 :            :         {
    6926                 :         58 :           set_user_assembler_name (decl, asmspec);
    6927                 :         58 :           DECL_HARD_REGISTER (decl) = 1;
    6928                 :            :         }
    6929                 :            :       else
    6930                 :            :         {
    6931                 :      84963 :           if (TREE_CODE (decl) == FUNCTION_DECL
    6932                 :      84963 :               && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
    6933                 :      17752 :             set_builtin_user_assembler_name (decl, asmspec);
    6934                 :      84963 :           set_user_assembler_name (decl, asmspec);
    6935                 :            :         }
    6936                 :            :     }
    6937                 :            : 
    6938                 :            :   /* Handle non-variables up front.  */
    6939                 :   11131000 :   if (!VAR_P (decl))
    6940                 :            :     {
    6941                 :    5817420 :       rest_of_decl_compilation (decl, toplev, at_eof);
    6942                 :    5817420 :       return;
    6943                 :            :     }
    6944                 :            : 
    6945                 :            :   /* If we see a class member here, it should be a static data
    6946                 :            :      member.  */
    6947                 :    5313540 :   if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
    6948                 :            :     {
    6949                 :     774775 :       gcc_assert (TREE_STATIC (decl));
    6950                 :            :       /* An in-class declaration of a static data member should be
    6951                 :            :          external; it is only a declaration, and not a definition.  */
    6952                 :     774775 :       if (init == NULL_TREE)
    6953                 :     774761 :         gcc_assert (DECL_EXTERNAL (decl)
    6954                 :            :                     || !TREE_PUBLIC (decl));
    6955                 :            :     }
    6956                 :            : 
    6957                 :            :   /* We don't create any RTL for local variables.  */
    6958                 :    5313540 :   if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    6959                 :            :     return;
    6960                 :            : 
    6961                 :            :   /* We defer emission of local statics until the corresponding
    6962                 :            :      DECL_EXPR is expanded.  But with constexpr its function might never
    6963                 :            :      be expanded, so go ahead and tell cgraph about the variable now.  */
    6964                 :    2833900 :   defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
    6965                 :      37840 :               && !var_in_maybe_constexpr_fn (decl))
    6966                 :    5630000 :              || DECL_VIRTUAL_P (decl));
    6967                 :            : 
    6968                 :            :   /* Defer template instantiations.  */
    6969                 :    2833900 :   if (DECL_LANG_SPECIFIC (decl)
    6970                 :    2833900 :       && DECL_IMPLICIT_INSTANTIATION (decl))
    6971                 :            :     defer_p = 1;
    6972                 :            : 
    6973                 :            :   /* If we're not deferring, go ahead and assemble the variable.  */
    6974                 :    2245470 :   if (!defer_p)
    6975                 :    1965830 :     rest_of_decl_compilation (decl, toplev, at_eof);
    6976                 :            : }
    6977                 :            : 
    6978                 :            : /* walk_tree helper for wrap_temporary_cleanups, below.  */
    6979                 :            : 
    6980                 :            : static tree
    6981                 :    2847170 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
    6982                 :            : {
    6983                 :            :   /* Stop at types or full-expression boundaries.  */
    6984                 :    2847170 :   if (TYPE_P (*stmt_p)
    6985                 :    2846620 :       || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
    6986                 :            :     {
    6987                 :        933 :       *walk_subtrees = 0;
    6988                 :        933 :       return NULL_TREE;
    6989                 :            :     }
    6990                 :            : 
    6991                 :    2846240 :   if (TREE_CODE (*stmt_p) == TARGET_EXPR)
    6992                 :            :     {
    6993                 :      27017 :       tree guard = (tree)data;
    6994                 :      27017 :       tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
    6995                 :            : 
    6996                 :      27017 :       tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
    6997                 :            :       /* Tell honor_protect_cleanup_actions to handle this as a separate
    6998                 :            :          cleanup.  */
    6999                 :      27017 :       TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
    7000                 :            :  
    7001                 :      27017 :       TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
    7002                 :            :     }
    7003                 :            : 
    7004                 :            :   return NULL_TREE;
    7005                 :            : }
    7006                 :            : 
    7007                 :            : /* We're initializing a local variable which has a cleanup GUARD.  If there
    7008                 :            :    are any temporaries used in the initializer INIT of this variable, we
    7009                 :            :    need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
    7010                 :            :    variable will be cleaned up properly if one of them throws.
    7011                 :            : 
    7012                 :            :    Unfortunately, there's no way to express this properly in terms of
    7013                 :            :    nesting, as the regions for the temporaries overlap the region for the
    7014                 :            :    variable itself; if there are two temporaries, the variable needs to be
    7015                 :            :    the first thing destroyed if either of them throws.  However, we only
    7016                 :            :    want to run the variable's cleanup if it actually got constructed.  So
    7017                 :            :    we need to guard the temporary cleanups with the variable's cleanup if
    7018                 :            :    they are run on the normal path, but not if they are run on the
    7019                 :            :    exceptional path.  We implement this by telling
    7020                 :            :    honor_protect_cleanup_actions to strip the variable cleanup from the
    7021                 :            :    exceptional path.  */
    7022                 :            : 
    7023                 :            : static void
    7024                 :     246885 : wrap_temporary_cleanups (tree init, tree guard)
    7025                 :            : {
    7026                 :          0 :   cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
    7027                 :          0 : }
    7028                 :            : 
    7029                 :            : /* Generate code to initialize DECL (a local variable).  */
    7030                 :            : 
    7031                 :            : static void
    7032                 :    2479620 : initialize_local_var (tree decl, tree init)
    7033                 :            : {
    7034                 :    2479620 :   tree type = TREE_TYPE (decl);
    7035                 :    2479620 :   tree cleanup;
    7036                 :    2479620 :   int already_used;
    7037                 :            : 
    7038                 :    2479620 :   gcc_assert (VAR_P (decl)
    7039                 :            :               || TREE_CODE (decl) == RESULT_DECL);
    7040                 :    2479620 :   gcc_assert (!TREE_STATIC (decl));
    7041                 :            : 
    7042                 :    2479620 :   if (DECL_SIZE (decl) == NULL_TREE)
    7043                 :            :     {
    7044                 :            :       /* If we used it already as memory, it must stay in memory.  */
    7045                 :          0 :       DECL_INITIAL (decl) = NULL_TREE;
    7046                 :          0 :       TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    7047                 :          0 :       return;
    7048                 :            :     }
    7049                 :            : 
    7050                 :    2479620 :   if (type == error_mark_node)
    7051                 :            :     return;
    7052                 :            : 
    7053                 :            :   /* Compute and store the initial value.  */
    7054                 :    2479620 :   already_used = TREE_USED (decl) || TREE_USED (type);
    7055                 :    2479620 :   if (TREE_USED (type))
    7056                 :         44 :     DECL_READ_P (decl) = 1;
    7057                 :            : 
    7058                 :            :   /* Generate a cleanup, if necessary.  */
    7059                 :    2479620 :   cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
    7060                 :            : 
    7061                 :            :   /* Perform the initialization.  */
    7062                 :    2479620 :   if (init)
    7063                 :            :     {
    7064                 :    1595840 :       tree rinit = (TREE_CODE (init) == INIT_EXPR
    7065                 :    1595840 :                     ? TREE_OPERAND (init, 1) : NULL_TREE);
    7066                 :    2645820 :       if (rinit && !TREE_SIDE_EFFECTS (rinit))
    7067                 :            :         {
    7068                 :            :           /* Stick simple initializers in DECL_INITIAL so that
    7069                 :            :              -Wno-init-self works (c++/34772).  */
    7070                 :     461394 :           gcc_assert (TREE_OPERAND (init, 0) == decl);
    7071                 :     461394 :           DECL_INITIAL (decl) = rinit;
    7072                 :            : 
    7073                 :     461394 :           if (warn_init_self && TYPE_REF_P (type))
    7074                 :            :             {
    7075                 :       1472 :               STRIP_NOPS (rinit);
    7076                 :       1472 :               if (rinit == decl)
    7077                 :          4 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    7078                 :            :                             OPT_Winit_self,
    7079                 :            :                             "reference %qD is initialized with itself", decl);
    7080                 :            :             }
    7081                 :            :         }
    7082                 :            :       else
    7083                 :            :         {
    7084                 :    1134440 :           int saved_stmts_are_full_exprs_p;
    7085                 :            : 
    7086                 :            :           /* If we're only initializing a single object, guard the
    7087                 :            :              destructors of any temporaries used in its initializer with
    7088                 :            :              its destructor.  This isn't right for arrays because each
    7089                 :            :              element initialization is a full-expression.  */
    7090                 :    1134440 :           if (cleanup && TREE_CODE (type) != ARRAY_TYPE)
    7091                 :     246885 :             wrap_temporary_cleanups (init, cleanup);
    7092                 :            : 
    7093                 :    1134440 :           gcc_assert (building_stmt_list_p ());
    7094                 :    1134440 :           saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    7095                 :    1134440 :           current_stmt_tree ()->stmts_are_full_exprs_p = 1;
    7096                 :    1134440 :           finish_expr_stmt (init);
    7097                 :    1134440 :           current_stmt_tree ()->stmts_are_full_exprs_p =
    7098                 :            :             saved_stmts_are_full_exprs_p;
    7099                 :            :         }
    7100                 :            :     }
    7101                 :            : 
    7102                 :            :   /* Set this to 0 so we can tell whether an aggregate which was
    7103                 :            :      initialized was ever used.  Don't do this if it has a
    7104                 :            :      destructor, so we don't complain about the 'resource
    7105                 :            :      allocation is initialization' idiom.  Now set
    7106                 :            :      attribute((unused)) on types so decls of that type will be
    7107                 :            :      marked used. (see TREE_USED, above.)  */
    7108                 :    2479620 :   if (TYPE_NEEDS_CONSTRUCTING (type)
    7109                 :     332804 :       && ! already_used
    7110                 :       1230 :       && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    7111                 :    2480520 :       && DECL_NAME (decl))
    7112                 :        890 :     TREE_USED (decl) = 0;
    7113                 :    2478730 :   else if (already_used)
    7114                 :    1884590 :     TREE_USED (decl) = 1;
    7115                 :            : 
    7116                 :    2479620 :   if (cleanup)
    7117                 :     248324 :     finish_decl_cleanup (decl, cleanup);
    7118                 :            : }
    7119                 :            : 
    7120                 :            : /* DECL is a VAR_DECL for a compiler-generated variable with static
    7121                 :            :    storage duration (like a virtual table) whose initializer is a
    7122                 :            :    compile-time constant.  Initialize the variable and provide it to the
    7123                 :            :    back end.  */
    7124                 :            : 
    7125                 :            : void
    7126                 :     211625 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
    7127                 :            : {
    7128                 :     211625 :   tree init;
    7129                 :     211625 :   gcc_assert (DECL_ARTIFICIAL (decl));
    7130                 :     211625 :   init = build_constructor (TREE_TYPE (decl), v);
    7131                 :     211625 :   gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
    7132                 :     211625 :   DECL_INITIAL (decl) = init;
    7133                 :     211625 :   DECL_INITIALIZED_P (decl) = 1;
    7134                 :            :   /* Mark the decl as constexpr so that we can access its content
    7135                 :            :      at compile time.  */
    7136                 :     211625 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    7137                 :     211625 :   DECL_DECLARED_CONSTEXPR_P (decl) = true;
    7138                 :     211625 :   determine_visibility (decl);
    7139                 :     211625 :   layout_var_decl (decl);
    7140                 :     211625 :   maybe_commonize_var (decl);
    7141                 :     211625 :   make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
    7142                 :     211625 : }
    7143                 :            : 
    7144                 :            : /* INIT is the initializer for a variable, as represented by the
    7145                 :            :    parser.  Returns true iff INIT is value-dependent.  */
    7146                 :            : 
    7147                 :            : static bool
    7148                 :     585576 : value_dependent_init_p (tree init)
    7149                 :            : {
    7150                 :     585576 :   if (TREE_CODE (init) == TREE_LIST)
    7151                 :            :     /* A parenthesized initializer, e.g.: int i (3, 2); ? */
    7152                 :         80 :     return any_value_dependent_elements_p (init);
    7153                 :     585496 :   else if (TREE_CODE (init) == CONSTRUCTOR)
    7154                 :            :   /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
    7155                 :            :     {
    7156                 :        261 :       if (dependent_type_p (TREE_TYPE (init)))
    7157                 :            :         return true;
    7158                 :            : 
    7159                 :        255 :       vec<constructor_elt, va_gc> *elts;
    7160                 :        255 :       size_t nelts;
    7161                 :        255 :       size_t i;
    7162                 :            : 
    7163                 :        255 :       elts = CONSTRUCTOR_ELTS (init);
    7164                 :        255 :       nelts = vec_safe_length (elts);
    7165                 :       1688 :       for (i = 0; i < nelts; ++i)
    7166                 :       1535 :         if (value_dependent_init_p ((*elts)[i].value))
    7167                 :            :           return true;
    7168                 :            :     }
    7169                 :            :   else
    7170                 :            :     /* It must be a simple expression, e.g., int i = 3;  */
    7171                 :     585235 :     return value_dependent_expression_p (init);
    7172                 :            :   
    7173                 :            :   return false;
    7174                 :            : }
    7175                 :            : 
    7176                 :            : // Returns true if a DECL is VAR_DECL with the concept specifier.
    7177                 :            : static inline bool
    7178                 :     112182 : is_concept_var (tree decl)
    7179                 :            : {
    7180                 :     112182 :   return (VAR_P (decl)
    7181                 :            :           // Not all variables have DECL_LANG_SPECIFIC.
    7182                 :     112182 :           && DECL_LANG_SPECIFIC (decl)
    7183                 :     170919 :           && DECL_DECLARED_CONCEPT_P (decl));
    7184                 :            : }
    7185                 :            : 
    7186                 :            : /* A helper function to be called via walk_tree.  If any label exists
    7187                 :            :    under *TP, it is (going to be) forced.  Set has_forced_label_in_static.  */
    7188                 :            : 
    7189                 :            : static tree
    7190                 :        407 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
    7191                 :            : {
    7192                 :        407 :   if (TYPE_P (*tp))
    7193                 :          0 :     *walk_subtrees = 0;
    7194                 :        407 :   if (TREE_CODE (*tp) == LABEL_DECL)
    7195                 :          8 :     cfun->has_forced_label_in_static = 1;
    7196                 :        407 :   return NULL_TREE;
    7197                 :            : }
    7198                 :            : 
    7199                 :            : /* Return true if DECL has either a trivial destructor, or for C++2A
    7200                 :            :    is constexpr and has a constexpr destructor.  */
    7201                 :            : 
    7202                 :            : static bool
    7203                 :    3480170 : decl_maybe_constant_destruction (tree decl, tree type)
    7204                 :            : {
    7205                 :    3480170 :   return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    7206                 :    3480170 :           || (cxx_dialect >= cxx2a
    7207                 :      56277 :               && VAR_P (decl)
    7208                 :      56259 :               && DECL_DECLARED_CONSTEXPR_P (decl)
    7209                 :         61 :               && type_has_constexpr_destructor (strip_array_types (type))));
    7210                 :            : }
    7211                 :            : 
    7212                 :            : static tree declare_simd_adjust_this (tree *, int *, void *);
    7213                 :            : 
    7214                 :            : /* Helper function of omp_declare_variant_finalize.  Finalize one
    7215                 :            :    "omp declare variant base" attribute.  Return true if it should be
    7216                 :            :    removed.  */
    7217                 :            : 
    7218                 :            : static bool
    7219                 :       1107 : omp_declare_variant_finalize_one (tree decl, tree attr)
    7220                 :            : {
    7221                 :       1107 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    7222                 :            :     {
    7223                 :        124 :       walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
    7224                 :            :                  DECL_ARGUMENTS (decl), NULL);
    7225                 :        124 :       walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
    7226                 :            :                  DECL_ARGUMENTS (decl), NULL);
    7227                 :            :     }
    7228                 :            : 
    7229                 :       1107 :   tree ctx = TREE_VALUE (TREE_VALUE (attr));
    7230                 :       1107 :   tree simd = omp_get_context_selector (ctx, "construct", "simd");
    7231                 :       1107 :   if (simd)
    7232                 :            :     {
    7233                 :        136 :       TREE_VALUE (simd)
    7234                 :         68 :         = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
    7235                 :         68 :                                                  TREE_VALUE (simd));
    7236                 :            :       /* FIXME, adjusting simd args unimplemented.  */
    7237                 :         68 :       return true;
    7238                 :            :     }
    7239                 :            : 
    7240                 :       1039 :   tree chain = TREE_CHAIN (TREE_VALUE (attr));
    7241                 :       1039 :   location_t varid_loc
    7242                 :       1039 :     = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
    7243                 :       1039 :   location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
    7244                 :       1039 :   cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
    7245                 :       1039 :   tree variant = TREE_PURPOSE (TREE_VALUE (attr));
    7246                 :            : 
    7247                 :       1039 :   location_t save_loc = input_location;
    7248                 :       1039 :   input_location = varid_loc;
    7249                 :            : 
    7250                 :       1039 :   releasing_vec args;
    7251                 :       1039 :   tree parm = DECL_ARGUMENTS (decl);
    7252                 :       1039 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    7253                 :        124 :     parm = DECL_CHAIN (parm);
    7254                 :       1719 :   for (; parm; parm = DECL_CHAIN (parm))
    7255                 :        680 :     if (type_dependent_expression_p (parm))
    7256                 :         24 :       vec_safe_push (args, build_constructor (TREE_TYPE (parm), NULL));
    7257                 :        656 :     else if (MAYBE_CLASS_TYPE_P (TREE_TYPE (parm)))
    7258                 :         48 :       vec_safe_push (args, build_local_temp (TREE_TYPE (parm)));
    7259                 :            :     else
    7260                 :        608 :       vec_safe_push (args, build_zero_cst (TREE_TYPE (parm)));
    7261                 :            : 
    7262                 :       1039 :   bool koenig_p = false;
    7263                 :       1039 :   if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
    7264                 :            :     {
    7265                 :       1031 :       if (identifier_p (variant)
    7266                 :            :           /* In C++2A, we may need to perform ADL for a template
    7267                 :            :              name.  */
    7268                 :       1015 :           || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
    7269                 :         24 :               && identifier_p (TREE_OPERAND (variant, 0))))
    7270                 :            :         {
    7271                 :         16 :           if (!args->is_empty ())
    7272                 :            :             {
    7273                 :         16 :               koenig_p = true;
    7274                 :         16 :               if (!any_type_dependent_arguments_p (args))
    7275                 :         16 :                 variant = perform_koenig_lookup (variant, args,
    7276                 :         16 :                                                  tf_warning_or_error);
    7277                 :            :             }
    7278                 :            :           else
    7279                 :          0 :             variant = unqualified_fn_lookup_error (variant);
    7280                 :            :         }
    7281                 :       1015 :       else if (!args->is_empty () && is_overloaded_fn (variant))
    7282                 :            :         {
    7283                 :        368 :           tree fn = get_first_fn (variant);
    7284                 :        368 :           fn = STRIP_TEMPLATE (fn);
    7285                 :        368 :           if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
    7286                 :        620 :                  || DECL_FUNCTION_MEMBER_P (fn)
    7287                 :        252 :                  || DECL_LOCAL_FUNCTION_P (fn)))
    7288                 :            :             {
    7289                 :        252 :               koenig_p = true;
    7290                 :        252 :               if (!any_type_dependent_arguments_p (args))
    7291                 :        252 :                 variant = perform_koenig_lookup (variant, args,
    7292                 :        252 :                                                  tf_warning_or_error);
    7293                 :            :             }
    7294                 :            :         }
    7295                 :            :     }
    7296                 :            : 
    7297                 :       1039 :   if (idk == CP_ID_KIND_QUALIFIED)
    7298                 :          8 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
    7299                 :            :                                 koenig_p, tf_warning_or_error);
    7300                 :            :   else
    7301                 :       1031 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    7302                 :            :                                 koenig_p, tf_warning_or_error);
    7303                 :       1039 :   if (variant == error_mark_node && !processing_template_decl)
    7304                 :            :     return true;
    7305                 :            : 
    7306                 :       1007 :   variant = cp_get_callee (variant);
    7307                 :       1007 :   if (variant)
    7308                 :            :     {
    7309                 :       1007 :       if (TREE_CODE (variant) == FUNCTION_DECL)
    7310                 :            :         ;
    7311                 :        979 :       else if (TREE_TYPE (variant) && INDIRECT_TYPE_P (TREE_TYPE (variant)))
    7312                 :        947 :         variant = cp_get_fndecl_from_callee (variant, false);
    7313                 :            :       else
    7314                 :            :         variant = NULL_TREE;
    7315                 :            :     }
    7316                 :            : 
    7317                 :       1007 :   input_location = save_loc;
    7318                 :            : 
    7319                 :       1007 :   if (variant)
    7320                 :            :     {
    7321                 :        975 :       const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
    7322                 :        975 :       if (!comptypes (TREE_TYPE (decl), TREE_TYPE (variant), 0))
    7323                 :            :         {
    7324                 :         72 :           error_at (varid_loc, "variant %qD and base %qD have incompatible "
    7325                 :            :                                "types", variant, decl);
    7326                 :         72 :           return true;
    7327                 :            :         }
    7328                 :        903 :       if (fndecl_built_in_p (variant)
    7329                 :        903 :           && (strncmp (varname, "__builtin_", strlen ("__builtin_")) == 0
    7330                 :          0 :               || strncmp (varname, "__sync_", strlen ("__sync_")) == 0
    7331                 :          0 :               || strncmp (varname, "__atomic_", strlen ("__atomic_")) == 0))
    7332                 :            :         {
    7333                 :          8 :           error_at (varid_loc, "variant %qD is a built-in", variant);
    7334                 :          8 :           return true;
    7335                 :            :         }
    7336                 :            :       else
    7337                 :            :         {
    7338                 :        895 :           tree construct = omp_get_context_selector (ctx, "construct", NULL);
    7339                 :        895 :           c_omp_mark_declare_variant (match_loc, variant, construct);
    7340                 :        895 :           if (!omp_context_selector_matches (ctx))
    7341                 :            :             return true;
    7342                 :        532 :           TREE_PURPOSE (TREE_VALUE (attr)) = variant;
    7343                 :            :         }
    7344                 :            :     }
    7345                 :         32 :   else if (!processing_template_decl)
    7346                 :            :     {
    7347                 :          0 :       error_at (varid_loc, "could not find variant declaration");
    7348                 :          0 :       return true;
    7349                 :            :     }
    7350                 :            : 
    7351                 :            :   return false;
    7352                 :            : }
    7353                 :            : 
    7354                 :            : /* Helper function, finish up "omp declare variant base" attribute
    7355                 :            :    now that there is a DECL.  ATTR is the first "omp declare variant base"
    7356                 :            :    attribute.  */
    7357                 :            : 
    7358                 :            : void
    7359                 :       1013 : omp_declare_variant_finalize (tree decl, tree attr)
    7360                 :            : {
    7361                 :       1013 :   size_t attr_len = strlen ("omp declare variant base");
    7362                 :       1013 :   tree *list = &DECL_ATTRIBUTES (decl);
    7363                 :       1013 :   bool remove_all = false;
    7364                 :       1013 :   location_t match_loc = DECL_SOURCE_LOCATION (decl);
    7365                 :       1013 :   if (TREE_CHAIN (TREE_VALUE (attr))
    7366                 :       1013 :       && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
    7367                 :       2026 :       && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
    7368                 :       1013 :     match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
    7369                 :       2026 :   if (DECL_CONSTRUCTOR_P (decl))
    7370                 :            :     {
    7371                 :         36 :       error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
    7372                 :         36 :       remove_all = true;
    7373                 :            :     }
    7374                 :        977 :   else if (DECL_DESTRUCTOR_P (decl))
    7375                 :            :     {
    7376                 :         12 :       error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
    7377                 :         12 :       remove_all = true;
    7378                 :            :     }
    7379                 :        965 :   else if (DECL_DEFAULTED_FN (decl))
    7380                 :            :     {
    7381                 :          3 :       error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
    7382                 :          3 :       remove_all = true;
    7383                 :            :     }
    7384                 :        962 :   else if (DECL_DELETED_FN (decl))
    7385                 :            :     {
    7386                 :          3 :       error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
    7387                 :          3 :       remove_all = true;
    7388                 :            :     }
    7389                 :        959 :   else if (DECL_VIRTUAL_P (decl))
    7390                 :            :     {
    7391                 :          0 :       error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
    7392                 :          0 :       remove_all = true;
    7393                 :            :     }
    7394                 :            :   /* This loop is like private_lookup_attribute, except that it works
    7395                 :            :      with tree * rather than tree, as we might want to remove the
    7396                 :            :      attributes that are diagnosed as errorneous.  */
    7397                 :       2174 :   while (*list)
    7398                 :            :     {
    7399                 :       1161 :       tree attr = get_attribute_name (*list);
    7400                 :       1161 :       size_t ident_len = IDENTIFIER_LENGTH (attr);
    7401                 :       1161 :       if (cmp_attribs ("omp declare variant base", attr_len,
    7402                 :       1161 :                        IDENTIFIER_POINTER (attr), ident_len))
    7403                 :            :         {
    7404                 :       1161 :           if (remove_all || omp_declare_variant_finalize_one (decl, *list))
    7405                 :            :             {
    7406                 :        597 :               *list = TREE_CHAIN (*list);
    7407                 :        597 :               continue;
    7408                 :            :             }
    7409                 :            :         }
    7410                 :        564 :       list = &TREE_CHAIN (*list);
    7411                 :            :     }
    7412                 :       1013 : }
    7413                 :            : 
    7414                 :            : /* Finish processing of a declaration;
    7415                 :            :    install its line number and initial value.
    7416                 :            :    If the length of an array type is not known before,
    7417                 :            :    it must be determined now, from the initial value, or it is an error.
    7418                 :            : 
    7419                 :            :    INIT is the initializer (if any) for DECL.  If INIT_CONST_EXPR_P is
    7420                 :            :    true, then INIT is an integral constant expression.
    7421                 :            : 
    7422                 :            :    FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
    7423                 :            :    if the (init) syntax was used.  */
    7424                 :            : 
    7425                 :            : void
    7426                 :   24188500 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
    7427                 :            :                 tree asmspec_tree, int flags)
    7428                 :            : {
    7429                 :   24188500 :   tree type;
    7430                 :   24188500 :   vec<tree, va_gc> *cleanups = NULL;
    7431                 :   24188500 :   const char *asmspec = NULL;
    7432                 :   24188500 :   int was_readonly = 0;
    7433                 :   24188500 :   bool var_definition_p = false;
    7434                 :   24188500 :   tree auto_node;
    7435                 :            : 
    7436                 :   24188500 :   if (decl == error_mark_node)
    7437                 :   11706200 :     return;
    7438                 :   24188500 :   else if (! decl)
    7439                 :            :     {
    7440                 :          0 :       if (init)
    7441                 :          0 :         error ("assignment (not initialization) in declaration");
    7442                 :          0 :       return;
    7443                 :            :     }
    7444                 :            : 
    7445                 :   24188500 :   gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    7446                 :            :   /* Parameters are handled by store_parm_decls, not cp_finish_decl.  */
    7447                 :   24188500 :   gcc_assert (TREE_CODE (decl) != PARM_DECL);
    7448                 :            : 
    7449                 :   24188500 :   type = TREE_TYPE (decl);
    7450                 :   24188500 :   if (type == error_mark_node)
    7451                 :            :     return;
    7452                 :            : 
    7453                 :            :   /* Warn about register storage specifiers except when in GNU global
    7454                 :            :      or local register variable extension.  */
    7455                 :   32153700 :   if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
    7456                 :            :     {
    7457                 :       2591 :       if (cxx_dialect >= cxx17)
    7458                 :       1274 :         pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    7459                 :            :                  "ISO C++17 does not allow %<register%> storage "
    7460                 :            :                  "class specifier");
    7461                 :            :       else
    7462                 :       1317 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    7463                 :            :                     "%<register%> storage class specifier used");
    7464                 :            :     }
    7465                 :            : 
    7466                 :            :   /* If a name was specified, get the string.  */
    7467                 :   24188100 :   if (at_namespace_scope_p ())
    7468                 :    7323580 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    7469                 :   24188100 :   if (asmspec_tree && asmspec_tree != error_mark_node)
    7470                 :      85021 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    7471                 :            : 
    7472                 :   24188100 :   if (current_class_type
    7473                 :   13294100 :       && CP_DECL_CONTEXT (decl) == current_class_type
    7474                 :    8644510 :       && TYPE_BEING_DEFINED (current_class_type)
    7475                 :    8462860 :       && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type)
    7476                 :   32356600 :       && (DECL_INITIAL (decl) || init))
    7477                 :   10723400 :     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
    7478                 :            : 
    7479                 :            :   /* Do auto deduction unless decl is a function or an uninstantiated
    7480                 :            :      template specialization.  */
    7481                 :   24188100 :   if (TREE_CODE (decl) != FUNCTION_DECL
    7482                 :   13564000 :       && !(init == NULL_TREE
    7483                 :    7194540 :            && DECL_LANG_SPECIFIC (decl)
    7484                 :    1925960 :            && DECL_TEMPLATE_INSTANTIATION (decl)
    7485                 :     240967 :            && !DECL_TEMPLATE_INSTANTIATED (decl))
    7486                 :   37271000 :       && (auto_node = type_uses_auto (type)))
    7487                 :            :     {
    7488                 :     364443 :       tree d_init;
    7489                 :     364443 :       if (init == NULL_TREE)
    7490                 :         51 :         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (auto_node));
    7491                 :     364443 :       d_init = init;
    7492                 :     364443 :       if (d_init)
    7493                 :            :         {
    7494                 :     364392 :           if (TREE_CODE (d_init) == TREE_LIST
    7495                 :     364807 :               && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    7496                 :        142 :             d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
    7497                 :            :                                                       tf_warning_or_error);
    7498                 :     364392 :           d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
    7499                 :            :         }
    7500                 :     364443 :       enum auto_deduction_context adc = adc_variable_type;
    7501                 :     728886 :       if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl))
    7502                 :            :         adc = adc_decomp_type;
    7503                 :     364443 :       type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
    7504                 :            :                                                    tf_warning_or_error, adc,
    7505                 :            :                                                    NULL_TREE, flags);
    7506                 :     364443 :       if (type == error_mark_node)
    7507                 :            :         return;
    7508                 :     364127 :       if (TREE_CODE (type) == FUNCTION_TYPE)
    7509                 :            :         {
    7510                 :          3 :           error ("initializer for %<decltype(auto) %D%> has function type; "
    7511                 :            :                  "did you forget the %<()%>?", decl);
    7512                 :          3 :           TREE_TYPE (decl) = error_mark_node;
    7513                 :          3 :           return;
    7514                 :            :         }
    7515                 :     364124 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    7516                 :            :     }
    7517                 :            : 
    7518                 :   24187800 :   if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
    7519                 :            :     {
    7520                 :         90 :       DECL_DECLARED_CONSTEXPR_P (decl) = 0;
    7521                 :         90 :       if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
    7522                 :            :         {
    7523                 :          6 :           init = NULL_TREE;
    7524                 :          6 :           DECL_EXTERNAL (decl) = 1;
    7525                 :            :         }
    7526                 :            :     }
    7527                 :            : 
    7528                 :   24187800 :   if (VAR_P (decl)
    7529                 :    7965350 :       && DECL_CLASS_SCOPE_P (decl)
    7530                 :    1597190 :       && verify_type_context (DECL_SOURCE_LOCATION (decl),
    7531                 :            :                               TCTX_STATIC_STORAGE, type)
    7532                 :   25784900 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    7533                 :    1416050 :     check_static_variable_definition (decl, type);
    7534                 :            : 
    7535                 :   24187800 :   if (init && TREE_CODE (decl) == FUNCTION_DECL)
    7536                 :            :     {
    7537                 :      38982 :       tree clone;
    7538                 :      38982 :       if (init == ridpointers[(int)RID_DELETE])
    7539                 :            :         {
    7540                 :            :           /* FIXME check this is 1st decl.  */
    7541                 :      36240 :           DECL_DELETED_FN (decl) = 1;
    7542                 :      36240 :           DECL_DECLARED_INLINE_P (decl) = 1;
    7543                 :      36240 :           DECL_INITIAL (decl) = error_mark_node;
    7544                 :      36285 :           FOR_EACH_CLONE (clone, decl)
    7545                 :            :             {
    7546                 :         36 :               DECL_DELETED_FN (clone) = 1;
    7547                 :         18 :               DECL_DECLARED_INLINE_P (clone) = 1;
    7548                 :         18 :               DECL_INITIAL (clone) = error_mark_node;
    7549                 :            :             }
    7550                 :      36240 :           init = NULL_TREE;
    7551                 :            :         }
    7552                 :       2742 :       else if (init == ridpointers[(int)RID_DEFAULT])
    7553                 :            :         {
    7554                 :       2726 :           if (defaultable_fn_check (decl))
    7555                 :       5434 :             DECL_DEFAULTED_FN (decl) = 1;
    7556                 :            :           else
    7557                 :          9 :             DECL_INITIAL (decl) = NULL_TREE;
    7558                 :            :         }
    7559                 :            :     }
    7560                 :            : 
    7561                 :   24187800 :   if (init && VAR_P (decl))
    7562                 :            :     {
    7563                 :    6094310 :       DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
    7564                 :            :       /* If DECL is a reference, then we want to know whether init is a
    7565                 :            :          reference constant; init_const_expr_p as passed tells us whether
    7566                 :            :          it's an rvalue constant.  */
    7567                 :    6094310 :       if (TYPE_REF_P (type))
    7568                 :     146800 :         init_const_expr_p = potential_constant_expression (init);
    7569                 :    6094310 :       if (init_const_expr_p)
    7570                 :            :         {
    7571                 :            :           /* Set these flags now for templates.  We'll update the flags in
    7572                 :            :              store_init_value for instantiations.  */
    7573                 :    5078840 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    7574                 :    5078840 :           if (decl_maybe_constant_var_p (decl)
    7575                 :            :               /* FIXME setting TREE_CONSTANT on refs breaks the back end.  */
    7576                 :    5078840 :               && !TYPE_REF_P (type))
    7577                 :    2181400 :             TREE_CONSTANT (decl) = 1;
    7578                 :            :         }
    7579                 :            :     }
    7580                 :            : 
    7581                 :   24187800 :   if (flag_openmp
    7582                 :     122109 :       && TREE_CODE (decl) == FUNCTION_DECL
    7583                 :            :       /* #pragma omp declare variant on methods handled in finish_struct
    7584                 :            :          instead.  */
    7585                 :   24240400 :       && (!DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)
    7586                 :      16575 :           || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
    7587                 :      72410 :     if (tree attr = lookup_attribute ("omp declare variant base",
    7588                 :      36205 :                                       DECL_ATTRIBUTES (decl)))
    7589                 :        727 :       omp_declare_variant_finalize (decl, attr);
    7590                 :            : 
    7591                 :   24187800 :   if (pro