LCOV - code coverage report
Current view: top level - gcc/cp - name-lookup.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.9 % 3894 3656
Test Date: 2024-04-20 14:03:02 Functions: 96.1 % 228 219
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Definitions for C++ name lookup routines.
       2                 :             :    Copyright (C) 2003-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
       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                 :             : #include "config.h"
      22                 :             : #define INCLUDE_MEMORY
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "cp-tree.h"
      26                 :             : #include "timevar.h"
      27                 :             : #include "stringpool.h"
      28                 :             : #include "print-tree.h"
      29                 :             : #include "attribs.h"
      30                 :             : #include "debug.h"
      31                 :             : #include "c-family/c-pragma.h"
      32                 :             : #include "gcc-rich-location.h"
      33                 :             : #include "spellcheck-tree.h"
      34                 :             : #include "parser.h"
      35                 :             : #include "c-family/name-hint.h"
      36                 :             : #include "c-family/known-headers.h"
      37                 :             : #include "c-family/c-spellcheck.h"
      38                 :             : #include "bitmap.h"
      39                 :             : 
      40                 :             : static cxx_binding *cxx_binding_make (tree value, tree type);
      41                 :             : static cp_binding_level *innermost_nonclass_level (void);
      42                 :             : static void set_identifier_type_value_with_scope (tree id, tree decl,
      43                 :             :                                                   cp_binding_level *b);
      44                 :             : static name_hint maybe_suggest_missing_std_header (location_t location,
      45                 :             :                                                    tree name);
      46                 :             : static name_hint suggest_alternatives_for_1 (location_t location, tree name,
      47                 :             :                                              bool suggest_misspellings);
      48                 :             : 
      49                 :             : /* Slots in BINDING_VECTOR.  */
      50                 :             : enum binding_slots
      51                 :             : {
      52                 :             :  BINDING_SLOT_CURRENT,  /* Slot for current TU.  */
      53                 :             :  BINDING_SLOT_GLOBAL,   /* Slot for merged global module. */
      54                 :             :  BINDING_SLOT_PARTITION, /* Slot for merged partition entities
      55                 :             :                             (optional).  */
      56                 :             : 
      57                 :             :  /* Number of always-allocated slots.  */
      58                 :             :  BINDING_SLOTS_FIXED = BINDING_SLOT_GLOBAL + 1
      59                 :             : };
      60                 :             : 
      61                 :             : /* Create an overload suitable for recording an artificial TYPE_DECL
      62                 :             :    and another decl.  We use this machanism to implement the struct
      63                 :             :    stat hack.  */
      64                 :             : 
      65                 :             : #define STAT_HACK_P(N) ((N) && TREE_CODE (N) == OVERLOAD && OVL_LOOKUP_P (N))
      66                 :             : #define STAT_TYPE_VISIBLE_P(N) TREE_USED (OVERLOAD_CHECK (N))
      67                 :             : #define STAT_TYPE(N) TREE_TYPE (N)
      68                 :             : #define STAT_DECL(N) OVL_FUNCTION (N)
      69                 :             : #define STAT_VISIBLE(N) OVL_CHAIN (N)
      70                 :             : #define MAYBE_STAT_DECL(N) (STAT_HACK_P (N) ? STAT_DECL (N) : N)
      71                 :             : #define MAYBE_STAT_TYPE(N) (STAT_HACK_P (N) ? STAT_TYPE (N) : NULL_TREE)
      72                 :             : 
      73                 :             : /* When a STAT_HACK_P is true, OVL_USING_P and OVL_EXPORT_P are valid
      74                 :             :    and apply to the hacked type.  */
      75                 :             : 
      76                 :             : /* For regular (maybe) overloaded functions, we have OVL_HIDDEN_P.
      77                 :             :    But we also need to indicate hiddenness on implicit type decls
      78                 :             :    (injected friend classes), and (coming soon) decls injected from
      79                 :             :    block-scope externs.  It is too awkward to press the existing
      80                 :             :    overload marking for that.  If we have a hidden non-function, we
      81                 :             :    always create a STAT_HACK, and use these two markers as needed.  */
      82                 :             : #define STAT_TYPE_HIDDEN_P(N) OVL_HIDDEN_P (N)
      83                 :             : #define STAT_DECL_HIDDEN_P(N) OVL_DEDUP_P (N)
      84                 :             : 
      85                 :             : /* Create a STAT_HACK node with DECL as the value binding and TYPE as
      86                 :             :    the type binding.  */
      87                 :             : 
      88                 :             : static tree
      89                 :      495772 : stat_hack (tree decl = NULL_TREE, tree type = NULL_TREE)
      90                 :             : {
      91                 :      495772 :   tree result = make_node (OVERLOAD);
      92                 :             : 
      93                 :             :   /* Mark this as a lookup, so we can tell this is a stat hack.  */
      94                 :      495772 :   OVL_LOOKUP_P (result) = true;
      95                 :      495772 :   STAT_DECL (result) = decl;
      96                 :      495772 :   STAT_TYPE (result) = type;
      97                 :      495772 :   return result;
      98                 :             : }
      99                 :             : 
     100                 :             : /* Create a local binding level for NAME.  */
     101                 :             : 
     102                 :             : static cxx_binding *
     103                 :   766676750 : create_local_binding (cp_binding_level *level, tree name)
     104                 :             : {
     105                 :   766676750 :   cxx_binding *binding = cxx_binding_make (NULL, NULL);
     106                 :             : 
     107                 :   766676750 :   LOCAL_BINDING_P (binding) = true;
     108                 :   766676750 :   binding->scope = level;
     109                 :   766676750 :   binding->previous = IDENTIFIER_BINDING (name);
     110                 :             : 
     111                 :   766676750 :   IDENTIFIER_BINDING (name) = binding;
     112                 :             :   
     113                 :   766676750 :   return binding;
     114                 :             : }
     115                 :             : 
     116                 :             : /* Find the binding for NAME in namespace NS.  If CREATE_P is true,
     117                 :             :    make an empty binding if there wasn't one.  */
     118                 :             : 
     119                 :             : static tree *
     120                 :  7887852570 : find_namespace_slot (tree ns, tree name, bool create_p = false)
     121                 :             : {
     122                 :  7887852570 :   tree *slot = DECL_NAMESPACE_BINDINGS (ns)
     123                 : 15405932833 :     ->find_slot_with_hash (name, name ? IDENTIFIER_HASH_VALUE (name) : 0,
     124                 :             :                            create_p ? INSERT : NO_INSERT);
     125                 :  7887852570 :   return slot;
     126                 :             : }
     127                 :             : 
     128                 :             : static tree
     129                 :       32618 : find_namespace_value (tree ns, tree name)
     130                 :             : {
     131                 :       32618 :   tree *b = find_namespace_slot (ns, name);
     132                 :             : 
     133                 :       32618 :   return b ? MAYBE_STAT_DECL (*b) : NULL_TREE;
     134                 :             : }
     135                 :             : 
     136                 :             : /* Look in *SLOT for a the binding of NAME in imported module IX.
     137                 :             :    Returns pointer to binding's slot, or NULL if not found.  Does a
     138                 :             :    binary search, as this is mainly used for random access during
     139                 :             :    importing.  Do not use for the fixed slots.  */
     140                 :             : 
     141                 :             : static binding_slot *
     142                 :      204839 : search_imported_binding_slot (tree *slot, unsigned ix)
     143                 :             : {
     144                 :      204839 :   gcc_assert (ix);
     145                 :             : 
     146                 :      204839 :   if (!*slot)
     147                 :             :     return NULL;
     148                 :             : 
     149                 :      204839 :   if (TREE_CODE (*slot) != BINDING_VECTOR)
     150                 :             :     return NULL;
     151                 :             :   
     152                 :      204839 :   unsigned clusters = BINDING_VECTOR_NUM_CLUSTERS (*slot);
     153                 :      204839 :   binding_cluster *cluster = BINDING_VECTOR_CLUSTER_BASE (*slot);
     154                 :             : 
     155                 :      204839 :   if (BINDING_VECTOR_SLOTS_PER_CLUSTER == BINDING_SLOTS_FIXED)
     156                 :             :     {
     157                 :      204839 :       clusters--;
     158                 :      204839 :       cluster++;
     159                 :             :     }
     160                 :             : 
     161                 :      409717 :   while (clusters > 1)
     162                 :             :     {
     163                 :          39 :       unsigned half = clusters / 2;
     164                 :          39 :       gcc_checking_assert (cluster[half].indices[0].span);
     165                 :          39 :       if (cluster[half].indices[0].base > ix)
     166                 :             :         clusters = half;
     167                 :             :       else
     168                 :             :         {
     169                 :          30 :           clusters -= half;
     170                 :          30 :           cluster += half;
     171                 :             :         }
     172                 :             :     }
     173                 :             : 
     174                 :      204839 :   if (clusters)
     175                 :             :     /* Is it in this cluster?  */
     176                 :      205677 :     for (unsigned off = 0; off != BINDING_VECTOR_SLOTS_PER_CLUSTER; off++)
     177                 :             :       {
     178                 :      205677 :         if (!cluster->indices[off].span)
     179                 :             :           break;
     180                 :      205677 :         if (cluster->indices[off].base > ix)
     181                 :             :           break;
     182                 :             : 
     183                 :      205677 :         if (cluster->indices[off].base + cluster->indices[off].span > ix)
     184                 :      204839 :           return &cluster->slots[off];
     185                 :             :       }
     186                 :             : 
     187                 :             :   return NULL;
     188                 :             : }
     189                 :             : 
     190                 :             : static void
     191                 :      206969 : init_global_partition (binding_cluster *cluster, tree decl)
     192                 :             : {
     193                 :      206969 :   bool named = true;
     194                 :             : 
     195                 :      206969 :   if (header_module_p ())
     196                 :             :     named = false;
     197                 :      206876 :   else if (TREE_PUBLIC (decl)
     198                 :      206876 :            && TREE_CODE (decl) == NAMESPACE_DECL
     199                 :      208249 :            && !DECL_NAMESPACE_ALIAS (decl))
     200                 :             :     named = false;
     201                 :      205503 :   else if (!get_originating_module (decl))
     202                 :             :     named = false;
     203                 :             : 
     204                 :           0 :   binding_slot *mslot;
     205                 :           0 :   if (named)
     206                 :           0 :     mslot = &cluster[BINDING_SLOT_PARTITION
     207                 :             :                      / BINDING_VECTOR_SLOTS_PER_CLUSTER]
     208                 :             :       .slots[BINDING_SLOT_PARTITION
     209                 :             :              % BINDING_VECTOR_SLOTS_PER_CLUSTER];
     210                 :             :   else
     211                 :      206969 :     mslot = &cluster[0].slots[BINDING_SLOT_GLOBAL];
     212                 :             : 
     213                 :      206969 :   if (*mslot)
     214                 :       44151 :     decl = ovl_make (decl, *mslot);
     215                 :      206969 :   *mslot = decl;
     216                 :             : 
     217                 :      206969 :   if (TREE_CODE (decl) == CONST_DECL)
     218                 :             :     {
     219                 :        8168 :       tree type = TREE_TYPE (decl);
     220                 :        8168 :       if (TREE_CODE (type) == ENUMERAL_TYPE
     221                 :        8168 :           && IDENTIFIER_ANON_P (DECL_NAME (TYPE_NAME (type)))
     222                 :       13643 :           && decl == TREE_VALUE (TYPE_VALUES (type)))
     223                 :             :         /* Anonymous enums are keyed by their first enumerator, put
     224                 :             :            the TYPE_DECL here too.  */
     225                 :         419 :         *mslot = ovl_make (TYPE_NAME (type), *mslot);
     226                 :             :     }
     227                 :      206969 : }
     228                 :             : 
     229                 :             : /* Get the fixed binding slot IX.  Creating the vector if CREATE is
     230                 :             :    non-zero.  If CREATE is < 0, make sure there is at least 1 spare
     231                 :             :    slot for an import.  (It is an error for CREATE < 0 and the slot to
     232                 :             :    already exist.)  */
     233                 :             : 
     234                 :             : static tree *
     235                 :   365751466 : get_fixed_binding_slot (tree *slot, tree name, unsigned ix, int create)
     236                 :             : {
     237                 :   365751466 :   gcc_checking_assert (ix <= BINDING_SLOT_PARTITION);
     238                 :             : 
     239                 :             :   /* An assumption is that the fixed slots all reside in one cluster.  */
     240                 :   365751466 :   gcc_checking_assert (BINDING_VECTOR_SLOTS_PER_CLUSTER >= BINDING_SLOTS_FIXED);
     241                 :             : 
     242                 :   365751466 :   if (!*slot || TREE_CODE (*slot) != BINDING_VECTOR)
     243                 :             :     {
     244                 :   365518015 :       if (ix == BINDING_SLOT_CURRENT)
     245                 :             :         /* The current TU can just use slot directly.  */
     246                 :             :         return slot;
     247                 :             : 
     248                 :      279247 :       if (!create)
     249                 :             :         return NULL;
     250                 :             : 
     251                 :             :       /* The partition slot is only needed when we're a named
     252                 :             :          module.  */
     253                 :      279247 :       bool partition_slot = named_module_p ();
     254                 :      279247 :       unsigned want = ((BINDING_SLOTS_FIXED + partition_slot + (create < 0)
     255                 :      279247 :                         + BINDING_VECTOR_SLOTS_PER_CLUSTER - 1)
     256                 :      279247 :                        / BINDING_VECTOR_SLOTS_PER_CLUSTER);
     257                 :      279247 :       tree new_vec = make_binding_vec (name, want);
     258                 :      279247 :       BINDING_VECTOR_NUM_CLUSTERS (new_vec) = want;
     259                 :      279247 :       binding_cluster *cluster = BINDING_VECTOR_CLUSTER_BASE (new_vec);
     260                 :             : 
     261                 :             :       /* Initialize the fixed slots.  */
     262                 :      837741 :       for (unsigned jx = BINDING_SLOTS_FIXED; jx--;)
     263                 :             :         {
     264                 :      558494 :           cluster[0].indices[jx].base = 0;
     265                 :      558494 :           cluster[0].indices[jx].span = 1;
     266                 :      558494 :           cluster[0].slots[jx] = NULL_TREE;
     267                 :             :         }
     268                 :             : 
     269                 :      279247 :       if (partition_slot)
     270                 :             :         {
     271                 :       30121 :           unsigned off = BINDING_SLOT_PARTITION % BINDING_VECTOR_SLOTS_PER_CLUSTER;
     272                 :       30121 :           unsigned ind = BINDING_SLOT_PARTITION / BINDING_VECTOR_SLOTS_PER_CLUSTER;
     273                 :       30121 :           cluster[ind].indices[off].base = 0;
     274                 :       30121 :           cluster[ind].indices[off].span = 1;
     275                 :       30121 :           cluster[ind].slots[off] = NULL_TREE;
     276                 :             :         }
     277                 :             : 
     278                 :      279247 :       if (tree orig = *slot)
     279                 :             :         {
     280                 :             :           /* Propagate existing value to current slot.  */
     281                 :             : 
     282                 :             :           /* Propagate global & module entities to the global and
     283                 :             :              partition slots.  */
     284                 :      162818 :           if (tree type = MAYBE_STAT_TYPE (orig))
     285                 :          44 :             init_global_partition (cluster, type);
     286                 :             : 
     287                 :      453190 :           for (ovl_iterator iter (MAYBE_STAT_DECL (orig)); iter; ++iter)
     288                 :             :             {
     289                 :      206925 :               tree decl = *iter;
     290                 :             : 
     291                 :             :               /* Internal linkage entities are in deduplicateable.  */
     292                 :      206925 :               init_global_partition (cluster, decl);
     293                 :             :             }
     294                 :             : 
     295                 :      162818 :           if (cluster[0].slots[BINDING_SLOT_GLOBAL]
     296                 :      162818 :               && !(TREE_CODE (orig) == NAMESPACE_DECL
     297                 :      164221 :                    && !DECL_NAMESPACE_ALIAS (orig)))
     298                 :             :             {
     299                 :             :               /* Note that we had some GMF entries.  */
     300                 :      161430 :               if (!STAT_HACK_P (orig))
     301                 :      161376 :                 orig = stat_hack (orig);
     302                 :             : 
     303                 :      161430 :               MODULE_BINDING_GLOBAL_P (orig) = true;
     304                 :             :             }
     305                 :             : 
     306                 :      162818 :           cluster[0].slots[BINDING_SLOT_CURRENT] = orig;
     307                 :             :         }
     308                 :             : 
     309                 :      279247 :       *slot = new_vec;
     310                 :      279247 :     }
     311                 :             :   else
     312                 :      233451 :     gcc_checking_assert (create >= 0);
     313                 :             : 
     314                 :      512698 :   unsigned off = ix % BINDING_VECTOR_SLOTS_PER_CLUSTER;
     315                 :      512698 :   binding_cluster &cluster
     316                 :      512698 :     = BINDING_VECTOR_CLUSTER (*slot, ix / BINDING_VECTOR_SLOTS_PER_CLUSTER);
     317                 :             : 
     318                 :             :   /* There must always be slots for these indices  */
     319                 :      512698 :   gcc_checking_assert (cluster.indices[off].span == 1
     320                 :             :                        && !cluster.indices[off].base
     321                 :             :                        && !cluster.slots[off].is_lazy ());
     322                 :             : 
     323                 :      512698 :   return reinterpret_cast<tree *> (&cluster.slots[off]);
     324                 :             : }
     325                 :             : 
     326                 :             : /* *SLOT is a namespace binding slot.  Append a slot for imported
     327                 :             :    module IX.  */
     328                 :             : 
     329                 :             : static binding_slot *
     330                 :      268525 : append_imported_binding_slot (tree *slot, tree name, unsigned ix)
     331                 :             : {
     332                 :      268525 :   gcc_checking_assert (ix);
     333                 :             : 
     334                 :      268525 :   if (!*slot ||  TREE_CODE (*slot) != BINDING_VECTOR)
     335                 :             :     /* Make an initial module vector.  */
     336                 :      260758 :     get_fixed_binding_slot (slot, name, BINDING_SLOT_GLOBAL, -1);
     337                 :        7767 :   else if (!BINDING_VECTOR_CLUSTER_LAST (*slot)
     338                 :        7767 :            ->indices[BINDING_VECTOR_SLOTS_PER_CLUSTER - 1].span)
     339                 :             :     /* There is space in the last cluster.  */;
     340                 :        7097 :   else if (BINDING_VECTOR_NUM_CLUSTERS (*slot)
     341                 :        7097 :            != BINDING_VECTOR_ALLOC_CLUSTERS (*slot))
     342                 :             :     /* There is space in the vector.  */
     343                 :           0 :     BINDING_VECTOR_NUM_CLUSTERS (*slot)++;
     344                 :             :   else
     345                 :             :     {
     346                 :             :       /* Extend the vector.  */
     347                 :        7097 :       unsigned have = BINDING_VECTOR_NUM_CLUSTERS (*slot);
     348                 :        7097 :       unsigned want = (have * 3 + 1) / 2;
     349                 :             : 
     350                 :        7097 :       if (want > (unsigned short)~0)
     351                 :           0 :         want = (unsigned short)~0;
     352                 :             : 
     353                 :        7097 :       tree new_vec = make_binding_vec (name, want);
     354                 :        7097 :       BINDING_VECTOR_NUM_CLUSTERS (new_vec) = have + 1;
     355                 :       14194 :       memcpy (BINDING_VECTOR_CLUSTER_BASE (new_vec),
     356                 :       14194 :               BINDING_VECTOR_CLUSTER_BASE (*slot),
     357                 :        7097 :               have * sizeof (binding_cluster));
     358                 :        7097 :       *slot = new_vec;
     359                 :             :     }
     360                 :             : 
     361                 :      268525 :   binding_cluster *last = BINDING_VECTOR_CLUSTER_LAST (*slot);
     362                 :      294751 :   for (unsigned off = 0; off != BINDING_VECTOR_SLOTS_PER_CLUSTER; off++)
     363                 :      294751 :     if (!last->indices[off].span)
     364                 :             :       {
     365                 :             :         /* Fill the free slot of the cluster.  */
     366                 :      268525 :         last->indices[off].base = ix;
     367                 :      268525 :         last->indices[off].span = 1;
     368                 :      268525 :         last->slots[off] = NULL_TREE;
     369                 :             :         /* Check monotonicity.  */
     370                 :      537050 :         gcc_checking_assert (last[off ? 0 : -1]
     371                 :             :                              .indices[off ? off - 1
     372                 :             :                                       : BINDING_VECTOR_SLOTS_PER_CLUSTER - 1]
     373                 :             :                              .base < ix);
     374                 :      268525 :         return &last->slots[off];
     375                 :             :       }
     376                 :             : 
     377                 :           0 :   gcc_unreachable ();
     378                 :             : }
     379                 :             : 
     380                 :             : /* Add DECL to the list of things declared in binding level B.  */
     381                 :             : 
     382                 :             : static void
     383                 :  1143818592 : add_decl_to_level (cp_binding_level *b, tree decl)
     384                 :             : {
     385                 :  1143818592 :   gcc_assert (b->kind != sk_class);
     386                 :             : 
     387                 :             :   /* Make sure we don't create a circular list.  xref_tag can end
     388                 :             :      up pushing the same artificial decl more than once.  We
     389                 :             :      should have already detected that in update_binding.  (This isn't a
     390                 :             :      complete verification of non-circularity.)  */
     391                 :  1143818592 :   gcc_assert (b->names != decl);
     392                 :             : 
     393                 :             :   /* We build up the list in reverse order, and reverse it later if
     394                 :             :      necessary.  */
     395                 :  1143818592 :   TREE_CHAIN (decl) = b->names;
     396                 :  1143818592 :   b->names = decl;
     397                 :             : 
     398                 :             :   /* If appropriate, add decl to separate list of statics.  We include
     399                 :             :      extern variables because they might turn out to be static later.
     400                 :             :      It's OK for this list to contain a few false positives.  */
     401                 :  1143818592 :   if (b->kind == sk_namespace
     402                 :  1143818592 :       && ((VAR_P (decl) && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
     403                 :   348503093 :           || (TREE_CODE (decl) == FUNCTION_DECL
     404                 :   291805530 :               && (!TREE_PUBLIC (decl)
     405                 :   291289044 :                   || decl_internal_context_p (decl)
     406                 :   291287893 :                   || DECL_DECLARED_INLINE_P (decl)))))
     407                 :    13416786 :     vec_safe_push (static_decls, decl);
     408                 :  1143818592 : }
     409                 :             : 
     410                 :             : /* Find the binding for NAME in the local binding level B.  */
     411                 :             : 
     412                 :             : static cxx_binding *
     413                 :   767987229 : find_local_binding (cp_binding_level *b, tree name)
     414                 :             : {
     415                 :   767987229 :   if (cxx_binding *binding = IDENTIFIER_BINDING (name))
     416                 :           0 :     for (;; b = b->level_chain)
     417                 :             :       {
     418                 :     2212670 :         if (binding->scope == b)
     419                 :             :           return binding;
     420                 :             : 
     421                 :             :         /* Cleanup contours are transparent to the language.  */
     422                 :     2209215 :         if (b->kind != sk_cleanup)
     423                 :             :           break;
     424                 :             :       }
     425                 :             :   return NULL;
     426                 :             : }
     427                 :             : 
     428                 :             : class name_lookup
     429                 :             : {
     430                 :             : public:
     431                 :             :   typedef std::pair<tree, tree> using_pair;
     432                 :             :   typedef auto_vec<using_pair, 16> using_queue;
     433                 :             : 
     434                 :             : public:
     435                 :             :   tree name;    /* The identifier being looked for.  */
     436                 :             : 
     437                 :             :   /* Usually we just add things to the VALUE binding, but we record
     438                 :             :      (hidden) IMPLICIT_TYPEDEFs on the type binding, which is used for
     439                 :             :      using-decl resolution.  */
     440                 :             :   tree value;   /* A (possibly ambiguous) set of things found.  */
     441                 :             :   tree type;    /* A type that has been found.  */
     442                 :             : 
     443                 :             :   LOOK_want want;  /* What kind of entity we want.  */
     444                 :             : 
     445                 :             :   bool deduping; /* Full deduping is needed because using declarations
     446                 :             :                     are in play.  */
     447                 :             :   vec<tree, va_heap, vl_embed> *scopes;
     448                 :             :   name_lookup *previous; /* Previously active lookup.  */
     449                 :             : 
     450                 :             : protected:
     451                 :             :   /* Marked scope stack for outermost name lookup.  */
     452                 :             :   static vec<tree, va_heap, vl_embed> *shared_scopes;
     453                 :             :   /* Currently active lookup.  */
     454                 :             :   static name_lookup *active;
     455                 :             : 
     456                 :             : public:
     457                 :  1377272510 :   name_lookup (tree n, LOOK_want w = LOOK_want::NORMAL)
     458                 :  1377272510 :   : name (n), value (NULL_TREE), type (NULL_TREE),
     459                 :  1377272510 :     want (w),
     460                 :  1377272510 :     deduping (false), scopes (NULL), previous (NULL)
     461                 :             :   {
     462                 :  1377272510 :     preserve_state ();
     463                 :             :   }
     464                 :  1377272510 :   ~name_lookup ()
     465                 :             :   {
     466                 :  1377272510 :     gcc_checking_assert (!deduping);
     467                 :  1377272510 :     restore_state ();
     468                 :  1377272510 :   }
     469                 :             : 
     470                 :             : private: /* Uncopyable, unmovable, unassignable. I am a rock. */
     471                 :             :   name_lookup (const name_lookup &);
     472                 :             :   name_lookup &operator= (const name_lookup &);
     473                 :             : 
     474                 :             :  public:
     475                 :             :   /* Turn on or off deduping mode.  */
     476                 :  1409447238 :   void dedup (bool state)
     477                 :             :   {
     478                 :  1409447238 :     if (deduping != state)
     479                 :             :       {
     480                 :    87779556 :         deduping = state;
     481                 :    87779556 :         lookup_mark (value, state);
     482                 :             :       }
     483                 :  1409447238 :   }
     484                 :             : 
     485                 :             : protected:
     486                 : 15781656368 :   static bool seen_p (tree scope)
     487                 :             :   {
     488                 : 15781656368 :     return LOOKUP_SEEN_P (scope);
     489                 :             :   }
     490                 :    20029830 :   static bool found_p (tree scope)
     491                 :             :   {
     492                 :    20029830 :     return LOOKUP_FOUND_P (scope);
     493                 :             :   }
     494                 :             :   
     495                 :             :   void mark_seen (tree scope); /* Mark and add to scope vector. */
     496                 :   301915786 :   static void mark_found (tree scope)
     497                 :             :   {
     498                 :   301915786 :     gcc_checking_assert (seen_p (scope));
     499                 :   301915786 :     LOOKUP_FOUND_P (scope) = true;
     500                 :   301915786 :   }
     501                 :  7674381701 :   bool see_and_mark (tree scope)
     502                 :             :   {
     503                 :  7674381701 :     bool ret = seen_p (scope);
     504                 :  7674381701 :     if (!ret)
     505                 :  1485495924 :       mark_seen (scope);
     506                 :  7526511577 :     return ret;
     507                 :             :   }
     508                 :             :   bool find_and_mark (tree scope);
     509                 :             : 
     510                 :             : private:
     511                 :             :   void preserve_state ();
     512                 :             :   void restore_state ();
     513                 :             : 
     514                 :             : public:
     515                 :             :   static tree ambiguous (tree thing, tree current);
     516                 :             :   void add_value (tree new_val);
     517                 :             : private:
     518                 :             :   void add_overload (tree fns);
     519                 :             :   void add_type (tree new_type);
     520                 :             :   bool process_binding (tree val_bind, tree type_bind);
     521                 :             :   unsigned process_module_binding (tree val_bind, tree type_bind, unsigned);
     522                 :             :   /* Look in only namespace.  */
     523                 :             :   bool search_namespace_only (tree scope);
     524                 :             :   /* Look in namespace and its (recursive) inlines. Ignore using
     525                 :             :      directives.  Return true if something found (inc dups). */
     526                 :             :   bool search_namespace (tree scope);
     527                 :             :   /* Look in the using directives of namespace + inlines using
     528                 :             :      qualified lookup rules.  */
     529                 :             :   bool search_usings (tree scope);
     530                 :             : 
     531                 :             : private:
     532                 :             :   void queue_namespace (using_queue& queue, int depth, tree scope);
     533                 :             :   void queue_usings (using_queue& queue, int depth, vec<tree, va_gc> *usings);
     534                 :             : 
     535                 :             : private:
     536                 :             :   void add_fns (tree);
     537                 :             : 
     538                 :             :  private:
     539                 :             :   void adl_expr (tree);
     540                 :             :   void adl_type (tree);
     541                 :             :   void adl_template_arg (tree);
     542                 :             :   void adl_class (tree);
     543                 :             :   void adl_enum (tree);
     544                 :             :   void adl_bases (tree);
     545                 :             :   void adl_class_only (tree);
     546                 :             :   void adl_namespace (tree);
     547                 :             :   void adl_class_fns (tree);
     548                 :             :   void adl_namespace_fns (tree, bitmap);
     549                 :             : 
     550                 :             : public:
     551                 :             :   /* Search namespace + inlines + maybe usings as qualified lookup.  */
     552                 :             :   bool search_qualified (tree scope, bool usings = true);
     553                 :             : 
     554                 :             :   /* Search namespace + inlines + usings as unqualified lookup.  */
     555                 :             :   bool search_unqualified (tree scope, cp_binding_level *);
     556                 :             : 
     557                 :             :   /* ADL lookup of ARGS.  */
     558                 :             :   tree search_adl (tree fns, vec<tree, va_gc> *args);
     559                 :             : };
     560                 :             : 
     561                 :             : /* Scope stack shared by all outermost lookups.  This avoids us
     562                 :             :    allocating and freeing on every single lookup.  */
     563                 :             : vec<tree, va_heap, vl_embed> *name_lookup::shared_scopes;
     564                 :             : 
     565                 :             : /* Currently active lookup.  */
     566                 :             : name_lookup *name_lookup::active;
     567                 :             : 
     568                 :             : /* Name lookup is recursive, becase ADL can cause template
     569                 :             :    instatiation.  This is of course a rare event, so we optimize for
     570                 :             :    it not happening.  When we discover an active name-lookup, which
     571                 :             :    must be an ADL lookup,  we need to unmark the marked scopes and also
     572                 :             :    unmark the lookup we might have been accumulating.  */
     573                 :             : 
     574                 :             : void
     575                 :  1377272510 : name_lookup::preserve_state ()
     576                 :             : {
     577                 :  1377272510 :   previous = active;
     578                 :  1377272510 :   if (previous)
     579                 :             :     {
     580                 :        8897 :       unsigned length = vec_safe_length (previous->scopes);
     581                 :        8897 :       vec_safe_reserve (previous->scopes, length * 2);
     582                 :       82679 :       for (unsigned ix = length; ix--;)
     583                 :             :         {
     584                 :       73782 :           tree decl = (*previous->scopes)[ix];
     585                 :             : 
     586                 :       73782 :           gcc_checking_assert (LOOKUP_SEEN_P (decl));
     587                 :       73782 :           LOOKUP_SEEN_P (decl) = false;
     588                 :             : 
     589                 :             :           /* Preserve the FOUND_P state on the interrupted lookup's
     590                 :             :              stack.  */
     591                 :       73782 :           if (LOOKUP_FOUND_P (decl))
     592                 :             :             {
     593                 :        8870 :               LOOKUP_FOUND_P (decl) = false;
     594                 :        8870 :               previous->scopes->quick_push (decl);
     595                 :             :             }
     596                 :             :         }
     597                 :             : 
     598                 :             :       /* Unmark the outer partial lookup.  */
     599                 :        8897 :       if (previous->deduping)
     600                 :           0 :         lookup_mark (previous->value, false);
     601                 :             :     }
     602                 :             :   else
     603                 :  1377263613 :     scopes = shared_scopes;
     604                 :  1377272510 :   active = this;
     605                 :  1377272510 : }
     606                 :             : 
     607                 :             : /* Restore the marking state of a lookup we interrupted.  */
     608                 :             : 
     609                 :             : void
     610                 :  1377272510 : name_lookup::restore_state ()
     611                 :             : {
     612                 :  1377272510 :   gcc_checking_assert (!deduping);
     613                 :             : 
     614                 :             :   /* Unmark and empty this lookup's scope stack.  */
     615                 : 10281056597 :   for (unsigned ix = vec_safe_length (scopes); ix--;)
     616                 :             :     {
     617                 :  7526511577 :       tree decl = scopes->pop ();
     618                 :  7526511577 :       gcc_checking_assert (LOOKUP_SEEN_P (decl));
     619                 :  7526511577 :       LOOKUP_SEEN_P (decl) = false;
     620                 :  7526511577 :       LOOKUP_FOUND_P (decl) = false;
     621                 :             :     }
     622                 :             : 
     623                 :  1377272510 :   active = previous;
     624                 :  1377272510 :   if (previous)
     625                 :             :     {
     626                 :        8897 :       free (scopes);
     627                 :             : 
     628                 :        8897 :       unsigned length = vec_safe_length (previous->scopes);
     629                 :       82679 :       for (unsigned ix = 0; ix != length; ix++)
     630                 :             :         {
     631                 :       81993 :           tree decl = (*previous->scopes)[ix];
     632                 :       81993 :           if (LOOKUP_SEEN_P (decl))
     633                 :             :             {
     634                 :             :               /* The remainder of the scope stack must be recording
     635                 :             :                  FOUND_P decls, which we want to pop off.  */
     636                 :        8870 :               do
     637                 :             :                 {
     638                 :        8870 :                   tree decl = previous->scopes->pop ();
     639                 :        8870 :                   gcc_checking_assert (LOOKUP_SEEN_P (decl)
     640                 :             :                                        && !LOOKUP_FOUND_P (decl));
     641                 :        8870 :                   LOOKUP_FOUND_P (decl) = true;
     642                 :             :                 }
     643                 :        8870 :               while (++ix != length);
     644                 :             :               break;
     645                 :             :             }
     646                 :             : 
     647                 :       73782 :           gcc_checking_assert (!LOOKUP_FOUND_P (decl));
     648                 :       73782 :           LOOKUP_SEEN_P (decl) = true;
     649                 :             :         }
     650                 :             : 
     651                 :             :       /* Remark the outer partial lookup.  */
     652                 :        8897 :       if (previous->deduping)
     653                 :           0 :         lookup_mark (previous->value, true);
     654                 :             :     }
     655                 :             :   else
     656                 :  1377263613 :     shared_scopes = scopes;
     657                 :  1377272510 : }
     658                 :             : 
     659                 :             : void
     660                 :  7526511577 : name_lookup::mark_seen (tree scope)
     661                 :             : {
     662                 :  7526511577 :   gcc_checking_assert (!seen_p (scope));
     663                 :  7526511577 :   LOOKUP_SEEN_P (scope) = true;
     664                 :  7526511577 :   vec_safe_push (scopes, scope);
     665                 :  7526511577 : }
     666                 :             : 
     667                 :             : bool
     668                 :           0 : name_lookup::find_and_mark (tree scope)
     669                 :             : {
     670                 :           0 :   bool result = LOOKUP_FOUND_P (scope);
     671                 :           0 :   if (!result)
     672                 :             :     {
     673                 :           0 :       LOOKUP_FOUND_P (scope) = true;
     674                 :           0 :       if (!LOOKUP_SEEN_P (scope))
     675                 :           0 :         vec_safe_push (scopes, scope);
     676                 :             :     }
     677                 :             : 
     678                 :           0 :   return result;
     679                 :             : }
     680                 :             : 
     681                 :             : /* THING and CURRENT are ambiguous, concatenate them.  */
     682                 :             : 
     683                 :             : tree
     684                 :         443 : name_lookup::ambiguous (tree thing, tree current)
     685                 :             : {
     686                 :         443 :   if (TREE_CODE (current) != TREE_LIST)
     687                 :             :     {
     688                 :         342 :       current = build_tree_list (NULL_TREE, current);
     689                 :         342 :       TREE_TYPE (current) = error_mark_node;
     690                 :             :     }
     691                 :         443 :   current = tree_cons (NULL_TREE, thing, current);
     692                 :         443 :   TREE_TYPE (current) = error_mark_node;
     693                 :             : 
     694                 :         443 :   return current;
     695                 :             : }
     696                 :             : 
     697                 :             : /* FNS is a new overload set to add to the exising set.  */
     698                 :             : 
     699                 :             : void
     700                 :   468945629 : name_lookup::add_overload (tree fns)
     701                 :             : {
     702                 :   468945629 :   if (!deduping && TREE_CODE (fns) == OVERLOAD)
     703                 :             :     {
     704                 :   337140916 :       tree probe = fns;
     705                 :   337140916 :       if (!bool (want & LOOK_want::HIDDEN_FRIEND))
     706                 :   337075580 :         probe = ovl_skip_hidden (probe);
     707                 :   337140916 :       if (probe && TREE_CODE (probe) == OVERLOAD
     708                 :   674281832 :           && OVL_DEDUP_P (probe))
     709                 :             :         /* We're about to add something found by multiple paths, so need to
     710                 :             :            engage deduping mode.  */
     711                 :    29836754 :         dedup (true);
     712                 :             :     }
     713                 :             : 
     714                 :   468945629 :   value = lookup_maybe_add (fns, value, deduping);
     715                 :   468945629 : }
     716                 :             : 
     717                 :             : /* Add a NEW_VAL, a found value binding into the current value binding.  */
     718                 :             : 
     719                 :             : void
     720                 :  1103548713 : name_lookup::add_value (tree new_val)
     721                 :             : {
     722                 :  1103548713 :   if (OVL_P (new_val) && (!value || OVL_P (value)))
     723                 :   449136191 :     add_overload (new_val);
     724                 :   654412522 :   else if (!value)
     725                 :   654197868 :     value = new_val;
     726                 :      214654 :   else if (value == new_val)
     727                 :             :     ;
     728                 :       12686 :   else if ((TREE_CODE (value) == TYPE_DECL
     729                 :       12522 :             && TREE_CODE (new_val) == TYPE_DECL
     730                 :       25208 :             && same_type_p (TREE_TYPE (value), TREE_TYPE (new_val))))
     731                 :             :     /* Typedefs to the same type. */;
     732                 :         276 :   else if (TREE_CODE (value) == NAMESPACE_DECL
     733                 :          69 :            && TREE_CODE (new_val) == NAMESPACE_DECL
     734                 :         345 :            && ORIGINAL_NAMESPACE (value) == ORIGINAL_NAMESPACE (new_val))
     735                 :             :     /* Namespace (possibly aliased) to the same namespace.  Locate
     736                 :             :        the namespace*/
     737                 :          32 :     value = ORIGINAL_NAMESPACE (value);
     738                 :             :   else
     739                 :             :     {
     740                 :             :       /* Disengage deduping mode.  */
     741                 :         244 :       dedup (false);
     742                 :         244 :       value = ambiguous (new_val, value);
     743                 :             :     }
     744                 :  1103548713 : }
     745                 :             : 
     746                 :             : /* Add a NEW_TYPE, a found type binding into the current type binding.  */
     747                 :             : 
     748                 :             : void
     749                 :     3277100 : name_lookup::add_type (tree new_type)
     750                 :             : {
     751                 :     3277100 :   if (!type)
     752                 :     3277096 :     type = new_type;
     753                 :           4 :   else if (TREE_CODE (type) == TREE_LIST
     754                 :           4 :            || !same_type_p (TREE_TYPE (type), TREE_TYPE (new_type)))
     755                 :           4 :     type = ambiguous (new_type, type);
     756                 :     3277100 : }
     757                 :             : 
     758                 :             : /* Process a found binding containing NEW_VAL and NEW_TYPE.  Returns
     759                 :             :    true if we actually found something noteworthy.  Hiddenness has
     760                 :             :    already been handled in the caller.  */
     761                 :             : 
     762                 :             : bool
     763                 :  1113645200 : name_lookup::process_binding (tree new_val, tree new_type)
     764                 :             : {
     765                 :             :   /* Did we really see a type? */
     766                 :  1113645200 :   if (new_type
     767                 :  1113645200 :       && (want & LOOK_want::TYPE_NAMESPACE) == LOOK_want::NAMESPACE)
     768                 :             :     new_type = NULL_TREE;
     769                 :             : 
     770                 :             :   /* Do we really see a value? */
     771                 :  1113645200 :   if (new_val)
     772                 :  1103642531 :     switch (TREE_CODE (new_val))
     773                 :             :       {
     774                 :   193201143 :       case TEMPLATE_DECL:
     775                 :             :         /* If we expect types or namespaces, and not templates,
     776                 :             :            or this is not a template class.  */
     777                 :   193201143 :         if (bool (want & LOOK_want::TYPE_NAMESPACE)
     778                 :   193201143 :             && !DECL_TYPE_TEMPLATE_P (new_val))
     779                 :             :           new_val = NULL_TREE;
     780                 :             :         break;
     781                 :   220304714 :       case TYPE_DECL:
     782                 :   220304714 :         if ((want & LOOK_want::TYPE_NAMESPACE) == LOOK_want::NAMESPACE
     783                 :   220304714 :             || (new_type && bool (want & LOOK_want::TYPE)))
     784                 :             :           new_val = NULL_TREE;
     785                 :             :         break;
     786                 :   188470393 :       case NAMESPACE_DECL:
     787                 :   188470393 :         if ((want & LOOK_want::TYPE_NAMESPACE) == LOOK_want::TYPE)
     788                 :             :           new_val = NULL_TREE;
     789                 :             :         break;
     790                 :   501666281 :       default:
     791                 :   501666281 :         if (bool (want & LOOK_want::TYPE_NAMESPACE))
     792                 :             :           new_val = NULL_TREE;
     793                 :             :       }
     794                 :             : 
     795                 :             :   if (!new_val)
     796                 :             :     {
     797                 :    10138335 :       new_val = new_type;
     798                 :    10138335 :       new_type = NULL_TREE;
     799                 :             :     }
     800                 :             : 
     801                 :             :   /* Merge into the lookup  */
     802                 :    10138335 :   if (new_val)
     803                 :  1103548713 :     add_value (new_val);
     804                 :  1113645200 :   if (new_type)
     805                 :     3277100 :     add_type (new_type);
     806                 :             : 
     807                 :  1113645200 :   return new_val != NULL_TREE;
     808                 :             : }
     809                 :             : 
     810                 :             : /* If we're importing a module containing this binding, add it to the
     811                 :             :    lookup set.  The trickiness is with namespaces, we only want to
     812                 :             :    find it once.  */
     813                 :             : 
     814                 :             : unsigned
     815                 :       49734 : name_lookup::process_module_binding (tree new_val, tree new_type,
     816                 :             :                                      unsigned marker)
     817                 :             : {
     818                 :             :   /* Optimize for (re-)finding a public namespace.  We only need to
     819                 :             :      look once.  */
     820                 :       49734 :   if (new_val && !new_type
     821                 :             :       && TREE_CODE (new_val) == NAMESPACE_DECL
     822                 :       47624 :       && TREE_PUBLIC (new_val)
     823                 :       63178 :       && !DECL_NAMESPACE_ALIAS (new_val))
     824                 :             :     {
     825                 :       13444 :       if (marker & 2)
     826                 :             :         return marker;
     827                 :        6948 :       marker |= 2;
     828                 :             :     }
     829                 :             : 
     830                 :       43238 :   if (new_type || new_val)
     831                 :       41181 :     marker |= process_binding (new_val, new_type);
     832                 :             : 
     833                 :             :   return marker;
     834                 :             : }
     835                 :             : 
     836                 :             : /* Look in exactly namespace SCOPE.  */
     837                 :             : 
     838                 :             : bool
     839                 :  7401855712 : name_lookup::search_namespace_only (tree scope)
     840                 :             : {
     841                 :  7401855712 :   bool found = false;
     842                 :  7401855712 :   if (tree *binding = find_namespace_slot (scope, name))
     843                 :             :     {
     844                 :  1113634356 :       tree val = *binding;
     845                 :  1113634356 :       if (TREE_CODE (val) == BINDING_VECTOR)
     846                 :             :         {
     847                 :             :           /* I presume the binding list is going to be sparser than
     848                 :             :              the import bitmap.  Hence iterate over the former
     849                 :             :              checking for bits set in the bitmap.  */
     850                 :       30337 :           bitmap imports = get_import_bitmap ();
     851                 :       30337 :           binding_cluster *cluster = BINDING_VECTOR_CLUSTER_BASE (val);
     852                 :       30337 :           int marker = 0;
     853                 :       30337 :           int dup_detect = 0;
     854                 :             : 
     855                 :       30337 :           if (tree bind = cluster->slots[BINDING_SLOT_CURRENT])
     856                 :             :             {
     857                 :       19844 :               if (!deduping)
     858                 :             :                 {
     859                 :       18392 :                   if (named_module_purview_p ())
     860                 :             :                     {
     861                 :         243 :                       dup_detect |= 2;
     862                 :             : 
     863                 :         243 :                       if (STAT_HACK_P (bind) && MODULE_BINDING_GLOBAL_P (bind))
     864                 :             :                         dup_detect |= 1;
     865                 :             :                     }
     866                 :             :                   else
     867                 :             :                     dup_detect |= 1;
     868                 :             :                 }
     869                 :       19844 :               tree type = NULL_TREE;
     870                 :       19844 :               tree value = bind;
     871                 :             : 
     872                 :       19844 :               if (STAT_HACK_P (bind))
     873                 :             :                 {
     874                 :       12666 :                   type = STAT_TYPE (bind);
     875                 :       12666 :                   value = STAT_DECL (bind);
     876                 :             : 
     877                 :       12666 :                   if (!bool (want & LOOK_want::HIDDEN_FRIEND))
     878                 :             :                     {
     879                 :       12628 :                       if (STAT_TYPE_HIDDEN_P (bind))
     880                 :           0 :                         type = NULL_TREE;
     881                 :       12628 :                       if (STAT_DECL_HIDDEN_P (bind))
     882                 :             :                         value = NULL_TREE;
     883                 :             :                       else
     884                 :       12628 :                         value = ovl_skip_hidden (value);
     885                 :             :                     }
     886                 :             :                 }
     887                 :        7178 :               else if (!bool (want & LOOK_want::HIDDEN_FRIEND))
     888                 :        7178 :                 value = ovl_skip_hidden (value);
     889                 :             : 
     890                 :       19844 :               marker = process_module_binding (value, type, marker);
     891                 :             :             }
     892                 :             : 
     893                 :             :           /* Scan the imported bindings.  */
     894                 :       30337 :           unsigned ix = BINDING_VECTOR_NUM_CLUSTERS (val);
     895                 :       30337 :           if (BINDING_VECTOR_SLOTS_PER_CLUSTER == BINDING_SLOTS_FIXED)
     896                 :             :             {
     897                 :       30337 :               ix--;
     898                 :       30337 :               cluster++;
     899                 :             :             }
     900                 :             : 
     901                 :             :           /* Do this in forward order, so we load modules in an order
     902                 :             :              the user expects.  */
     903                 :       60173 :           for (; ix--; cluster++)
     904                 :       89508 :             for (unsigned jx = 0; jx != BINDING_VECTOR_SLOTS_PER_CLUSTER; jx++)
     905                 :             :               {
     906                 :             :                 /* Are we importing this module?  */
     907                 :       59672 :                 if (unsigned base = cluster->indices[jx].base)
     908                 :       30276 :                   if (unsigned span = cluster->indices[jx].span)
     909                 :       30279 :                     do
     910                 :       30279 :                       if (bitmap_bit_p (imports, base))
     911                 :       29890 :                         goto found;
     912                 :         389 :                     while (++base, --span);
     913                 :       29782 :                 continue;
     914                 :             : 
     915                 :       29890 :               found:;
     916                 :             :                 /* Is it loaded?  */
     917                 :       29890 :                 if (cluster->slots[jx].is_lazy ())
     918                 :             :                   {
     919                 :        1750 :                     gcc_assert (cluster->indices[jx].span == 1);
     920                 :        1750 :                     lazy_load_binding (cluster->indices[jx].base,
     921                 :             :                                        scope, name, &cluster->slots[jx]);
     922                 :             :                   }
     923                 :       29890 :                 tree bind = cluster->slots[jx];
     924                 :       29890 :                 if (!bind)
     925                 :             :                   /* Load errors could mean there's nothing here.  */
     926                 :           0 :                   continue;
     927                 :             : 
     928                 :             :                 /* Extract what we can see from here.  If there's no
     929                 :             :                    stat_hack, then everything was exported.  */
     930                 :       29890 :                 tree type = NULL_TREE;
     931                 :             : 
     932                 :             : 
     933                 :             :                 /* If STAT_HACK_P is false, everything is visible, and
     934                 :             :                    there's no duplication possibilities.  */
     935                 :       29890 :                 if (STAT_HACK_P (bind))
     936                 :             :                   {
     937                 :       17618 :                     if (!deduping)
     938                 :             :                       {
     939                 :             :                         /* Do we need to engage deduplication?  */
     940                 :       16157 :                         int dup = 0;
     941                 :       16157 :                         if (MODULE_BINDING_GLOBAL_P (bind))
     942                 :             :                           dup = 1;
     943                 :        1654 :                         else if (MODULE_BINDING_PARTITION_P (bind))
     944                 :        1201 :                           dup = 2;
     945                 :       16157 :                         if (unsigned hit = dup_detect & dup)
     946                 :             :                           {
     947                 :       10865 :                             if ((hit & 1 && BINDING_VECTOR_GLOBAL_DUPS_P (val))
     948                 :       11561 :                                 || (hit & 2
     949                 :         212 :                                     && BINDING_VECTOR_PARTITION_DUPS_P (val)))
     950                 :       10503 :                               dedup (true);
     951                 :             :                           }
     952                 :       16157 :                         dup_detect |= dup;
     953                 :             :                       }
     954                 :             : 
     955                 :       17618 :                     if (STAT_TYPE_VISIBLE_P (bind))
     956                 :        1232 :                       type = STAT_TYPE (bind);
     957                 :       17618 :                     bind = STAT_VISIBLE (bind);
     958                 :             :                   }
     959                 :             : 
     960                 :             :                 /* And process it.  */
     961                 :       29890 :                 marker = process_module_binding (bind, type, marker);
     962                 :       29782 :               }
     963                 :       30337 :           found |= marker & 1;
     964                 :             :         }
     965                 :             :       else
     966                 :             :         {
     967                 :             :           /* Only a current module binding, visible from the current module.  */
     968                 :  1113604019 :           tree bind = *binding;
     969                 :  1113604019 :           tree value = bind, type = NULL_TREE;
     970                 :             : 
     971                 :  1113604019 :           if (STAT_HACK_P (bind))
     972                 :             :             {
     973                 :     3319645 :               type = STAT_TYPE (bind);
     974                 :     3319645 :               value = STAT_DECL (bind);
     975                 :             : 
     976                 :     3319645 :               if (!bool (want & LOOK_want::HIDDEN_FRIEND))
     977                 :             :                 {
     978                 :     3319426 :                   if (STAT_TYPE_HIDDEN_P (bind))
     979                 :           4 :                     type = NULL_TREE;
     980                 :     3319426 :                   if (STAT_DECL_HIDDEN_P (bind))
     981                 :             :                     value = NULL_TREE;
     982                 :             :                   else
     983                 :     3318899 :                     value = ovl_skip_hidden (value);
     984                 :             :                 }
     985                 :             :             }
     986                 :  1110284374 :           else if (!bool (want & LOOK_want::HIDDEN_FRIEND))
     987                 :  1109617728 :             value = ovl_skip_hidden (value);
     988                 :             : 
     989                 :  1113604019 :           found |= process_binding (value, type);
     990                 :             :         }
     991                 :             :     }
     992                 :             : 
     993                 :  7401855712 :   return found;
     994                 :             : }
     995                 :             : 
     996                 :             : /* Conditionally look in namespace SCOPE and inline children.  */
     997                 :             : 
     998                 :             : bool
     999                 :  1366069936 : name_lookup::search_namespace (tree scope)
    1000                 :             : {
    1001                 :  1366069936 :   if (see_and_mark (scope))
    1002                 :             :     /* We've visited this scope before.  Return what we found then.  */
    1003                 :           0 :     return found_p (scope);
    1004                 :             : 
    1005                 :             :   /* Look in exactly namespace. */
    1006                 :  1366069936 :   bool found = search_namespace_only (scope);
    1007                 :             : 
    1008                 :             :   /* Don't look into inline children, if we're looking for an
    1009                 :             :      anonymous name -- it must be in the current scope, if anywhere.  */
    1010                 :  1366069936 :   if (name)
    1011                 :             :     /* Recursively look in its inline children.  */
    1012                 :  1366068089 :     if (vec<tree, va_gc> *inlinees = DECL_NAMESPACE_INLINEES (scope))
    1013                 :  1481335680 :       for (unsigned ix = inlinees->length (); ix--;)
    1014                 :  1087222632 :         found |= search_namespace ((*inlinees)[ix]);
    1015                 :             : 
    1016                 :  1366069936 :   if (found)
    1017                 :   286677705 :     mark_found (scope);
    1018                 :             : 
    1019                 :             :   return found;
    1020                 :             : }
    1021                 :             : 
    1022                 :             : /* Recursively follow using directives of SCOPE & its inline children.
    1023                 :             :    Such following is essentially a flood-fill algorithm.  */
    1024                 :             : 
    1025                 :             : bool
    1026                 :     1601268 : name_lookup::search_usings (tree scope)
    1027                 :             : {
    1028                 :             :   /* We do not check seen_p here, as that was already set during the
    1029                 :             :      namespace_only walk.  */
    1030                 :     1601268 :   if (found_p (scope))
    1031                 :             :     return true;
    1032                 :             : 
    1033                 :     1601268 :   bool found = false;
    1034                 :     1601268 :   if (vec<tree, va_gc> *usings = NAMESPACE_LEVEL (scope)->using_directives)
    1035                 :      384877 :     for (unsigned ix = usings->length (); ix--;)
    1036                 :      192637 :       found |= search_qualified ((*usings)[ix], true);
    1037                 :             : 
    1038                 :             :   /* Look in its inline children.  */
    1039                 :     1601268 :   if (vec<tree, va_gc> *inlinees = DECL_NAMESPACE_INLINEES (scope))
    1040                 :      739405 :     for (unsigned ix = inlinees->length (); ix--;)
    1041                 :      371028 :       found |= search_usings ((*inlinees)[ix]);
    1042                 :             : 
    1043                 :     1601268 :   if (found)
    1044                 :        1438 :     mark_found (scope);
    1045                 :             : 
    1046                 :             :   return found;
    1047                 :             : }
    1048                 :             : 
    1049                 :             : /* Qualified namespace lookup in SCOPE.
    1050                 :             :    1) Look in SCOPE (+inlines).  If found, we're done.
    1051                 :             :    2) Otherwise, if USINGS is true,
    1052                 :             :       recurse for every using directive of SCOPE (+inlines).
    1053                 :             : 
    1054                 :             :    Trickiness is (a) loops and (b) multiple paths to same namespace.
    1055                 :             :    In both cases we want to not repeat any lookups, and know whether
    1056                 :             :    to stop the caller's step #2.  Do this via the FOUND_P marker.  */
    1057                 :             : 
    1058                 :             : bool
    1059                 :   278847304 : name_lookup::search_qualified (tree scope, bool usings)
    1060                 :             : {
    1061                 :   278847304 :   bool found = false;
    1062                 :             : 
    1063                 :   278847304 :   if (seen_p (scope))
    1064                 :           0 :     found = found_p (scope);
    1065                 :             :   else 
    1066                 :             :     {
    1067                 :   278847304 :       found = search_namespace (scope);
    1068                 :   278847304 :       if (!found && usings)
    1069                 :     1230240 :         found = search_usings (scope);
    1070                 :             :     }
    1071                 :             : 
    1072                 :   278847304 :   dedup (false);
    1073                 :             : 
    1074                 :   278847304 :   return found;
    1075                 :             : }
    1076                 :             : 
    1077                 :             : /* Add SCOPE to the unqualified search queue, recursively add its
    1078                 :             :    inlines and those via using directives.  */
    1079                 :             : 
    1080                 :             : void
    1081                 :  6103742053 : name_lookup::queue_namespace (using_queue& queue, int depth, tree scope)
    1082                 :             : {
    1083                 :  6103742053 :   if (see_and_mark (scope))
    1084                 :  6103742053 :     return;
    1085                 :             : 
    1086                 :             :   /* Record it.  */
    1087                 :             :   tree common = scope;
    1088                 : 12233271344 :   while (SCOPE_DEPTH (common) > depth)
    1089                 :  6192255691 :     common = CP_DECL_CONTEXT (common);
    1090                 :  6041015653 :   queue.safe_push (using_pair (common, scope));
    1091                 :             : 
    1092                 :             :   /* Queue its inline children.  */
    1093                 :  6041015653 :   if (vec<tree, va_gc> *inlinees = DECL_NAMESPACE_INLINEES (scope))
    1094                 :  6025194651 :     for (unsigned ix = inlinees->length (); ix--;)
    1095                 :  4429185948 :       queue_namespace (queue, depth, (*inlinees)[ix]);
    1096                 :             : 
    1097                 :             :   /* Queue its using targets.  */
    1098                 :  6041015653 :   queue_usings (queue, depth, NAMESPACE_LEVEL (scope)->using_directives);
    1099                 :             : }
    1100                 :             : 
    1101                 :             : /* Add the namespaces in USINGS to the unqualified search queue.  */
    1102                 :             : 
    1103                 :             : void
    1104                 :  9408968384 : name_lookup::queue_usings (using_queue& queue, int depth, vec<tree, va_gc> *usings)
    1105                 :             : {
    1106                 :  9408968384 :   if (usings)
    1107                 :    32112956 :     for (unsigned ix = usings->length (); ix--;)
    1108                 :    16240819 :       queue_namespace (queue, depth, (*usings)[ix]);
    1109                 :  9408968384 : }
    1110                 :             : 
    1111                 :             : /* Unqualified namespace lookup in SCOPE.
    1112                 :             :    1) add scope+inlins to worklist.
    1113                 :             :    2) recursively add target of every using directive
    1114                 :             :    3) for each worklist item where SCOPE is common ancestor, search it
    1115                 :             :    4) if nothing find, scope=parent, goto 1.  */
    1116                 :             : 
    1117                 :             : bool
    1118                 :  1064926243 : name_lookup::search_unqualified (tree scope, cp_binding_level *level)
    1119                 :             : {
    1120                 :  1064926243 :   using_queue queue;
    1121                 :  1064926243 :   bool found = false;
    1122                 :             : 
    1123                 :             :   /* Queue local using-directives.  */
    1124                 :  4432878974 :   for (; level->kind != sk_namespace; level = level->level_chain)
    1125                 :  3367952731 :     queue_usings (queue, SCOPE_DEPTH (scope), level->using_directives);
    1126                 :             : 
    1127                 :  3317689171 :   for (; !found; scope = CP_DECL_CONTEXT (scope))
    1128                 :             :     {
    1129                 :  1658315286 :       gcc_assert (!DECL_NAMESPACE_ALIAS (scope));
    1130                 :  1658315286 :       int depth = SCOPE_DEPTH (scope);
    1131                 :             : 
    1132                 :             :       /* Queue namespaces reachable from SCOPE. */
    1133                 :  1658315286 :       queue_namespace (queue, depth, scope);
    1134                 :             : 
    1135                 :             :       /* Search every queued namespace where SCOPE is the common
    1136                 :             :          ancestor.  Adjust the others.  */
    1137                 :  1658315286 :       unsigned ix = 0;
    1138                 :  1669678660 :       do
    1139                 :             :         {
    1140                 :  1669678660 :           using_pair &pair = queue[ix];
    1141                 :  7718078749 :           while (pair.first == scope)
    1142                 :             :             {
    1143                 :  6035785776 :               found |= search_namespace_only (pair.second);
    1144                 :  6035785776 :               pair = queue.pop ();
    1145                 :  6035785776 :               if (ix == queue.length ())
    1146                 :  1657064347 :                 goto done;
    1147                 :             :             }
    1148                 :             :           /* The depth is the same as SCOPE, find the parent scope.  */
    1149                 :    12614313 :           if (SCOPE_DEPTH (pair.first) == depth)
    1150                 :    12609609 :             pair.first = CP_DECL_CONTEXT (pair.first);
    1151                 :    12614313 :           ix++;
    1152                 :             :         }
    1153                 :    25228626 :       while (ix < queue.length ());
    1154                 :     1250939 :     done:;
    1155                 :  1658315286 :       if (scope == global_namespace)
    1156                 :             :         break;
    1157                 :             : 
    1158                 :             :       /* If looking for hidden friends, we only look in the innermost
    1159                 :             :          namespace scope.  [namespace.memdef]/3 If a friend
    1160                 :             :          declaration in a non-local class first declares a class,
    1161                 :             :          function, class template or function template the friend is a
    1162                 :             :          member of the innermost enclosing namespace.  See also
    1163                 :             :          [basic.lookup.unqual]/7 */
    1164                 :  1126956909 :       if (bool (want & LOOK_want::HIDDEN_FRIEND))
    1165                 :             :         break;
    1166                 :             :     }
    1167                 :             : 
    1168                 :  1064926243 :   dedup (false);
    1169                 :             : 
    1170                 :  1064926243 :   return found;
    1171                 :  1064926243 : }
    1172                 :             : 
    1173                 :             : /* FNS is a value binding.  If it is a (set of overloaded) functions,
    1174                 :             :    add them into the current value.  */
    1175                 :             : 
    1176                 :             : void
    1177                 :    21455798 : name_lookup::add_fns (tree fns)
    1178                 :             : {
    1179                 :    21455798 :   if (!fns)
    1180                 :             :     return;
    1181                 :    19814384 :   else if (TREE_CODE (fns) == OVERLOAD)
    1182                 :             :     {
    1183                 :    12727817 :       if (TREE_TYPE (fns) != unknown_type_node)
    1184                 :       87109 :         fns = OVL_FUNCTION (fns);
    1185                 :             :     }
    1186                 :     7086567 :   else if (!DECL_DECLARES_FUNCTION_P (fns))
    1187                 :             :     return;
    1188                 :             : 
    1189                 :    19809438 :   add_overload (fns);
    1190                 :             : }
    1191                 :             : 
    1192                 :             : /* Add the overloaded fns of SCOPE.  */
    1193                 :             : 
    1194                 :             : void
    1195                 :    90048307 : name_lookup::adl_namespace_fns (tree scope, bitmap imports)
    1196                 :             : {
    1197                 :    90048307 :   if (tree *binding = find_namespace_slot (scope, name))
    1198                 :             :     {
    1199                 :    16476928 :       tree val = *binding;
    1200                 :    16476928 :       if (TREE_CODE (val) != BINDING_VECTOR)
    1201                 :    16466795 :         add_fns (ovl_skip_hidden (MAYBE_STAT_DECL (val)));
    1202                 :             :       else
    1203                 :             :         {
    1204                 :             :           /* I presume the binding list is going to be sparser than
    1205                 :             :              the import bitmap.  Hence iterate over the former
    1206                 :             :              checking for bits set in the bitmap.  */
    1207                 :       10133 :           binding_cluster *cluster = BINDING_VECTOR_CLUSTER_BASE (val);
    1208                 :       10133 :           int dup_detect = 0;
    1209                 :             : 
    1210                 :       10133 :           if (tree bind = cluster->slots[BINDING_SLOT_CURRENT])
    1211                 :             :             {
    1212                 :             :               /* The current TU's bindings must be visible, we don't
    1213                 :             :                  need to check the bitmaps.  */
    1214                 :             : 
    1215                 :        7470 :               if (!deduping)
    1216                 :             :                 {
    1217                 :        2461 :                   if (named_module_purview_p ())
    1218                 :             :                     {
    1219                 :           6 :                       dup_detect |= 2;
    1220                 :             : 
    1221                 :           6 :                       if (STAT_HACK_P (bind) && MODULE_BINDING_GLOBAL_P (bind))
    1222                 :             :                         dup_detect |= 1;
    1223                 :             :                     }
    1224                 :             :                   else
    1225                 :             :                     dup_detect |= 1;
    1226                 :             :                 }
    1227                 :             : 
    1228                 :        7470 :               add_fns (ovl_skip_hidden (MAYBE_STAT_DECL (bind)));
    1229                 :             :             }
    1230                 :             : 
    1231                 :             :           /* Scan the imported bindings.  */
    1232                 :       10133 :           unsigned ix = BINDING_VECTOR_NUM_CLUSTERS (val);
    1233                 :       10133 :           if (BINDING_VECTOR_SLOTS_PER_CLUSTER == BINDING_SLOTS_FIXED)
    1234                 :             :             {
    1235                 :       10133 :               ix--;
    1236                 :       10133 :               cluster++;
    1237                 :             :             }
    1238                 :             : 
    1239                 :             :           /* Do this in forward order, so we load modules in an order
    1240                 :             :              the user expects.  */
    1241                 :       19766 :           for (; ix--; cluster++)
    1242                 :       28899 :             for (unsigned jx = 0; jx != BINDING_VECTOR_SLOTS_PER_CLUSTER; jx++)
    1243                 :             :               {
    1244                 :             :                 /* Functions are never on merged slots.  */
    1245                 :       19266 :                 if (!cluster->indices[jx].base
    1246                 :        9642 :                     || cluster->indices[jx].span != 1)
    1247                 :        9624 :                   continue;
    1248                 :             : 
    1249                 :             :                 /* Is this slot visible?  */
    1250                 :        9642 :                 if (!bitmap_bit_p (imports, cluster->indices[jx].base))
    1251                 :           0 :                   continue;
    1252                 :             : 
    1253                 :             :                 /* Is it loaded.  */
    1254                 :        9642 :                 if (cluster->slots[jx].is_lazy ())
    1255                 :          12 :                   lazy_load_binding (cluster->indices[jx].base,
    1256                 :             :                                      scope, name, &cluster->slots[jx]);
    1257                 :             : 
    1258                 :        9642 :                 tree bind = cluster->slots[jx];
    1259                 :        9642 :                 if (!bind)
    1260                 :             :                   /* Load errors could mean there's nothing here.  */
    1261                 :           0 :                   continue;
    1262                 :             : 
    1263                 :        9642 :                 if (STAT_HACK_P (bind))
    1264                 :             :                   {
    1265                 :        9588 :                     if (!deduping)
    1266                 :             :                       {
    1267                 :             :                         /* Do we need to engage deduplication?  */
    1268                 :        3737 :                         int dup = 0;
    1269                 :        3737 :                         if (MODULE_BINDING_GLOBAL_P (bind))
    1270                 :             :                           dup = 1;
    1271                 :          21 :                         else if (MODULE_BINDING_PARTITION_P (bind))
    1272                 :          12 :                           dup = 2;
    1273                 :        3737 :                         if (unsigned hit = dup_detect & dup)
    1274                 :        2177 :                           if ((hit & 1 && BINDING_VECTOR_GLOBAL_DUPS_P (val))
    1275                 :        2247 :                               || (hit & 2
    1276                 :           6 :                                   && BINDING_VECTOR_PARTITION_DUPS_P (val)))
    1277                 :        2113 :                             dedup (true);
    1278                 :        3737 :                         dup_detect |= dup;
    1279                 :             :                       }
    1280                 :             : 
    1281                 :        9588 :                     bind = STAT_VISIBLE (bind);
    1282                 :             :                   }
    1283                 :             : 
    1284                 :        9642 :                 add_fns (bind);
    1285                 :             :               }
    1286                 :             :         }
    1287                 :             :     }
    1288                 :    90048307 : }
    1289                 :             : 
    1290                 :             : /* Add the hidden friends of SCOPE.  */
    1291                 :             : 
    1292                 :             : void
    1293                 :    20843947 : name_lookup::adl_class_fns (tree type)
    1294                 :             : {
    1295                 :             :   /* Add friends.  */
    1296                 :    20843947 :   for (tree list = DECL_FRIENDLIST (TYPE_MAIN_DECL (type));
    1297                 :    49795567 :        list; list = TREE_CHAIN (list))
    1298                 :    28951620 :     if (name == FRIEND_NAME (list))
    1299                 :             :       {
    1300                 :     2748703 :         tree context = NULL_TREE; /* Lazily computed.  */
    1301                 :     7744536 :         for (tree friends = FRIEND_DECLS (list); friends;
    1302                 :     4995833 :              friends = TREE_CHAIN (friends))
    1303                 :             :           {
    1304                 :     4995833 :             tree fn = TREE_VALUE (friends);
    1305                 :             : 
    1306                 :             :             /* Only interested in global functions with potentially hidden
    1307                 :             :                (i.e. unqualified) declarations.  */
    1308                 :     4995833 :             if (!context)
    1309                 :     2748703 :               context = decl_namespace_context (type);
    1310                 :     4995833 :             if (CP_DECL_CONTEXT (fn) != context)
    1311                 :       21011 :               continue;
    1312                 :             : 
    1313                 :     4974822 :             dedup (true);
    1314                 :             : 
    1315                 :             :             /* Template specializations are never found by name lookup.
    1316                 :             :                (Templates themselves can be found, but not template
    1317                 :             :                specializations.)  */
    1318                 :     4974822 :             if (TREE_CODE (fn) == FUNCTION_DECL && DECL_USE_TEMPLATE (fn))
    1319                 :        2931 :               continue;
    1320                 :             : 
    1321                 :     4971891 :             add_fns (fn);
    1322                 :             :           }
    1323                 :             :       }
    1324                 :    20843947 : }
    1325                 :             : 
    1326                 :             : /* Find the containing non-inlined namespace, add it and all its
    1327                 :             :    inlinees.  */
    1328                 :             : 
    1329                 :             : void
    1330                 :    98538903 : name_lookup::adl_namespace (tree scope)
    1331                 :             : {
    1332                 :   168733024 :   if (see_and_mark (scope))
    1333                 :             :     return;
    1334                 :             : 
    1335                 :             :   /* Look down into inline namespaces.  */
    1336                 :    90048307 :   if (vec<tree, va_gc> *inlinees = DECL_NAMESPACE_INLINEES (scope))
    1337                 :    94918584 :     for (unsigned ix = inlinees->length (); ix--;)
    1338                 :    70194121 :       adl_namespace ((*inlinees)[ix]);
    1339                 :             : 
    1340                 :    90048307 :   if (DECL_NAMESPACE_INLINE_P (scope))
    1341                 :             :     /* Mark parent.  */
    1342                 :    70194121 :     adl_namespace (CP_DECL_CONTEXT (scope));
    1343                 :             : }
    1344                 :             : 
    1345                 :             : /* Adds the class and its friends to the lookup structure.  */
    1346                 :             : 
    1347                 :             : void
    1348                 :    20949402 : name_lookup::adl_class_only (tree type)
    1349                 :             : {
    1350                 :             :   /* Backend-built structures, such as __builtin_va_list, aren't
    1351                 :             :      affected by all this.  */
    1352                 :    20949402 :   if (!CLASS_TYPE_P (type))
    1353                 :             :     return;
    1354                 :             : 
    1355                 :    20949402 :   type = TYPE_MAIN_VARIANT (type);
    1356                 :             : 
    1357                 :    20949402 :   if (see_and_mark (type))
    1358                 :             :     return;
    1359                 :             : 
    1360                 :    20843947 :   tree context = decl_namespace_context (type);
    1361                 :    20843947 :   adl_namespace (context);
    1362                 :             : }
    1363                 :             : 
    1364                 :             : /* Adds the class and its bases to the lookup structure.
    1365                 :             :    Returns true on error.  */
    1366                 :             : 
    1367                 :             : void
    1368                 :    19067507 : name_lookup::adl_bases (tree type)
    1369                 :             : {
    1370                 :    19067507 :   adl_class_only (type);
    1371                 :             : 
    1372                 :             :   /* Process baseclasses.  */
    1373                 :    19067507 :   if (tree binfo = TYPE_BINFO (type))
    1374                 :             :     {
    1375                 :             :       tree base_binfo;
    1376                 :             :       int i;
    1377                 :             : 
    1378                 :    22867070 :       for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    1379                 :     3830864 :         adl_bases (BINFO_TYPE (base_binfo));
    1380                 :             :     }
    1381                 :    19067507 : }
    1382                 :             : 
    1383                 :             : /* Adds everything associated with a class argument type to the lookup
    1384                 :             :    structure.
    1385                 :             : 
    1386                 :             :    If T is a class type (including unions), its associated classes are: the
    1387                 :             :    class itself; the class of which it is a member, if any; and its direct
    1388                 :             :    and indirect base classes. Its associated namespaces are the namespaces
    1389                 :             :    of which its associated classes are members. Furthermore, if T is a
    1390                 :             :    class template specialization, its associated namespaces and classes
    1391                 :             :    also include: the namespaces and classes associated with the types of
    1392                 :             :    the template arguments provided for template type parameters (excluding
    1393                 :             :    template template parameters); the namespaces of which any template
    1394                 :             :    template arguments are members; and the classes of which any member
    1395                 :             :    templates used as template template arguments are members. [ Note:
    1396                 :             :    non-type template arguments do not contribute to the set of associated
    1397                 :             :    namespaces.  --end note] */
    1398                 :             : 
    1399                 :             : void
    1400                 :    18511007 : name_lookup::adl_class (tree type)
    1401                 :             : {
    1402                 :             :   /* Backend build structures, such as __builtin_va_list, aren't
    1403                 :             :      affected by all this.  */
    1404                 :    18511007 :   if (!CLASS_TYPE_P (type))
    1405                 :             :     return;
    1406                 :             : 
    1407                 :    18428562 :   type = TYPE_MAIN_VARIANT (type);
    1408                 :             : 
    1409                 :             :   /* We don't set found here because we have to have set seen first,
    1410                 :             :      which is done in the adl_bases walk.  */
    1411                 :    18428562 :   if (found_p (type))
    1412                 :             :     return;
    1413                 :             : 
    1414                 :    15236643 :   complete_type (type);
    1415                 :    15236643 :   adl_bases (type);
    1416                 :    15236643 :   mark_found (type);
    1417                 :             : 
    1418                 :    15236643 :   if (TYPE_CLASS_SCOPE_P (type))
    1419                 :      846324 :     adl_class_only (TYPE_CONTEXT (type));
    1420                 :             : 
    1421                 :             :   /* Process template arguments.  */
    1422                 :    15236643 :   if (CLASSTYPE_TEMPLATE_INFO (type)
    1423                 :    15236643 :       && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
    1424                 :             :     {
    1425                 :     8237049 :       tree list = INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (type));
    1426                 :    23290894 :       for (int i = 0; i < TREE_VEC_LENGTH (list); ++i)
    1427                 :    15053845 :         adl_template_arg (TREE_VEC_ELT (list, i));
    1428                 :             :     }
    1429                 :             : }
    1430                 :             : 
    1431                 :             : void
    1432                 :    14887286 : name_lookup::adl_enum (tree type)
    1433                 :             : {
    1434                 :    14887286 :   type = TYPE_MAIN_VARIANT (type);
    1435                 :    14887286 :   if (see_and_mark (type))
    1436                 :             :     return;
    1437                 :             : 
    1438                 :     8533734 :   if (TYPE_CLASS_SCOPE_P (type))
    1439                 :     1035563 :     adl_class_only (TYPE_CONTEXT (type));
    1440                 :             :   else
    1441                 :     7498171 :     adl_namespace (decl_namespace_context (type));
    1442                 :             : }
    1443                 :             : 
    1444                 :             : void
    1445                 :    57274647 : name_lookup::adl_expr (tree expr)
    1446                 :             : {
    1447                 :    57274647 :   if (!expr)
    1448                 :             :     return;
    1449                 :             : 
    1450                 :    57274647 :   gcc_assert (!TYPE_P (expr));
    1451                 :             : 
    1452                 :    57274647 :   if (TREE_TYPE (expr) != unknown_type_node)
    1453                 :             :     {
    1454                 :    57266299 :       adl_type (unlowered_expr_type (expr));
    1455                 :    57266299 :       return;
    1456                 :             :     }
    1457                 :             : 
    1458                 :        8348 :   if (TREE_CODE (expr) == ADDR_EXPR)
    1459                 :         537 :     expr = TREE_OPERAND (expr, 0);
    1460                 :        8348 :   if (TREE_CODE (expr) == COMPONENT_REF
    1461                 :        8348 :       || TREE_CODE (expr) == OFFSET_REF)
    1462                 :         506 :     expr = TREE_OPERAND (expr, 1);
    1463                 :        8348 :   expr = MAYBE_BASELINK_FUNCTIONS (expr);
    1464                 :             : 
    1465                 :        8348 :   if (OVL_P (expr))
    1466                 :       16229 :     for (lkp_iterator iter (expr); iter; ++iter)
    1467                 :        8300 :       adl_type (TREE_TYPE (*iter));
    1468                 :         419 :   else if (TREE_CODE (expr) == TEMPLATE_ID_EXPR)
    1469                 :             :     {
    1470                 :             :       /* The working paper doesn't currently say how to handle
    1471                 :             :          template-id arguments.  The sensible thing would seem to be
    1472                 :             :          to handle the list of template candidates like a normal
    1473                 :             :          overload set, and handle the template arguments like we do
    1474                 :             :          for class template specializations.  */
    1475                 :             : 
    1476                 :             :       /* First the templates.  */
    1477                 :         419 :       adl_expr (TREE_OPERAND (expr, 0));
    1478                 :             : 
    1479                 :             :       /* Now the arguments.  */
    1480                 :         419 :       if (tree args = TREE_OPERAND (expr, 1))
    1481                 :         844 :         for (int ix = TREE_VEC_LENGTH (args); ix--;)
    1482                 :         425 :           adl_template_arg (TREE_VEC_ELT (args, ix));
    1483                 :             :     }
    1484                 :             : }
    1485                 :             : 
    1486                 :             : void
    1487                 :    70115434 : name_lookup::adl_type (tree type)
    1488                 :             : {
    1489                 :    77997321 :   if (!type)
    1490                 :             :     return;
    1491                 :             : 
    1492                 :    77997321 :   if (TYPE_PTRDATAMEM_P (type))
    1493                 :             :     {
    1494                 :             :       /* Pointer to member: associate class type and value type.  */
    1495                 :         719 :       adl_type (TYPE_PTRMEM_CLASS_TYPE (type));
    1496                 :         719 :       adl_type (TYPE_PTRMEM_POINTED_TO_TYPE (type));
    1497                 :         719 :       return;
    1498                 :             :     }
    1499                 :             : 
    1500                 :    77996602 :   switch (TREE_CODE (type))
    1501                 :             :     {
    1502                 :    17211482 :     case RECORD_TYPE:
    1503                 :    17211482 :       if (TYPE_PTRMEMFUNC_P (type))
    1504                 :             :         {
    1505                 :       47323 :           adl_type (TYPE_PTRMEMFUNC_FN_TYPE (type));
    1506                 :       47323 :           return;
    1507                 :             :         }
    1508                 :             :       /* FALLTHRU */
    1509                 :    18511007 :     case UNION_TYPE:
    1510                 :    18511007 :       adl_class (type);
    1511                 :    18511007 :       return;
    1512                 :             : 
    1513                 :      123689 :     case METHOD_TYPE:
    1514                 :             :       /* The basetype is referenced in the first arg type, so just
    1515                 :             :          fall through.  */
    1516                 :      123689 :     case FUNCTION_TYPE:
    1517                 :             :       /* Associate the parameter types.  */
    1518                 :      566055 :       for (tree args = TYPE_ARG_TYPES (type); args; args = TREE_CHAIN (args))
    1519                 :      442366 :         adl_type (TREE_VALUE (args));
    1520                 :             :       /* FALLTHROUGH */
    1521                 :             : 
    1522                 :     7833842 :     case POINTER_TYPE:
    1523                 :     7833842 :     case REFERENCE_TYPE:
    1524                 :     7833842 :     case ARRAY_TYPE:
    1525                 :     7833842 :       adl_type (TREE_TYPE (type));
    1526                 :     7833842 :       return;
    1527                 :             : 
    1528                 :    14887286 :     case ENUMERAL_TYPE:
    1529                 :    14887286 :       adl_enum (type);
    1530                 :    14887286 :       return;
    1531                 :             : 
    1532                 :         562 :     case LANG_TYPE:
    1533                 :         562 :       gcc_assert (type == unknown_type_node
    1534                 :             :                   || type == init_list_type_node);
    1535                 :             :       return;
    1536                 :             : 
    1537                 :           3 :     case TYPE_PACK_EXPANSION:
    1538                 :           3 :       adl_type (PACK_EXPANSION_PATTERN (type));
    1539                 :           3 :       return;
    1540                 :             : 
    1541                 :             :     default:
    1542                 :             :       break;
    1543                 :             :     }
    1544                 :             : }
    1545                 :             : 
    1546                 :             : /* Adds everything associated with a template argument to the lookup
    1547                 :             :    structure.  */
    1548                 :             : 
    1549                 :             : void
    1550                 :    15100752 : name_lookup::adl_template_arg (tree arg)
    1551                 :             : {
    1552                 :             :   /* [basic.lookup.koenig]
    1553                 :             : 
    1554                 :             :      If T is a template-id, its associated namespaces and classes are
    1555                 :             :      ... the namespaces and classes associated with the types of the
    1556                 :             :      template arguments provided for template type parameters
    1557                 :             :      (excluding template template parameters); the namespaces in which
    1558                 :             :      any template template arguments are defined; and the classes in
    1559                 :             :      which any member templates used as template template arguments
    1560                 :             :      are defined.  [Note: non-type template arguments do not
    1561                 :             :      contribute to the set of associated namespaces.  ]  */
    1562                 :             : 
    1563                 :             :   /* Consider first template template arguments.  */
    1564                 :    15100752 :   if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM
    1565                 :    15100752 :       || TREE_CODE (arg) == UNBOUND_CLASS_TEMPLATE)
    1566                 :             :     ;
    1567                 :    15100752 :   else if (TREE_CODE (arg) == TEMPLATE_DECL)
    1568                 :             :     {
    1569                 :        2672 :       tree ctx = CP_DECL_CONTEXT (arg);
    1570                 :             : 
    1571                 :             :       /* It's not a member template.  */
    1572                 :        2672 :       if (TREE_CODE (ctx) == NAMESPACE_DECL)
    1573                 :        2664 :         adl_namespace (ctx);
    1574                 :             :       /* Otherwise, it must be member template.  */
    1575                 :             :       else
    1576                 :           8 :         adl_class_only (ctx);
    1577                 :             :     }
    1578                 :             :   /* It's an argument pack; handle it recursively.  */
    1579                 :    15098080 :   else if (ARGUMENT_PACK_P (arg))
    1580                 :             :     {
    1581                 :       13325 :       tree args = ARGUMENT_PACK_ARGS (arg);
    1582                 :       13325 :       int i, len = TREE_VEC_LENGTH (args);
    1583                 :       59807 :       for (i = 0; i < len; ++i) 
    1584                 :       46482 :         adl_template_arg (TREE_VEC_ELT (args, i));
    1585                 :             :     }
    1586                 :             :   /* It's not a template template argument, but it is a type template
    1587                 :             :      argument.  */
    1588                 :    15084755 :   else if (TYPE_P (arg))
    1589                 :    12397650 :     adl_type (arg);
    1590                 :    15100752 : }
    1591                 :             : 
    1592                 :             : /* Perform ADL lookup.  FNS is the existing lookup result and ARGS are
    1593                 :             :    the call arguments.  */
    1594                 :             : 
    1595                 :             : tree
    1596                 :    31167072 : name_lookup::search_adl (tree fns, vec<tree, va_gc> *args)
    1597                 :             : {
    1598                 :    31167072 :   gcc_checking_assert (!vec_safe_length (scopes));
    1599                 :             :   
    1600                 :             :   /* Gather each associated entity onto the lookup's scope list.  */
    1601                 :    31167072 :   unsigned ix;
    1602                 :    31167072 :   tree arg;
    1603                 :             : 
    1604                 :    88441400 :   FOR_EACH_VEC_ELT_REVERSE (*args, ix, arg)
    1605                 :             :     /* OMP reduction operators put an ADL-significant type as the
    1606                 :             :        first arg. */
    1607                 :    57274328 :     if (TYPE_P (arg))
    1608                 :         100 :       adl_type (arg);
    1609                 :             :     else
    1610                 :    57274228 :       adl_expr (arg);
    1611                 :             : 
    1612                 :    31167072 :   if (vec_safe_length (scopes))
    1613                 :             :     {
    1614                 :             :       /* Now do the lookups.  */
    1615                 :    17457774 :       value = fns;
    1616                 :    17457774 :       if (fns)
    1617                 :    13391481 :         dedup (true);
    1618                 :             : 
    1619                 :             :       /* INST_PATH will be NULL, if this is /not/ 2nd-phase ADL.  */
    1620                 :    17457774 :       bitmap inst_path = NULL;
    1621                 :             :       /* VISIBLE is the regular import bitmap.  */
    1622                 :    17457774 :       bitmap visible = visible_instantiation_path (&inst_path);
    1623                 :             : 
    1624                 :   136883762 :       for (unsigned ix = scopes->length (); ix--;)
    1625                 :             :         {
    1626                 :   119425988 :           tree scope = (*scopes)[ix];
    1627                 :   119425988 :           if (TREE_CODE (scope) == NAMESPACE_DECL)
    1628                 :    90048307 :             adl_namespace_fns (scope, visible);
    1629                 :             :           else
    1630                 :             :             {
    1631                 :    29377681 :               if (RECORD_OR_UNION_TYPE_P (scope))
    1632                 :    20843947 :                 adl_class_fns (scope);
    1633                 :             : 
    1634                 :             :               /* During 2nd phase ADL: Any exported declaration D in N
    1635                 :             :                  declared within the purview of a named module M
    1636                 :             :                  (10.2) is visible if there is an associated entity
    1637                 :             :                  attached to M with the same innermost enclosing
    1638                 :             :                  non-inline namespace as D.
    1639                 :             :                  [basic.lookup.argdep]/4.4 */ 
    1640                 :             : 
    1641                 :    29377681 :               if (!inst_path)
    1642                 :             :                 /* Not 2nd phase.  */
    1643                 :    29305363 :                 continue;
    1644                 :             : 
    1645                 :       72318 :               tree ctx = CP_DECL_CONTEXT (TYPE_NAME (scope));
    1646                 :       72318 :               if (TREE_CODE (ctx) != NAMESPACE_DECL)
    1647                 :             :                 /* Not namespace-scope class.  */
    1648                 :        3752 :                 continue;
    1649                 :             : 
    1650                 :       68566 :               tree origin = get_originating_module_decl (TYPE_NAME (scope));
    1651                 :       68566 :               tree not_tmpl = STRIP_TEMPLATE (origin);
    1652                 :       68566 :               if (!DECL_LANG_SPECIFIC (not_tmpl)
    1653                 :      117481 :                   || !DECL_MODULE_IMPORT_P (not_tmpl))
    1654                 :             :                 /* Not imported.  */
    1655                 :       60431 :                 continue;
    1656                 :             : 
    1657                 :        8135 :               unsigned module = get_importing_module (origin);
    1658                 :             : 
    1659                 :        8135 :               if (!bitmap_bit_p (inst_path, module))
    1660                 :             :                 /* Not on path of instantiation.  */
    1661                 :           3 :                 continue;
    1662                 :             : 
    1663                 :        8132 :               if (bitmap_bit_p (visible, module))
    1664                 :             :                 /* If the module was in the visible set, we'll look at
    1665                 :             :                    its namespace partition anyway.  */
    1666                 :        8132 :                 continue;
    1667                 :             : 
    1668                 :           0 :               if (tree *slot = find_namespace_slot (ctx, name, false))
    1669                 :           0 :                 if (binding_slot *mslot = search_imported_binding_slot (slot, module))
    1670                 :             :                   {
    1671                 :           0 :                     if (mslot->is_lazy ())
    1672                 :           0 :                       lazy_load_binding (module, ctx, name, mslot);
    1673                 :             : 
    1674                 :           0 :                     if (tree bind = *mslot)
    1675                 :             :                       {
    1676                 :             :                         /* We must turn on deduping, because some other class
    1677                 :             :                            from this module might also be in this namespace.  */
    1678                 :           0 :                         dedup (true);
    1679                 :             : 
    1680                 :             :                         /* Add the exported fns  */
    1681                 :           0 :                         if (STAT_HACK_P (bind))
    1682                 :           0 :                           add_fns (STAT_VISIBLE (bind));
    1683                 :             :                       }
    1684                 :             :                   }
    1685                 :             :             }
    1686                 :             :         }
    1687                 :             : 
    1688                 :    17457774 :       fns = value;
    1689                 :    17457774 :       dedup (false);
    1690                 :             :     }
    1691                 :             : 
    1692                 :    31167072 :   return fns;
    1693                 :             : }
    1694                 :             : 
    1695                 :             : static bool qualified_namespace_lookup (tree, name_lookup *);
    1696                 :             : static void consider_binding_level (tree name,
    1697                 :             :                                     best_match <tree, const char *> &bm,
    1698                 :             :                                     cp_binding_level *lvl,
    1699                 :             :                                     bool look_within_fields,
    1700                 :             :                                     enum lookup_name_fuzzy_kind kind);
    1701                 :             : 
    1702                 :             : /* ADL lookup of NAME.  FNS is the result of regular lookup, and we
    1703                 :             :    don't add duplicates to it.  ARGS is the vector of call
    1704                 :             :    arguments (which will not be empty).  */
    1705                 :             : 
    1706                 :             : tree
    1707                 :    31167072 : lookup_arg_dependent (tree name, tree fns, vec<tree, va_gc> *args)
    1708                 :             : {
    1709                 :    31167072 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    1710                 :    31167072 :   name_lookup lookup (name);
    1711                 :    31167072 :   return lookup.search_adl (fns, args);
    1712                 :    31167072 : }
    1713                 :             : 
    1714                 :             : /* FNS is an overload set of conversion functions.  Return the
    1715                 :             :    overloads converting to TYPE.  */
    1716                 :             : 
    1717                 :             : static tree
    1718                 :      334101 : extract_conversion_operator (tree fns, tree type)
    1719                 :             : {
    1720                 :      334101 :   tree convs = NULL_TREE;
    1721                 :      334101 :   tree tpls = NULL_TREE;
    1722                 :             : 
    1723                 :     1086712 :   for (ovl_iterator iter (fns); iter; ++iter)
    1724                 :             :     {
    1725                 :      513474 :       if (same_type_p (DECL_CONV_FN_TYPE (*iter), type))
    1726                 :      402008 :         convs = lookup_add (*iter, convs);
    1727                 :             : 
    1728                 :      513474 :       if (TREE_CODE (*iter) == TEMPLATE_DECL)
    1729                 :       59841 :         tpls = lookup_add (*iter, tpls);
    1730                 :             :     }
    1731                 :             : 
    1732                 :      334101 :   if (!convs)
    1733                 :       66550 :     convs = tpls;
    1734                 :             : 
    1735                 :      334101 :   return convs;
    1736                 :             : }
    1737                 :             : 
    1738                 :             : /* Binary search of (ordered) MEMBER_VEC for NAME.  */
    1739                 :             : 
    1740                 :             : static tree
    1741                 :  2597467224 : member_vec_binary_search (vec<tree, va_gc> *member_vec, tree name)
    1742                 :             : {
    1743                 : 15756988082 :   for (unsigned lo = 0, hi = member_vec->length (); lo < hi;)
    1744                 :             :     {
    1745                 : 11206587377 :       unsigned mid = (lo + hi) / 2;
    1746                 : 11206587377 :       tree binding = (*member_vec)[mid];
    1747                 : 22413174754 :       tree binding_name = OVL_NAME (binding);
    1748                 :             : 
    1749                 : 11206587377 :       if (binding_name > name)
    1750                 :             :         hi = mid;
    1751                 :  5418966674 :       else if (binding_name < name)
    1752                 :  4774432931 :         lo = mid + 1;
    1753                 :             :       else
    1754                 :   644533743 :         return binding;
    1755                 :             :     }
    1756                 :             : 
    1757                 :             :   return NULL_TREE;
    1758                 :             : }
    1759                 :             : 
    1760                 :             : /* Linear search of (unordered) MEMBER_VEC for NAME.  */
    1761                 :             : 
    1762                 :             : static tree
    1763                 :   643063879 : member_vec_linear_search (vec<tree, va_gc> *member_vec, tree name)
    1764                 :             : {
    1765                 :  6107027173 :   for (int ix = member_vec->length (); ix--;)
    1766                 :  5512419327 :     if (tree binding = (*member_vec)[ix])
    1767                 :  5512419327 :       if (OVL_NAME (binding) == name)
    1768                 :    48456033 :         return binding;
    1769                 :             : 
    1770                 :             :   return NULL_TREE;
    1771                 :             : }
    1772                 :             : 
    1773                 :             : /* Linear search of (partially ordered) fields of KLASS for NAME.  */
    1774                 :             : 
    1775                 :             : static tree
    1776                 :  2318798545 : fields_linear_search (tree klass, tree name, bool want_type)
    1777                 :             : {
    1778                 : 34047712531 :   for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
    1779                 :             :     {
    1780                 : 31813745616 :       tree decl = fields;
    1781                 :             : 
    1782                 : 31813745616 :       if (TREE_CODE (decl) == FIELD_DECL
    1783                 : 31813745616 :           && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
    1784                 :             :         {
    1785                 :    30325531 :           if (tree temp = search_anon_aggr (TREE_TYPE (decl), name, want_type))
    1786                 :       12139 :             return temp;
    1787                 :             :         }
    1788                 :             : 
    1789                 : 31813733477 :       if (DECL_NAME (decl) != name)
    1790                 : 31687358432 :         continue;
    1791                 :             :       
    1792                 :   126375045 :       if (TREE_CODE (decl) == USING_DECL)
    1793                 :             :         {
    1794                 :      794188 :           decl = strip_using_decl (decl);
    1795                 :      794188 :           if (is_overloaded_fn (decl))
    1796                 :      193877 :             continue;
    1797                 :             :         }
    1798                 :             : 
    1799                 :   126181168 :       if (DECL_DECLARES_FUNCTION_P (decl))
    1800                 :             :         /* Functions are found separately.  */
    1801                 :    40933665 :         continue;
    1802                 :             : 
    1803                 :    85247503 :       if (!want_type || DECL_DECLARES_TYPE_P (decl))
    1804                 :    84819491 :         return decl;
    1805                 :             :     }
    1806                 :             : 
    1807                 :             :   return NULL_TREE;
    1808                 :             : }
    1809                 :             : 
    1810                 :             : /* Like fields_linear_search, but specific for "_" name.  There can be multiple
    1811                 :             :    name-independent non-static data members and in that case a TREE_LIST with the
    1812                 :             :    ambiguous decls should be returned.  */
    1813                 :             : 
    1814                 :             : static tree
    1815                 :         577 : name_independent_linear_search (tree val, tree klass, tree name)
    1816                 :             : {
    1817                 :        2902 :   for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
    1818                 :             :     {
    1819                 :        2325 :       tree decl = fields;
    1820                 :             : 
    1821                 :        2325 :       if (TREE_CODE (decl) == FIELD_DECL
    1822                 :        2325 :           && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
    1823                 :             :         {
    1824                 :           0 :           if (tree temp = search_anon_aggr (TREE_TYPE (decl), name, false))
    1825                 :             :             {
    1826                 :           0 :               decl = temp;
    1827                 :           0 :               goto add;
    1828                 :             :             }
    1829                 :             :         }
    1830                 :             : 
    1831                 :        2325 :       if (DECL_NAME (decl) != name)
    1832                 :        2313 :         continue;
    1833                 :             : 
    1834                 :          12 :       if (TREE_CODE (decl) == USING_DECL)
    1835                 :             :         {
    1836                 :           0 :           decl = strip_using_decl (decl);
    1837                 :           0 :           if (is_overloaded_fn (decl))
    1838                 :           0 :             continue;
    1839                 :             :         }
    1840                 :             : 
    1841                 :          12 :       if (DECL_DECLARES_FUNCTION_P (decl))
    1842                 :             :         /* Functions are found separately.  */
    1843                 :           0 :         continue;
    1844                 :             : 
    1845                 :          12 :     add:
    1846                 :          12 :       if (val == NULL_TREE)
    1847                 :             :         val = decl;
    1848                 :             :       else
    1849                 :             :         {
    1850                 :           3 :           if (TREE_CODE (val) != TREE_LIST)
    1851                 :             :             {
    1852                 :           3 :               if (TREE_CODE (val) == OVERLOAD
    1853                 :           0 :                   && OVL_DEDUP_P (val)
    1854                 :           3 :                   && TREE_CODE (decl) == USING_DECL)
    1855                 :             :                 {
    1856                 :           0 :                   val = ovl_make (decl, val);
    1857                 :           0 :                   continue;
    1858                 :             :                 }
    1859                 :           3 :               val = tree_cons (NULL_TREE, val, NULL_TREE);
    1860                 :           3 :               TREE_TYPE (val) = error_mark_node;
    1861                 :             :             }
    1862                 :           3 :           if (TREE_CODE (decl) == TREE_LIST)
    1863                 :           0 :             val = chainon (decl, val);
    1864                 :             :           else
    1865                 :             :             {
    1866                 :           3 :               val = tree_cons (NULL_TREE, decl, val);
    1867                 :           3 :               TREE_TYPE (val) = error_mark_node;
    1868                 :             :             }
    1869                 :             :         }
    1870                 :             :     }
    1871                 :             : 
    1872                 :         577 :   return val;
    1873                 :             : }
    1874                 :             : 
    1875                 :             : /* Look for NAME member inside of anonymous aggregate ANON.  Although
    1876                 :             :    such things should only contain FIELD_DECLs, we check that too
    1877                 :             :    late, and would give very confusing errors if we weren't
    1878                 :             :    permissive here.  */
    1879                 :             : 
    1880                 :             : tree
    1881                 :    30325531 : search_anon_aggr (tree anon, tree name, bool want_type)
    1882                 :             : {
    1883                 :    30325531 :   gcc_assert (COMPLETE_TYPE_P (anon));
    1884                 :    30325531 :   tree ret = get_class_binding_direct (anon, name, want_type);
    1885                 :    30325531 :   return ret;
    1886                 :             : }
    1887                 :             : 
    1888                 :             : /* Look for NAME as an immediate member of KLASS (including
    1889                 :             :    anon-members or unscoped enum member).  TYPE_OR_FNS is zero for
    1890                 :             :    regular search.  >0 to get a type binding (if there is one) and <0
    1891                 :             :    if you want (just) the member function binding.
    1892                 :             : 
    1893                 :             :    Use this if you do not want lazy member creation.  */
    1894                 :             : 
    1895                 :             : tree
    1896                 :  4964204741 : get_class_binding_direct (tree klass, tree name, bool want_type)
    1897                 :             : {
    1898                 :  4964204741 :   gcc_checking_assert (RECORD_OR_UNION_TYPE_P (klass));
    1899                 :             : 
    1900                 :             :   /* Conversion operators can only be found by the marker conversion
    1901                 :             :      operator name.  */
    1902                 :  4964204741 :   bool conv_op = IDENTIFIER_CONV_OP_P (name);
    1903                 :  4964204741 :   tree lookup = conv_op ? conv_op_identifier : name;
    1904                 :  4964204741 :   tree val = NULL_TREE;
    1905                 :  4964204741 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    1906                 :             : 
    1907                 :  4964204741 :   if (COMPLETE_TYPE_P (klass) && member_vec)
    1908                 :             :     {
    1909                 :  2597142652 :       val = member_vec_binary_search (member_vec, lookup);
    1910                 :  2597142652 :       if (!val)
    1911                 :             :         ;
    1912                 :   644209744 :       else if (TREE_CODE (val) == OVERLOAD
    1913                 :   644209744 :                && OVL_NAME_INDEPENDENT_DECL_P (val))
    1914                 :             :         {
    1915                 :         160 :           if (want_type)
    1916                 :             :             {
    1917                 :         120 :               while (TREE_CODE (val) == OVERLOAD
    1918                 :         120 :                      && OVL_NAME_INDEPENDENT_DECL_P (val))
    1919                 :          63 :                 val = OVL_CHAIN (val);
    1920                 :          57 :               if (STAT_HACK_P (val))
    1921                 :          12 :                 val = STAT_TYPE (val);
    1922                 :          45 :               else if (!DECL_DECLARES_TYPE_P (val))
    1923                 :             :                 val = NULL_TREE;
    1924                 :             :             }
    1925                 :             :           else
    1926                 :             :             {
    1927                 :             :               /* OVERLOAD with a special OVL_NAME_INDEPENDENT_DECL_P
    1928                 :             :                  flag is used under the hood to represent lookup
    1929                 :             :                  results which include name-independent declarations,
    1930                 :             :                  and get_class_binding_direct is turning that into
    1931                 :             :                  TREE_LIST representation (which the callers expect for
    1932                 :             :                  ambiguous lookups) instead.
    1933                 :             :                  There are 2 reasons for that:
    1934                 :             :                  1) in order to keep the member_vec binary search fast, I
    1935                 :             :                  think it is better to keep OVL_NAME usable on all elements
    1936                 :             :                  because having to special case TREE_LIST would slow
    1937                 :             :                  everything down;
    1938                 :             :                  2) the callers need to be able to chain the results anyway
    1939                 :             :                  and so need an unshared TREE_LIST they can tweak/destroy.  */
    1940                 :             :               tree ovl = val;
    1941                 :             :               val = NULL_TREE;
    1942                 :         218 :               while (TREE_CODE (ovl) == OVERLOAD
    1943                 :         218 :                      && OVL_NAME_INDEPENDENT_DECL_P (ovl))
    1944                 :             :                 {
    1945                 :         115 :                   val = tree_cons (NULL_TREE, OVL_FUNCTION (ovl), val);
    1946                 :         115 :                   TREE_TYPE (val) = error_mark_node;
    1947                 :         115 :                   ovl = OVL_CHAIN (ovl);
    1948                 :             :                 }
    1949                 :         103 :               if (STAT_HACK_P (ovl))
    1950                 :           6 :                 val = tree_cons (NULL_TREE, STAT_DECL (ovl), val);
    1951                 :             :               else
    1952                 :          97 :                 val = tree_cons (NULL_TREE, ovl, val);
    1953                 :         103 :               TREE_TYPE (val) = error_mark_node;
    1954                 :             :             }
    1955                 :             :         }
    1956                 :   644209584 :       else if (STAT_HACK_P (val))
    1957                 :         228 :         val = want_type ? STAT_TYPE (val) : STAT_DECL (val);
    1958                 :   644209356 :       else if (want_type && !DECL_DECLARES_TYPE_P (val))
    1959                 :             :         val = NULL_TREE;
    1960                 :             :     }
    1961                 :             :   else
    1962                 :             :     {
    1963                 :  2367062089 :       if (member_vec && !want_type)
    1964                 :   643063879 :         val = member_vec_linear_search (member_vec, lookup);
    1965                 :             : 
    1966                 :  2367062089 :       if (id_equal (lookup, "_") && !want_type)
    1967                 :         577 :         val = name_independent_linear_search (val, klass, lookup);
    1968                 :  2367061512 :       else if (!val || (TREE_CODE (val) == OVERLOAD && OVL_DEDUP_P (val)))
    1969                 :             :         /* Dependent using declarations are a 'field', make sure we
    1970                 :             :            return that even if we saw an overload already.  */
    1971                 :  2318795403 :         if (tree field_val = fields_linear_search (klass, lookup, want_type))
    1972                 :             :           {
    1973                 :    84828488 :             if (!val)
    1974                 :             :               val = field_val;
    1975                 :           0 :             else if (TREE_CODE (field_val) == USING_DECL)
    1976                 :           0 :               val = ovl_make (field_val, val);
    1977                 :             :           }
    1978                 :             :     }
    1979                 :             : 
    1980                 :             :   /* Extract the conversion operators asked for, unless the general
    1981                 :             :      conversion operator was requested.   */
    1982                 :  4964204741 :   if (val && conv_op)
    1983                 :             :     {
    1984                 :    14098337 :       gcc_checking_assert (OVL_FUNCTION (val) == conv_op_marker);
    1985                 :    14098337 :       val = OVL_CHAIN (val);
    1986                 :    14098337 :       if (tree type = TREE_TYPE (name))
    1987                 :      334101 :         val = extract_conversion_operator (val, type);
    1988                 :             :     }
    1989                 :             : 
    1990                 :  4964204741 :   return val;
    1991                 :             : }
    1992                 :             : 
    1993                 :             : /* We're about to lookup NAME in KLASS.  Make sure any lazily declared
    1994                 :             :    members are now declared.  */
    1995                 :             : 
    1996                 :             : static void
    1997                 :  2776201003 : maybe_lazily_declare (tree klass, tree name)
    1998                 :             : {
    1999                 :             :   /* See big comment anout module_state::write_pendings regarding adding a check
    2000                 :             :      bit.  */
    2001                 :  2776201003 :   if (modules_p ())
    2002                 :    12106097 :     lazy_load_pendings (TYPE_NAME (klass));
    2003                 :             : 
    2004                 :             :   /* Lazily declare functions, if we're going to search these.  */
    2005                 :  2776201003 :   if (IDENTIFIER_CTOR_P (name))
    2006                 :             :     {
    2007                 :    52842575 :       if (CLASSTYPE_LAZY_DEFAULT_CTOR (klass))
    2008                 :     2224797 :         lazily_declare_fn (sfk_constructor, klass);
    2009                 :    52842575 :       if (CLASSTYPE_LAZY_COPY_CTOR (klass))
    2010                 :     3933686 :         lazily_declare_fn (sfk_copy_constructor, klass);
    2011                 :    52842575 :       if (CLASSTYPE_LAZY_MOVE_CTOR (klass))
    2012                 :     3052817 :         lazily_declare_fn (sfk_move_constructor, klass);
    2013                 :             :     }
    2014                 :  2723358428 :   else if (IDENTIFIER_DTOR_P (name))
    2015                 :             :     {
    2016                 :    54996189 :       if (CLASSTYPE_LAZY_DESTRUCTOR (klass))
    2017                 :     4444663 :         lazily_declare_fn (sfk_destructor, klass);
    2018                 :             :     }
    2019                 :  2668362239 :   else if (name == assign_op_identifier)
    2020                 :             :     {
    2021                 :    11143226 :       if (CLASSTYPE_LAZY_COPY_ASSIGN (klass))
    2022                 :     1235838 :         lazily_declare_fn (sfk_copy_assignment, klass);
    2023                 :    11143226 :       if (CLASSTYPE_LAZY_MOVE_ASSIGN (klass))
    2024                 :      841091 :         lazily_declare_fn (sfk_move_assignment, klass);
    2025                 :             :     }
    2026                 :  2776201003 : }
    2027                 :             : 
    2028                 :             : /* Look for NAME's binding in exactly KLASS.  See
    2029                 :             :    get_class_binding_direct for argument description.  Does lazy
    2030                 :             :    special function creation as necessary.  */
    2031                 :             : 
    2032                 :             : tree
    2033                 :  4567911609 : get_class_binding (tree klass, tree name, bool want_type /*=false*/)
    2034                 :             : {
    2035                 :  4567911609 :   klass = complete_type (klass);
    2036                 :             : 
    2037                 :  4567911609 :   if (COMPLETE_TYPE_P (klass))
    2038                 :  2776201003 :     maybe_lazily_declare (klass, name);
    2039                 :             : 
    2040                 :  4567911609 :   return get_class_binding_direct (klass, name, want_type);
    2041                 :             : }
    2042                 :             : 
    2043                 :             : /* Find the slot containing overloads called 'NAME'.  If there is no
    2044                 :             :    such slot and the class is complete, create an empty one, at the
    2045                 :             :    correct point in the sorted member vector.  Otherwise return NULL.
    2046                 :             :    Deals with conv_op marker handling.  */
    2047                 :             : 
    2048                 :             : tree *
    2049                 :   273871833 : find_member_slot (tree klass, tree name)
    2050                 :             : {
    2051                 :   273871833 :   bool complete_p = COMPLETE_TYPE_P (klass);
    2052                 :             : 
    2053                 :   273871833 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    2054                 :   273871833 :   if (!member_vec)
    2055                 :             :     {
    2056                 :    19437808 :       vec_alloc (member_vec, 8);
    2057                 :    19437808 :       CLASSTYPE_MEMBER_VEC (klass) = member_vec;
    2058                 :    19437808 :       if (complete_p)
    2059                 :             :         /* If the class is complete but had no member_vec, we need to
    2060                 :             :            add the TYPE_FIELDS into it.  We're also most likely to be
    2061                 :             :            adding ctors & dtors, so ask for 6 spare slots (the
    2062                 :             :            abstract cdtors and their clones).  */
    2063                 :     1865217 :         member_vec = set_class_bindings (klass, 6);
    2064                 :             :     }
    2065                 :             : 
    2066                 :   513723950 :   if (IDENTIFIER_CONV_OP_P (name))
    2067                 :     1686158 :     name = conv_op_identifier;
    2068                 :             : 
    2069                 :   273871833 :   unsigned ix, length = member_vec->length ();
    2070                 :  3339196833 :   for (ix = 0; ix < length; ix++)
    2071                 :             :     {
    2072                 :  3200529981 :       tree *slot = &(*member_vec)[ix];
    2073                 :  6401059962 :       tree fn_name = OVL_NAME (*slot);
    2074                 :             : 
    2075                 :  3200529981 :       if (fn_name == name)
    2076                 :             :         {
    2077                 :             :           /* If we found an existing slot, it must be a function set.
    2078                 :             :              Even with insertion after completion, because those only
    2079                 :             :              happen with artificial fns that have unspellable names.
    2080                 :             :              This means we do not have to deal with the stat hack
    2081                 :             :              either.  */
    2082                 :   128842499 :           gcc_checking_assert (OVL_P (*slot));
    2083                 :   128842499 :           if (name == conv_op_identifier)
    2084                 :             :             {
    2085                 :      420167 :               gcc_checking_assert (OVL_FUNCTION (*slot) == conv_op_marker);
    2086                 :             :               /* Skip the conv-op marker. */
    2087                 :      420167 :               slot = &OVL_CHAIN (*slot);
    2088                 :             :             }
    2089                 :   128842499 :           return slot;
    2090                 :             :         }
    2091                 :             : 
    2092                 :  3071687482 :       if (complete_p && fn_name > name)
    2093                 :             :         break;
    2094                 :             :     }
    2095                 :             : 
    2096                 :             :   /* No slot found, add one if the class is complete.  */
    2097                 :   145029334 :   if (complete_p)
    2098                 :             :     {
    2099                 :             :       /* Do exact allocation, as we don't expect to add many.  */
    2100                 :    21223070 :       gcc_assert (name != conv_op_identifier);
    2101                 :    21223070 :       vec_safe_reserve_exact (member_vec, 1);
    2102                 :    21223070 :       CLASSTYPE_MEMBER_VEC (klass) = member_vec;
    2103                 :    21223070 :       member_vec->quick_insert (ix, NULL_TREE);
    2104                 :    21223070 :       return &(*member_vec)[ix];
    2105                 :             :     }
    2106                 :             : 
    2107                 :             :   return NULL;
    2108                 :             : }
    2109                 :             : 
    2110                 :             : /* KLASS is an incomplete class to which we're adding a method NAME.
    2111                 :             :    Add a slot and deal with conv_op marker handling.  */
    2112                 :             : 
    2113                 :             : tree *
    2114                 :   123806244 : add_member_slot (tree klass, tree name)
    2115                 :             : {
    2116                 :   123806244 :   gcc_assert (!COMPLETE_TYPE_P (klass));
    2117                 :             : 
    2118                 :   123806244 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    2119                 :   123806244 :   vec_safe_push (member_vec, NULL_TREE);
    2120                 :   123806244 :   CLASSTYPE_MEMBER_VEC (klass) = member_vec;
    2121                 :             : 
    2122                 :   123806244 :   tree *slot = &member_vec->last ();
    2123                 :   229140942 :   if (IDENTIFIER_CONV_OP_P (name))
    2124                 :             :     {
    2125                 :             :       /* Install the marker prefix.  */
    2126                 :     1265991 :       *slot = ovl_make (conv_op_marker, NULL_TREE);
    2127                 :     1265991 :       slot = &OVL_CHAIN (*slot);
    2128                 :             :     }
    2129                 :             : 
    2130                 :   123806244 :   return slot;
    2131                 :             : }
    2132                 :             : 
    2133                 :             : /* Comparison function to compare two MEMBER_VEC entries by name.
    2134                 :             :    Because we can have duplicates during insertion of TYPE_FIELDS, we
    2135                 :             :    do extra checking so deduping doesn't have to deal with so many
    2136                 :             :    cases.  */
    2137                 :             : 
    2138                 :             : static int
    2139                 :  4999310893 : member_name_cmp (const void *a_p, const void *b_p)
    2140                 :             : {
    2141                 :  4999310893 :   tree a = *(const tree *)a_p;
    2142                 :  4999310893 :   tree b = *(const tree *)b_p;
    2143                 :  4999310893 :   tree name_a = DECL_NAME (TREE_CODE (a) == OVERLOAD ? OVL_FUNCTION (a) : a);
    2144                 :  4999310893 :   tree name_b = DECL_NAME (TREE_CODE (b) == OVERLOAD ? OVL_FUNCTION (b) : b);
    2145                 :             : 
    2146                 :  4999310893 :   gcc_checking_assert (name_a && name_b);
    2147                 :  4999310893 :   if (name_a != name_b)
    2148                 :  7343134205 :     return name_a < name_b ? -1 : +1;
    2149                 :             : 
    2150                 :    15179099 :   if (name_a == conv_op_identifier)
    2151                 :             :     {
    2152                 :             :       /* Strip the conv-op markers. */
    2153                 :     1076092 :       gcc_checking_assert (OVL_FUNCTION (a) == conv_op_marker
    2154                 :             :                            && OVL_FUNCTION (b) == conv_op_marker);
    2155                 :      538046 :       a = OVL_CHAIN (a);
    2156                 :      538046 :       b = OVL_CHAIN (b);
    2157                 :             :     }
    2158                 :             : 
    2159                 :    15179099 :   if (TREE_CODE (a) == OVERLOAD)
    2160                 :     5559684 :     a = OVL_FUNCTION (a);
    2161                 :    15179099 :   if (TREE_CODE (b) == OVERLOAD)
    2162                 :     5078842 :     b = OVL_FUNCTION (b);
    2163                 :             : 
    2164                 :    15179099 :   if (id_equal (name_a, "_"))
    2165                 :             :     {
    2166                 :             :       /* Sort name-independent members first.  */
    2167                 :         264 :       if (name_independent_decl_p (a))
    2168                 :             :         {
    2169                 :         234 :           if (name_independent_decl_p (b))
    2170                 :             :             {
    2171                 :         183 :               if (DECL_UID (a) != DECL_UID (b))
    2172                 :         183 :                 return DECL_UID (a) < DECL_UID (b) ? -1 : +1;
    2173                 :           0 :               gcc_assert (a == b);
    2174                 :             :               return 0;
    2175                 :             :             }
    2176                 :             :           else
    2177                 :             :             return -1;
    2178                 :             :         }
    2179                 :          30 :       else if (name_independent_decl_p (b))
    2180                 :             :         return +1;
    2181                 :             :     }
    2182                 :             : 
    2183                 :             :   /* We're in STAT_HACK or USING_DECL territory (or possibly error-land). */
    2184                 :    15178835 :   if (TREE_CODE (a) != TREE_CODE (b))
    2185                 :             :     {
    2186                 :             :       /* If one of them is a TYPE_DECL, it loses.  */
    2187                 :    14421728 :       if (TREE_CODE (a) == TYPE_DECL)
    2188                 :             :         return +1;
    2189                 :    14421292 :       else if (TREE_CODE (b) == TYPE_DECL)
    2190                 :             :         return -1;
    2191                 :             : 
    2192                 :             :       /* If one of them is a USING_DECL, it loses.  */
    2193                 :    14420844 :       if (TREE_CODE (a) == USING_DECL)
    2194                 :             :         return +1;
    2195                 :     7503448 :       else if (TREE_CODE (b) == USING_DECL)
    2196                 :             :         return -1;
    2197                 :             : 
    2198                 :             :       /* There are no other cases with different kinds of decls, as
    2199                 :             :          duplicate detection should have kicked in earlier.  However,
    2200                 :             :          some erroneous cases get though. */
    2201                 :           0 :       gcc_assert (errorcount);
    2202                 :             :     }
    2203                 :             :   
    2204                 :             :   /* Using source location would be the best thing here, but we can
    2205                 :             :      get identically-located decls in the following circumstances:
    2206                 :             : 
    2207                 :             :      1) duplicate artificial type-decls for the same type.
    2208                 :             : 
    2209                 :             :      2) pack expansions of using-decls.
    2210                 :             : 
    2211                 :             :      We should not be doing #1, but in either case it doesn't matter
    2212                 :             :      how we order these.  Use UID as a proxy for source ordering, so
    2213                 :             :      that identically-located decls still have a well-defined stable
    2214                 :             :      ordering.  */
    2215                 :      757107 :   if (DECL_UID (a) != DECL_UID (b))
    2216                 :      757089 :     return DECL_UID (a) < DECL_UID (b) ? -1 : +1;
    2217                 :          18 :   gcc_assert (a == b);
    2218                 :             :   return 0;
    2219                 :             : }
    2220                 :             : 
    2221                 :             : static struct {
    2222                 :             :   gt_pointer_operator new_value;
    2223                 :             :   void *cookie;
    2224                 :             : } resort_data;
    2225                 :             : 
    2226                 :             : /* This routine compares two fields like member_name_cmp but using the
    2227                 :             :    pointer operator in resort_field_decl_data.  We don't have to deal
    2228                 :             :    with duplicates here.  */
    2229                 :             : 
    2230                 :             : static int
    2231                 :     9740208 : resort_member_name_cmp (const void *a_p, const void *b_p)
    2232                 :             : {
    2233                 :     9740208 :   tree a = *(const tree *)a_p;
    2234                 :     9740208 :   tree b = *(const tree *)b_p;
    2235                 :    19480416 :   tree name_a = OVL_NAME (a);
    2236                 :    19480416 :   tree name_b = OVL_NAME (b);
    2237                 :             : 
    2238                 :     9740208 :   resort_data.new_value (&name_a, &name_a, resort_data.cookie);
    2239                 :     9740208 :   resort_data.new_value (&name_b, &name_b, resort_data.cookie);
    2240                 :             : 
    2241                 :     9740208 :   gcc_checking_assert (name_a != name_b);
    2242                 :             : 
    2243                 :     9740208 :   return name_a < name_b ? -1 : +1;
    2244                 :             : }
    2245                 :             : 
    2246                 :             : /* Resort CLASSTYPE_MEMBER_VEC because pointers have been reordered.  */
    2247                 :             : 
    2248                 :             : void
    2249                 :       60256 : resort_type_member_vec (void *obj, void */*orig_obj*/,
    2250                 :             :                         gt_pointer_operator new_value, void* cookie)
    2251                 :             : {
    2252                 :       60256 :   if (vec<tree, va_gc> *member_vec = (vec<tree, va_gc> *) obj)
    2253                 :             :     {
    2254                 :       60256 :       resort_data.new_value = new_value;
    2255                 :       60256 :       resort_data.cookie = cookie;
    2256                 :       60256 :       member_vec->qsort (resort_member_name_cmp);
    2257                 :             :     }
    2258                 :       60256 : }
    2259                 :             : 
    2260                 :             : /* Recursively count the number of fields in KLASS, including anonymous
    2261                 :             :    union members.  */
    2262                 :             : 
    2263                 :             : static unsigned
    2264                 :    55322865 : count_class_fields (tree klass)
    2265                 :             : {
    2266                 :    55322865 :   unsigned n_fields = 0;
    2267                 :             : 
    2268                 :   478837442 :   for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
    2269                 :   423514577 :     if (DECL_DECLARES_FUNCTION_P (fields))
    2270                 :             :       /* Functions are dealt with separately.  */;
    2271                 :   195925822 :     else if (TREE_CODE (fields) == FIELD_DECL
    2272                 :   195925822 :              && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
    2273                 :      168885 :       n_fields += count_class_fields (TREE_TYPE (fields));
    2274                 :   195756937 :     else if (DECL_NAME (fields))
    2275                 :   175897058 :       n_fields += 1;
    2276                 :             : 
    2277                 :    55322865 :   return n_fields;
    2278                 :             : }
    2279                 :             : 
    2280                 :             : /* Append all the nonfunction members fields of KLASS to MEMBER_VEC.
    2281                 :             :    Recurse for anonymous members.  MEMBER_VEC must have space.  */
    2282                 :             : 
    2283                 :             : static void
    2284                 :    20051520 : member_vec_append_class_fields (vec<tree, va_gc> *member_vec, tree klass)
    2285                 :             : {
    2286                 :   359759768 :   for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
    2287                 :   339708248 :     if (DECL_DECLARES_FUNCTION_P (fields))
    2288                 :             :       /* Functions are handled separately.  */;
    2289                 :   112119508 :     else if (TREE_CODE (fields) == FIELD_DECL
    2290                 :   112119508 :              && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
    2291                 :      158522 :       member_vec_append_class_fields (member_vec, TREE_TYPE (fields));
    2292                 :   111960986 :     else if (DECL_NAME (fields))
    2293                 :             :       {
    2294                 :   107375286 :         tree field = fields;
    2295                 :             :         /* Mark a conv-op USING_DECL with the conv-op-marker.  */
    2296                 :   107375286 :         if (TREE_CODE (field) == USING_DECL
    2297                 :   109298634 :             && IDENTIFIER_CONV_OP_P (DECL_NAME (field)))
    2298                 :      134495 :           field = ovl_make (conv_op_marker, field);
    2299                 :   107375286 :         member_vec->quick_push (field);
    2300                 :             :       }
    2301                 :    20051520 : }
    2302                 :             : 
    2303                 :             : /* Append all of the enum values of ENUMTYPE to MEMBER_VEC.
    2304                 :             :    MEMBER_VEC must have space.  */
    2305                 :             : 
    2306                 :             : static void
    2307                 :          21 : member_vec_append_enum_values (vec<tree, va_gc> *member_vec, tree enumtype)
    2308                 :             : {
    2309                 :          21 :   for (tree values = TYPE_VALUES (enumtype);
    2310                 :          51 :        values; values = TREE_CHAIN (values))
    2311                 :          30 :     member_vec->quick_push (TREE_VALUE (values));
    2312                 :          21 : }
    2313                 :             : 
    2314                 :             : /* MEMBER_VEC has just had new DECLs added to it, but is sorted.
    2315                 :             :    DeDup adjacent DECLS of the same name.  We already dealt with
    2316                 :             :    conflict resolution when adding the fields or methods themselves.
    2317                 :             :    There are four cases (which could all be combined):
    2318                 :             :    1) a TYPE_DECL and non TYPE_DECL.  Deploy STAT_HACK as appropriate.
    2319                 :             :    2) a USING_DECL and an overload.  If the USING_DECL is dependent,
    2320                 :             :    it wins.  Otherwise the OVERLOAD does.
    2321                 :             :    3) two USING_DECLS.
    2322                 :             :    4) name-independent members plus others. ...
    2323                 :             : 
    2324                 :             :    member_name_cmp will have ordered duplicates as
    2325                 :             :    <name_independent><fns><using><type>  */
    2326                 :             : 
    2327                 :             : static void
    2328                 :    19893019 : member_vec_dedup (vec<tree, va_gc> *member_vec)
    2329                 :             : {
    2330                 :    19893019 :   unsigned len = member_vec->length ();
    2331                 :    19893019 :   unsigned store = 0;
    2332                 :             : 
    2333                 :    19893019 :   if (!len)
    2334                 :             :     return;
    2335                 :             : 
    2336                 :    39786032 :   tree name = OVL_NAME ((*member_vec)[0]);
    2337                 :   247322138 :   for (unsigned jx, ix = 0; ix < len; ix = jx)
    2338                 :             :     {
    2339                 :             :       tree current = NULL_TREE;
    2340                 :             :       tree to_type = NULL_TREE;
    2341                 :             :       tree to_using = NULL_TREE;
    2342                 :             :       tree marker = NULL_TREE;
    2343                 :             :       unsigned name_independent = ix;
    2344                 :             : 
    2345                 :   458610796 :       for (jx = ix; jx < len; jx++)
    2346                 :             :         {
    2347                 :   438717780 :           tree next = (*member_vec)[jx];
    2348                 :   438717780 :           if (jx != ix)
    2349                 :             :             {
    2350                 :   211288658 :               tree next_name = OVL_NAME (next);
    2351                 :   211288658 :               if (next_name != name)
    2352                 :             :                 {
    2353                 :             :                   name = next_name;
    2354                 :             :                   break;
    2355                 :             :                 }
    2356                 :             :             }
    2357                 :             : 
    2358                 :   436247036 :           if (IDENTIFIER_CONV_OP_P (name))
    2359                 :             :             {
    2360                 :     1400486 :               marker = next;
    2361                 :     1400486 :               next = OVL_CHAIN (next);
    2362                 :             :             }
    2363                 :             : 
    2364                 :   231181674 :           if (TREE_CODE (next) == USING_DECL)
    2365                 :             :             {
    2366                 :     9568114 :               if (IDENTIFIER_CTOR_P (name))
    2367                 :             :                 /* Dependent inherited ctor. */
    2368                 :      190213 :                 continue;
    2369                 :             : 
    2370                 :     9377901 :               next = strip_using_decl (next);
    2371                 :     9377901 :               if (TREE_CODE (next) == USING_DECL)
    2372                 :             :                 {
    2373                 :     7647005 :                   to_using = next;
    2374                 :     7647005 :                   continue;
    2375                 :             :                 }
    2376                 :             : 
    2377                 :     1730896 :               if (is_overloaded_fn (next))
    2378                 :     1381833 :                 continue;
    2379                 :             :             }
    2380                 :             : 
    2381                 :   221962623 :           if (DECL_DECLARES_TYPE_P (next))
    2382                 :             :             {
    2383                 :    65747026 :               to_type = next;
    2384                 :    65747026 :               continue;
    2385                 :             :             }
    2386                 :             : 
    2387                 :   156215597 :           if (name_independent_decl_p (next))
    2388                 :         137 :             name_independent = jx + 1;
    2389                 :   156215460 :           else if (!current)
    2390                 :   155952538 :             current = next;
    2391                 :             :         }
    2392                 :             : 
    2393                 :   227429122 :       if (to_using)
    2394                 :             :         {
    2395                 :     7617996 :           if (!current)
    2396                 :             :             current = to_using;
    2397                 :             :           else
    2398                 :     1749810 :             current = ovl_make (to_using, current);
    2399                 :             :         }
    2400                 :             : 
    2401                 :   227429122 :       if (to_type)
    2402                 :             :         {
    2403                 :    65588371 :           if (!current)
    2404                 :             :             current = to_type;
    2405                 :             :           else
    2406                 :         208 :             current = stat_hack (current, to_type);
    2407                 :             :         }
    2408                 :             : 
    2409                 :   227429259 :       for (unsigned kx = name_independent; kx > ix; --kx)
    2410                 :         137 :         if (!current)
    2411                 :          83 :           current = (*member_vec)[kx - 1];
    2412                 :          54 :         else if (current == to_type)
    2413                 :           6 :           current = stat_hack ((*member_vec)[kx - 1], to_type);
    2414                 :             :         else
    2415                 :             :           {
    2416                 :          48 :             current = ovl_make ((*member_vec)[kx - 1], current);
    2417                 :          48 :             OVL_NAME_INDEPENDENT_DECL_P (current) = 1;
    2418                 :             :           }
    2419                 :             : 
    2420                 :   227429122 :       if (current)
    2421                 :             :         {
    2422                 :   227408970 :           if (marker)
    2423                 :             :             {
    2424                 :     1265991 :               OVL_CHAIN (marker) = current;
    2425                 :     1265991 :               current = marker;
    2426                 :             :             }
    2427                 :   227408970 :           (*member_vec)[store++] = current;
    2428                 :             :         }
    2429                 :             :     }
    2430                 :             : 
    2431                 :    23665720 :   while (store++ < len)
    2432                 :     3772704 :     member_vec->pop ();
    2433                 :             : }
    2434                 :             : 
    2435                 :             : /* Add the non-function members to CLASSTYPE_MEMBER_VEC.  If there is
    2436                 :             :    no existing MEMBER_VEC and fewer than 8 fields, do nothing.  We
    2437                 :             :    know there must be at least 1 field -- the self-reference
    2438                 :             :    TYPE_DECL, except for anon aggregates, which will have at least
    2439                 :             :    one field anyway.  If EXTRA < 0, always create the vector.  */
    2440                 :             : 
    2441                 :             : vec<tree, va_gc> *
    2442                 :    55153959 : set_class_bindings (tree klass, int extra)
    2443                 :             : {
    2444                 :    55153959 :   unsigned n_fields = count_class_fields (klass);
    2445                 :    55153959 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    2446                 :             : 
    2447                 :    55153959 :   if (member_vec || n_fields >= 8 || extra < 0)
    2448                 :             :     {
    2449                 :             :       /* Append the new fields.  */
    2450                 :    19892992 :       vec_safe_reserve_exact (member_vec, n_fields + (extra >= 0 ? extra : 0));
    2451                 :    19892992 :       member_vec_append_class_fields (member_vec, klass);
    2452                 :             :     }
    2453                 :             : 
    2454                 :    55153959 :   if (member_vec)
    2455                 :             :     {
    2456                 :    19892992 :       CLASSTYPE_MEMBER_VEC (klass) = member_vec;
    2457                 :    19892992 :       member_vec->qsort (member_name_cmp);
    2458                 :    19892992 :       member_vec_dedup (member_vec);
    2459                 :             :     }
    2460                 :             : 
    2461                 :    55153959 :   return member_vec;
    2462                 :             : }
    2463                 :             : 
    2464                 :             : /* Insert lately defined enum ENUMTYPE into KLASS for the sorted case.  */
    2465                 :             : 
    2466                 :             : void
    2467                 :          42 : insert_late_enum_def_bindings (tree klass, tree enumtype)
    2468                 :             : {
    2469                 :          42 :   int n_fields;
    2470                 :          42 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    2471                 :             : 
    2472                 :             :   /* The enum bindings will already be on the TYPE_FIELDS, so don't
    2473                 :             :      count them twice.  */
    2474                 :          42 :   if (!member_vec)
    2475                 :          21 :     n_fields = count_class_fields (klass);
    2476                 :             :   else
    2477                 :          21 :     n_fields = list_length (TYPE_VALUES (enumtype));
    2478                 :             : 
    2479                 :          42 :   if (member_vec || n_fields >= 8)
    2480                 :             :     {
    2481                 :          27 :       vec_safe_reserve_exact (member_vec, n_fields);
    2482                 :          27 :       if (CLASSTYPE_MEMBER_VEC (klass))
    2483                 :          21 :         member_vec_append_enum_values (member_vec, enumtype);
    2484                 :             :       else
    2485                 :           6 :         member_vec_append_class_fields (member_vec, klass);
    2486                 :          27 :       CLASSTYPE_MEMBER_VEC (klass) = member_vec;
    2487                 :          27 :       member_vec->qsort (member_name_cmp);
    2488                 :          27 :       member_vec_dedup (member_vec);
    2489                 :             :     }
    2490                 :          42 : }
    2491                 :             : 
    2492                 :             : /* The binding oracle; see cp-tree.h.  */
    2493                 :             : 
    2494                 :             : cp_binding_oracle_function *cp_binding_oracle;
    2495                 :             : 
    2496                 :             : /* If we have a binding oracle, ask it for all namespace-scoped
    2497                 :             :    definitions of NAME.  */
    2498                 :             : 
    2499                 :             : static inline void
    2500                 :  4207519775 : query_oracle (tree name)
    2501                 :             : {
    2502                 :  4207519775 :   if (!cp_binding_oracle)
    2503                 :             :     return;
    2504                 :             : 
    2505                 :             :   /* LOOKED_UP holds the set of identifiers that we have already
    2506                 :             :      looked up with the oracle.  */
    2507                 :           0 :   static hash_set<tree> looked_up;
    2508                 :           0 :   if (looked_up.add (name))
    2509                 :             :     return;
    2510                 :             : 
    2511                 :           0 :   cp_binding_oracle (CP_ORACLE_IDENTIFIER, name);
    2512                 :             : }
    2513                 :             : 
    2514                 :             : #ifndef ENABLE_SCOPE_CHECKING
    2515                 :             : #  define ENABLE_SCOPE_CHECKING 0
    2516                 :             : #else
    2517                 :             : #  define ENABLE_SCOPE_CHECKING 1
    2518                 :             : #endif
    2519                 :             : 
    2520                 :             : /* A free list of "cxx_binding"s, connected by their PREVIOUS.  */
    2521                 :             : 
    2522                 :             : static GTY((deletable)) cxx_binding *free_bindings;
    2523                 :             : 
    2524                 :             : /* Initialize VALUE and TYPE field for BINDING, and set the PREVIOUS
    2525                 :             :    field to NULL.  */
    2526                 :             : 
    2527                 :             : static inline void
    2528                 :  1160127407 : cxx_binding_init (cxx_binding *binding, tree value, tree type)
    2529                 :             : {
    2530                 :  1160127407 :   binding->value = value;
    2531                 :  1160127407 :   binding->type = type;
    2532                 :  1160127407 :   binding->previous = NULL;
    2533                 :             : }
    2534                 :             : 
    2535                 :             : /* (GC)-allocate a binding object with VALUE and TYPE member initialized.  */
    2536                 :             : 
    2537                 :             : static cxx_binding *
    2538                 :  1160127407 : cxx_binding_make (tree value, tree type)
    2539                 :             : {
    2540                 :  1160127407 :   cxx_binding *binding = free_bindings;
    2541                 :             : 
    2542                 :  1160127407 :   if (binding)
    2543                 :  1151049974 :     free_bindings = binding->previous;
    2544                 :             :   else
    2545                 :     9077433 :     binding = ggc_alloc<cxx_binding> ();
    2546                 :             : 
    2547                 :             :   /* Clear flags by default.  */
    2548                 :  1160127407 :   LOCAL_BINDING_P (binding) = false;
    2549                 :  1160127407 :   INHERITED_VALUE_BINDING_P (binding) = false;
    2550                 :  1160127407 :   HIDDEN_TYPE_BINDING_P (binding) = false;
    2551                 :             : 
    2552                 :  1160127407 :   cxx_binding_init (binding, value, type);
    2553                 :             : 
    2554                 :  1160127407 :   return binding;
    2555                 :             : }
    2556                 :             : 
    2557                 :             : /* Put BINDING back on the free list.  */
    2558                 :             : 
    2559                 :             : static inline void
    2560                 :  1160123604 : cxx_binding_free (cxx_binding *binding)
    2561                 :             : {
    2562                 :  1160123604 :   binding->scope = NULL;
    2563                 :  1160123604 :   binding->previous = free_bindings;
    2564                 :  1160123604 :   free_bindings = binding;
    2565                 :   767330230 : }
    2566                 :             : 
    2567                 :             : /* Create a new binding for NAME (with the indicated VALUE and TYPE
    2568                 :             :    bindings) in the class scope indicated by SCOPE.  */
    2569                 :             : 
    2570                 :             : static cxx_binding *
    2571                 :   392797149 : new_class_binding (tree name, tree value, tree type, cp_binding_level *scope)
    2572                 :             : {
    2573                 :   392797149 :   cp_class_binding cb = {cxx_binding_make (value, type), name};
    2574                 :   392797149 :   cxx_binding *binding = cb.base;
    2575                 :   392797149 :   vec_safe_push (scope->class_shadowed, cb);
    2576                 :   392797149 :   binding->scope = scope;
    2577                 :   392797149 :   return binding;
    2578                 :             : }
    2579                 :             : 
    2580                 :             : /* Make DECL the innermost binding for ID.  The LEVEL is the binding
    2581                 :             :    level at which this declaration is being bound.  */
    2582                 :             : 
    2583                 :             : void
    2584                 :   261514723 : push_binding (tree id, tree decl, cp_binding_level* level)
    2585                 :             : {
    2586                 :   261514723 :   cxx_binding *binding;
    2587                 :             : 
    2588                 :   261514723 :   if (level != class_binding_level)
    2589                 :             :     {
    2590                 :      653508 :       binding = cxx_binding_make (decl, NULL_TREE);
    2591                 :      653508 :       binding->scope = level;
    2592                 :             :     }
    2593                 :             :   else
    2594                 :   260861215 :     binding = new_class_binding (id, decl, /*type=*/NULL_TREE, level);
    2595                 :             : 
    2596                 :             :   /* Now, fill in the binding information.  */
    2597                 :   261514723 :   binding->previous = IDENTIFIER_BINDING (id);
    2598                 :   261514723 :   LOCAL_BINDING_P (binding) = (level != class_binding_level);
    2599                 :             : 
    2600                 :             :   /* And put it on the front of the list of bindings for ID.  */
    2601                 :   261514723 :   IDENTIFIER_BINDING (id) = binding;
    2602                 :   261514723 : }
    2603                 :             : 
    2604                 :             : /* Remove the binding for DECL which should be the innermost binding
    2605                 :             :    for ID.  */
    2606                 :             : 
    2607                 :             : void
    2608                 :   791271495 : pop_local_binding (tree id, tree decl)
    2609                 :             : {
    2610                 :  1559280191 :   if (!id || IDENTIFIER_ANON_P (id))
    2611                 :             :     /* It's easiest to write the loops that call this function without
    2612                 :             :        checking whether or not the entities involved have names.  We
    2613                 :             :        get here for such an entity.  */
    2614                 :             :     return;
    2615                 :             : 
    2616                 :             :   /* Get the innermost binding for ID.  */
    2617                 :   767330503 :   cxx_binding *binding = IDENTIFIER_BINDING (id);
    2618                 :             : 
    2619                 :             :   /* The name should be bound.  */
    2620                 :   767330503 :   gcc_assert (binding != NULL);
    2621                 :             : 
    2622                 :             :   /* The DECL will be either the ordinary binding or the type binding
    2623                 :             :      for this identifier.  Remove that binding.  We don't have to
    2624                 :             :      clear HIDDEN_TYPE_BINDING_P, as the whole binding will be going
    2625                 :             :      away.  */
    2626                 :   767330503 :   if (binding->value == decl)
    2627                 :   767330110 :     binding->value = NULL_TREE;
    2628                 :         393 :   else if (binding->type == decl)
    2629                 :         186 :     binding->type = NULL_TREE;
    2630                 :             :   else
    2631                 :             :     {
    2632                 :             :       /* Name-independent variable was found after at least one declaration
    2633                 :             :          with the same name.  */
    2634                 :         207 :       gcc_assert (TREE_CODE (binding->value) == TREE_LIST);
    2635                 :         207 :       if (TREE_VALUE (binding->value) != decl)
    2636                 :             :         {
    2637                 :          75 :           binding->value = nreverse (binding->value);
    2638                 :             :           /* Skip over TREE_LISTs added in pushdecl for check_local_shadow
    2639                 :             :              detected declarations, formerly at the tail, now at the start
    2640                 :             :              of the list.  */
    2641                 :          75 :           while (TREE_PURPOSE (binding->value) == error_mark_node)
    2642                 :           0 :             binding->value = TREE_CHAIN (binding->value);
    2643                 :             :         }
    2644                 :         207 :       gcc_assert (TREE_VALUE (binding->value) == decl);
    2645                 :         207 :       binding->value = TREE_CHAIN (binding->value);
    2646                 :         207 :       while (binding->value
    2647                 :         252 :              && TREE_PURPOSE (binding->value) == error_mark_node)
    2648                 :          45 :         binding->value = TREE_CHAIN (binding->value);
    2649                 :             :     }
    2650                 :             : 
    2651                 :   767330503 :   if (!binding->value && !binding->type)
    2652                 :             :     {
    2653                 :             :       /* We're completely done with the innermost binding for this
    2654                 :             :          identifier.  Unhook it from the list of bindings.  */
    2655                 :   767330230 :       IDENTIFIER_BINDING (id) = binding->previous;
    2656                 :             : 
    2657                 :             :       /* Add it to the free list.  */
    2658                 :   767330230 :       cxx_binding_free (binding);
    2659                 :             :     }
    2660                 :             : }
    2661                 :             : 
    2662                 :             : /* Remove the bindings for the decls of the current level and leave
    2663                 :             :    the current scope.  */
    2664                 :             : 
    2665                 :             : void
    2666                 :   178575171 : pop_bindings_and_leave_scope (void)
    2667                 :             : {
    2668                 :   411287993 :   for (tree t = get_local_decls (); t; t = DECL_CHAIN (t))
    2669                 :             :     {
    2670                 :   232712822 :       tree decl = TREE_CODE (t) == TREE_LIST ? TREE_VALUE (t) : t;
    2671                 :   465425644 :       tree name = OVL_NAME (decl);
    2672                 :             : 
    2673                 :   232712822 :       pop_local_binding (name, decl);
    2674                 :             :     }
    2675                 :             : 
    2676                 :   178575171 :   leave_scope ();
    2677                 :   178575171 : }
    2678                 :             : 
    2679                 :             : /* Strip non dependent using declarations. If DECL is dependent,
    2680                 :             :    surreptitiously create a typename_type and return it.  */
    2681                 :             : 
    2682                 :             : tree
    2683                 :  3960376203 : strip_using_decl (tree decl)
    2684                 :             : {
    2685                 :  3960376203 :   if (decl == NULL_TREE)
    2686                 :             :     return NULL_TREE;
    2687                 :             : 
    2688                 :  3965524265 :   while (TREE_CODE (decl) == USING_DECL && !DECL_DEPENDENT_P (decl))
    2689                 :     5166666 :     decl = USING_DECL_DECLS (decl);
    2690                 :             : 
    2691                 :    19069926 :   if (TREE_CODE (decl) == USING_DECL && DECL_DEPENDENT_P (decl)
    2692                 :  3979427525 :       && USING_DECL_TYPENAME_P (decl))
    2693                 :             :     {
    2694                 :             :       /* We have found a type introduced by a using
    2695                 :             :          declaration at class scope that refers to a dependent
    2696                 :             :          type.
    2697                 :             :              
    2698                 :             :          using typename :: [opt] nested-name-specifier unqualified-id ;
    2699                 :             :       */
    2700                 :      140693 :       decl = make_typename_type (USING_DECL_SCOPE (decl),
    2701                 :      140693 :                                  DECL_NAME (decl),
    2702                 :             :                                  typename_type, tf_error);
    2703                 :      140693 :       if (decl != error_mark_node)
    2704                 :      140693 :         decl = TYPE_NAME (decl);
    2705                 :             :     }
    2706                 :             : 
    2707                 :             :   return decl;
    2708                 :             : }
    2709                 :             : 
    2710                 :             : /* Return true if OVL is an overload for an anticipated builtin.  */
    2711                 :             : 
    2712                 :             : static bool
    2713                 :    23173236 : anticipated_builtin_p (tree ovl)
    2714                 :             : {
    2715                 :    23173236 :   return (TREE_CODE (ovl) == OVERLOAD
    2716                 :    21094593 :           && OVL_HIDDEN_P (ovl)
    2717                 :    29113813 :           && DECL_IS_UNDECLARED_BUILTIN (OVL_FUNCTION (ovl)));
    2718                 :             : }
    2719                 :             : 
    2720                 :             : /* BINDING records an existing declaration for a name in the current scope.
    2721                 :             :    But, DECL is another declaration for that same identifier in the
    2722                 :             :    same scope.  This is the `struct stat' hack whereby a non-typedef
    2723                 :             :    class name or enum-name can be bound at the same level as some other
    2724                 :             :    kind of entity.
    2725                 :             :    3.3.7/1
    2726                 :             : 
    2727                 :             :      A class name (9.1) or enumeration name (7.2) can be hidden by the
    2728                 :             :      name of an object, function, or enumerator declared in the same scope.
    2729                 :             :      If a class or enumeration name and an object, function, or enumerator
    2730                 :             :      are declared in the same scope (in any order) with the same name, the
    2731                 :             :      class or enumeration name is hidden wherever the object, function, or
    2732                 :             :      enumerator name is visible.
    2733                 :             : 
    2734                 :             :    It's the responsibility of the caller to check that
    2735                 :             :    inserting this name is valid here.  Returns nonzero if the new binding
    2736                 :             :    was successful.  */
    2737                 :             : 
    2738                 :             : static bool
    2739                 :      279072 : supplement_binding (cxx_binding *binding, tree decl)
    2740                 :             : {
    2741                 :      279072 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    2742                 :             : 
    2743                 :      279072 :   tree bval = binding->value;
    2744                 :      279072 :   bool ok = true;
    2745                 :      279072 :   if (bval
    2746                 :      279072 :       && TREE_CODE (bval) == TREE_LIST
    2747                 :      279078 :       && name_independent_decl_p (TREE_VALUE (bval)))
    2748                 :             :     bval = TREE_VALUE (bval);
    2749                 :      279072 :   tree target_bval = strip_using_decl (bval);
    2750                 :      279072 :   tree target_decl = strip_using_decl (decl);
    2751                 :             : 
    2752                 :       15769 :   if (TREE_CODE (target_decl) == TYPE_DECL && DECL_ARTIFICIAL (target_decl)
    2753                 :       15569 :       && target_decl != target_bval
    2754                 :      294629 :       && (TREE_CODE (target_bval) != TYPE_DECL
    2755                 :             :           /* We allow pushing an enum multiple times in a class
    2756                 :             :              template in order to handle late matching of underlying
    2757                 :             :              type on an opaque-enum-declaration followed by an
    2758                 :             :              enum-specifier.  */
    2759                 :       15421 :           || (processing_template_decl
    2760                 :        2007 :               && TREE_CODE (TREE_TYPE (target_decl)) == ENUMERAL_TYPE
    2761                 :           0 :               && TREE_CODE (TREE_TYPE (target_bval)) == ENUMERAL_TYPE
    2762                 :           0 :               && (dependent_type_p (ENUM_UNDERLYING_TYPE
    2763                 :             :                                     (TREE_TYPE (target_decl)))
    2764                 :           0 :                   || dependent_type_p (ENUM_UNDERLYING_TYPE
    2765                 :             :                                        (TREE_TYPE (target_bval)))))))
    2766                 :             :     /* The new name is the type name.  */
    2767                 :         136 :     binding->type = decl;
    2768                 :      278936 :   else if (/* TARGET_BVAL is null when push_class_level_binding moves
    2769                 :             :               an inherited type-binding out of the way to make room
    2770                 :             :               for a new value binding.  */
    2771                 :             :            !target_bval
    2772                 :             :            /* TARGET_BVAL is error_mark_node when TARGET_DECL's name
    2773                 :             :               has been used in a non-class scope prior declaration.
    2774                 :             :               In that case, we should have already issued a
    2775                 :             :               diagnostic; for graceful error recovery purpose, pretend
    2776                 :             :               this was the intended declaration for that name.  */
    2777                 :      278936 :            || target_bval == error_mark_node
    2778                 :             :            /* If TARGET_BVAL is anticipated but has not yet been
    2779                 :             :               declared, pretend it is not there at all.  */
    2780                 :      557872 :            || anticipated_builtin_p (target_bval))
    2781                 :           0 :     binding->value = decl;
    2782                 :      278936 :   else if (TREE_CODE (target_bval) == TYPE_DECL
    2783                 :       15854 :            && DECL_ARTIFICIAL (target_bval)
    2784                 :       15810 :            && target_decl != target_bval
    2785                 :      294734 :            && (TREE_CODE (target_decl) != TYPE_DECL
    2786                 :       15577 :                || same_type_p (TREE_TYPE (target_decl),
    2787                 :             :                                TREE_TYPE (target_bval))))
    2788                 :             :     {
    2789                 :             :       /* The old binding was a type name.  It was placed in
    2790                 :             :          VALUE field because it was thought, at the point it was
    2791                 :             :          declared, to be the only entity with such a name.  Move the
    2792                 :             :          type name into the type slot; it is now hidden by the new
    2793                 :             :          binding.  */
    2794                 :       15766 :       binding->type = bval;
    2795                 :       15766 :       binding->value = decl;
    2796                 :       15766 :       binding->value_is_inherited = false;
    2797                 :             :     }
    2798                 :      263170 :   else if (TREE_CODE (target_bval) == TYPE_DECL
    2799                 :          88 :            && TREE_CODE (target_decl) == TYPE_DECL
    2800                 :          88 :            && DECL_NAME (target_decl) == DECL_NAME (target_bval)
    2801                 :          88 :            && binding->scope->kind != sk_class
    2802                 :      263171 :            && (same_type_p (TREE_TYPE (target_decl), TREE_TYPE (target_bval))
    2803                 :             :                /* If either type involves template parameters, we must
    2804                 :             :                   wait until instantiation.  */
    2805                 :           0 :                || uses_template_parms (TREE_TYPE (target_decl))
    2806                 :           0 :                || uses_template_parms (TREE_TYPE (target_bval))))
    2807                 :             :     /* We have two typedef-names, both naming the same type to have
    2808                 :             :        the same name.  In general, this is OK because of:
    2809                 :             : 
    2810                 :             :          [dcl.typedef]
    2811                 :             : 
    2812                 :             :          In a given scope, a typedef specifier can be used to redefine
    2813                 :             :          the name of any type declared in that scope to refer to the
    2814                 :             :          type to which it already refers.
    2815                 :             : 
    2816                 :             :        However, in class scopes, this rule does not apply due to the
    2817                 :             :        stricter language in [class.mem] prohibiting redeclarations of
    2818                 :             :        members.  */
    2819                 :             :     ok = false;
    2820                 :             :   /* There can be two block-scope declarations of the same variable,
    2821                 :             :      so long as they are `extern' declarations.  However, there cannot
    2822                 :             :      be two declarations of the same static data member:
    2823                 :             : 
    2824                 :             :        [class.mem]
    2825                 :             : 
    2826                 :             :        A member shall not be declared twice in the
    2827                 :             :        member-specification.  */
    2828                 :      263169 :   else if (VAR_P (target_decl)
    2829                 :           8 :            && VAR_P (target_bval)
    2830                 :           8 :            && DECL_EXTERNAL (target_decl) && DECL_EXTERNAL (target_bval)
    2831                 :      263177 :            && !DECL_CLASS_SCOPE_P (target_decl))
    2832                 :             :     {
    2833                 :           0 :       duplicate_decls (decl, binding->value);
    2834                 :           0 :       ok = false;
    2835                 :             :     }
    2836                 :      263169 :   else if (TREE_CODE (decl) == NAMESPACE_DECL
    2837                 :           0 :            && TREE_CODE (bval) == NAMESPACE_DECL
    2838                 :           0 :            && DECL_NAMESPACE_ALIAS (decl)
    2839                 :           0 :            && DECL_NAMESPACE_ALIAS (bval)
    2840                 :      263169 :            && ORIGINAL_NAMESPACE (bval) == ORIGINAL_NAMESPACE (decl))
    2841                 :             :     /* [namespace.alias]
    2842                 :             : 
    2843                 :             :       In a declarative region, a namespace-alias-definition can be
    2844                 :             :       used to redefine a namespace-alias declared in that declarative
    2845                 :             :       region to refer only to the namespace to which it already
    2846                 :             :       refers.  */
    2847                 :             :     ok = false;
    2848                 :      263169 :   else if (TREE_CODE (bval) == USING_DECL
    2849                 :      263169 :            && CONST_DECL_USING_P (decl))
    2850                 :             :     /* Let the clone hide the using-decl that introduced it.  */
    2851                 :      262936 :     binding->value = decl;
    2852                 :         233 :   else if (name_independent_decl_p (decl))
    2853                 :             :     {
    2854                 :          63 :       if (cxx_dialect < cxx26)
    2855                 :          63 :         pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
    2856                 :             :                  "name-independent declarations only available with "
    2857                 :             :                  "%<-std=c++2c%> or %<-std=gnu++2c%>");
    2858                 :          63 :       binding->value = name_lookup::ambiguous (decl, binding->value);
    2859                 :             :     }
    2860                 :             :   else
    2861                 :             :     {
    2862                 :         170 :       if (!error_operand_p (bval))
    2863                 :         170 :         diagnose_name_conflict (decl, bval);
    2864                 :             :       ok = false;
    2865                 :             :     }
    2866                 :             : 
    2867                 :      558144 :   return ok;
    2868                 :      279072 : }
    2869                 :             : 
    2870                 :             : /* Diagnose a name conflict between DECL and BVAL.
    2871                 :             : 
    2872                 :             :    This is non-static so maybe_push_used_methods can use it and avoid changing
    2873                 :             :    the diagnostic for inherit/using4.C; otherwise it should not be used from
    2874                 :             :    outside this file.  */
    2875                 :             : 
    2876                 :             : void
    2877                 :         306 : diagnose_name_conflict (tree decl, tree bval)
    2878                 :             : {
    2879                 :         306 :   if (TREE_CODE (decl) == TREE_CODE (bval)
    2880                 :         228 :       && TREE_CODE (decl) != NAMESPACE_DECL
    2881                 :         220 :       && !DECL_DECLARES_FUNCTION_P (decl)
    2882                 :         156 :       && (TREE_CODE (decl) != TYPE_DECL
    2883                 :          28 :           || DECL_ARTIFICIAL (decl) == DECL_ARTIFICIAL (bval))
    2884                 :         458 :       && CP_DECL_CONTEXT (decl) == CP_DECL_CONTEXT (bval))
    2885                 :             :     {
    2886                 :         103 :       if (concept_definition_p (decl))
    2887                 :           2 :         error ("redeclaration of %q#D with different template parameters",
    2888                 :             :                decl);
    2889                 :             :       else
    2890                 :         101 :         error ("redeclaration of %q#D", decl);
    2891                 :             :     }
    2892                 :             :   else
    2893                 :         203 :     error ("%q#D conflicts with a previous declaration", decl);
    2894                 :             : 
    2895                 :         306 :   inform (location_of (bval), "previous declaration %q#D", bval);
    2896                 :         306 : }
    2897                 :             : 
    2898                 :             : /* Replace BINDING's current value on its scope's name list with
    2899                 :             :    NEWVAL.  */
    2900                 :             : 
    2901                 :             : static void
    2902                 :         124 : update_local_overload (cxx_binding *binding, tree newval)
    2903                 :             : {
    2904                 :         124 :   tree *d;
    2905                 :             : 
    2906                 :         142 :   for (d = &binding->scope->names; ; d = &TREE_CHAIN (*d))
    2907                 :         142 :     if (*d == binding->value)
    2908                 :             :       {
    2909                 :             :         /* Stitch new list node in.  */
    2910                 :          73 :         *d = tree_cons (DECL_NAME (*d), NULL_TREE, TREE_CHAIN (*d));
    2911                 :          73 :         break;
    2912                 :             :       }
    2913                 :          69 :     else if (TREE_CODE (*d) == TREE_LIST && TREE_VALUE (*d) == binding->value)
    2914                 :             :       break;
    2915                 :             : 
    2916                 :         124 :   TREE_VALUE (*d) = newval;
    2917                 :         124 : }
    2918                 :             : 
    2919                 :             : /* Compares the parameter-type-lists of ONE and TWO and
    2920                 :             :    returns false if they are different.  If the DECLs are template
    2921                 :             :    functions, the return types and the template parameter lists are
    2922                 :             :    compared too (DR 565).  */
    2923                 :             : 
    2924                 :             : static bool
    2925                 :     3656893 : matching_fn_p (tree one, tree two)
    2926                 :             : {
    2927                 :     3656893 :   if (TREE_CODE (one) != TREE_CODE (two))
    2928                 :             :     return false;
    2929                 :             : 
    2930                 :     1844619 :   if (!compparms (TYPE_ARG_TYPES (TREE_TYPE (one)),
    2931                 :     1844619 :                   TYPE_ARG_TYPES (TREE_TYPE (two))))
    2932                 :             :     return false;
    2933                 :             : 
    2934                 :         125 :   if (TREE_CODE (one) == TEMPLATE_DECL)
    2935                 :             :     {
    2936                 :             :       /* Compare template parms.  */
    2937                 :          90 :       if (!comp_template_parms (DECL_TEMPLATE_PARMS (one),
    2938                 :          45 :                                 DECL_TEMPLATE_PARMS (two)))
    2939                 :             :         return false;
    2940                 :             : 
    2941                 :             :       /* And return type.  */
    2942                 :          21 :       if (!same_type_p (TREE_TYPE (TREE_TYPE (one)),
    2943                 :             :                         TREE_TYPE (TREE_TYPE (two))))
    2944                 :             :         return false;
    2945                 :             :     }
    2946                 :             : 
    2947                 :          89 :   if (!equivalently_constrained (one, two))
    2948                 :             :     return false;
    2949                 :             : 
    2950                 :             :   return true;
    2951                 :             : }
    2952                 :             : 
    2953                 :             : /* Push DECL into nonclass LEVEL BINDING or SLOT.  OLD is the current
    2954                 :             :    binding value (possibly with anticipated builtins stripped).
    2955                 :             :    Diagnose conflicts and return updated decl.  */
    2956                 :             : 
    2957                 :             : static tree
    2958                 :  1117601567 : update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot,
    2959                 :             :                 tree old, tree decl, bool hiding = false)
    2960                 :             : {
    2961                 :  1117601567 :   tree old_type = NULL_TREE;
    2962                 :  1117601567 :   bool hide_type = false;
    2963                 :  1117601567 :   bool hide_value = false;
    2964                 :  1117601567 :   bool name_independent_p = false;
    2965                 :             : 
    2966                 :  1117601567 :   if (!slot)
    2967                 :             :     {
    2968                 :   766677098 :       old_type = binding->type;
    2969                 :   766677098 :       hide_type = HIDDEN_TYPE_BINDING_P (binding);
    2970                 :   766677098 :       if (!old_type)
    2971                 :   766677094 :         hide_value = hide_type, hide_type = false;
    2972                 :   766677098 :       name_independent_p = name_independent_decl_p (decl);
    2973                 :             :     }
    2974                 :   350924469 :   else if (STAT_HACK_P (*slot))
    2975                 :             :     {
    2976                 :          79 :       old_type = STAT_TYPE (*slot);
    2977                 :          79 :       hide_type = STAT_TYPE_HIDDEN_P (*slot);
    2978                 :          79 :       hide_value = STAT_DECL_HIDDEN_P (*slot);
    2979                 :             :     }
    2980                 :             : 
    2981                 :  1117601567 :   tree to_val = decl;
    2982                 :  1117601567 :   tree to_type = old_type;
    2983                 :  1117601567 :   bool local_overload = false;
    2984                 :             : 
    2985                 :  1117601567 :   gcc_assert (!level || level->kind == sk_namespace ? !binding
    2986                 :             :               : level->kind != sk_class && !slot);
    2987                 :             : 
    2988                 :  1117601567 :   if (old == error_mark_node)
    2989                 :      100623 :     old = NULL_TREE;
    2990                 :             : 
    2991                 :  1117601567 :   if (DECL_IMPLICIT_TYPEDEF_P (decl))
    2992                 :             :     {
    2993                 :             :       /* Pushing an artificial decl.  We should not find another
    2994                 :             :          artificial decl here already -- lookup_elaborated_type will
    2995                 :             :          have already found it.  */
    2996                 :     4953163 :       gcc_checking_assert (!to_type
    2997                 :             :                            && !(old && DECL_IMPLICIT_TYPEDEF_P (old)));
    2998                 :             : 
    2999                 :             :       if (old)
    3000                 :             :         {
    3001                 :             :           /* Put DECL into the type slot.  */
    3002                 :             :           gcc_checking_assert (!to_type);
    3003                 :             :           hide_type = hiding;
    3004                 :             :           to_type = decl;
    3005                 :             :           to_val = old;
    3006                 :             :         }
    3007                 :             :       else
    3008                 :             :         hide_value = hiding;
    3009                 :             : 
    3010                 :     4953163 :       goto done;
    3011                 :             :     }
    3012                 :             : 
    3013                 :  1112648404 :   if (old && DECL_IMPLICIT_TYPEDEF_P (old))
    3014                 :             :     {
    3015                 :             :       /* OLD is an implicit typedef.  Move it to to_type.  */
    3016                 :       75429 :       gcc_checking_assert (!to_type);
    3017                 :             : 
    3018                 :             :       to_type = old;
    3019                 :             :       hide_type = hide_value;
    3020                 :             :       old = NULL_TREE;
    3021                 :             :       hide_value = false;
    3022                 :             :     }
    3023                 :             : 
    3024                 :  1112648404 :   if (DECL_DECLARES_FUNCTION_P (decl))
    3025                 :             :     {
    3026                 :   320586702 :       if (!old)
    3027                 :             :         ;
    3028                 :    22660361 :       else if (OVL_P (old))
    3029                 :             :         {
    3030                 :   601123576 :           for (ovl_iterator iter (old); iter; ++iter)
    3031                 :             :             {
    3032                 :   291306357 :               tree fn = *iter;
    3033                 :             : 
    3034                 :   291306357 :               if (iter.using_p () && matching_fn_p (fn, decl))
    3035                 :             :                 {
    3036                 :          44 :                   gcc_checking_assert (!iter.hidden_p ());
    3037                 :             :                   /* If a function declaration in namespace scope or
    3038                 :             :                      block scope has the same name and the same
    3039                 :             :                      parameter-type- list (8.3.5) as a function
    3040                 :             :                      introduced by a using-declaration, and the
    3041                 :             :                      declarations do not declare the same function,
    3042                 :             :                      the program is ill-formed.  [namespace.udecl]/14 */
    3043                 :          44 :                   if (tree match = duplicate_decls (decl, fn, hiding))
    3044                 :           8 :                     return match;
    3045                 :             :                   else
    3046                 :             :                     /* FIXME: To preserve existing error behavior, we
    3047                 :             :                        still push the decl.  This might change.  */
    3048                 :          36 :                     diagnose_name_conflict (decl, fn);
    3049                 :             :                 }
    3050                 :             :             }
    3051                 :    22660353 :         }
    3052                 :             :       else
    3053                 :           0 :         goto conflict;
    3054                 :             : 
    3055                 :   320586694 :       if (to_type != old_type
    3056                 :       38590 :           && warn_shadow
    3057                 :           8 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (to_type))
    3058                 :   320586702 :           && !(DECL_IN_SYSTEM_HEADER (decl)
    3059                 :           0 :                && DECL_IN_SYSTEM_HEADER (to_type)))
    3060                 :           8 :         warning (OPT_Wshadow, "%q#D hides constructor for %q#D",
    3061                 :             :                  decl, to_type);
    3062                 :             : 
    3063                 :   320586694 :       local_overload = old && level && level->kind != sk_namespace;
    3064                 :   320586694 :       to_val = ovl_insert (decl, old, -int (hiding));
    3065                 :             :     }
    3066                 :   792061702 :   else if (old)
    3067                 :             :     {
    3068                 :         178 :       if (name_independent_p)
    3069                 :         132 :         to_val = name_lookup::ambiguous (decl, old);
    3070                 :          46 :       else if (TREE_CODE (old) != TREE_CODE (decl))
    3071                 :             :         /* Different kinds of decls conflict.  */
    3072                 :           0 :         goto conflict;
    3073                 :          46 :       else if (TREE_CODE (old) == TYPE_DECL)
    3074                 :             :         {
    3075                 :           3 :           if (same_type_p (TREE_TYPE (old), TREE_TYPE (decl)))
    3076                 :             :             /* Two type decls to the same type.  Do nothing.  */
    3077                 :             :             return old;
    3078                 :             :           else
    3079                 :           0 :             goto conflict;
    3080                 :             :         }
    3081                 :          43 :       else if (TREE_CODE (old) == NAMESPACE_DECL)
    3082                 :             :         {
    3083                 :             :           /* Two maybe-aliased namespaces.  If they're to the same target
    3084                 :             :              namespace, that's ok.  */
    3085                 :          12 :           if (ORIGINAL_NAMESPACE (old) != ORIGINAL_NAMESPACE (decl))
    3086                 :           8 :             goto conflict;
    3087                 :             : 
    3088                 :             :           /* The new one must be an alias at this point.  */
    3089                 :           4 :           gcc_assert (DECL_NAMESPACE_ALIAS (decl));
    3090                 :             :           return old;
    3091                 :             :         }
    3092                 :          31 :       else if (TREE_CODE (old) == VAR_DECL)
    3093                 :             :         {
    3094                 :             :           /* There can be two block-scope declarations of the same
    3095                 :             :              variable, so long as they are `extern' declarations.  */
    3096                 :          26 :           if (!DECL_EXTERNAL (old) || !DECL_EXTERNAL (decl))
    3097                 :          19 :             goto conflict;
    3098                 :           7 :           else if (tree match = duplicate_decls (decl, old))
    3099                 :             :             {
    3100                 :           3 :               gcc_checking_assert (!hide_value && !hiding);
    3101                 :             :               return match;
    3102                 :             :             }
    3103                 :             :           else
    3104                 :           4 :             goto conflict;
    3105                 :             :         }
    3106                 :             :       else
    3107                 :             :         {
    3108                 :           5 :         conflict:
    3109                 :          36 :           diagnose_name_conflict (decl, old);
    3110                 :          36 :           to_val = NULL_TREE;
    3111                 :             :         }
    3112                 :             :     }
    3113                 :   792061524 :   else if (hiding)
    3114                 :       25290 :     hide_value = true;
    3115                 :             : 
    3116                 :   792036234 :  done:
    3117                 :  1117601549 :   if (to_val)
    3118                 :             :     {
    3119                 :  1117601513 :       if (local_overload)
    3120                 :             :         {
    3121                 :          76 :           gcc_checking_assert (binding->value && OVL_P (binding->value));
    3122                 :          76 :           update_local_overload (binding, to_val);
    3123                 :             :         }
    3124                 :  1117601437 :       else if (level
    3125                 :  1117601437 :                && !(TREE_CODE (decl) == NAMESPACE_DECL
    3126                 :      737425 :                     && !DECL_NAMESPACE_ALIAS (decl)))
    3127                 :             :         /* Don't add namespaces here.  They're done in
    3128                 :             :            push_namespace.  */
    3129                 :  1116910271 :         add_decl_to_level (level, decl);
    3130                 :             : 
    3131                 :  1117601513 :       if (slot)
    3132                 :             :         {
    3133                 :   350924438 :           if (STAT_HACK_P (*slot))
    3134                 :             :             {
    3135                 :          79 :               STAT_TYPE (*slot) = to_type;
    3136                 :          79 :               STAT_DECL (*slot) = to_val;
    3137                 :          79 :               STAT_TYPE_HIDDEN_P (*slot) = hide_type;
    3138                 :          79 :               STAT_DECL_HIDDEN_P (*slot) = hide_value;
    3139                 :             :             }
    3140                 :   350924359 :           else if (to_type || hide_value)
    3141                 :             :             {
    3142                 :      130031 :               *slot = stat_hack (to_val, to_type);
    3143                 :      130031 :               STAT_TYPE_HIDDEN_P (*slot) = hide_type;
    3144                 :      130031 :               STAT_DECL_HIDDEN_P (*slot) = hide_value;
    3145                 :             :             }
    3146                 :             :           else
    3147                 :             :             {
    3148                 :   350794328 :               gcc_checking_assert (!hide_type);
    3149                 :   350794328 :               *slot = to_val;
    3150                 :             :             }
    3151                 :             :         }
    3152                 :             :       else
    3153                 :             :         {
    3154                 :   766677075 :           binding->type = to_type;
    3155                 :   766677075 :           binding->value = to_val;
    3156                 :   766677075 :           HIDDEN_TYPE_BINDING_P (binding) = hide_type || hide_value;
    3157                 :             :         }
    3158                 :             :     }
    3159                 :             : 
    3160                 :             :   return decl;
    3161                 :             : }
    3162                 :             : 
    3163                 :             : /* Table of identifiers to extern C declarations (or LISTS thereof).  */
    3164                 :             : 
    3165                 :             : static GTY(()) hash_table<named_decl_hash> *extern_c_decls;
    3166                 :             : 
    3167                 :             : /* DECL has C linkage. If we have an existing instance, make sure the
    3168                 :             :    new one is compatible.  Make sure it has the same exception
    3169                 :             :    specification [7.5, 7.6].  Add DECL to the map.  */
    3170                 :             : 
    3171                 :             : static void
    3172                 :   282402802 : check_extern_c_conflict (tree decl)
    3173                 :             : {
    3174                 :             :   /* Ignore artificial or system header decls.  */
    3175                 :   282402802 :   if (DECL_ARTIFICIAL (decl) || DECL_IN_SYSTEM_HEADER (decl))
    3176                 :   282279730 :     return;
    3177                 :             : 
    3178                 :             :   /* This only applies to decls at namespace scope.  */
    3179                 :      123072 :   if (!DECL_NAMESPACE_SCOPE_P (decl))
    3180                 :             :     return;
    3181                 :             : 
    3182                 :      123058 :   if (!extern_c_decls)
    3183                 :       36441 :     extern_c_decls = hash_table<named_decl_hash>::create_ggc (127);
    3184                 :             : 
    3185                 :      123058 :   tree *slot = extern_c_decls
    3186                 :      123058 :     ->find_slot_with_hash (DECL_NAME (decl),
    3187                 :      123058 :                            IDENTIFIER_HASH_VALUE (DECL_NAME (decl)), INSERT);
    3188                 :      123058 :   if (tree old = *slot)
    3189                 :             :     {
    3190                 :         418 :       if (TREE_CODE (old) == OVERLOAD)
    3191                 :          23 :         old = OVL_FUNCTION (old);
    3192                 :             : 
    3193                 :         418 :       int mismatch = 0;
    3194                 :         418 :       if (DECL_CONTEXT (old) == DECL_CONTEXT (decl))
    3195                 :             :         ; /* If they're in the same context, we'll have already complained
    3196                 :             :              about a (possible) mismatch, when inserting the decl.  */
    3197                 :         398 :       else if (!decls_match (decl, old))
    3198                 :             :         mismatch = 1;
    3199                 :         370 :       else if (TREE_CODE (decl) == FUNCTION_DECL
    3200                 :         724 :                && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old)),
    3201                 :         354 :                                       TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
    3202                 :             :                                       ce_normal))
    3203                 :             :         mismatch = -1;
    3204                 :         366 :       else if (DECL_ASSEMBLER_NAME_SET_P (old))
    3205                 :          12 :         SET_DECL_ASSEMBLER_NAME (decl, DECL_ASSEMBLER_NAME (old));
    3206                 :             : 
    3207                 :          12 :       if (mismatch)
    3208                 :             :         {
    3209                 :          32 :           auto_diagnostic_group d;
    3210                 :          32 :           pedwarn (DECL_SOURCE_LOCATION (decl), 0,
    3211                 :             :                    "conflicting C language linkage declaration %q#D", decl);
    3212                 :          32 :           inform (DECL_SOURCE_LOCATION (old),
    3213                 :             :                   "previous declaration %q#D", old);
    3214                 :          32 :           if (mismatch < 0)
    3215                 :           4 :             inform (DECL_SOURCE_LOCATION (decl),
    3216                 :             :                     "due to different exception specifications");
    3217                 :          32 :         }
    3218                 :             :       else
    3219                 :             :         {
    3220                 :         386 :           if (old == *slot)
    3221                 :             :             /* The hash table expects OVERLOADS, so construct one with
    3222                 :             :                OLD as both the function and the chain.  This allocate
    3223                 :             :                an excess OVERLOAD node, but it's rare to have multiple
    3224                 :             :                extern "C" decls of the same name.  And we save
    3225                 :             :                complicating the hash table logic (which is used
    3226                 :             :                elsewhere).  */
    3227                 :         379 :             *slot = ovl_make (old, old);
    3228                 :             : 
    3229                 :         386 :           slot = &OVL_CHAIN (*slot);
    3230                 :             : 
    3231                 :             :           /* Chain it on for c_linkage_binding's use.  */
    3232                 :         386 :           *slot = tree_cons (NULL_TREE, decl, *slot);
    3233                 :             :         }
    3234                 :             :     }
    3235                 :             :   else
    3236                 :      122640 :     *slot = decl;
    3237                 :             : }
    3238                 :             : 
    3239                 :             : /* Returns a list of C-linkage decls with the name NAME.  Used in
    3240                 :             :    c-family/c-pragma.cc to implement redefine_extname pragma.  */
    3241                 :             : 
    3242                 :             : tree
    3243                 :          24 : c_linkage_bindings (tree name)
    3244                 :             : {
    3245                 :          24 :   if (extern_c_decls)
    3246                 :          32 :     if (tree *slot = extern_c_decls
    3247                 :          16 :         ->find_slot_with_hash (name, IDENTIFIER_HASH_VALUE (name), NO_INSERT))
    3248                 :             :       {
    3249                 :           8 :         tree result = *slot;
    3250                 :           8 :         if (TREE_CODE (result) == OVERLOAD)
    3251                 :           4 :           result = OVL_CHAIN (result);
    3252                 :           8 :         return result;
    3253                 :             :       }
    3254                 :             : 
    3255                 :             :   return NULL_TREE;
    3256                 :             : }
    3257                 :             : 
    3258                 :             : /* Subroutine of check_local_shadow.  */
    3259                 :             : 
    3260                 :             : static void
    3261                 :         214 : inform_shadowed (tree shadowed)
    3262                 :             : {
    3263                 :         214 :   inform (DECL_SOURCE_LOCATION (shadowed),
    3264                 :             :           "shadowed declaration is here");
    3265                 :         214 : }
    3266                 :             : 
    3267                 :             : /* DECL is being declared at a local scope.  Emit suitable shadow
    3268                 :             :    warnings.  */
    3269                 :             : 
    3270                 :             : static tree
    3271                 :   766677098 : check_local_shadow (tree decl)
    3272                 :             : {
    3273                 :             :   /* Don't complain about the parms we push and then pop
    3274                 :             :      while tentatively parsing a function declarator.  */
    3275                 :   766677098 :   if (TREE_CODE (decl) == PARM_DECL && !DECL_CONTEXT (decl))
    3276                 :             :     return NULL_TREE;
    3277                 :             : 
    3278                 :   555330917 :   if (DECL_FUNCTION_SCOPE_P (decl))
    3279                 :             :     {
    3280                 :   352899403 :       tree ctx = DECL_CONTEXT (decl);
    3281                 :   705798806 :       if (DECL_CLONED_FUNCTION_P (ctx)
    3282                 :   331639566 :           || DECL_TEMPLATE_INSTANTIATED (ctx)
    3283                 :   283608191 :           || (DECL_LANG_SPECIFIC (ctx)
    3284                 :   283608191 :               && DECL_DEFAULTED_FN (ctx))
    3285                 :   652684054 :           || (LAMBDA_FUNCTION_P (ctx)
    3286                 :     2771620 :               && LAMBDA_EXPR_REGEN_INFO (CLASSTYPE_LAMBDA_EXPR
    3287                 :             :                                          (DECL_CONTEXT (ctx)))))
    3288                 :             :         /* It suffices to check shadowing only when actually parsing.
    3289                 :             :            So punt for clones, instantiations, defaulted functions and
    3290                 :             :            regenerated lambdas.  This optimization helps reduce lazy
    3291                 :             :            loading cascades with modules.  */
    3292                 :             :         return NULL_TREE;
    3293                 :             :     }
    3294                 :             : 
    3295                 :   483983252 :   tree old = NULL_TREE;
    3296                 :   483983252 :   cp_binding_level *old_scope = NULL;
    3297                 :   483983252 :   if (cxx_binding *binding = outer_binding (DECL_NAME (decl), NULL, true))
    3298                 :             :     {
    3299                 :     1395546 :       old = binding->value;
    3300                 :     1395546 :       old_scope = binding->scope;
    3301                 :             :     }
    3302                 :             : 
    3303                 :     1395546 :   if (old
    3304                 :     1395546 :       && (TREE_CODE (old) == PARM_DECL
    3305                 :      616571 :           || VAR_P (old)
    3306                 :      147085 :           || (TREE_CODE (old) == TYPE_DECL
    3307                 :       87399 :               && (!DECL_ARTIFICIAL (old)
    3308                 :       57108 :                   || TREE_CODE (decl) == TYPE_DECL)))
    3309                 :     1335753 :       && DECL_FUNCTION_SCOPE_P (old)
    3310                 :     2644654 :       && (!DECL_ARTIFICIAL (decl)
    3311                 :     1074636 :           || is_capture_proxy (decl)
    3312                 :      289569 :           || DECL_IMPLICIT_TYPEDEF_P (decl)
    3313                 :      289531 :           || (VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))))
    3314                 :             :     {
    3315                 :             :       /* DECL shadows a local thing possibly of interest.  */
    3316                 :             : 
    3317                 :             :       /* DR 2211: check that captures and parameters
    3318                 :             :          do not have the same name. */
    3319                 :      959584 :       if (is_capture_proxy (decl))
    3320                 :             :         {
    3321                 :      785067 :           if (current_lambda_expr ()
    3322                 :      785067 :               && DECL_CONTEXT (old) == lambda_function (current_lambda_expr ())
    3323                 :          30 :               && TREE_CODE (old) == PARM_DECL
    3324                 :      785085 :               && DECL_NAME (decl) != this_identifier)
    3325                 :          18 :             error_at (DECL_SOURCE_LOCATION (old),
    3326                 :             :                       "lambda parameter %qD "
    3327                 :             :                       "previously declared as a capture", old);
    3328                 :      785067 :           return NULL_TREE;
    3329                 :             :         }
    3330                 :             :       /* Don't complain if it's from an enclosing function.  */
    3331                 :      174517 :       else if (DECL_CONTEXT (old) == current_function_decl
    3332                 :      159931 :                && TREE_CODE (decl) != PARM_DECL
    3333                 :      334448 :                && TREE_CODE (old) == PARM_DECL)
    3334                 :             :         {
    3335                 :             :           /* Go to where the parms should be and see if we find
    3336                 :             :              them there.  */
    3337                 :       10171 :           cp_binding_level *b = current_binding_level->level_chain;
    3338                 :             : 
    3339                 :       10171 :           if (in_function_try_handler && b->kind == sk_catch)
    3340                 :          51 :             b = b->level_chain;
    3341                 :             : 
    3342                 :             :           /* Skip artificially added scopes which aren't present
    3343                 :             :              in the C++ standard, e.g. for function-try-block or
    3344                 :             :              ctor/dtor cleanups.  */
    3345                 :       10277 :           while (b->artificial)
    3346                 :         106 :             b = b->level_chain;
    3347                 :             : 
    3348                 :             :           /* [basic.scope.param] A parameter name shall not be redeclared
    3349                 :             :              in the outermost block of the function definition.  */
    3350                 :       10171 :           if (b->kind == sk_function_parms)
    3351                 :             :             {
    3352                 :         143 :               if (name_independent_decl_p (decl))
    3353                 :             :                 return old;
    3354                 :             : 
    3355                 :         128 :               auto_diagnostic_group d;
    3356                 :         128 :               bool emit = true;
    3357                 :         128 :               if (DECL_EXTERNAL (decl))
    3358                 :          54 :                 emit = pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
    3359                 :             :                                 "declaration of %q#D shadows a parameter",
    3360                 :             :                                 decl);
    3361                 :             :               else
    3362                 :          74 :                 error_at (DECL_SOURCE_LOCATION (decl),
    3363                 :             :                           "declaration of %q#D shadows a parameter", decl);
    3364                 :         128 :               if (emit)
    3365                 :         128 :                 inform (DECL_SOURCE_LOCATION (old),
    3366                 :             :                         "%q#D previously declared here", old);
    3367                 :         128 :               return NULL_TREE;
    3368                 :         128 :             }
    3369                 :             :         }
    3370                 :             : 
    3371                 :             :       /* The local structure or class can't use parameters of
    3372                 :             :          the containing function anyway.  */
    3373                 :      174374 :       if (DECL_CONTEXT (old) != current_function_decl)
    3374                 :             :         {
    3375                 :       14586 :           for (cp_binding_level *scope = current_binding_level;
    3376                 :       36935 :                scope != old_scope; scope = scope->level_chain)
    3377                 :       34685 :             if (scope->kind == sk_class
    3378                 :       51587 :                 && !LAMBDA_TYPE_P (scope->this_entity))
    3379                 :             :               return NULL_TREE;
    3380                 :             :         }
    3381                 :             :       /* Error if redeclaring a local declared in a
    3382                 :             :          init-statement or in the condition of an if or
    3383                 :             :          switch statement when the new declaration is in the
    3384                 :             :          outermost block of the controlled statement.
    3385                 :             :          Redeclaring a variable from a for or while condition is
    3386                 :             :          detected elsewhere.  */
    3387                 :      159788 :       else if (VAR_P (old)
    3388                 :      149084 :                && old_scope == current_binding_level->level_chain
    3389                 :        1782 :                && (old_scope->kind == sk_cond || old_scope->kind == sk_for))
    3390                 :             :         {
    3391                 :         165 :           if (name_independent_decl_p (decl))
    3392                 :             :             return old;
    3393                 :             : 
    3394                 :         138 :           auto_diagnostic_group d;
    3395                 :         138 :           bool emit = true;
    3396                 :         138 :           if (DECL_EXTERNAL (decl))
    3397                 :          64 :             emit = pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
    3398                 :             :                             "redeclaration of %q#D", decl);
    3399                 :             :           else
    3400                 :          74 :             error_at (DECL_SOURCE_LOCATION (decl),
    3401                 :             :                       "redeclaration of %q#D", decl);
    3402                 :         138 :           if (emit)
    3403                 :         138 :             inform (DECL_SOURCE_LOCATION (old),
    3404                 :             :                     "%q#D previously declared here", old);
    3405                 :         138 :           return NULL_TREE;
    3406                 :         138 :         }
    3407                 :             :       /* C++11:
    3408                 :             :          3.3.3/3:  The name declared in an exception-declaration (...)
    3409                 :             :          shall not be redeclared in the outermost block of the handler.
    3410                 :             :          3.3.3/2:  A parameter name shall not be redeclared (...) in
    3411                 :             :          the outermost block of any handler associated with a
    3412                 :             :          function-try-block.  */
    3413                 :      159623 :       else if (TREE_CODE (old) == VAR_DECL
    3414                 :      148919 :                && old_scope == current_binding_level->level_chain
    3415                 :        1617 :                && old_scope->kind == sk_catch)
    3416                 :             :         {
    3417                 :          23 :           if (name_independent_decl_p (decl))
    3418                 :             :             return old;
    3419                 :             : 
    3420                 :          20 :           auto_diagnostic_group d;
    3421                 :          20 :           bool emit;
    3422                 :          20 :           if (DECL_EXTERNAL (decl))
    3423                 :           8 :             emit = pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
    3424                 :             :                             "redeclaration of %q#D", decl);
    3425                 :             :           else
    3426                 :          12 :             emit = permerror (DECL_SOURCE_LOCATION (decl),
    3427                 :             :                               "redeclaration of %q#D", decl);
    3428                 :          20 :           if (emit)
    3429                 :          20 :             inform (DECL_SOURCE_LOCATION (old),
    3430                 :             :                     "%q#D previously declared here", old);
    3431                 :          20 :           return NULL_TREE;
    3432                 :          20 :         }
    3433                 :             : 
    3434                 :             :       /* Don't emit -Wshadow* warnings for name-independent decls.  */
    3435                 :      161850 :       if (name_independent_decl_p (decl) || name_independent_decl_p (old))
    3436                 :             :         return NULL_TREE;
    3437                 :             : 
    3438                 :             :       /* If '-Wshadow=compatible-local' is specified without other
    3439                 :             :          -Wshadow= flags, we will warn only when the type of the
    3440                 :             :          shadowing variable (DECL) can be converted to that of the
    3441                 :             :          shadowed parameter (OLD_LOCAL). The reason why we only check
    3442                 :             :          if DECL's type can be converted to OLD_LOCAL's type (but not the
    3443                 :             :          other way around) is because when users accidentally shadow a
    3444                 :             :          parameter, more than often they would use the variable
    3445                 :             :          thinking (mistakenly) it's still the parameter. It would be
    3446                 :             :          rare that users would use the variable in the place that
    3447                 :             :          expects the parameter but thinking it's a new decl.
    3448                 :             :          If either object is a TYPE_DECL, '-Wshadow=compatible-local'
    3449                 :             :          warns regardless of whether one of the types involved
    3450                 :             :          is a subclass of the other, since that is never okay.  */
    3451                 :             : 
    3452                 :      161793 :       enum opt_code warning_code;
    3453                 :      161793 :       if (warn_shadow)
    3454                 :             :         warning_code = OPT_Wshadow;
    3455                 :      161717 :       else if ((TREE_CODE (decl) == TYPE_DECL)
    3456                 :      161717 :                ^ (TREE_CODE (old) == TYPE_DECL))
    3457                 :             :         /* If exactly one is a type, they aren't compatible.  */
    3458                 :             :         warning_code = OPT_Wshadow_local;
    3459                 :      161691 :       else if ((TREE_TYPE (old)
    3460                 :      161691 :                 && TREE_TYPE (decl)
    3461                 :      161688 :                 && same_type_p (TREE_TYPE (old), TREE_TYPE (decl)))
    3462                 :       31396 :                || TREE_CODE (decl) == TYPE_DECL
    3463                 :       31388 :                || TREE_CODE (old) == TYPE_DECL
    3464                 :      193079 :                || (!dependent_type_p (TREE_TYPE (decl))
    3465                 :       12088 :                    && !dependent_type_p (TREE_TYPE (old))
    3466                 :             :                    /* If the new decl uses auto, we don't yet know
    3467                 :             :                       its type (the old type cannot be using auto
    3468                 :             :                       at this point, without also being
    3469                 :             :                       dependent).  This is an indication we're
    3470                 :             :                       (now) doing the shadow checking too
    3471                 :             :                       early.  */
    3472                 :       12072 :                    && !type_uses_auto (TREE_TYPE (decl))
    3473                 :       11960 :                    && can_convert_arg (TREE_TYPE (old), TREE_TYPE (decl),
    3474                 :             :                                        decl, LOOKUP_IMPLICIT, tf_none)))
    3475                 :             :         warning_code = OPT_Wshadow_compatible_local;
    3476                 :             :       else
    3477                 :             :         warning_code = OPT_Wshadow_local;
    3478                 :             : 
    3479                 :      161793 :       const char *msg;
    3480                 :      161793 :       if (TREE_CODE (old) == PARM_DECL)
    3481                 :             :         msg = "declaration of %q#D shadows a parameter";
    3482                 :      149911 :       else if (is_capture_proxy (old))
    3483                 :             :         msg = "declaration of %qD shadows a lambda capture";
    3484                 :             :       else
    3485                 :      149650 :         msg = "declaration of %qD shadows a previous local";
    3486                 :             : 
    3487                 :      161793 :       auto_diagnostic_group d;
    3488                 :      161793 :       if (warning_at (DECL_SOURCE_LOCATION (decl), warning_code, msg, decl))
    3489                 :         140 :         inform_shadowed (old);
    3490                 :      161793 :       return NULL_TREE;
    3491                 :      161793 :     }
    3492                 :             : 
    3493                 :   483023668 :   if (!warn_shadow)
    3494                 :             :     return NULL_TREE;
    3495                 :             : 
    3496                 :             :   /* Don't emit -Wshadow for name-independent decls.  */
    3497                 :         736 :   if (name_independent_decl_p (decl))
    3498                 :             :     return NULL_TREE;
    3499                 :             : 
    3500                 :             :   /* Don't warn for artificial things that are not implicit typedefs.  */
    3501                 :         658 :   if (DECL_ARTIFICIAL (decl) && !DECL_IMPLICIT_TYPEDEF_P (decl))
    3502                 :             :     return NULL_TREE;
    3503                 :             : 
    3504                 :         406 :   if (nonlambda_method_basetype ())
    3505                 :         120 :     if (tree member = lookup_member (current_nonlambda_class_type (),
    3506                 :         120 :                                      DECL_NAME (decl), /*protect=*/0,
    3507                 :             :                                      /*want_type=*/false, tf_warning_or_error))
    3508                 :             :       {
    3509                 :          42 :         member = MAYBE_BASELINK_FUNCTIONS (member);
    3510                 :             : 
    3511                 :             :         /* Warn if a variable shadows a non-function, or the variable
    3512                 :             :            is a function or a pointer-to-function.  */
    3513                 :          30 :         if ((!OVL_P (member)
    3514                 :          12 :              || TREE_CODE (decl) == FUNCTION_DECL
    3515                 :          12 :              || (TREE_TYPE (decl)
    3516                 :           8 :                  && (TYPE_PTRFN_P (TREE_TYPE (decl))
    3517                 :           8 :                      || TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))))
    3518                 :          76 :             && !warning_suppressed_p (decl, OPT_Wshadow))
    3519                 :             :           {
    3520                 :          34 :             auto_diagnostic_group d;
    3521                 :          34 :             if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wshadow,
    3522                 :             :                             "declaration of %qD shadows a member of %qT",
    3523                 :             :                             decl, current_nonlambda_class_type ())
    3524                 :          34 :                 && DECL_P (member))
    3525                 :             :               {
    3526                 :          34 :                 inform_shadowed (member);
    3527                 :          34 :                 suppress_warning (decl, OPT_Wshadow);
    3528                 :             :               }
    3529                 :          34 :           }
    3530                 :          42 :         return NULL_TREE;
    3531                 :             :       }
    3532                 :             : 
    3533                 :             :   /* Now look for a namespace shadow.  */
    3534                 :         364 :   old = find_namespace_value (current_namespace, DECL_NAME (decl));
    3535                 :         364 :   if (old
    3536                 :          90 :       && (VAR_P (old)
    3537                 :          58 :           || (TREE_CODE (old) == TYPE_DECL
    3538                 :          20 :               && (!DECL_ARTIFICIAL (old)
    3539                 :          12 :                   || TREE_CODE (decl) == TYPE_DECL)))
    3540                 :          44 :       && !DECL_EXTERNAL (decl)
    3541                 :          40 :       && !instantiating_current_function_p ()
    3542                 :         404 :       && !warning_suppressed_p (decl, OPT_Wshadow))
    3543                 :             :     /* XXX shadow warnings in outer-more namespaces */
    3544                 :             :     {
    3545                 :          40 :       auto_diagnostic_group d;
    3546                 :          40 :       if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wshadow,
    3547                 :             :                       "declaration of %qD shadows a global declaration",
    3548                 :             :                       decl))
    3549                 :             :         {
    3550                 :          40 :           inform_shadowed (old);
    3551                 :          40 :           suppress_warning (decl, OPT_Wshadow);
    3552                 :             :         }
    3553                 :          40 :       return NULL_TREE;
    3554                 :          40 :     }
    3555                 :             : 
    3556                 :             :   return NULL_TREE;
    3557                 :             : }
    3558                 :             : 
    3559                 :             : /* DECL is being pushed inside function CTX.  Set its context, if
    3560                 :             :    needed.  */
    3561                 :             : 
    3562                 :             : static void
    3563                 :   344580653 : set_decl_context_in_fn (tree ctx, tree decl)
    3564                 :             : {
    3565                 :   344580653 :   if (TREE_CODE (decl) == FUNCTION_DECL
    3566                 :   344580653 :       || (VAR_P (decl) && DECL_EXTERNAL (decl)))
    3567                 :             :     /* Make sure local externs are marked as such.  OMP UDRs really
    3568                 :             :        are nested functions.  */
    3569                 :       32886 :     gcc_checking_assert (DECL_LOCAL_DECL_P (decl)
    3570                 :             :                          && (DECL_NAMESPACE_SCOPE_P (decl)
    3571                 :             :                              || (TREE_CODE (decl) == FUNCTION_DECL
    3572                 :             :                                  && DECL_OMP_DECLARE_REDUCTION_P (decl))));
    3573                 :             : 
    3574                 :   344580653 :   if (!DECL_CONTEXT (decl)
    3575                 :             :       /* When parsing the parameter list of a function declarator,
    3576                 :             :          don't set DECL_CONTEXT to an enclosing function.  */
    3577                 :   345448915 :       && !(TREE_CODE (decl) == PARM_DECL
    3578                 :      868262 :            && parsing_function_declarator ()))
    3579                 :    78124709 :     DECL_CONTEXT (decl) = ctx;
    3580                 :   344580653 : }
    3581                 :             : 
    3582                 :             : /* DECL is a local extern decl.  Find or create the namespace-scope
    3583                 :             :    decl that it aliases.  Also, determines the linkage of DECL.  */
    3584                 :             : 
    3585                 :             : void
    3586                 :       32519 : push_local_extern_decl_alias (tree decl)
    3587                 :             : {
    3588                 :       32519 :   if (dependent_type_p (TREE_TYPE (decl))
    3589                 :       32519 :       || (processing_template_decl
    3590                 :       11720 :           && VAR_P (decl)
    3591                 :          58 :           && CP_DECL_THREAD_LOCAL_P (decl)))
    3592                 :             :     return;
    3593                 :             :   /* EH specs were not part of the function type prior to c++17, but
    3594                 :             :      we still can't go pushing dependent eh specs into the namespace.  */
    3595                 :       32428 :   if (cxx_dialect < cxx17
    3596                 :        3429 :       && TREE_CODE (decl) == FUNCTION_DECL
    3597                 :       35209 :       && (value_dependent_expression_p
    3598                 :        2781 :           (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)))))
    3599                 :             :     return;
    3600                 :             : 
    3601                 :       32427 :   gcc_checking_assert (!DECL_LANG_SPECIFIC (decl)
    3602                 :             :                        || !DECL_TEMPLATE_INFO (decl));
    3603                 :       32427 :   if (DECL_LANG_SPECIFIC (decl) && DECL_LOCAL_DECL_ALIAS (decl))
    3604                 :             :     /* We're instantiating a non-dependent local decl, it already
    3605                 :             :        knows the alias.  */
    3606                 :             :     return;
    3607                 :             : 
    3608                 :       32258 :   tree alias = NULL_TREE;
    3609                 :             : 
    3610                 :       32258 :   if (DECL_SIZE (decl) && !TREE_CONSTANT (DECL_SIZE (decl)))
    3611                 :             :     /* Do not let a VLA creep into a namespace.  Diagnostic will be
    3612                 :             :        emitted in layout_var_decl later.  */
    3613                 :           4 :     alias = error_mark_node;
    3614                 :             :   else
    3615                 :             :     {
    3616                 :             :       /* First look for a decl that matches.  */
    3617                 :       32254 :       tree ns = CP_DECL_CONTEXT (decl);
    3618                 :       32254 :       tree binding = find_namespace_value (ns, DECL_NAME (decl));
    3619                 :             : 
    3620                 :       32254 :       if (binding && TREE_CODE (binding) != TREE_LIST)
    3621                 :         938 :         for (ovl_iterator iter (binding); iter; ++iter)
    3622                 :         688 :           if (decls_match (decl, *iter, /*record_versions*/false))
    3623                 :             :             {
    3624                 :         508 :               alias = *iter;
    3625                 :         508 :               break;
    3626                 :             :             }
    3627                 :             : 
    3628                 :         614 :       if (!alias)
    3629                 :             :         {
    3630                 :             :           /* No existing namespace-scope decl.  Make one.  */
    3631                 :       31746 :           alias = copy_decl (decl);
    3632                 :       31746 :           if (TREE_CODE (alias) == FUNCTION_DECL)
    3633                 :             :             {
    3634                 :             :               /* Recontextualize the parms.  */
    3635                 :       30706 :               for (tree *chain = &DECL_ARGUMENTS (alias);
    3636                 :       31291 :                    *chain; chain = &DECL_CHAIN (*chain))
    3637                 :             :                 {
    3638                 :         585 :                   *chain = copy_decl (*chain);
    3639                 :         585 :                   DECL_CONTEXT (*chain) = alias;
    3640                 :             :                 }
    3641                 :             : 
    3642                 :       30706 :               tree type = TREE_TYPE (alias);
    3643                 :       30706 :               for (tree args = TYPE_ARG_TYPES (type);
    3644                 :       62262 :                    args; args = TREE_CHAIN (args))
    3645                 :       31601 :                 if (TREE_PURPOSE (args))
    3646                 :             :                   {
    3647                 :             :                     /* There are default args.  Lose them.  */
    3648                 :          45 :                     tree nargs = NULL_TREE;
    3649                 :          45 :                     tree *chain = &nargs;
    3650                 :          45 :                     for (args = TYPE_ARG_TYPES (type);
    3651                 :         111 :                          args; args = TREE_CHAIN (args))
    3652                 :         111 :                       if (args == void_list_node)
    3653                 :             :                         {
    3654                 :          45 :                           *chain = args;
    3655                 :          45 :                           break;
    3656                 :             :                         }
    3657                 :             :                       else
    3658                 :             :                         {
    3659                 :          66 :                           *chain
    3660                 :          66 :                             = build_tree_list (NULL_TREE, TREE_VALUE (args));
    3661                 :          66 :                           chain = &TREE_CHAIN (*chain);
    3662                 :             :                         }
    3663                 :             : 
    3664                 :          45 :                     tree fn_type = build_function_type (TREE_TYPE (type), nargs);
    3665                 :             : 
    3666                 :          45 :                     fn_type = apply_memfn_quals
    3667                 :          45 :                       (fn_type, type_memfn_quals (type));
    3668                 :             : 
    3669                 :          45 :                     fn_type = build_cp_fntype_variant
    3670                 :          45 :                       (fn_type, type_memfn_rqual (type),
    3671                 :          45 :                        TYPE_RAISES_EXCEPTIONS (type),
    3672                 :          45 :                        TYPE_HAS_LATE_RETURN_TYPE (type));
    3673                 :             : 
    3674                 :          45 :                     TREE_TYPE (alias) = fn_type;
    3675                 :          45 :                     break;
    3676                 :             :                   }
    3677                 :             :             }
    3678                 :             : 
    3679                 :             :           /* This is the real thing.  */
    3680                 :       31746 :           DECL_LOCAL_DECL_P (alias) = false;
    3681                 :             : 
    3682                 :             :           /* Expected default linkage is from the namespace.  */
    3683                 :       31746 :           TREE_PUBLIC (alias) = TREE_PUBLIC (ns);
    3684                 :       31746 :           push_nested_namespace (ns);
    3685                 :       31746 :           alias = pushdecl (alias, /* hiding= */true);
    3686                 :       31746 :           pop_nested_namespace (ns);
    3687                 :       31746 :           if (VAR_P (decl)
    3688                 :        1040 :               && CP_DECL_THREAD_LOCAL_P (decl)
    3689                 :       31769 :               && alias != error_mark_node)
    3690                 :          20 :             set_decl_tls_model (alias, DECL_TLS_MODEL (decl));
    3691                 :             : 
    3692                 :             :           /* Adjust visibility.  */
    3693                 :       31746 :           determine_visibility (alias);
    3694                 :             :         }
    3695                 :             :     }
    3696                 :             : 
    3697                 :       32258 :   retrofit_lang_decl (decl);
    3698                 :       32258 :   DECL_LOCAL_DECL_ALIAS (decl) = alias;
    3699                 :             : }
    3700                 :             : 
    3701                 :             : /* If DECL has non-internal linkage, and we have a module vector,
    3702                 :             :    record it in the appropriate slot.  We have already checked for
    3703                 :             :    duplicates.  */
    3704                 :             : 
    3705                 :             : static void
    3706                 :      277931 : maybe_record_mergeable_decl (tree *slot, tree name, tree decl)
    3707                 :             : {
    3708                 :      277931 :   if (TREE_CODE (*slot) != BINDING_VECTOR)
    3709                 :             :     return;
    3710                 :             : 
    3711                 :          39 :   if (!TREE_PUBLIC (CP_DECL_CONTEXT (decl)))
    3712                 :             :     /* Member of internal namespace.  */
    3713                 :             :     return;
    3714                 :             : 
    3715                 :          39 :   tree not_tmpl = STRIP_TEMPLATE (decl);
    3716                 :          39 :   if ((TREE_CODE (not_tmpl) == FUNCTION_DECL
    3717                 :           0 :        || VAR_P (not_tmpl))
    3718                 :          39 :       && DECL_THIS_STATIC (not_tmpl))
    3719                 :             :     /* Internal linkage.  */
    3720                 :             :     return;
    3721                 :             : 
    3722                 :          39 :   bool is_attached = (DECL_LANG_SPECIFIC (not_tmpl)
    3723                 :          78 :                       && DECL_MODULE_ATTACH_P (not_tmpl));
    3724                 :             :   tree *gslot = get_fixed_binding_slot
    3725                 :          39 :     (slot, name, is_attached ? BINDING_SLOT_PARTITION : BINDING_SLOT_GLOBAL,
    3726                 :             :      true);
    3727                 :             : 
    3728                 :          39 :   if (!is_attached)
    3729                 :             :     {
    3730                 :          33 :       binding_slot &orig
    3731                 :          33 :         = BINDING_VECTOR_CLUSTER (*slot, 0).slots[BINDING_SLOT_CURRENT];
    3732                 :             : 
    3733                 :          33 :       if (!STAT_HACK_P (tree (orig)))
    3734                 :           9 :         orig = stat_hack (tree (orig));
    3735                 :             : 
    3736                 :          33 :       MODULE_BINDING_GLOBAL_P (tree (orig)) = true;
    3737                 :             :     }
    3738                 :             : 
    3739                 :          39 :   add_mergeable_namespace_entity (gslot, decl);
    3740                 :             : }
    3741                 :             : 
    3742                 :             : /* DECL is being pushed.  Check whether it hides or ambiguates
    3743                 :             :    something seen as an import.  This include decls seen in our own
    3744                 :             :    interface, which is OK.  Also, check for merging a
    3745                 :             :    global/partition decl.  */
    3746                 :             : 
    3747                 :             : static tree
    3748                 :         374 : check_module_override (tree decl, tree mvec, bool hiding,
    3749                 :             :                        tree scope, tree name)
    3750                 :             : {
    3751                 :         374 :   tree match = NULL_TREE;
    3752                 :         374 :   bitmap imports = get_import_bitmap ();
    3753                 :         374 :   binding_cluster *cluster = BINDING_VECTOR_CLUSTER_BASE (mvec);
    3754                 :         374 :   unsigned ix = BINDING_VECTOR_NUM_CLUSTERS (mvec);
    3755                 :             : 
    3756                 :         374 :   if (BINDING_VECTOR_SLOTS_PER_CLUSTER == BINDING_SLOTS_FIXED)
    3757                 :             :     {
    3758                 :         374 :       cluster++;
    3759                 :         374 :       ix--;
    3760                 :             :     }
    3761                 :             : 
    3762                 :         532 :   for (; ix--; cluster++)
    3763                 :         791 :     for (unsigned jx = 0; jx != BINDING_VECTOR_SLOTS_PER_CLUSTER; jx++)
    3764                 :             :       {
    3765                 :             :         /* Are we importing this module?  */
    3766                 :         633 :         if (cluster->indices[jx].span != 1)
    3767                 :         149 :           continue;
    3768                 :         484 :         if (!cluster->indices[jx].base)
    3769                 :         129 :           continue;
    3770                 :         355 :         if (!bitmap_bit_p (imports, cluster->indices[jx].base))
    3771                 :           9 :           continue;
    3772                 :             :         /* Is it loaded? */
    3773                 :         346 :         if (cluster->slots[jx].is_lazy ())
    3774                 :             :           {
    3775                 :           1 :             gcc_assert (cluster->indices[jx].span == 1);
    3776                 :           1 :             lazy_load_binding (cluster->indices[jx].base,
    3777                 :             :                                scope, name, &cluster->slots[jx]);
    3778                 :             :           }
    3779                 :         346 :         tree bind = cluster->slots[jx];
    3780                 :         346 :         if (!bind)
    3781                 :             :           /* Errors could cause there to be nothing.  */
    3782                 :           0 :           continue;
    3783                 :             : 
    3784                 :         346 :         if (STAT_HACK_P (bind))
    3785                 :             :           /* We do not have to check STAT_TYPE here, the xref_tag
    3786                 :             :              machinery deals with that problem. */
    3787                 :         325 :           bind = STAT_VISIBLE (bind);
    3788                 :             : 
    3789                 :         472 :         for (ovl_iterator iter (bind); iter; ++iter)
    3790                 :         269 :           if (!iter.using_p ())
    3791                 :             :             {
    3792                 :         269 :               match = duplicate_decls (decl, *iter, hiding);
    3793                 :         269 :               if (match)
    3794                 :         197 :                 goto matched;
    3795                 :             :             }
    3796                 :             :       }
    3797                 :             : 
    3798                 :         177 :   if (TREE_PUBLIC (scope) && TREE_PUBLIC (STRIP_TEMPLATE (decl))
    3799                 :             :       /* Namespaces are dealt with specially in
    3800                 :             :          make_namespace_finish.  */
    3801                 :         342 :       && !(TREE_CODE (decl) == NAMESPACE_DECL && !DECL_NAMESPACE_ALIAS (decl)))
    3802                 :             :     {
    3803                 :             :       /* Look in the appropriate mergeable decl slot.  */
    3804                 :         156 :       tree mergeable = NULL_TREE;
    3805                 :         156 :       if (named_module_p ())
    3806                 :          12 :         mergeable = BINDING_VECTOR_CLUSTER (mvec, BINDING_SLOT_PARTITION
    3807                 :             :                                            / BINDING_VECTOR_SLOTS_PER_CLUSTER)
    3808                 :           6 :           .slots[BINDING_SLOT_PARTITION % BINDING_VECTOR_SLOTS_PER_CLUSTER];
    3809                 :             :       else
    3810                 :         150 :         mergeable = BINDING_VECTOR_CLUSTER (mvec, 0).slots[BINDING_SLOT_GLOBAL];
    3811                 :             : 
    3812                 :         455 :       for (ovl_iterator iter (mergeable); iter; ++iter)
    3813                 :             :         {
    3814                 :         203 :           match = duplicate_decls (decl, *iter, hiding);
    3815                 :         203 :           if (match)
    3816                 :          34 :             goto matched;
    3817                 :             :         }
    3818                 :             :     }
    3819                 :             : 
    3820                 :             :   return NULL_TREE;
    3821                 :             : 
    3822                 :         231 :  matched:
    3823                 :         231 :   if (match != error_mark_node)
    3824                 :             :     {
    3825                 :         207 :       if (named_module_p ())
    3826                 :         117 :         BINDING_VECTOR_PARTITION_DUPS_P (mvec) = true;
    3827                 :             :       else
    3828                 :          90 :         BINDING_VECTOR_GLOBAL_DUPS_P (mvec) = true;
    3829                 :             :     }
    3830                 :             : 
    3831                 :             :   return match;
    3832                 :             : 
    3833                 :             :   
    3834                 :             : }
    3835                 :             : 
    3836                 :             : /* Record DECL as belonging to the current lexical scope.  Check for
    3837                 :             :    errors (such as an incompatible declaration for the same name
    3838                 :             :    already seen in the same scope).
    3839                 :             : 
    3840                 :             :    The new binding is hidden if HIDING is true (an anticipated builtin
    3841                 :             :    or hidden friend).
    3842                 :             : 
    3843                 :             :    Returns either DECL or an old decl for the same name.  If an old
    3844                 :             :    decl is returned, it may have been smashed to agree with what DECL
    3845                 :             :    says.  */
    3846                 :             : 
    3847                 :             : tree
    3848                 :  1151557260 : pushdecl (tree decl, bool hiding)
    3849                 :             : {
    3850                 :  1151557260 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    3851                 :             : 
    3852                 :  1151557260 :   if (decl == error_mark_node)
    3853                 :             :     return error_mark_node;
    3854                 :             : 
    3855                 :  1151557252 :   if (!DECL_TEMPLATE_PARM_P (decl) && current_function_decl && !hiding)
    3856                 :   344580653 :     set_decl_context_in_fn (current_function_decl, decl);
    3857                 :             : 
    3858                 :             :   /* The binding level we will be pushing into.  During local class
    3859                 :             :      pushing, we want to push to the containing scope.  */
    3860                 :  1151557252 :   cp_binding_level *level = current_binding_level;
    3861                 :  1151557252 :   while (level->kind == sk_class
    3862                 :  1151557451 :          || level->kind == sk_cleanup)
    3863                 :         199 :     level = level->level_chain;
    3864                 :             : 
    3865                 :             :   /* An anonymous namespace has a NULL DECL_NAME, but we still want to
    3866                 :             :      insert it.  Other NULL-named decls, not so much.  */
    3867                 :  1151557252 :   tree name = DECL_NAME (decl);
    3868                 :  2279045142 :   if (name ? !IDENTIFIER_ANON_P (name) : TREE_CODE (decl) == NAMESPACE_DECL)
    3869                 :             :     {
    3870                 :  1126082870 :       cxx_binding *binding = NULL; /* Local scope binding.  */
    3871                 :  1126082870 :       tree ns = NULL_TREE; /* Searched namespace.  */
    3872                 :  1126082870 :       tree *slot = NULL; /* Binding slot in namespace.  */
    3873                 :  1126082870 :       tree *mslot = NULL; /* Current module slot in namespace.  */
    3874                 :  1126082870 :       tree old = NULL_TREE;
    3875                 :  1126082870 :       bool name_independent_p = false;
    3876                 :  1126082870 :       bool name_independent_diagnosed_p = false;
    3877                 :             : 
    3878                 :  1126082870 :       if (level->kind == sk_namespace)
    3879                 :             :         {
    3880                 :             :           /* We look in the decl's namespace for an existing
    3881                 :             :              declaration, even though we push into the current
    3882                 :             :              namespace.  */
    3883                 :   718805564 :           ns = (DECL_NAMESPACE_SCOPE_P (decl)
    3884                 :   718805564 :                 ? CP_DECL_CONTEXT (decl) : current_namespace);
    3885                 :             :           /* Create the binding, if this is current namespace, because
    3886                 :             :              that's where we'll be pushing anyway.  */
    3887                 :   359402782 :           slot = find_namespace_slot (ns, name, ns == current_namespace);
    3888                 :   359402782 :           if (slot)
    3889                 :             :             {
    3890                 :   718805502 :               mslot = get_fixed_binding_slot (slot, name, BINDING_SLOT_CURRENT,
    3891                 :   359402751 :                                               ns == current_namespace);
    3892                 :   359402751 :               old = MAYBE_STAT_DECL (*mslot);
    3893                 :             :             }
    3894                 :             :         }
    3895                 :             :       else
    3896                 :             :         {
    3897                 :   766680088 :           binding = find_local_binding (level, name);
    3898                 :   766680088 :           if (binding)
    3899                 :        3330 :             old = binding->value;
    3900                 :   766680088 :           name_independent_p = name_independent_decl_p (decl);
    3901                 :             :         }
    3902                 :             : 
    3903                 :  1126082870 :       if (old == error_mark_node)
    3904                 :      100623 :         old = NULL_TREE;
    3905                 :             : 
    3906                 :  1126082870 :       tree oldi, oldn;
    3907                 :  1148942614 :       for (oldi = old; oldi; oldi = oldn)
    3908                 :             :         {
    3909                 :    31341011 :           if (TREE_CODE (oldi) == TREE_LIST)
    3910                 :             :             {
    3911                 :          54 :               gcc_checking_assert (level->kind != sk_namespace
    3912                 :             :                                    && name_independent_decl_p
    3913                 :             :                                                         (TREE_VALUE (old)));
    3914                 :          27 :               oldn = TREE_CHAIN (oldi);
    3915                 :          27 :               oldi = TREE_VALUE (oldi);
    3916                 :             :             }
    3917                 :             :           else
    3918                 :             :             oldn = NULL_TREE;
    3919                 :   634102147 :           for (ovl_iterator iter (oldi); iter; ++iter)
    3920                 :   311975446 :             if (iter.using_p ())
    3921                 :             :               ; /* Ignore using decls here.  */
    3922                 :   308658957 :             else if (iter.hidden_p ()
    3923                 :    59592652 :                      && TREE_CODE (*iter) == FUNCTION_DECL
    3924                 :    40720533 :                      && DECL_LANG_SPECIFIC (*iter)
    3925                 :   349379490 :                      && DECL_MODULE_IMPORT_P (*iter))
    3926                 :             :               ; /* An undeclared builtin imported from elsewhere.  */
    3927                 :   308658954 :             else if (name_independent_p)
    3928                 :             :               {
    3929                 :             :                 /* Ignore name-independent declarations.  */
    3930                 :         123 :                 if (cxx_dialect < cxx26 && !name_independent_diagnosed_p)
    3931                 :          87 :                   pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
    3932                 :             :                            "name-independent declarations only available with "
    3933                 :             :                            "%<-std=c++2c%> or %<-std=gnu++2c%>");
    3934                 :             :                 name_independent_diagnosed_p = true;
    3935                 :             :               }
    3936                 :   617317662 :             else if (tree match
    3937                 :   308658831 :                      = duplicate_decls (decl, *iter, hiding, iter.hidden_p ()))
    3938                 :             :               {
    3939                 :     8481267 :                 if (match == error_mark_node)
    3940                 :             :                   ;
    3941                 :     8480300 :                 else if (TREE_CODE (match) == TYPE_DECL)
    3942                 :       22861 :                   gcc_checking_assert (REAL_IDENTIFIER_TYPE_VALUE (name)
    3943                 :             :                                        == (level->kind == sk_namespace
    3944                 :             :                                            ? NULL_TREE : TREE_TYPE (match)));
    3945                 :     8457439 :                 else if (iter.hidden_p () && !hiding)
    3946                 :             :                   {
    3947                 :             :                     /* Unhiding a previously hidden decl.  */
    3948                 :     3743119 :                     tree head = iter.reveal_node (oldi);
    3949                 :     3743119 :                     if (head != oldi)
    3950                 :             :                       {
    3951                 :       18886 :                         gcc_checking_assert (ns);
    3952                 :       18886 :                         if (STAT_HACK_P (*slot))
    3953                 :           0 :                           STAT_DECL (*slot) = head;
    3954                 :             :                         else
    3955                 :       18886 :                           *slot = head;
    3956                 :             :                       }
    3957                 :     3743119 :                     if (DECL_EXTERN_C_P (match))
    3958                 :             :                       /* We need to check and register the decl now.  */
    3959                 :     3499360 :                       check_extern_c_conflict (match);
    3960                 :             :                   }
    3961                 :     4714320 :                 else if (slot
    3962                 :     4714320 :                          && !hiding
    3963                 :     4010108 :                          && STAT_HACK_P (*slot)
    3964                 :     4714344 :                          && STAT_DECL_HIDDEN_P (*slot))
    3965                 :             :                   {
    3966                 :             :                     /* Unhide the non-function.  */
    3967                 :          24 :                     gcc_checking_assert (oldi == match);
    3968                 :          24 :                     if (!STAT_TYPE (*slot))
    3969                 :          24 :                       *slot = match;
    3970                 :             :                     else
    3971                 :           0 :                       STAT_DECL (*slot) = match;
    3972                 :             :                   }
    3973                 :     8481267 :                 return match;
    3974                 :             :               }
    3975                 :             :         }
    3976                 :             : 
    3977                 :             :       /* Check for redeclaring an import.  */
    3978                 :  1117601603 :       if (slot && *slot && TREE_CODE (*slot) == BINDING_VECTOR)
    3979                 :         748 :         if (tree match
    3980                 :         374 :             = check_module_override (decl, *slot, hiding, ns, name))
    3981                 :             :           {
    3982                 :         231 :             if (match == error_mark_node)
    3983                 :             :               return match;
    3984                 :             : 
    3985                 :             :             /* We found a decl in an interface, push it into this
    3986                 :             :                binding.  */
    3987                 :         207 :             decl = update_binding (NULL, binding, mslot, old,
    3988                 :             :                                    match, hiding);
    3989                 :             : 
    3990                 :         207 :             return decl;
    3991                 :             :           }
    3992                 :             : 
    3993                 :             :       /* We are pushing a new decl.  */
    3994                 :             : 
    3995                 :             :       /* Skip a hidden builtin we failed to match already.  There can
    3996                 :             :          only be one.  */
    3997                 :  1117601372 :       if (old && anticipated_builtin_p (old))
    3998                 :      842714 :         old = OVL_CHAIN (old);
    3999                 :             : 
    4000                 :  1117601372 :       check_template_shadow (decl);
    4001                 :             : 
    4002                 :  1117601372 :       if (DECL_DECLARES_FUNCTION_P (decl))
    4003                 :             :         {
    4004                 :   320586552 :           check_default_args (decl);
    4005                 :             : 
    4006                 :   320586552 :           if (hiding)
    4007                 :             :             {
    4008                 :    75767342 :               if (level->kind != sk_namespace)
    4009                 :             :                 {
    4010                 :             :                   /* In a local class, a friend function declaration must
    4011                 :             :                      find a matching decl in the innermost non-class scope.
    4012                 :             :                      [class.friend/11] */
    4013                 :          12 :                   error_at (DECL_SOURCE_LOCATION (decl),
    4014                 :             :                             "friend declaration %qD in local class without "
    4015                 :             :                             "prior local declaration", decl);
    4016                 :             :                   /* Don't attempt to push it.  */
    4017                 :          12 :                   return error_mark_node;
    4018                 :             :                 }
    4019                 :             :             }
    4020                 :             :         }
    4021                 :             : 
    4022                 :  1117601360 :       if (level->kind != sk_namespace)
    4023                 :             :         {
    4024                 :   766677098 :           tree local_shadow = check_local_shadow (decl);
    4025                 :   766677098 :           if (name_independent_p && local_shadow)
    4026                 :             :             {
    4027                 :          45 :               if (cxx_dialect < cxx26 && !name_independent_diagnosed_p)
    4028                 :          45 :                 pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
    4029                 :             :                          "name-independent declarations only available with "
    4030                 :             :                          "%<-std=c++2c%> or %<-std=gnu++2c%>");
    4031                 :          45 :               name_independent_diagnosed_p = true;
    4032                 :             :               /* When a name-independent declaration is pushed into a scope
    4033                 :             :                  which itself does not contain a _ named declaration yet (so
    4034                 :             :                  _ name lookups wouldn't be normally ambiguous), but it
    4035                 :             :                  shadows a _ declaration in some outer scope in cases
    4036                 :             :                  described in [basic.scope.block]/2 where if the names of
    4037                 :             :                  the shadowed and shadowing declarations were different it
    4038                 :             :                  would be ill-formed program, arrange for _ name lookups
    4039                 :             :                  in this scope to be ambiguous.  */
    4040                 :          45 :               if (old == NULL_TREE)
    4041                 :             :                 {
    4042                 :          45 :                   old = build_tree_list (error_mark_node, local_shadow);
    4043                 :          45 :                   TREE_TYPE (old) = error_mark_node;
    4044                 :             :                 }
    4045                 :             :             }
    4046                 :             : 
    4047                 :   766677098 :           if (TREE_CODE (decl) == NAMESPACE_DECL)
    4048                 :             :             /* A local namespace alias.  */
    4049                 :       41463 :             set_identifier_type_value_with_scope (name, NULL_TREE, level);
    4050                 :             : 
    4051                 :   766677098 :           if (!binding)
    4052                 :   766676750 :             binding = create_local_binding (level, name);
    4053                 :             :         }
    4054                 :   350924262 :       else if (!slot)
    4055                 :             :         {
    4056                 :          31 :           ns = current_namespace;
    4057                 :          31 :           slot = find_namespace_slot (ns, name, true);
    4058                 :          31 :           mslot = get_fixed_binding_slot (slot, name, BINDING_SLOT_CURRENT, true);
    4059                 :             :           /* Update OLD to reflect the namespace we're going to be
    4060                 :             :              pushing into.  */
    4061                 :          31 :           old = MAYBE_STAT_DECL (*mslot);
    4062                 :             :         }
    4063                 :             : 
    4064                 :  1117601360 :       old = update_binding (level, binding, mslot, old, decl, hiding);
    4065                 :             : 
    4066                 :  1117601360 :       if (old != decl)
    4067                 :             :         /* An existing decl matched, use it.  */
    4068                 :             :         decl = old;
    4069                 :             :       else
    4070                 :             :         {
    4071                 :  1117601342 :           if (TREE_CODE (decl) == TYPE_DECL)
    4072                 :             :             {
    4073                 :   206282513 :               tree type = TREE_TYPE (decl);
    4074                 :             : 
    4075                 :   206282513 :               if (type != error_mark_node)
    4076                 :             :                 {
    4077                 :   206282444 :                   if (TYPE_NAME (type) != decl)
    4078                 :    19328610 :                     set_underlying_type (decl);
    4079                 :             : 
    4080                 :   206282444 :                   set_identifier_type_value_with_scope (name, decl, level);
    4081                 :             : 
    4082                 :   206282444 :                   if (level->kind != sk_namespace
    4083                 :   206282444 :                       && !instantiating_current_function_p ())
    4084                 :             :                     /* This is a locally defined typedef in a function that
    4085                 :             :                        is not a template instantation, record it to implement
    4086                 :             :                        -Wunused-local-typedefs.  */
    4087                 :   193099117 :                     record_locally_defined_typedef (decl);
    4088                 :             :                 }
    4089                 :             :             }
    4090                 :   911318829 :           else if (VAR_OR_FUNCTION_DECL_P (decl))
    4091                 :             :             {
    4092                 :   368106517 :               if (DECL_EXTERN_C_P (decl))
    4093                 :   278880874 :                 check_extern_c_conflict (decl);
    4094                 :             : 
    4095                 :   368106517 :               if (!DECL_LOCAL_DECL_P (decl)
    4096                 :   368106517 :                   && VAR_P (decl))
    4097                 :    70938849 :                 maybe_register_incomplete_var (decl);
    4098                 :             : 
    4099                 :   368106517 :               if (DECL_LOCAL_DECL_P (decl)
    4100                 :   368106517 :                   && NAMESPACE_SCOPE_P (decl))
    4101                 :       32511 :                 push_local_extern_decl_alias (decl);
    4102                 :             :             }
    4103                 :             : 
    4104                 :  1117601342 :           if (level->kind == sk_namespace
    4105                 :   350924251 :               && TREE_PUBLIC (level->this_entity)
    4106                 :  1468521139 :               && module_p ())
    4107                 :      277931 :             maybe_record_mergeable_decl (slot, name, decl);
    4108                 :             :         }
    4109                 :             :     }
    4110                 :             :   else
    4111                 :    25474382 :     add_decl_to_level (level, decl);
    4112                 :             : 
    4113                 :             :   return decl;
    4114                 :  1151557260 : }
    4115                 :             : 
    4116                 :             : /* A mergeable entity is being loaded into namespace NS slot NAME.
    4117                 :             :    Create and return the appropriate vector slot for that.  Either a
    4118                 :             :    GMF slot or a module-specific one.  */
    4119                 :             : 
    4120                 :             : tree *
    4121                 :      249870 : mergeable_namespace_slots (tree ns, tree name, bool is_attached, tree *vec)
    4122                 :             : {
    4123                 :      249870 :   tree *mslot = find_namespace_slot (ns, name, true);
    4124                 :      249870 :   tree *vslot = get_fixed_binding_slot
    4125                 :      499295 :     (mslot, name, is_attached ? BINDING_SLOT_PARTITION : BINDING_SLOT_GLOBAL,
    4126                 :             :      true);
    4127                 :             : 
    4128                 :      249870 :   gcc_checking_assert (TREE_CODE (*mslot) == BINDING_VECTOR);
    4129                 :      249870 :   *vec = *mslot;
    4130                 :             : 
    4131                 :      249870 :   return vslot;
    4132                 :             : }
    4133                 :             : 
    4134                 :             : /* DECL is a new mergeable namespace-scope decl.  Add it to the
    4135                 :             :    mergeable entities on GSLOT.  */
    4136                 :             : 
    4137                 :             : void
    4138                 :       88187 : add_mergeable_namespace_entity (tree *gslot, tree decl)
    4139                 :             : {
    4140                 :       88187 :   *gslot = ovl_make (decl, *gslot);
    4141                 :       88187 : }
    4142                 :             : 
    4143                 :             : /* A mergeable entity of KLASS called NAME is being loaded.  Return
    4144                 :             :    the set of things it could be.  All such non-as_base classes have
    4145                 :             :    been given a member vec.  */
    4146                 :             : 
    4147                 :             : tree
    4148                 :      327714 : lookup_class_binding (tree klass, tree name)
    4149                 :             : {
    4150                 :      327714 :   tree found = NULL_TREE;
    4151                 :             : 
    4152                 :      327714 :   if (!COMPLETE_TYPE_P (klass))
    4153                 :             :     ;
    4154                 :      327714 :   else if (TYPE_LANG_SPECIFIC (klass))
    4155                 :             :     {
    4156                 :      324572 :       vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    4157                 :             : 
    4158                 :      324572 :       found = member_vec_binary_search (member_vec, name);
    4159                 :      324572 :       if (!found)
    4160                 :             :         ;
    4161                 :      323999 :       else if (STAT_HACK_P (found))
    4162                 :             :         /* Rearrange the stat hack so that we don't need to expose that
    4163                 :             :            internal detail.  */
    4164                 :           6 :         found = ovl_make (STAT_TYPE (found), STAT_DECL (found));
    4165                 :      613972 :       else if (IDENTIFIER_CONV_OP_P (name))
    4166                 :             :         {
    4167                 :        1347 :           gcc_checking_assert (name == conv_op_identifier);
    4168                 :        1347 :           found = OVL_CHAIN (found);
    4169                 :             :         }
    4170                 :             :     }
    4171                 :             :   else
    4172                 :             :     {
    4173                 :        3142 :       gcc_checking_assert (IS_FAKE_BASE_TYPE (klass)
    4174                 :             :                            || TYPE_PTRMEMFUNC_P (klass));
    4175                 :        3142 :       found = fields_linear_search (klass, name, false);
    4176                 :             :     }
    4177                 :             : 
    4178                 :      327714 :   return found;
    4179                 :             : }
    4180                 :             : 
    4181                 :             : /* Given a namespace-level binding BINDING, walk it, calling CALLBACK
    4182                 :             :    for all decls of the current module.  When partitions are involved,
    4183                 :             :    decls might be mentioned more than once.   Return the accumulation of
    4184                 :             :    CALLBACK results.  */
    4185                 :             : 
    4186                 :             : unsigned
    4187                 :     4810164 : walk_module_binding (tree binding, bitmap partitions,
    4188                 :             :                      bool (*callback) (tree decl, WMB_Flags, void *data),
    4189                 :             :                      void *data)
    4190                 :             : {
    4191                 :             :   // FIXME: We don't quite deal with using decls naming stat hack
    4192                 :             :   // type.
    4193                 :     4810164 :   tree current = binding;
    4194                 :     4810164 :   unsigned count = 0;
    4195                 :             : 
    4196                 :     4810164 :   if (TREE_CODE (binding) == BINDING_VECTOR)
    4197                 :       16500 :     current = BINDING_VECTOR_CLUSTER (binding, 0).slots[BINDING_SLOT_CURRENT];
    4198                 :             : 
    4199                 :     4811294 :   bool decl_hidden = false;
    4200                 :     4810164 :   if (tree type = MAYBE_STAT_TYPE (current))
    4201                 :             :     {
    4202                 :          86 :       WMB_Flags flags = WMB_None;
    4203                 :          86 :       if (STAT_TYPE_HIDDEN_P (current))
    4204                 :           0 :         flags = WMB_Flags (flags | WMB_Hidden);
    4205                 :          86 :       count += callback (type, flags, data);
    4206                 :          86 :       decl_hidden = STAT_DECL_HIDDEN_P (current);
    4207                 :             :     }
    4208                 :             : 
    4209                 :     9681265 :   for (ovl_iterator iter (MAYBE_STAT_DECL (current)); iter; ++iter)
    4210                 :             :     {
    4211                 :     4871101 :       if (iter.hidden_p ())
    4212                 :             :         decl_hidden = true;
    4213                 :     4871101 :       if (!(decl_hidden && DECL_IS_UNDECLARED_BUILTIN (*iter)))
    4214                 :             :         {
    4215                 :     3681614 :           WMB_Flags flags = WMB_None;
    4216                 :     3681614 :           if (decl_hidden)
    4217                 :        6859 :             flags = WMB_Flags (flags | WMB_Hidden);
    4218                 :     3681614 :           if (iter.using_p ())
    4219                 :             :             {
    4220                 :       19073 :               flags = WMB_Flags (flags | WMB_Using);
    4221                 :       19073 :               if (iter.exporting_p ())
    4222                 :       14910 :                 flags = WMB_Flags (flags | WMB_Export);
    4223                 :             :             }
    4224                 :     3681614 :           count += callback (*iter, flags, data);
    4225                 :             :         }
    4226                 :     4871101 :       decl_hidden = false;
    4227                 :             :     }
    4228                 :             : 
    4229                 :     4810164 :   if (partitions && TREE_CODE (binding) == BINDING_VECTOR)
    4230                 :             :     {
    4231                 :             :       /* Process partition slots.  */
    4232                 :         111 :       binding_cluster *cluster = BINDING_VECTOR_CLUSTER_BASE (binding);
    4233                 :         111 :       unsigned ix = BINDING_VECTOR_NUM_CLUSTERS (binding);
    4234                 :         111 :       if (BINDING_VECTOR_SLOTS_PER_CLUSTER == BINDING_SLOTS_FIXED)
    4235                 :             :         {
    4236                 :         111 :           ix--;
    4237                 :         111 :           cluster++;
    4238                 :             :         }
    4239                 :             : 
    4240                 :         111 :       bool maybe_dups = BINDING_VECTOR_PARTITION_DUPS_P (binding);
    4241                 :             : 
    4242                 :         231 :       for (; ix--; cluster++)
    4243                 :         360 :         for (unsigned jx = 0; jx != BINDING_VECTOR_SLOTS_PER_CLUSTER; jx++)
    4244                 :         240 :           if (!cluster->slots[jx].is_lazy ())
    4245                 :         237 :             if (tree bind = cluster->slots[jx])
    4246                 :             :               {
    4247                 :         138 :                 if (TREE_CODE (bind) == NAMESPACE_DECL
    4248                 :         138 :                     && !DECL_NAMESPACE_ALIAS (bind))
    4249                 :             :                   {
    4250                 :           9 :                     if (unsigned base = cluster->indices[jx].base)
    4251                 :           9 :                       if (unsigned span = cluster->indices[jx].span)
    4252                 :           9 :                         do
    4253                 :           9 :                           if (bitmap_bit_p (partitions, base))
    4254                 :           9 :                             goto found;
    4255                 :           0 :                         while (++base, --span);
    4256                 :             :                     /* Not a partition's namespace.  */
    4257                 :           0 :                     continue;
    4258                 :           9 :                   found:
    4259                 :             : 
    4260                 :           9 :                     WMB_Flags flags = WMB_None;
    4261                 :           9 :                     if (maybe_dups)
    4262                 :           0 :                       flags = WMB_Flags (flags | WMB_Dups);
    4263                 :           9 :                     count += callback (bind, flags, data);
    4264                 :           0 :                   }
    4265                 :         129 :                 else if (STAT_HACK_P (bind) && MODULE_BINDING_PARTITION_P (bind))
    4266                 :             :                   {
    4267                 :          66 :                     if (tree btype = STAT_TYPE (bind))
    4268                 :             :                       {
    4269                 :           0 :                         WMB_Flags flags = WMB_None;
    4270                 :           0 :                         if (maybe_dups)
    4271                 :           0 :                           flags = WMB_Flags (flags | WMB_Dups);
    4272                 :           0 :                         if (STAT_TYPE_HIDDEN_P (bind))
    4273                 :           0 :                           flags = WMB_Flags (flags | WMB_Hidden);
    4274                 :             : 
    4275                 :           0 :                         count += callback (btype, flags, data);
    4276                 :             :                       }
    4277                 :          66 :                     bool hidden = STAT_DECL_HIDDEN_P (bind);
    4278                 :          66 :                     for (ovl_iterator iter (MAYBE_STAT_DECL (STAT_DECL (bind)));
    4279                 :         132 :                          iter; ++iter)
    4280                 :             :                       {
    4281                 :          66 :                         if (iter.hidden_p ())
    4282                 :             :                           hidden = true;
    4283                 :          66 :                         gcc_checking_assert
    4284                 :             :                           (!(hidden && DECL_IS_UNDECLARED_BUILTIN (*iter)));
    4285                 :             : 
    4286                 :          66 :                         WMB_Flags flags = WMB_None;
    4287                 :          66 :                         if (maybe_dups)
    4288                 :          18 :                           flags = WMB_Flags (flags | WMB_Dups);
    4289                 :          66 :                         if (decl_hidden)
    4290                 :           0 :                           flags = WMB_Flags (flags | WMB_Hidden);
    4291                 :          66 :                         if (iter.using_p ())
    4292                 :             :                           {
    4293                 :           0 :                             flags = WMB_Flags (flags | WMB_Using);
    4294                 :           0 :                             if (iter.exporting_p ())
    4295                 :           0 :                               flags = WMB_Flags (flags | WMB_Export);
    4296                 :             :                           }
    4297                 :          66 :                         count += callback (*iter, flags, data);
    4298                 :          66 :                         hidden = false;
    4299                 :             :                       }
    4300                 :             :                   }
    4301                 :             :               }
    4302                 :             :     }
    4303                 :             : 
    4304                 :     4810164 :   return count;
    4305                 :             : }
    4306                 :             : 
    4307                 :             : /* Imported module MOD has a binding to NS::NAME, stored in section
    4308                 :             :    SNUM.  */
    4309                 :             : 
    4310                 :             : bool
    4311                 :      265632 : import_module_binding  (tree ns, tree name, unsigned mod, unsigned snum)
    4312                 :             : {
    4313                 :      265632 :   tree *slot = find_namespace_slot (ns, name, true);
    4314                 :      265632 :   binding_slot *mslot = append_imported_binding_slot (slot, name, mod);
    4315                 :             : 
    4316                 :      265632 :   if (mslot->is_lazy () || *mslot)
    4317                 :             :     /* Oops, something was already there.  */
    4318                 :             :     return false;
    4319                 :             : 
    4320                 :      265632 :   mslot->set_lazy (snum);
    4321                 :      265632 :   return true;
    4322                 :             : }
    4323                 :             : 
    4324                 :             : /* An import of MODULE is binding NS::NAME.  There should be no
    4325                 :             :    existing binding for >= MODULE.  MOD_GLOB indicates whether MODULE
    4326                 :             :    is a header_unit (-1) or part of the current module (+1).  VALUE
    4327                 :             :    and TYPE are the value and type bindings. VISIBLE are the value
    4328                 :             :    bindings being exported.  */
    4329                 :             : 
    4330                 :             : bool
    4331                 :      204839 : set_module_binding (tree ns, tree name, unsigned mod, int mod_glob,
    4332                 :             :                     tree value, tree type, tree visible)
    4333                 :             : {
    4334                 :      204839 :   if (!value)
    4335                 :             :     /* Bogus BMIs could give rise to nothing to bind.  */
    4336                 :             :     return false;
    4337                 :             : 
    4338                 :      204839 :   gcc_assert (TREE_CODE (value) != NAMESPACE_DECL
    4339                 :             :               || DECL_NAMESPACE_ALIAS (value));
    4340                 :      204839 :   gcc_checking_assert (mod);
    4341                 :             : 
    4342                 :      204839 :   tree *slot = find_namespace_slot (ns, name, true);
    4343                 :      204839 :   binding_slot *mslot = search_imported_binding_slot (slot, mod);
    4344                 :             : 
    4345                 :      204839 :   if (!mslot || !mslot->is_lazy ())
    4346                 :             :     /* Again, bogus BMI could give find to missing or already loaded slot.  */
    4347                 :             :     return false;
    4348                 :             : 
    4349                 :      204839 :   tree bind = value;
    4350                 :      204839 :   if (type || visible != bind || mod_glob)
    4351                 :             :     {
    4352                 :      203673 :       bind = stat_hack (bind, type);
    4353                 :      203673 :       STAT_VISIBLE (bind) = visible;
    4354                 :         439 :       if ((mod_glob > 0 && TREE_PUBLIC (ns))
    4355                 :      203673 :           || (type && DECL_MODULE_EXPORT_P (type)))
    4356                 :         473 :         STAT_TYPE_VISIBLE_P (bind) = true;
    4357                 :             :     }
    4358                 :             : 
    4359                 :             :   /* Note if this is this-module or global binding.  */
    4360                 :      203673 :   if (mod_glob > 0)
    4361                 :         439 :     MODULE_BINDING_PARTITION_P (bind) = true;
    4362                 :      204400 :   else if (mod_glob < 0)
    4363                 :      203088 :     MODULE_BINDING_GLOBAL_P (bind) = true;
    4364                 :             : 
    4365                 :      204839 :   *mslot = bind;
    4366                 :             : 
    4367                 :      204839 :   return true;
    4368                 :             : }
    4369                 :             : 
    4370                 :             : void
    4371                 :       89444 : add_module_namespace_decl (tree ns, tree decl)
    4372                 :             : {
    4373                 :       89444 :   gcc_assert (!DECL_CHAIN (decl));
    4374                 :       89444 :   gcc_checking_assert (!(VAR_OR_FUNCTION_DECL_P (decl)
    4375                 :             :                          && DECL_LOCAL_DECL_P (decl)));
    4376                 :       89444 :   if (CHECKING_P)
    4377                 :             :     /* Expensive already-there? check.  */
    4378                 :   156057171 :     for (auto probe = NAMESPACE_LEVEL (ns)->names; probe;
    4379                 :   155967727 :          probe = DECL_CHAIN (probe))
    4380                 :   155967727 :       gcc_assert (decl != probe);
    4381                 :             : 
    4382                 :       89444 :   add_decl_to_level (NAMESPACE_LEVEL (ns), decl);
    4383                 :             : 
    4384                 :       89444 :   if (VAR_P (decl))
    4385                 :        1878 :     maybe_register_incomplete_var (decl);
    4386                 :             : 
    4387                 :       87566 :   if (VAR_OR_FUNCTION_DECL_P (decl)
    4388                 :      124174 :       && DECL_EXTERN_C_P (decl))
    4389                 :       22568 :     check_extern_c_conflict (decl);
    4390                 :       89444 : }
    4391                 :             : 
    4392                 :             : /* Enter DECL into the symbol table, if that's appropriate.  Returns
    4393                 :             :    DECL, or a modified version thereof.  */
    4394                 :             : 
    4395                 :             : tree
    4396                 :   123319253 : maybe_push_decl (tree decl)
    4397                 :             : {
    4398                 :   123319253 :   tree type = TREE_TYPE (decl);
    4399                 :             : 
    4400                 :             :   /* Add this decl to the current binding level, but not if it comes
    4401                 :             :      from another scope, e.g. a static member variable.  TEM may equal
    4402                 :             :      DECL or it may be a previous decl of the same name.  */
    4403                 :   123319253 :   if (decl == error_mark_node
    4404                 :   123319248 :       || (TREE_CODE (decl) != PARM_DECL
    4405                 :   123319248 :           && DECL_CONTEXT (decl) != NULL_TREE
    4406                 :             :           /* Definitions of namespace members outside their namespace are
    4407                 :             :              possible.  */
    4408                 :    45819750 :           && !DECL_NAMESPACE_SCOPE_P (decl))
    4409                 :   122044691 :       || (TREE_CODE (decl) == TEMPLATE_DECL && !namespace_bindings_p ())
    4410                 :   122044691 :       || type == unknown_type_node
    4411                 :             :       /* The declaration of a template specialization does not affect
    4412                 :             :          the functions available for overload resolution, so we do not
    4413                 :             :          call pushdecl.  */
    4414                 :   245363944 :       || (TREE_CODE (decl) == FUNCTION_DECL
    4415                 :    34756071 :           && DECL_TEMPLATE_SPECIALIZATION (decl)))
    4416                 :     1366435 :     return decl;
    4417                 :             :   else
    4418                 :   121952818 :     return pushdecl (decl);
    4419                 :             : }
    4420                 :             : 
    4421                 :             : /* Bind DECL to ID in the current_binding_level, assumed to be a local
    4422                 :             :    binding level.  If IS_USING is true, DECL got here through a
    4423                 :             :    using-declaration.  */
    4424                 :             : 
    4425                 :             : static void
    4426                 :      653533 : push_local_binding (tree id, tree decl, bool is_using)
    4427                 :             : {
    4428                 :             :   /* Skip over any local classes.  This makes sense if we call
    4429                 :             :      push_local_binding with a friend decl of a local class.  */
    4430                 :      653533 :   cp_binding_level *b = innermost_nonclass_level ();
    4431                 :             : 
    4432                 :      653533 :   gcc_assert (b->kind != sk_namespace);
    4433                 :      653533 :   if (find_local_binding (b, id))
    4434                 :             :     {
    4435                 :             :       /* Supplement the existing binding.  */
    4436                 :          25 :       if (!supplement_binding (IDENTIFIER_BINDING (id), decl))
    4437                 :             :         /* It didn't work.  Something else must be bound at this
    4438                 :             :            level.  Do not add DECL to the list of things to pop
    4439                 :             :            later.  */
    4440                 :             :         return;
    4441                 :             :     }
    4442                 :             :   else
    4443                 :             :     /* Create a new binding.  */
    4444                 :      653508 :     push_binding (id, decl, b);
    4445                 :             : 
    4446                 :      653532 :   if (TREE_CODE (decl) == OVERLOAD || is_using)
    4447                 :             :     /* We must put the OVERLOAD or using into a TREE_LIST since we
    4448                 :             :        cannot use the decl's chain itself.  */
    4449                 :      653532 :     decl = build_tree_list (id, decl);
    4450                 :             : 
    4451                 :             :   /* And put DECL on the list of things declared by the current
    4452                 :             :      binding level.  */
    4453                 :      653532 :   add_decl_to_level (b, decl);
    4454                 :             : }
    4455                 :             : 
    4456                 :             : 
    4457                 :             : /* true means unconditionally make a BLOCK for the next level pushed.  */
    4458                 :             : 
    4459                 :             : static bool keep_next_level_flag;
    4460                 :             : 
    4461                 :             : static int binding_depth = 0;
    4462                 :             : 
    4463                 :             : static void
    4464                 :           0 : indent (int depth)
    4465                 :             : {
    4466                 :           0 :   int i;
    4467                 :             : 
    4468                 :           0 :   for (i = 0; i < depth * 2; i++)
    4469                 :           0 :     putc (' ', stderr);
    4470                 :           0 : }
    4471                 :             : 
    4472                 :             : /* Return a string describing the kind of SCOPE we have.  */
    4473                 :             : static const char *
    4474                 :           0 : cp_binding_level_descriptor (cp_binding_level *scope)
    4475                 :             : {
    4476                 :             :   /* The order of this table must match the "scope_kind"
    4477                 :             :      enumerators.  */
    4478                 :           0 :   static const char* scope_kind_names[] = {
    4479                 :             :     "block-scope",
    4480                 :             :     "cleanup-scope",
    4481                 :             :     "try-scope",
    4482                 :             :     "catch-scope",
    4483                 :             :     "for-scope",
    4484                 :             :     "cond-init-scope",
    4485                 :             :     "stmt-expr-scope",
    4486                 :             :     "function-parameter-scope",
    4487                 :             :     "class-scope",
    4488                 :             :     "enum-scope",
    4489                 :             :     "namespace-scope",
    4490                 :             :     "template-parameter-scope",
    4491                 :             :     "template-explicit-spec-scope",
    4492                 :             :     "transaction-scope",
    4493                 :             :     "openmp-scope"
    4494                 :             :   };
    4495                 :           0 :   static_assert (ARRAY_SIZE (scope_kind_names) == sk_count,
    4496                 :             :                  "must keep names aligned with scope_kind enum");
    4497                 :             : 
    4498                 :           0 :   scope_kind kind = scope->kind;
    4499                 :           0 :   if (kind == sk_template_parms && scope->explicit_spec_p)
    4500                 :           0 :     kind = sk_template_spec;
    4501                 :             : 
    4502                 :           0 :   return scope_kind_names[kind];
    4503                 :             : }
    4504                 :             : 
    4505                 :             : /* Output a debugging information about SCOPE when performing
    4506                 :             :    ACTION at LINE.  */
    4507                 :             : static void
    4508                 :           0 : cp_binding_level_debug (cp_binding_level *scope, int line, const char *action)
    4509                 :             : {
    4510                 :           0 :   const char *desc = cp_binding_level_descriptor (scope);
    4511                 :           0 :   if (scope->this_entity)
    4512                 :           0 :     verbatim ("%s %<%s(%E)%> %p %d", action, desc,
    4513                 :             :               scope->this_entity, (void *) scope, line);
    4514                 :             :   else
    4515                 :           0 :     verbatim ("%s %s %p %d", action, desc, (void *) scope, line);
    4516                 :           0 : }
    4517                 :             : 
    4518                 :             : /* A chain of binding_level structures awaiting reuse.  */
    4519                 :             : 
    4520                 :             : static GTY((deletable)) cp_binding_level *free_binding_level;
    4521                 :             : 
    4522                 :             : /* Insert SCOPE as the innermost binding level.  */
    4523                 :             : 
    4524                 :             : void
    4525                 :  1052727988 : push_binding_level (cp_binding_level *scope)
    4526                 :             : {
    4527                 :             :   /* Add it to the front of currently active scopes stack.  */
    4528                 :  1052727988 :   scope->level_chain = current_binding_level;
    4529                 :  1052727988 :   current_binding_level = scope;
    4530                 :  1052727988 :   keep_next_level_flag = false;
    4531                 :             : 
    4532                 :  1052727988 :   if (ENABLE_SCOPE_CHECKING)
    4533                 :             :     {
    4534                 :             :       scope->binding_depth = binding_depth;
    4535                 :             :       indent (binding_depth);
    4536                 :             :       cp_binding_level_debug (scope, LOCATION_LINE (input_location),
    4537                 :             :                               "push");
    4538                 :             :       binding_depth++;
    4539                 :             :     }
    4540                 :  1052727988 : }
    4541                 :             : 
    4542                 :             : /* Create a new KIND scope and make it the top of the active scopes stack.
    4543                 :             :    ENTITY is the scope of the associated C++ entity (namespace, class,
    4544                 :             :    function, C++0x enumeration); it is NULL otherwise.  */
    4545                 :             : 
    4546                 :             : cp_binding_level *
    4547                 :   884242945 : begin_scope (scope_kind kind, tree entity)
    4548                 :             : {
    4549                 :   884242945 :   cp_binding_level *scope;
    4550                 :             : 
    4551                 :             :   /* Reuse or create a struct for this binding level.  */
    4552                 :   884242945 :   if (!ENABLE_SCOPE_CHECKING && free_binding_level)
    4553                 :             :     {
    4554                 :   856639500 :       scope = free_binding_level;
    4555                 :   856639500 :       free_binding_level = scope->level_chain;
    4556                 :   856639500 :       memset (scope, 0, sizeof (cp_binding_level));
    4557                 :             :     }
    4558                 :             :   else
    4559                 :    27603445 :     scope = ggc_cleared_alloc<cp_binding_level> ();
    4560                 :             : 
    4561                 :   884242945 :   scope->this_entity = entity;
    4562                 :   884242945 :   scope->more_cleanups_ok = true;
    4563                 :   884242945 :   switch (kind)
    4564                 :             :     {
    4565                 :         465 :     case sk_cleanup:
    4566                 :         465 :       scope->keep = true;
    4567                 :         465 :       break;
    4568                 :             : 
    4569                 :     4906868 :     case sk_template_spec:
    4570                 :     4906868 :       scope->explicit_spec_p = true;
    4571                 :     4906868 :       kind = sk_template_parms;
    4572                 :             :       /* Fall through.  */
    4573                 :   573468806 :     case sk_template_parms:
    4574                 :   573468806 :     case sk_block:
    4575                 :   573468806 :     case sk_try:
    4576                 :   573468806 :     case sk_catch:
    4577                 :   573468806 :     case sk_for:
    4578                 :   573468806 :     case sk_cond:
    4579                 :   573468806 :     case sk_class:
    4580                 :   573468806 :     case sk_scoped_enum:
    4581                 :   573468806 :     case sk_transaction:
    4582                 :   573468806 :     case sk_omp:
    4583                 :   573468806 :     case sk_stmt_expr:
    4584                 :   573468806 :       scope->keep = keep_next_level_flag;
    4585                 :   573468806 :       break;
    4586                 :             : 
    4587                 :   310673051 :     case sk_function_parms:
    4588                 :   310673051 :       scope->keep = keep_next_level_flag;
    4589                 :   310673051 :       break;
    4590                 :             : 
    4591                 :      100623 :     case sk_namespace:
    4592                 :      100623 :       NAMESPACE_LEVEL (entity) = scope;
    4593                 :      100623 :       break;
    4594                 :             : 
    4595                 :           0 :     default:
    4596                 :             :       /* Should not happen.  */
    4597                 :           0 :       gcc_unreachable ();
    4598                 :   884242945 :       break;
    4599                 :             :     }
    4600                 :   884242945 :   scope->kind = kind;
    4601                 :             : 
    4602                 :   884242945 :   push_binding_level (scope);
    4603                 :             : 
    4604                 :   884242945 :   return scope;
    4605                 :             : }
    4606                 :             : 
    4607                 :             : /* We're about to leave current scope.  Pop the top of the stack of
    4608                 :             :    currently active scopes.  Return the enclosing scope, now active.  */
    4609                 :             : 
    4610                 :             : cp_binding_level *
    4611                 :  1098971101 : leave_scope (void)
    4612                 :             : {
    4613                 :  1098971101 :   cp_binding_level *scope = current_binding_level;
    4614                 :             : 
    4615                 :  1098971101 :   if (scope->kind == sk_namespace && class_binding_level)
    4616                 :           0 :     current_binding_level = class_binding_level;
    4617                 :             : 
    4618                 :             :   /* We cannot leave a scope, if there are none left.  */
    4619                 :  1098971101 :   if (NAMESPACE_LEVEL (global_namespace))
    4620                 :  1098971101 :     gcc_assert (!global_scope_p (scope));
    4621                 :             : 
    4622                 :  1098971101 :   if (ENABLE_SCOPE_CHECKING)
    4623                 :             :     {
    4624                 :             :       indent (--binding_depth);
    4625                 :             :       cp_binding_level_debug (scope, LOCATION_LINE (input_location),
    4626                 :             :                               "leave");
    4627                 :             :     }
    4628                 :             : 
    4629                 :             :   /* Move one nesting level up.  */
    4630                 :  1098971101 :   current_binding_level = scope->level_chain;
    4631                 :             : 
    4632                 :             :   /* Namespace-scopes are left most probably temporarily, not
    4633                 :             :      completely; they can be reopened later, e.g. in namespace-extension
    4634                 :             :      or any name binding activity that requires us to resume a
    4635                 :             :      namespace.  For classes, we cache some binding levels.  For other
    4636                 :             :      scopes, we just make the structure available for reuse.  */
    4637                 :  1098971101 :   if (scope->kind != sk_namespace
    4638                 :  1052605591 :       && scope != previous_class_level)
    4639                 :             :     {
    4640                 :   833508322 :       scope->level_chain = free_binding_level;
    4641                 :   833508322 :       gcc_assert (!ENABLE_SCOPE_CHECKING
    4642                 :             :                   || scope->binding_depth == binding_depth);
    4643                 :   833508322 :       free_binding_level = scope;
    4644                 :             :     }
    4645                 :             : 
    4646                 :  1098971101 :   if (scope->kind == sk_class)
    4647                 :             :     {
    4648                 :             :       /* Reset DEFINING_CLASS_P to allow for reuse of a
    4649                 :             :          class-defining scope in a non-defining context.  */
    4650                 :   342645611 :       scope->defining_class_p = 0;
    4651                 :             : 
    4652                 :             :       /* Find the innermost enclosing class scope, and reset
    4653                 :             :          CLASS_BINDING_LEVEL appropriately.  */
    4654                 :   342645611 :       class_binding_level = NULL;
    4655                 :  1079327900 :       for (scope = current_binding_level; scope; scope = scope->level_chain)
    4656                 :   781675442 :         if (scope->kind == sk_class)
    4657                 :             :           {
    4658                 :    44993153 :             class_binding_level = scope;
    4659                 :    44993153 :             break;
    4660                 :             :           }
    4661                 :             :     }
    4662                 :             : 
    4663                 :  1098971101 :   return current_binding_level;
    4664                 :             : }
    4665                 :             : 
    4666                 :             : /* When we exit a toplevel class scope, we save its binding level so
    4667                 :             :    that we can restore it quickly.  Here, we've entered some other
    4668                 :             :    class, so we must invalidate our cache.  */
    4669                 :             : 
    4670                 :             : void
    4671                 :    24430627 : invalidate_class_lookup_cache (void)
    4672                 :             : {
    4673                 :    24430627 :   previous_class_level->level_chain = free_binding_level;
    4674                 :    24430627 :   free_binding_level = previous_class_level;
    4675                 :    24430627 :   previous_class_level = NULL;
    4676                 :    24430627 : }
    4677                 :             : 
    4678                 :             : static void
    4679                 :    46365519 : resume_scope (cp_binding_level* b)
    4680                 :             : {
    4681                 :             :   /* Resuming binding levels is meant only for namespaces,
    4682                 :             :      and those cannot nest into classes.  */
    4683                 :    46365519 :   gcc_assert (!class_binding_level);
    4684                 :             :   /* Also, resuming a non-directly nested namespace is a no-no.  */
    4685                 :    46365519 :   gcc_assert (b->level_chain == current_binding_level);
    4686                 :    46365519 :   current_binding_level = b;
    4687                 :    46365519 :   if (ENABLE_SCOPE_CHECKING)
    4688                 :             :     {
    4689                 :             :       b->binding_depth = binding_depth;
    4690                 :             :       indent (binding_depth);
    4691                 :             :       cp_binding_level_debug (b, LOCATION_LINE (input_location), "resume");
    4692                 :             :       binding_depth++;
    4693                 :             :     }
    4694                 :    46365519 : }
    4695                 :             : 
    4696                 :             : /* Return the innermost binding level that is not for a class scope.  */
    4697                 :             : 
    4698                 :             : static cp_binding_level *
    4699                 :  1383965156 : innermost_nonclass_level (void)
    4700                 :             : {
    4701                 :  1383965156 :   cp_binding_level *b;
    4702                 :             : 
    4703                 :  1383965156 :   b = current_binding_level;
    4704                 :  1591734972 :   while (b->kind == sk_class)
    4705                 :   207769816 :     b = b->level_chain;
    4706                 :             : 
    4707                 :  1383965156 :   return b;
    4708                 :             : }
    4709                 :             : 
    4710                 :             : /* We're defining an object of type TYPE.  If it needs a cleanup, but
    4711                 :             :    we're not allowed to add any more objects with cleanups to the current
    4712                 :             :    scope, create a new binding level.  */
    4713                 :             : 
    4714                 :             : void
    4715                 :     5061902 : maybe_push_cleanup_level (tree type)
    4716                 :             : {
    4717                 :     5061902 :   if (type != error_mark_node
    4718                 :     5061690 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
    4719                 :     5382446 :       && current_binding_level->more_cleanups_ok == 0)
    4720                 :             :     {
    4721                 :         465 :       begin_scope (sk_cleanup, NULL);
    4722                 :         465 :       current_binding_level->statement_list = push_stmt_list ();
    4723                 :             :     }
    4724                 :     5061902 : }
    4725                 :             : 
    4726                 :             : /* Return true if we are in the global binding level.  */
    4727                 :             : 
    4728                 :             : bool
    4729                 :      328957 : global_bindings_p (void)
    4730                 :             : {
    4731                 :      328957 :   return global_scope_p (current_binding_level);
    4732                 :             : }
    4733                 :             : 
    4734                 :             : /* True if we are currently in a toplevel binding level.  This
    4735                 :             :    means either the global binding level or a namespace in a toplevel
    4736                 :             :    binding level.  Since there are no non-toplevel namespace levels,
    4737                 :             :    this really means any namespace or template parameter level.  We
    4738                 :             :    also include a class whose context is toplevel.  */
    4739                 :             : 
    4740                 :             : bool
    4741                 :  1359968129 : toplevel_bindings_p (void)
    4742                 :             : {
    4743                 :  1359968129 :   cp_binding_level *b = innermost_nonclass_level ();
    4744                 :             : 
    4745                 :  1359968129 :   return b->kind == sk_namespace || b->kind == sk_template_parms;
    4746                 :             : }
    4747                 :             : 
    4748                 :             : /* True if this is a namespace scope, or if we are defining a class
    4749                 :             :    which is itself at namespace scope, or whose enclosing class is
    4750                 :             :    such a class, etc.  */
    4751                 :             : 
    4752                 :             : bool
    4753                 :    23341471 : namespace_bindings_p (void)
    4754                 :             : {
    4755                 :    23341471 :   cp_binding_level *b = innermost_nonclass_level ();
    4756                 :             : 
    4757                 :    23341471 :   return b->kind == sk_namespace;
    4758                 :             : }
    4759                 :             : 
    4760                 :             : /* True if the innermost non-class scope is a block scope.  */
    4761                 :             : 
    4762                 :             : bool
    4763                 :        2023 : local_bindings_p (void)
    4764                 :             : {
    4765                 :        2023 :   cp_binding_level *b = innermost_nonclass_level ();
    4766                 :        2023 :   return b->kind < sk_function_parms || b->kind == sk_omp;
    4767                 :             : }
    4768                 :             : 
    4769                 :             : /* True if the current level needs to have a BLOCK made.  */
    4770                 :             : 
    4771                 :             : bool
    4772                 :   282837255 : kept_level_p (void)
    4773                 :             : {
    4774                 :   282837255 :   return (current_binding_level->blocks != NULL_TREE
    4775                 :   253968578 :           || current_binding_level->keep
    4776                 :   247534731 :           || current_binding_level->kind == sk_cleanup
    4777                 :   247534731 :           || current_binding_level->names != NULL_TREE
    4778                 :   502119866 :           || current_binding_level->using_directives);
    4779                 :             : }
    4780                 :             : 
    4781                 :             : /* Returns the kind of the innermost scope.  */
    4782                 :             : 
    4783                 :             : scope_kind
    4784                 :  2359822525 : innermost_scope_kind (void)
    4785                 :             : {
    4786                 :  2359822525 :   return current_binding_level->kind;
    4787                 :             : }
    4788                 :             : 
    4789                 :             : /* Returns true if this scope was created to store template parameters.  */
    4790                 :             : 
    4791                 :             : bool
    4792                 :   535570751 : template_parm_scope_p (void)
    4793                 :             : {
    4794                 :   535570751 :   return innermost_scope_kind () == sk_template_parms;
    4795                 :             : }
    4796                 :             : 
    4797                 :             : /* If KEEP is true, make a BLOCK node for the next binding level,
    4798                 :             :    unconditionally.  Otherwise, use the normal logic to decide whether
    4799                 :             :    or not to create a BLOCK.  */
    4800                 :             : 
    4801                 :             : void
    4802                 :    10193158 : keep_next_level (bool keep)
    4803                 :             : {
    4804                 :    10193158 :   keep_next_level_flag = keep;
    4805                 :    10193158 : }
    4806                 :             : 
    4807                 :             : /* Return the list of declarations of the current local scope.  */
    4808                 :             : 
    4809                 :             : tree
    4810                 :   310401843 : get_local_decls (void)
    4811                 :             : {
    4812                 :   310401843 :   gcc_assert (current_binding_level->kind != sk_namespace
    4813                 :             :               && current_binding_level->kind != sk_class);
    4814                 :   310401843 :   return current_binding_level->names;
    4815                 :             : }
    4816                 :             : 
    4817                 :             : /* Return how many function prototypes we are currently nested inside.  */
    4818                 :             : 
    4819                 :             : int
    4820                 :   251213593 : function_parm_depth (void)
    4821                 :             : {
    4822                 :   251213593 :   int level = 0;
    4823                 :   251213593 :   cp_binding_level *b;
    4824                 :             : 
    4825                 :   251213593 :   for (b = current_binding_level;
    4826                 :   503152348 :        b->kind == sk_function_parms;
    4827                 :   251938755 :        b = b->level_chain)
    4828                 :   251938755 :     ++level;
    4829                 :             : 
    4830                 :   251213593 :   return level;
    4831                 :             : }
    4832                 :             : 
    4833                 :             : /* For debugging.  */
    4834                 :             : static int no_print_functions = 0;
    4835                 :             : static int no_print_builtins = 0;
    4836                 :             : 
    4837                 :             : static void
    4838                 :           0 : print_binding_level (cp_binding_level* lvl)
    4839                 :             : {
    4840                 :           0 :   tree t;
    4841                 :           0 :   int i = 0, len;
    4842                 :           0 :   if (lvl->this_entity)
    4843                 :           0 :     print_node_brief (stderr, "entity=", lvl->this_entity, 1);
    4844                 :           0 :   fprintf (stderr, " blocks=%p", (void *) lvl->blocks);
    4845                 :           0 :   if (lvl->more_cleanups_ok)
    4846                 :           0 :     fprintf (stderr, " more-cleanups-ok");
    4847                 :           0 :   if (lvl->have_cleanups)
    4848                 :           0 :     fprintf (stderr, " have-cleanups");
    4849                 :           0 :   fprintf (stderr, "\n");
    4850                 :           0 :   if (lvl->names)
    4851                 :             :     {
    4852                 :           0 :       fprintf (stderr, " names:\t");
    4853                 :             :       /* We can probably fit 3 names to a line?  */
    4854                 :           0 :       for (t = lvl->names; t; t = TREE_CHAIN (t))
    4855                 :             :         {
    4856                 :           0 :           if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL))
    4857                 :           0 :             continue;
    4858                 :           0 :           if (no_print_builtins
    4859                 :           0 :               && (TREE_CODE (t) == TYPE_DECL)
    4860                 :           0 :               && DECL_IS_UNDECLARED_BUILTIN (t))
    4861                 :           0 :             continue;
    4862                 :             : 
    4863                 :             :           /* Function decls tend to have longer names.  */
    4864                 :           0 :           if (TREE_CODE (t) == FUNCTION_DECL)
    4865                 :             :             len = 3;
    4866                 :             :           else
    4867                 :           0 :             len = 2;
    4868                 :           0 :           i += len;
    4869                 :           0 :           if (i > 6)
    4870                 :             :             {
    4871                 :           0 :               fprintf (stderr, "\n\t");
    4872                 :           0 :               i = len;
    4873                 :             :             }
    4874                 :           0 :           print_node_brief (stderr, "", t, 0);
    4875                 :           0 :           if (t == error_mark_node)
    4876                 :             :             break;
    4877                 :             :         }
    4878                 :           0 :       if (i)
    4879                 :           0 :         fprintf (stderr, "\n");
    4880                 :             :     }
    4881                 :           0 :   if (vec_safe_length (lvl->class_shadowed))
    4882                 :             :     {
    4883                 :           0 :       size_t i;
    4884                 :           0 :       cp_class_binding *b;
    4885                 :           0 :       fprintf (stderr, " class-shadowed:");
    4886                 :           0 :       FOR_EACH_VEC_ELT (*lvl->class_shadowed, i, b)
    4887                 :           0 :         fprintf (stderr, " %s ", IDENTIFIER_POINTER (b->identifier));
    4888                 :           0 :       fprintf (stderr, "\n");
    4889                 :             :     }
    4890                 :           0 :   if (lvl->type_shadowed)
    4891                 :             :     {
    4892                 :           0 :       fprintf (stderr, " type-shadowed:");
    4893                 :           0 :       for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
    4894                 :             :         {
    4895                 :           0 :           fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
    4896                 :             :         }
    4897                 :           0 :       fprintf (stderr, "\n");
    4898                 :             :     }
    4899                 :           0 : }
    4900                 :             : 
    4901                 :             : DEBUG_FUNCTION void
    4902                 :           0 : debug (cp_binding_level &ref)
    4903                 :             : {
    4904                 :           0 :   print_binding_level (&ref);
    4905                 :           0 : }
    4906                 :             : 
    4907                 :             : DEBUG_FUNCTION void
    4908                 :           0 : debug (cp_binding_level *ptr)
    4909                 :             : {
    4910                 :           0 :   if (ptr)
    4911                 :           0 :     debug (*ptr);
    4912                 :             :   else
    4913                 :           0 :     fprintf (stderr, "<nil>\n");
    4914                 :           0 : }
    4915                 :             : 
    4916                 :             : static void
    4917                 :           0 : print_other_binding_stack (cp_binding_level *stack)
    4918                 :             : {
    4919                 :           0 :   cp_binding_level *level;
    4920                 :           0 :   for (level = stack; !global_scope_p (level); level = level->level_chain)
    4921                 :             :     {
    4922                 :           0 :       fprintf (stderr, "binding level %p\n", (void *) level);
    4923                 :           0 :       print_binding_level (level);
    4924                 :             :     }
    4925                 :           0 : }
    4926                 :             : 
    4927                 :             : DEBUG_FUNCTION void
    4928                 :           0 : print_binding_stack (void)
    4929                 :             : {
    4930                 :           0 :   cp_binding_level *b;
    4931                 :           0 :   fprintf (stderr, "current_binding_level=%p\n"
    4932                 :             :            "class_binding_level=%p\n"
    4933                 :             :            "NAMESPACE_LEVEL (global_namespace)=%p\n",
    4934                 :           0 :            (void *) current_binding_level, (void *) class_binding_level,
    4935                 :           0 :            (void *) NAMESPACE_LEVEL (global_namespace));
    4936                 :           0 :   if (class_binding_level)
    4937                 :             :     {
    4938                 :           0 :       for (b = class_binding_level; b; b = b->level_chain)
    4939                 :           0 :         if (b == current_binding_level)
    4940                 :             :           break;
    4941                 :           0 :       if (b)
    4942                 :             :         b = class_binding_level;
    4943                 :             :       else
    4944                 :           0 :         b = current_binding_level;
    4945                 :             :     }
    4946                 :             :   else
    4947                 :           0 :     b = current_binding_level;
    4948                 :           0 :   print_other_binding_stack (b);
    4949                 :           0 :   fprintf (stderr, "global:\n");
    4950                 :           0 :   print_binding_level (NAMESPACE_LEVEL (global_namespace));
    4951                 :           0 : }
    4952                 :             : 
    4953                 :             : /* Push a definition of struct, union or enum tag named ID.  into
    4954                 :             :    binding_level B.  DECL is a TYPE_DECL for the type.  DECL has
    4955                 :             :    already been pushed into its binding level.  This is bookkeeping to
    4956                 :             :    find it easily.  */
    4957                 :             : 
    4958                 :             : static void
    4959                 :   329958550 : set_identifier_type_value_with_scope (tree id, tree decl, cp_binding_level *b)
    4960                 :             : {
    4961                 :   329958550 :   if (b->kind == sk_namespace)
    4962                 :             :     /* At namespace scope we should not see an identifier type value.  */
    4963                 :    22315542 :     gcc_checking_assert (!REAL_IDENTIFIER_TYPE_VALUE (id)
    4964                 :             :                          /* We could be pushing a friend underneath a template
    4965                 :             :                             parm (ill-formed).  */
    4966                 :             :                          || (TEMPLATE_PARM_P
    4967                 :             :                              (TYPE_NAME (REAL_IDENTIFIER_TYPE_VALUE (id)))));
    4968                 :             :   else
    4969                 :             :     {
    4970                 :             :       /* Push the current type value, so we can restore it later  */
    4971                 :   307643008 :       tree old = REAL_IDENTIFIER_TYPE_VALUE (id);
    4972                 :   307643008 :       b->type_shadowed = tree_cons (id, old, b->type_shadowed);
    4973                 :   307643008 :       tree type = decl ? TREE_TYPE (decl) : NULL_TREE;
    4974                 :   307643008 :       TREE_TYPE (b->type_shadowed) = type;
    4975                 :   307643008 :       SET_IDENTIFIER_TYPE_VALUE (id, type);
    4976                 :             :     }
    4977                 :   329958550 : }
    4978                 :             : 
    4979                 :             : /* As set_identifier_type_value_with_scope, but using
    4980                 :             :    current_binding_level.  */
    4981                 :             : 
    4982                 :             : void
    4983                 :   114936385 : set_identifier_type_value (tree id, tree decl)
    4984                 :             : {
    4985                 :   114936385 :   set_identifier_type_value_with_scope (id, decl, current_binding_level);
    4986                 :   114936385 : }
    4987                 :             : 
    4988                 :             : /* Return the name for the constructor (or destructor) for the
    4989                 :             :    specified class.  */
    4990                 :             : 
    4991                 :             : tree
    4992                 :   319939122 : constructor_name (tree type)
    4993                 :             : {
    4994                 :   319939122 :   tree decl = TYPE_NAME (TYPE_MAIN_VARIANT (type));
    4995                 :             : 
    4996                 :   319939122 :   return decl ? DECL_NAME (decl) : NULL_TREE;
    4997                 :             : }
    4998                 :             : 
    4999                 :             : /* Returns TRUE if NAME is the name for the constructor for TYPE,
    5000                 :             :    which must be a class type.  */
    5001                 :             : 
    5002                 :             : bool
    5003                 :   299504740 : constructor_name_p (tree name, tree type)
    5004                 :             : {
    5005                 :   299504740 :   gcc_assert (MAYBE_CLASS_TYPE_P (type));
    5006                 :             : 
    5007                 :             :   /* These don't have names.  */
    5008                 :   299504740 :   if (TREE_CODE (type) == DECLTYPE_TYPE
    5009                 :   299504737 :       || TREE_CODE (type) == TYPEOF_TYPE)
    5010                 :             :     return false;
    5011                 :             : 
    5012                 :   299504737 :   if (name && name == constructor_name (type))
    5013                 :             :     return true;
    5014                 :             : 
    5015                 :             :   return false;
    5016                 :             : }
    5017                 :             : 
    5018                 :             : /* Same as pushdecl, but define X in binding-level LEVEL.  We rely on the
    5019                 :             :    caller to set DECL_CONTEXT properly.
    5020                 :             : 
    5021                 :             :    Warning: For class and block-scope this must only be used when X
    5022                 :             :    will be the new innermost binding for its name, as we tack it onto
    5023                 :             :    the front of IDENTIFIER_BINDING without checking to see if the
    5024                 :             :    current IDENTIFIER_BINDING comes from a closer binding level than
    5025                 :             :    LEVEL.
    5026                 :             : 
    5027                 :             :    Warning: For namespace scope, this will look in LEVEL for an
    5028                 :             :    existing binding to match, but if not found will push the decl into
    5029                 :             :    CURRENT_NAMESPACE.  Use push_nested_namespace/pushdecl/
    5030                 :             :    pop_nested_namespace if you really need to push it into a foreign
    5031                 :             :    namespace.  */
    5032                 :             : 
    5033                 :             : static tree
    5034                 :    51626917 : do_pushdecl_with_scope (tree x, cp_binding_level *level, bool hiding = false)
    5035                 :             : {
    5036                 :    51626917 :   cp_binding_level *b;
    5037                 :             : 
    5038                 :    51626917 :   if (level->kind == sk_class)
    5039                 :             :     {
    5040                 :           0 :       gcc_checking_assert (!hiding);
    5041                 :           0 :       b = class_binding_level;
    5042                 :           0 :       class_binding_level = level;
    5043                 :           0 :       pushdecl_class_level (x);
    5044                 :           0 :       class_binding_level = b;
    5045                 :             :     }
    5046                 :             :   else
    5047                 :             :     {
    5048                 :    51626917 :       tree function_decl = current_function_decl;
    5049                 :    51626917 :       if (level->kind == sk_namespace)
    5050                 :    48811568 :         current_function_decl = NULL_TREE;
    5051                 :    51626917 :       b = current_binding_level;
    5052                 :    51626917 :       current_binding_level = level;
    5053                 :    51626917 :       x = pushdecl (x, hiding);
    5054                 :    51626917 :       current_binding_level = b;
    5055                 :    51626917 :       current_function_decl = function_decl;
    5056                 :             :     }
    5057                 :    51626917 :   return x;
    5058                 :             : }
    5059                 :             : 
    5060                 :             : /* Inject X into the local scope just before the function parms.  */
    5061                 :             : 
    5062                 :             : tree
    5063                 :     1404396 : pushdecl_outermost_localscope (tree x)
    5064                 :             : {
    5065                 :     1404396 :   cp_binding_level *b = NULL;
    5066                 :     1404396 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    5067                 :             : 
    5068                 :             :   /* Find the scope just inside the function parms.  */
    5069                 :     1404396 :   for (cp_binding_level *n = current_binding_level;
    5070                 :     3587388 :        n->kind != sk_function_parms; n = b->level_chain)
    5071                 :     2182992 :     b = n;
    5072                 :             : 
    5073                 :     1404396 :   return b ? do_pushdecl_with_scope (x, b) : error_mark_node;
    5074                 :     1404396 : }
    5075                 :             : 
    5076                 :             : /* Checks if BINDING is a binding that we can export.  */
    5077                 :             : 
    5078                 :             : static bool
    5079                 :       17754 : check_can_export_using_decl (tree binding)
    5080                 :             : {
    5081                 :       17754 :   tree decl = STRIP_TEMPLATE (binding);
    5082                 :             : 
    5083                 :             :   /* Linkage is determined by the owner of an enumerator.  */
    5084                 :       17754 :   if (TREE_CODE (decl) == CONST_DECL)
    5085                 :          70 :     decl = TYPE_NAME (DECL_CONTEXT (decl));
    5086                 :             : 
    5087                 :             :   /* If the using decl is exported, the things it refers
    5088                 :             :      to must also be exported (or not have module attachment).  */
    5089                 :       17754 :   if (!DECL_MODULE_EXPORT_P (decl)
    5090                 :       17754 :       && (DECL_LANG_SPECIFIC (decl)
    5091                 :         123 :           && DECL_MODULE_ATTACH_P (decl)))
    5092                 :             :     {
    5093                 :         103 :       bool internal_p = !TREE_PUBLIC (decl);
    5094                 :             : 
    5095                 :             :       /* A template in an anonymous namespace doesn't constrain TREE_PUBLIC
    5096                 :             :          until it's instantiated, so double-check its context.  */
    5097                 :         103 :       if (!internal_p && TREE_CODE (binding) == TEMPLATE_DECL)
    5098                 :          33 :         internal_p = decl_internal_context_p (decl);
    5099                 :             : 
    5100                 :         103 :       auto_diagnostic_group d;
    5101                 :         103 :       error ("exporting %q#D that does not have external linkage",
    5102                 :             :              binding);
    5103                 :         103 :       if (TREE_CODE (decl) == TYPE_DECL && !DECL_IMPLICIT_TYPEDEF_P (decl))
    5104                 :             :         /* An un-exported explicit type alias has no linkage.  */
    5105                 :          18 :         inform (DECL_SOURCE_LOCATION (binding),
    5106                 :             :                 "%q#D declared here with no linkage", binding);
    5107                 :          85 :       else if (internal_p)
    5108                 :          41 :         inform (DECL_SOURCE_LOCATION (binding),
    5109                 :             :                 "%q#D declared here with internal linkage", binding);
    5110                 :             :       else
    5111                 :          44 :         inform (DECL_SOURCE_LOCATION (binding),
    5112                 :             :                 "%q#D declared here with module linkage", binding);
    5113                 :         103 :       return false;
    5114                 :         103 :     }
    5115                 :             : 
    5116                 :             :   return true;
    5117                 :             : }
    5118                 :             : 
    5119                 :             : /* Process a local-scope or namespace-scope using declaration.  LOOKUP
    5120                 :             :    is the result of qualified lookup (both value & type are
    5121                 :             :    significant).  FN_SCOPE_P indicates if we're at function-scope (as
    5122                 :             :    opposed to namespace-scope).  *VALUE_P and *TYPE_P are the current
    5123                 :             :    bindings, which are altered to reflect the newly brought in
    5124                 :             :    declarations.  */
    5125                 :             : 
    5126                 :             : static bool
    5127                 :     6364232 : do_nonmember_using_decl (name_lookup &lookup, bool fn_scope_p,
    5128                 :             :                          bool insert_p, tree *value_p, tree *type_p)
    5129                 :             : {
    5130                 :     6364232 :   tree value = *value_p;
    5131                 :     6364232 :   tree type = *type_p;
    5132                 :     6364232 :   bool failed = false;
    5133                 :             : 
    5134                 :             :   /* Shift the old and new bindings around so we're comparing class and
    5135                 :             :      enumeration names to each other.  */
    5136                 :     6364232 :   if (value && DECL_IMPLICIT_TYPEDEF_P (value))
    5137                 :             :     {
    5138                 :             :       type = value;
    5139                 :             :       value = NULL_TREE;
    5140                 :             :     }
    5141                 :             : 
    5142                 :     6364232 :   if (lookup.value && DECL_IMPLICIT_TYPEDEF_P (lookup.value))
    5143                 :             :     {
    5144                 :      112861 :       lookup.type = lookup.value;
    5145                 :      112861 :       lookup.value = NULL_TREE;
    5146                 :             :     }
    5147                 :             : 
    5148                 :             :   /* Only process exporting if we're going to be inserting.  */
    5149                 :     6364232 :   bool revealing_p = insert_p && !fn_scope_p && module_has_cmi_p ();
    5150                 :             : 
    5151                 :             :   /* First do the value binding.  */
    5152                 :     6364232 :   if (!lookup.value)
    5153                 :             :     /* Nothing (only implicit typedef found).  */
    5154                 :      112861 :     gcc_checking_assert (lookup.type);
    5155                 :     6251371 :   else if (OVL_P (lookup.value) && (!value || OVL_P (value)))
    5156                 :             :     {
    5157                 :    13429503 :       for (lkp_iterator usings (lookup.value); usings; ++usings)
    5158                 :             :         {
    5159                 :     8191422 :           tree new_fn = *usings;
    5160                 :     8191422 :           bool exporting = revealing_p && module_exporting_p ();
    5161                 :       15575 :           if (exporting)
    5162                 :       15575 :             exporting = check_can_export_using_decl (new_fn);
    5163                 :             : 
    5164                 :             :           /* [namespace.udecl]
    5165                 :             : 
    5166                 :             :              If a function declaration in namespace scope or block
    5167                 :             :              scope has the same name and the same parameter types as a
    5168                 :             :              function introduced by a using declaration the program is
    5169                 :             :              ill-formed.  */
    5170                 :             :           /* This seems overreaching, asking core -- why do we care
    5171                 :             :              about decls in the namespace that we cannot name (because
    5172                 :             :              they are not transitively imported.  We just check the
    5173                 :             :              decls that are in this TU.  */
    5174                 :     8191422 :           bool found = false;
    5175                 :   101951273 :           for (ovl_iterator old (value); !found && old; ++old)
    5176                 :             :             {
    5177                 :    47163157 :               tree old_fn = *old;
    5178                 :             : 
    5179                 :    47163157 :               if (new_fn == old_fn)
    5180                 :             :                 {
    5181                 :             :                   /* The function already exists in the current
    5182                 :             :                      namespace.  We will still want to insert it if
    5183                 :             :                      it is revealing a not-revealed thing.  */
    5184                 :      270698 :                   found = true;
    5185                 :      270698 :                   if (!revealing_p)
    5186                 :             :                     ;
    5187                 :         668 :                   else if (old.using_p ())
    5188                 :             :                     {
    5189                 :         641 :                       if (exporting)
    5190                 :             :                         /* Update in place.  'tis ok.  */
    5191                 :         635 :                         OVL_EXPORT_P (old.get_using ()) = true;
    5192                 :             :                       ;
    5193                 :             :                     }
    5194                 :          27 :                   else if (DECL_MODULE_EXPORT_P (new_fn))
    5195                 :             :                     ;
    5196                 :             :                   else
    5197                 :             :                     {
    5198                 :          27 :                       value = old.remove_node (value);
    5199                 :          27 :                       found = false;
    5200                 :             :                     }
    5201                 :             :                   break;
    5202                 :             :                 }
    5203                 :    46892459 :               else if (old.using_p ())
    5204                 :    43718927 :                 continue; /* This is a using decl. */
    5205                 :     3173532 :               else if (old.hidden_p () && DECL_IS_UNDECLARED_BUILTIN (old_fn))
    5206                 :     2797399 :                 continue; /* This is an anticipated builtin.  */
    5207                 :      376133 :               else if (!matching_fn_p (new_fn, old_fn))
    5208                 :      376089 :                 continue; /* Parameters do not match.  */
    5209                 :          44 :               else if (decls_match (new_fn, old_fn))
    5210                 :             :                 {
    5211                 :             :                   /* Extern "C" in different namespaces.  */
    5212                 :             :                   found = true;
    5213                 :             :                   break;
    5214                 :             :                 }
    5215                 :             :               else
    5216                 :             :                 {
    5217                 :          28 :                   diagnose_name_conflict (new_fn, old_fn);
    5218                 :          28 :                   failed = true;
    5219                 :          28 :                   found = true;
    5220                 :          28 :                   break;
    5221                 :             :                 }
    5222                 :             :             }
    5223                 :             : 
    5224                 :     8191422 :           if (!found && insert_p)
    5225                 :             :             /* Unlike the decl-pushing case we don't drop anticipated
    5226                 :             :                builtins here.  They don't cause a problem, and we'd
    5227                 :             :                like to match them with a future declaration.  */
    5228                 :     7920707 :             value = ovl_insert (new_fn, value, 1 + exporting);
    5229                 :             :         }
    5230                 :     5238081 :     }
    5231                 :     1013290 :   else if (value
    5232                 :             :            /* Ignore anticipated builtins.  */
    5233                 :       34583 :            && !anticipated_builtin_p (value)
    5234                 :     1047869 :            && (fn_scope_p || !decls_match (lookup.value, value)))
    5235                 :             :     {
    5236                 :          24 :       diagnose_name_conflict (lookup.value, value);
    5237                 :          24 :       failed = true;
    5238                 :             :     }
    5239                 :     1013266 :   else if (insert_p)
    5240                 :             :     {
    5241                 :     1013263 :       if (revealing_p
    5242                 :        1959 :           && module_exporting_p ()
    5243                 :        1959 :           && check_can_export_using_decl (lookup.value)
    5244                 :        1901 :           && lookup.value == value
    5245                 :     1013324 :           && !DECL_MODULE_EXPORT_P (value))
    5246                 :             :         {
    5247                 :             :           /* We're redeclaring the same value, but this time as
    5248                 :             :              newly exported: make sure to mark it as such.  */
    5249                 :          11 :           if (TREE_CODE (value) == TEMPLATE_DECL)
    5250                 :             :             {
    5251                 :           5 :               DECL_MODULE_EXPORT_P (value) = true;
    5252                 :             : 
    5253                 :           5 :               tree result = DECL_TEMPLATE_RESULT (value);
    5254                 :           5 :               retrofit_lang_decl (result);
    5255                 :           5 :               DECL_MODULE_PURVIEW_P (result) = true;
    5256                 :           5 :               DECL_MODULE_EXPORT_P (result) = true;
    5257                 :             :             }
    5258                 :             :           else
    5259                 :             :             {
    5260                 :           6 :               retrofit_lang_decl (value);
    5261                 :           6 :               DECL_MODULE_PURVIEW_P (value) = true;
    5262                 :           6 :               DECL_MODULE_EXPORT_P (value) = true;
    5263                 :             :             }
    5264                 :             :         }
    5265                 :             :       else
    5266                 :     1013252 :         value = lookup.value;
    5267                 :             :     }
    5268                 :             :   
    5269                 :             :   /* Now the type binding.  */
    5270                 :     6364232 :   if (lookup.type)
    5271                 :             :     {
    5272                 :      112880 :       if (type && !decls_match (lookup.type, type))
    5273                 :             :         {
    5274                 :           4 :           diagnose_name_conflict (lookup.type, type);
    5275                 :           4 :           failed = true;
    5276                 :             :         }
    5277                 :      112876 :       else if (insert_p)
    5278                 :             :         {
    5279                 :      112876 :           if (revealing_p
    5280                 :         223 :               && module_exporting_p ()
    5281                 :         220 :               && check_can_export_using_decl (lookup.type)
    5282                 :         208 :               && lookup.type == type
    5283                 :      112879 :               && !DECL_MODULE_EXPORT_P (type))
    5284                 :             :             {
    5285                 :             :               /* We're redeclaring the same type, but this time as
    5286                 :             :                  newly exported: make sure to mark it as such.  */
    5287                 :           3 :               retrofit_lang_decl (type);
    5288                 :           3 :               DECL_MODULE_PURVIEW_P (type) = true;
    5289                 :           3 :               DECL_MODULE_EXPORT_P (type) = true;
    5290                 :             :             }
    5291                 :             :           else
    5292                 :      112873 :             type = lookup.type;
    5293                 :             :         }
    5294                 :             :     }
    5295                 :             : 
    5296                 :     6364232 :   if (insert_p)
    5297                 :             :     {
    5298                 :             :       /* If value is empty, shift any class or enumeration name back.  */
    5299                 :     6364223 :       if (!value)
    5300                 :             :         {
    5301                 :      112849 :           value = type;
    5302                 :      112849 :           type = NULL_TREE;
    5303                 :             :         }
    5304                 :     6364223 :       *value_p = value;
    5305                 :     6364223 :       *type_p = type;
    5306                 :             :     }
    5307                 :             : 
    5308                 :     6364232 :   return failed;
    5309                 :             : }
    5310                 :             : 
    5311                 :             : /* Returns true if ANCESTOR encloses DESCENDANT, including matching.
    5312                 :             :    Both are namespaces.  */
    5313                 :             : 
    5314                 :             : bool
    5315                 :   106249815 : is_nested_namespace (tree ancestor, tree descendant, bool inline_only)
    5316                 :             : {
    5317                 :   106249815 :   int depth = SCOPE_DEPTH (ancestor);
    5318                 :             : 
    5319                 :   106249815 :   if (!depth && !inline_only)
    5320                 :             :     /* The global namespace encloses everything.  */
    5321                 :             :     return true;
    5322                 :             : 
    5323                 :   108163139 :   while (SCOPE_DEPTH (descendant) > depth
    5324                 :   108163139 :          && (!inline_only || DECL_NAMESPACE_INLINE_P (descendant)))
    5325                 :     2003400 :     descendant = CP_DECL_CONTEXT (descendant);
    5326                 :             : 
    5327                 :   106159739 :   return ancestor == descendant;
    5328                 :             : }
    5329                 :             : 
    5330                 :             : /* Returns true if ROOT (a non-alias namespace, class, or function)
    5331                 :             :    encloses CHILD.  CHILD may be either a class type or a namespace
    5332                 :             :    (maybe alias).  */
    5333                 :             : 
    5334                 :             : bool
    5335                 :    78227291 : is_ancestor (tree root, tree child)
    5336                 :             : {
    5337                 :    78227291 :   gcc_checking_assert ((TREE_CODE (root) == NAMESPACE_DECL
    5338                 :             :                         && !DECL_NAMESPACE_ALIAS (root))
    5339                 :             :                        || TREE_CODE (root) == FUNCTION_DECL
    5340                 :             :                        || CLASS_TYPE_P (root));
    5341                 :    78227291 :   gcc_checking_assert (TREE_CODE (child) == NAMESPACE_DECL
    5342                 :             :                        || CLASS_TYPE_P (child));
    5343                 :             : 
    5344                 :             :   /* The global namespace encloses everything.  Early-out for the
    5345                 :             :      common case.  */
    5346                 :    78227291 :   if (root == global_namespace)
    5347                 :             :     return true;
    5348                 :             : 
    5349                 :             :   /* Search CHILD until we reach namespace scope.  */
    5350                 :   162047404 :   while (TREE_CODE (child) != NAMESPACE_DECL)
    5351                 :             :     {
    5352                 :             :       /* If we've reached the ROOT, it encloses CHILD.  */
    5353                 :    84080818 :       if (root == child)
    5354                 :             :         return true;
    5355                 :             : 
    5356                 :             :       /* Go out one level.  */
    5357                 :    84080753 :       if (TYPE_P (child))
    5358                 :    83173722 :         child = TYPE_NAME (child);
    5359                 :    84080753 :       child = CP_DECL_CONTEXT (child);
    5360                 :             :     }
    5361                 :             : 
    5362                 :    77966586 :   if (TREE_CODE (root) != NAMESPACE_DECL)
    5363                 :             :     /* Failed to meet the non-namespace we were looking for.  */
    5364                 :             :     return false;
    5365                 :             : 
    5366                 :    77966568 :   if (tree alias = DECL_NAMESPACE_ALIAS (child))
    5367                 :           4 :     child = alias;
    5368                 :             : 
    5369                 :    77966568 :   return is_nested_namespace (root, child);
    5370                 :             : }
    5371                 :             : 
    5372                 :             : /* Enter the class or namespace scope indicated by T suitable for name
    5373                 :             :    lookup.  T can be arbitrary scope, not necessary nested inside the
    5374                 :             :    current scope.  Returns a non-null scope to pop iff pop_scope
    5375                 :             :    should be called later to exit this scope.  */
    5376                 :             : 
    5377                 :             : tree
    5378                 :   290122671 : push_scope (tree t)
    5379                 :             : {
    5380                 :   290122671 :   if (TREE_CODE (t) == NAMESPACE_DECL)
    5381                 :    68245433 :     push_decl_namespace (t);
    5382                 :   221877238 :   else if (CLASS_TYPE_P (t))
    5383                 :             :     {
    5384                 :   160996467 :       if (!at_class_scope_p ()
    5385                 :   160996467 :           || !same_type_p (current_class_type, t))
    5386                 :    75617825 :         push_nested_class (t);
    5387                 :             :       else
    5388                 :             :         /* T is the same as the current scope.  There is therefore no
    5389                 :             :            need to re-enter the scope.  Since we are not actually
    5390                 :             :            pushing a new scope, our caller should not call
    5391                 :             :            pop_scope.  */
    5392                 :             :         t = NULL_TREE;
    5393                 :             :     }
    5394                 :             : 
    5395                 :   290122671 :   return t;
    5396                 :             : }
    5397                 :             : 
    5398                 :             : /* Leave scope pushed by push_scope.  */
    5399                 :             : 
    5400                 :             : void
    5401                 :   204744508 : pop_scope (tree t)
    5402                 :             : {
    5403                 :   204744508 :   if (t == NULL_TREE)
    5404                 :             :     return;
    5405                 :   204744026 :   if (TREE_CODE (t) == NAMESPACE_DECL)
    5406                 :    68245430 :     pop_decl_namespace ();
    5407                 :   136498596 :   else if CLASS_TYPE_P (t)
    5408                 :    75617825 :     pop_nested_class ();
    5409                 :             : }
    5410                 :             : 
    5411                 :             : /* Subroutine of push_inner_scope.  */
    5412                 :             : 
    5413                 :             : static void
    5414                 :      245113 : push_inner_scope_r (tree outer, tree inner)
    5415                 :             : {
    5416                 :      245113 :   tree prev;
    5417                 :             : 
    5418                 :      245113 :   if (outer == inner
    5419                 :      245113 :       || (TREE_CODE (inner) != NAMESPACE_DECL && !CLASS_TYPE_P (inner)))
    5420                 :             :     return;
    5421                 :             : 
    5422                 :      245098 :   prev = CP_DECL_CONTEXT (TREE_CODE (inner) == NAMESPACE_DECL ? inner : TYPE_NAME (inner));
    5423                 :      245098 :   if (outer != prev)
    5424                 :        2351 :     push_inner_scope_r (outer, prev);
    5425                 :      245098 :   if (TREE_CODE (inner) == NAMESPACE_DECL)
    5426                 :             :     {
    5427                 :             :       cp_binding_level *save_template_parm = 0;
    5428                 :             :       /* Temporary take out template parameter scopes.  They are saved
    5429                 :             :          in reversed order in save_template_parm.  */
    5430                 :       53976 :       while (current_binding_level->kind == sk_template_parms)
    5431                 :             :         {
    5432                 :       26916 :           cp_binding_level *b = current_binding_level;
    5433                 :       26916 :           current_binding_level = b->level_chain;
    5434                 :       26916 :           b->level_chain = save_template_parm;
    5435                 :       26916 :           save_template_parm = b;
    5436                 :             :         }
    5437                 :             : 
    5438                 :       27060 :       resume_scope (NAMESPACE_LEVEL (inner));
    5439                 :       27060 :       current_namespace = inner;
    5440                 :             : 
    5441                 :             :       /* Restore template parameter scopes.  */
    5442                 :       53976 :       while (save_template_parm)
    5443                 :             :         {
    5444                 :       26916 :           cp_binding_level *b = save_template_parm;
    5445                 :       26916 :           save_template_parm = b->level_chain;
    5446                 :       26916 :           b->level_chain = current_binding_level;
    5447                 :       26916 :           current_binding_level = b;
    5448                 :             :         }
    5449                 :             :     }
    5450                 :             :   else
    5451                 :      218038 :     pushclass (inner);
    5452                 :             : }
    5453                 :             : 
    5454                 :             : /* Enter the scope INNER from current scope.  INNER must be a scope
    5455                 :             :    nested inside current scope.  This works with both name lookup and
    5456                 :             :    pushing name into scope.  In case a template parameter scope is present,
    5457                 :             :    namespace is pushed under the template parameter scope according to
    5458                 :             :    name lookup rule in 14.6.1/6.
    5459                 :             : 
    5460                 :             :    Return the former current scope suitable for pop_inner_scope.  */
    5461                 :             : 
    5462                 :             : tree
    5463                 :      242762 : push_inner_scope (tree inner)
    5464                 :             : {
    5465                 :      242762 :   tree outer = current_scope ();
    5466                 :      242762 :   if (!outer)
    5467                 :           0 :     outer = current_namespace;
    5468                 :             : 
    5469                 :      242762 :   push_inner_scope_r (outer, inner);
    5470                 :      242762 :   return outer;
    5471                 :             : }
    5472                 :             : 
    5473                 :             : /* Exit the current scope INNER back to scope OUTER.  */
    5474                 :             : 
    5475                 :             : void
    5476                 :      242762 : pop_inner_scope (tree outer, tree inner)
    5477                 :             : {
    5478                 :      242762 :   if (outer == inner
    5479                 :      242762 :       || (TREE_CODE (inner) != NAMESPACE_DECL && !CLASS_TYPE_P (inner)))
    5480                 :             :     return;
    5481                 :             : 
    5482                 :      487848 :   while (outer != inner)
    5483                 :             :     {
    5484                 :      245101 :       if (TREE_CODE (inner) == NAMESPACE_DECL)
    5485                 :             :         {
    5486                 :             :           cp_binding_level *save_template_parm = 0;
    5487                 :             :           /* Temporary take out template parameter scopes.  They are saved
    5488                 :             :              in reversed order in save_template_parm.  */
    5489                 :       53976 :           while (current_binding_level->kind == sk_template_parms)
    5490                 :             :             {
    5491                 :       26916 :               cp_binding_level *b = current_binding_level;
    5492                 :       26916 :               current_binding_level = b->level_chain;
    5493                 :       26916 :               b->level_chain = save_template_parm;
    5494                 :       26916 :               save_template_parm = b;
    5495                 :             :             }
    5496                 :             : 
    5497                 :       27060 :           pop_namespace ();
    5498                 :             : 
    5499                 :             :           /* Restore template parameter scopes.  */
    5500                 :       81036 :           while (save_template_parm)
    5501                 :             :             {
    5502                 :       26916 :               cp_binding_level *b = save_template_parm;
    5503                 :       26916 :               save_template_parm = b->level_chain;
    5504                 :       26916 :               b->level_chain = current_binding_level;
    5505                 :       26916 :               current_binding_level = b;
    5506                 :             :             }
    5507                 :             :         }
    5508                 :             :       else
    5509                 :      218041 :         popclass ();
    5510                 :             : 
    5511                 :      245098 :       inner = CP_DECL_CONTEXT (TREE_CODE (inner) == NAMESPACE_DECL ? inner : TYPE_NAME (inner));
    5512                 :             :     }
    5513                 :             : }
    5514                 :             : 
    5515                 :             : /* Do a pushlevel for class declarations.  */
    5516                 :             : 
    5517                 :             : void
    5518                 :   174182253 : pushlevel_class (void)
    5519                 :             : {
    5520                 :   174182253 :   class_binding_level = begin_scope (sk_class, current_class_type);
    5521                 :   174182253 : }
    5522                 :             : 
    5523                 :             : /* ...and a poplevel for class declarations.  */
    5524                 :             : 
    5525                 :             : void
    5526                 :   342645614 : poplevel_class (void)
    5527                 :             : {
    5528                 :   342645614 :   cp_binding_level *level = class_binding_level;
    5529                 :   342645614 :   cp_class_binding *cb;
    5530                 :   342645614 :   size_t i;
    5531                 :   342645614 :   tree shadowed;
    5532                 :             : 
    5533                 :   342645614 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    5534                 :   342645614 :   gcc_assert (level != 0);
    5535                 :             : 
    5536                 :             :   /* If we're leaving a toplevel class, cache its binding level.  */
    5537                 :   342645611 :   if (current_class_depth == 1)
    5538                 :   219097269 :     previous_class_level = level;
    5539                 :   342645611 :   for (shadowed = level->type_shadowed;
    5540                 :  1208830930 :        shadowed;
    5541                 :   866185319 :        shadowed = TREE_CHAIN (shadowed))
    5542                 :   866185319 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed), TREE_VALUE (shadowed));
    5543                 :             : 
    5544                 :             :   /* Remove the bindings for all of the class-level declarations.  */
    5545                 :   342645611 :   if (level->class_shadowed)
    5546                 :             :     {
    5547                 :   512785360 :       FOR_EACH_VEC_ELT (*level->class_shadowed, i, cb)
    5548                 :             :         {
    5549                 :   392793374 :           IDENTIFIER_BINDING (cb->identifier) = cb->base->previous;
    5550                 :   392793374 :           cxx_binding_free (cb->base);
    5551                 :             :         }
    5552                 :   119991986 :       ggc_free (level->class_shadowed);
    5553                 :   119991986 :       level->class_shadowed = NULL;
    5554                 :             :     }
    5555                 :             : 
    5556                 :             :   /* Now, pop out of the binding level which we created up in the
    5557                 :             :      `pushlevel_class' routine.  */
    5558                 :   342645611 :   gcc_assert (current_binding_level == level);
    5559                 :   342645611 :   leave_scope ();
    5560                 :   342645611 : }
    5561                 :             : 
    5562                 :             : /* Set INHERITED_VALUE_BINDING_P on BINDING to true or false, as
    5563                 :             :    appropriate.  DECL is the value to which a name has just been
    5564                 :             :    bound.  CLASS_TYPE is the class in which the lookup occurred.  */
    5565                 :             : 
    5566                 :             : static void
    5567                 :   131935934 : set_inherited_value_binding_p (cxx_binding *binding, tree decl,
    5568                 :             :                                tree class_type)
    5569                 :             : {
    5570                 :   131935934 :   if (binding->value == decl && TREE_CODE (decl) != TREE_LIST)
    5571                 :             :     {
    5572                 :   131379504 :       tree context;
    5573                 :             : 
    5574                 :   131379504 :       if (is_overloaded_fn (decl))
    5575                 :    38275937 :         context = ovl_scope (decl);
    5576                 :             :       else
    5577                 :             :         {
    5578                 :    93103567 :           gcc_assert (DECL_P (decl));
    5579                 :    93103567 :           context = context_for_name_lookup (decl);
    5580                 :             :         }
    5581                 :             : 
    5582                 :   131379504 :       if (is_properly_derived_from (class_type, context))
    5583                 :    16590231 :         INHERITED_VALUE_BINDING_P (binding) = 1;
    5584                 :             :       else
    5585                 :   114789273 :         INHERITED_VALUE_BINDING_P (binding) = 0;
    5586                 :             :     }
    5587                 :      556430 :   else if (binding->value == decl)
    5588                 :             :     /* We only encounter a TREE_LIST when there is an ambiguity in the
    5589                 :             :        base classes.  Such an ambiguity can be overridden by a
    5590                 :             :        definition in this class.  */
    5591                 :      556430 :     INHERITED_VALUE_BINDING_P (binding) = 1;
    5592                 :             :   else
    5593                 :           0 :     INHERITED_VALUE_BINDING_P (binding) = 0;
    5594                 :   131935934 : }
    5595                 :             : 
    5596                 :             : /* Make the declaration of X appear in CLASS scope.  */
    5597                 :             : 
    5598                 :             : bool
    5599                 :   152228300 : pushdecl_class_level (tree x)
    5600                 :             : {
    5601                 :   152228300 :   bool is_valid = true;
    5602                 :             : 
    5603                 :             :   /* Do nothing if we're adding to an outer lambda closure type,
    5604                 :             :      outer_binding will add it later if it's needed.  */
    5605                 :   152228300 :   if (current_class_type != class_binding_level->this_entity)
    5606                 :             :     return true;
    5607                 :             : 
    5608                 :   152228300 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    5609                 :             :   /* Get the name of X.  */
    5610                 :   304456600 :   tree name = OVL_NAME (x);
    5611                 :             : 
    5612                 :   152228300 :   if (name)
    5613                 :             :     {
    5614                 :   151933643 :       is_valid = push_class_level_binding (name, x);
    5615                 :   151933643 :       if (TREE_CODE (x) == TYPE_DECL)
    5616                 :   110110634 :         set_identifier_type_value (name, x);
    5617                 :             :     }
    5618                 :      294657 :   else if (ANON_AGGR_TYPE_P (TREE_TYPE (x)))
    5619                 :             :     {
    5620                 :             :       /* If X is an anonymous aggregate, all of its members are
    5621                 :             :          treated as if they were members of the class containing the
    5622                 :             :          aggregate, for naming purposes.  */
    5623                 :      159347 :       location_t save_location = input_location;
    5624                 :      159347 :       tree anon = TREE_TYPE (x);
    5625                 :      159347 :       if (vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (anon))
    5626                 :      191866 :         for (unsigned ix = member_vec->length (); ix--;)
    5627                 :             :           {
    5628                 :      176470 :             tree binding = (*member_vec)[ix];
    5629                 :      176470 :             if (STAT_HACK_P (binding))
    5630                 :             :               {
    5631                 :           0 :                 if (!pushdecl_class_level (STAT_TYPE (binding)))
    5632                 :           0 :                   is_valid = false;
    5633                 :           0 :                 binding = STAT_DECL (binding);
    5634                 :             :               }
    5635                 :      176470 :             if (!pushdecl_class_level (binding))
    5636                 :           0 :               is_valid = false;
    5637                 :             :         }
    5638                 :             :       else
    5639                 :      631659 :         for (tree f = TYPE_FIELDS (anon); f; f = DECL_CHAIN (f))
    5640                 :      487708 :           if (TREE_CODE (f) == FIELD_DECL)
    5641                 :             :             {
    5642                 :      309258 :               input_location = DECL_SOURCE_LOCATION (f);
    5643                 :      309258 :               if (!pushdecl_class_level (f))
    5644                 :      487708 :                 is_valid = false;
    5645                 :             :             }
    5646                 :      159347 :       input_location = save_location;
    5647                 :             :     }
    5648                 :   152228300 :   return is_valid;
    5649                 :   152228300 : }
    5650                 :             : 
    5651                 :             : /* Return the BINDING (if any) for NAME in SCOPE, which is a class
    5652                 :             :    scope.  If the value returned is non-NULL, and the PREVIOUS field
    5653                 :             :    is not set, callers must set the PREVIOUS field explicitly.  */
    5654                 :             : 
    5655                 :             : static cxx_binding *
    5656                 :  1655834887 : get_class_binding (tree name, cp_binding_level *scope)
    5657                 :             : {
    5658                 :  1655834887 :   tree class_type;
    5659                 :  1655834887 :   tree type_binding;
    5660                 :  1655834887 :   tree value_binding;
    5661                 :  1655834887 :   cxx_binding *binding;
    5662                 :             : 
    5663                 :  1655834887 :   class_type = scope->this_entity;
    5664                 :             : 
    5665                 :             :   /* Get the type binding.  */
    5666                 :  1655834887 :   type_binding = lookup_member (class_type, name,
    5667                 :             :                                 /*protect=*/2, /*want_type=*/true,
    5668                 :             :                                 tf_warning_or_error);
    5669                 :             :   /* Get the value binding.  */
    5670                 :  1655834887 :   value_binding = lookup_member (class_type, name,
    5671                 :             :                                  /*protect=*/2, /*want_type=*/false,
    5672                 :             :                                  tf_warning_or_error);
    5673                 :             : 
    5674                 :             :   /* If we found either a type binding or a value binding, create a
    5675                 :             :      new binding object.  */
    5676                 :  1655834887 :   if (type_binding || value_binding)
    5677                 :             :     {
    5678                 :   131935934 :       binding = new_class_binding (name,
    5679                 :             :                                    value_binding,
    5680                 :             :                                    type_binding,
    5681                 :             :                                    scope);
    5682                 :   131935934 :       set_inherited_value_binding_p (binding, value_binding, class_type);
    5683                 :             :     }
    5684                 :             :   else
    5685                 :             :     binding = NULL;
    5686                 :             : 
    5687                 :  1655834887 :   return binding;
    5688                 :             : }
    5689                 :             : 
    5690                 :             : /* Make the declaration(s) of X appear in CLASS scope under the name
    5691                 :             :    NAME.  Returns true if the binding is valid.  */
    5692                 :             : 
    5693                 :             : bool
    5694                 :   380853410 : push_class_level_binding (tree name, tree x)
    5695                 :             : {
    5696                 :   380853410 :   cxx_binding *binding;
    5697                 :   380853410 :   tree decl = x;
    5698                 :   380853410 :   bool ok;
    5699                 :             : 
    5700                 :   380853410 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    5701                 :             : 
    5702                 :             :   /* The class_binding_level will be NULL if x is a template
    5703                 :             :      parameter name in a member template.  */
    5704                 :   380853410 :   if (!class_binding_level)
    5705                 :             :     return true;
    5706                 :             : 
    5707                 :   380853410 :   if (name == error_mark_node)
    5708                 :             :     return false;
    5709                 :             : 
    5710                 :             :   /* Can happen for an erroneous declaration (c++/60384).  */
    5711                 :   380853410 :   if (!identifier_p (name))
    5712                 :             :     {
    5713                 :           3 :       gcc_assert (errorcount || sorrycount);
    5714                 :             :       return false;
    5715                 :             :     }
    5716                 :             : 
    5717                 :             :   /* Check for invalid member names.  But don't worry about a default
    5718                 :             :      argument-scope lambda being pushed after the class is complete.  */
    5719                 :   380853422 :   gcc_assert (TYPE_BEING_DEFINED (current_class_type)
    5720                 :             :               || LAMBDA_TYPE_P (TREE_TYPE (decl)));
    5721                 :             :   /* Check that we're pushing into the right binding level.  */
    5722                 :   380853407 :   gcc_assert (current_class_type == class_binding_level->this_entity);
    5723                 :             : 
    5724                 :             :   /* We could have been passed a tree list if this is an ambiguous
    5725                 :             :      declaration. If so, pull the declaration out because
    5726                 :             :      check_template_shadow will not handle a TREE_LIST.  */
    5727                 :   380853407 :   if (TREE_CODE (decl) == TREE_LIST
    5728                 :   380853407 :       && TREE_TYPE (decl) == error_mark_node)
    5729                 :           0 :     decl = TREE_VALUE (decl);
    5730                 :             : 
    5731                 :   380853407 :   if (!check_template_shadow (decl))
    5732                 :             :     return false;
    5733                 :             : 
    5734                 :             :   /* [class.mem]
    5735                 :             : 
    5736                 :             :      If T is the name of a class, then each of the following shall
    5737                 :             :      have a name different from T:
    5738                 :             : 
    5739                 :             :      -- every static data member of class T;
    5740                 :             : 
    5741                 :             :      -- every member of class T that is itself a type;
    5742                 :             : 
    5743                 :             :      -- every enumerator of every member of class T that is an
    5744                 :             :         enumerated type;
    5745                 :             : 
    5746                 :             :      -- every member of every anonymous union that is a member of
    5747                 :             :         class T.
    5748                 :             : 
    5749                 :             :      (Non-static data members were also forbidden to have the same
    5750                 :             :      name as T until TC1.)  */
    5751                 :   380853355 :   if ((VAR_P (x)
    5752                 :   380853355 :        || TREE_CODE (x) == CONST_DECL
    5753                 :   367038662 :        || (TREE_CODE (x) == TYPE_DECL
    5754                 :   110110615 :            && !DECL_SELF_REFERENCE_P (x))
    5755                 :             :        /* A data member of an anonymous union.  */
    5756                 :   309476698 :        || (TREE_CODE (x) == FIELD_DECL
    5757                 :    22040856 :            && DECL_CONTEXT (x) != current_class_type))
    5758                 :   438864813 :       && DECL_NAME (x) == DECL_NAME (TYPE_NAME (current_class_type)))
    5759                 :             :     {
    5760                 :          31 :       tree scope = context_for_name_lookup (x);
    5761                 :          31 :       if (TYPE_P (scope) && same_type_p (scope, current_class_type))
    5762                 :             :         {
    5763                 :          31 :           error_at (DECL_SOURCE_LOCATION (x),
    5764                 :             :                     "%qD has the same name as the class in which it is "
    5765                 :             :                     "declared", x);
    5766                 :          31 :           return false;
    5767                 :             :         }
    5768                 :             :     }
    5769                 :             : 
    5770                 :             :   /* Get the current binding for NAME in this class, if any.  */
    5771                 :   380853324 :   binding = IDENTIFIER_BINDING (name);
    5772                 :   380853324 :   if (!binding || binding->scope != class_binding_level)
    5773                 :             :     {
    5774                 :   271847050 :       binding = get_class_binding (name, class_binding_level);
    5775                 :             :       /* If a new binding was created, put it at the front of the
    5776                 :             :          IDENTIFIER_BINDING list.  */
    5777                 :   271847050 :       if (binding)
    5778                 :             :         {
    5779                 :    10985835 :           binding->previous = IDENTIFIER_BINDING (name);
    5780                 :    10985835 :           IDENTIFIER_BINDING (name) = binding;
    5781                 :             :         }
    5782                 :             :     }
    5783                 :             : 
    5784                 :             :   /* If there is already a binding, then we may need to update the
    5785                 :             :      current value.  */
    5786                 :   119992109 :   if (binding && binding->value)
    5787                 :             :     {
    5788                 :   119992109 :       tree bval = binding->value;
    5789                 :   119992109 :       tree old_decl = NULL_TREE;
    5790                 :   119992109 :       tree target_decl = strip_using_decl (decl);
    5791                 :   119992109 :       tree target_bval = strip_using_decl (bval);
    5792                 :             : 
    5793                 :   119992109 :       if (INHERITED_VALUE_BINDING_P (binding))
    5794                 :             :         {
    5795                 :             :           /* If the old binding was from a base class, and was for a
    5796                 :             :              tag name, slide it over to make room for the new binding.
    5797                 :             :              The old binding is still visible if explicitly qualified
    5798                 :             :              with a class-key.  */
    5799                 :    13101933 :           if (TREE_CODE (target_bval) == TYPE_DECL
    5800                 :     6760600 :               && DECL_ARTIFICIAL (target_bval)
    5801                 :    13682410 :               && !(TREE_CODE (target_decl) == TYPE_DECL
    5802                 :      580465 :                    && DECL_ARTIFICIAL (target_decl)))
    5803                 :             :             {
    5804                 :       65984 :               old_decl = binding->type;
    5805                 :       65984 :               binding->type = bval;
    5806                 :       65984 :               binding->value = NULL_TREE;
    5807                 :       65984 :               INHERITED_VALUE_BINDING_P (binding) = 0;
    5808                 :             :             }
    5809                 :             :           else
    5810                 :             :             {
    5811                 :    13035949 :               old_decl = bval;
    5812                 :             :               /* Any inherited type declaration is hidden by the type
    5813                 :             :                  declaration in the derived class.  */
    5814                 :    13035949 :               if (TREE_CODE (target_decl) == TYPE_DECL
    5815                 :    13035949 :                   && DECL_ARTIFICIAL (target_decl))
    5816                 :      515007 :                 binding->type = NULL_TREE;
    5817                 :             :             }
    5818                 :             :         }
    5819                 :   106890176 :       else if (TREE_CODE (decl) == USING_DECL
    5820                 :        3179 :                && TREE_CODE (bval) == USING_DECL
    5821                 :   106890266 :                && same_type_p (USING_DECL_SCOPE (decl),
    5822                 :             :                                USING_DECL_SCOPE (bval)))
    5823                 :             :         /* This is a using redeclaration that will be diagnosed later
    5824                 :             :            in supplement_binding */
    5825                 :             :         ;
    5826                 :   106890135 :       else if (TREE_CODE (decl) == USING_DECL
    5827                 :        3138 :                && TREE_CODE (bval) == USING_DECL
    5828                 :          49 :                && DECL_DEPENDENT_P (decl)
    5829                 :   106890146 :                && DECL_DEPENDENT_P (bval))
    5830                 :             :         return true;
    5831                 :   106890124 :       else if (TREE_CODE (decl) == USING_DECL
    5832                 :        3127 :                && DECL_DEPENDENT_P (decl)
    5833                 :   106893184 :                && OVL_P (target_bval))
    5834                 :             :         /* The new dependent using beats an old overload.  */
    5835                 :             :         old_decl = bval;
    5836                 :   106887064 :       else if (TREE_CODE (bval) == USING_DECL
    5837                 :      690600 :                && DECL_DEPENDENT_P (bval)
    5838                 :   107270833 :                && OVL_P (target_decl))
    5839                 :             :         /* The old dependent using beats a new overload.  */
    5840                 :             :         return true;
    5841                 :   106503311 :       else if (OVL_P (target_decl)
    5842                 :   106224337 :                && OVL_P (target_bval))
    5843                 :             :         /* The new overload set contains the old one.  */
    5844                 :             :         old_decl = bval;
    5845                 :             : 
    5846                 :   119329298 :       if (old_decl && binding->scope == class_binding_level)
    5847                 :             :         {
    5848                 :   119329298 :           binding->value = x;
    5849                 :             :           /* It is always safe to clear INHERITED_VALUE_BINDING_P
    5850                 :             :              here.  This function is only used to register bindings
    5851                 :             :              from with the class definition itself.  */
    5852                 :   119329298 :           INHERITED_VALUE_BINDING_P (binding) = 0;
    5853                 :   119329298 :           return true;
    5854                 :             :         }
    5855                 :             :     }
    5856                 :             : 
    5857                 :             :   /* Note that we declared this value so that we can issue an error if
    5858                 :             :      this is an invalid redeclaration of a name already used for some
    5859                 :             :      other purpose.  */
    5860                 :   261140262 :   note_name_declared_in_class (name, decl);
    5861                 :             : 
    5862                 :             :   /* If we didn't replace an existing binding, put the binding on the
    5863                 :             :      stack of bindings for the identifier, and update the shadowed
    5864                 :             :      list.  */
    5865                 :   261140262 :   if (binding && binding->scope == class_binding_level)
    5866                 :             :     /* Supplement the existing binding.  */
    5867                 :      279047 :     ok = supplement_binding (binding, decl);
    5868                 :             :   else
    5869                 :             :     {
    5870                 :             :       /* Create a new binding.  */
    5871                 :   260861215 :       push_binding (name, decl, class_binding_level);
    5872                 :   260861215 :       ok = true;
    5873                 :             :     }
    5874                 :             : 
    5875                 :             :   return ok;
    5876                 :   380853410 : }
    5877                 :             : 
    5878                 :             : /* Process and lookup a using decl SCOPE::lookup.name, filling in
    5879                 :             :    lookup.values & lookup.type.  Return a USING_DECL, or NULL_TREE on
    5880                 :             :    failure.  */
    5881                 :             : 
    5882                 :             : static tree
    5883                 :     8784483 : lookup_using_decl (tree scope, name_lookup &lookup)
    5884                 :             : {
    5885                 :     8784483 :   tree current = current_scope ();
    5886                 :     8784483 :   bool dependent_p = false;
    5887                 :     8784483 :   tree binfo = NULL_TREE;
    5888                 :     8784483 :   base_kind b_kind = bk_not_base;
    5889                 :             : 
    5890                 :             :   /* Because C++20 breaks the invariant that only member using-decls
    5891                 :             :      refer to members and only non-member using-decls refer to
    5892                 :             :      non-members, we first do the lookups, and then do validation that
    5893                 :             :      what we found is ok.  */
    5894                 :             : 
    5895                 :     8784483 :   if (TREE_CODE (scope) == ENUMERAL_TYPE
    5896                 :      367255 :       && cxx_dialect < cxx20
    5897                 :      367255 :       && UNSCOPED_ENUM_P (scope)
    5898                 :     8784499 :       && !TYPE_FUNCTION_SCOPE_P (scope))
    5899                 :             :     {
    5900                 :             :       /* PR c++/60265 argued that since C++11 added explicit enum scope, we
    5901                 :             :          should allow it as meaning the enclosing scope.  I don't see any
    5902                 :             :          justification for this in C++11, but let's keep allowing it.  */
    5903                 :          14 :       tree ctx = CP_TYPE_CONTEXT (scope);
    5904                 :          36 :       if (CLASS_TYPE_P (ctx) == CLASS_TYPE_P (current))
    5905                 :     8784483 :         scope = ctx;
    5906                 :             :     }
    5907                 :             : 
    5908                 :             :   /* You cannot using-decl a destructor.  */
    5909                 :     8784483 :   if (TREE_CODE (lookup.name) == BIT_NOT_EXPR)
    5910                 :             :     {
    5911                 :           6 :       error ("%<%T%s%D%> names destructor", scope,
    5912                 :           3 :              &"::"[scope == global_namespace ? 2 : 0], lookup.name);
    5913                 :           3 :       return NULL_TREE;
    5914                 :             :     }
    5915                 :             : 
    5916                 :     8784480 :   if (TREE_CODE (scope) == NAMESPACE_DECL)
    5917                 :             :     {
    5918                 :             :       /* Naming a namespace member.  */
    5919                 :     6259955 :       qualified_namespace_lookup (scope, &lookup);
    5920                 :             : 
    5921                 :     6259955 :       if (TYPE_P (current)
    5922                 :           4 :           && (!lookup.value
    5923                 :           0 :               || lookup.type
    5924                 :           0 :               || cxx_dialect < cxx20
    5925                 :           0 :               || TREE_CODE (lookup.value) != CONST_DECL))
    5926                 :             :         {
    5927                 :           4 :           error ("using-declaration for non-member at class scope");
    5928                 :           4 :           return NULL_TREE;
    5929                 :             :         }
    5930                 :             :     }
    5931                 :     2524525 :   else if (TREE_CODE (scope) == ENUMERAL_TYPE)
    5932                 :             :     {
    5933                 :             :       /* Naming an enumeration member.  */
    5934                 :      367242 :       if (cxx_dialect < cxx20)
    5935                 :          12 :         error ("%<using%> with enumeration scope %q#T "
    5936                 :             :                "only available with %<-std=c++20%> or %<-std=gnu++20%>",
    5937                 :             :                scope);
    5938                 :      367242 :       lookup.value = lookup_enumerator (scope, lookup.name);
    5939                 :             :     }
    5940                 :             :   else
    5941                 :             :     {
    5942                 :             :       /* Naming a class member.  This is awkward in C++20, because we
    5943                 :             :          might be naming an enumerator of an unrelated class.  */
    5944                 :             : 
    5945                 :     2157283 :       tree npscope = scope;
    5946                 :     2157283 :       if (PACK_EXPANSION_P (scope))
    5947                 :        9396 :         npscope = PACK_EXPANSION_PATTERN (scope);
    5948                 :             : 
    5949                 :     2157283 :       if (!MAYBE_CLASS_TYPE_P (npscope))
    5950                 :             :         {
    5951                 :          11 :           error ("%qT is not a class, namespace, or enumeration", npscope);
    5952                 :          11 :           return NULL_TREE;
    5953                 :             :         }
    5954                 :             : 
    5955                 :             :       /* Using T::T declares inheriting ctors, even if T is a typedef.  */
    5956                 :     2157272 :       if (lookup.name == TYPE_IDENTIFIER (npscope)
    5957                 :     2157272 :           || constructor_name_p (lookup.name, npscope))
    5958                 :             :         {
    5959                 :      205090 :           if (!TYPE_P (current))
    5960                 :             :             {
    5961                 :           0 :               error ("non-member using-declaration names constructor of %qT",
    5962                 :             :                      npscope);
    5963                 :           0 :               return NULL_TREE;
    5964                 :             :             }
    5965                 :      205090 :           maybe_warn_cpp0x (CPP0X_INHERITING_CTORS);
    5966                 :      205090 :           lookup.name = ctor_identifier;
    5967                 :      205090 :           CLASSTYPE_NON_AGGREGATE (current) = true;
    5968                 :             :         }
    5969                 :             : 
    5970                 :     2157272 :       if (!TYPE_P (current) && cxx_dialect < cxx20)
    5971                 :             :         {
    5972                 :           6 :           error ("using-declaration for member at non-class scope");
    5973                 :           6 :           return NULL_TREE;
    5974                 :             :         }
    5975                 :             : 
    5976                 :     2157266 :       bool depscope = dependent_scope_p (scope);
    5977                 :             : 
    5978                 :     2157266 :       if (depscope)
    5979                 :             :         /* Leave binfo null.  */;
    5980                 :     1590573 :       else if (TYPE_P (current))
    5981                 :             :         {
    5982                 :     1590566 :           binfo = lookup_base (current, scope, ba_any, &b_kind, tf_none);
    5983                 :     1590566 :           gcc_checking_assert (b_kind >= bk_not_base);
    5984                 :             : 
    5985                 :     1590566 :           if (b_kind == bk_not_base && any_dependent_bases_p ())
    5986                 :             :             /* Treat as-if dependent.  */
    5987                 :             :             depscope = true;
    5988                 :     1590544 :           else if (lookup.name == ctor_identifier
    5989                 :     1590544 :                    && (b_kind < bk_proper_base || !binfo_direct_p (binfo)))
    5990                 :             :             {
    5991                 :          15 :               if (any_dependent_bases_p ())
    5992                 :             :                 depscope = true;
    5993                 :             :               else
    5994                 :             :                 {
    5995                 :          15 :                   error ("%qT is not a direct base of %qT", scope, current);
    5996                 :          15 :                   return NULL_TREE;
    5997                 :             :                 }
    5998                 :             :             }
    5999                 :             : 
    6000                 :     1590551 :           if (b_kind < bk_proper_base)
    6001                 :          56 :             binfo = TYPE_BINFO (scope);
    6002                 :             :         }
    6003                 :             :       else
    6004                 :           7 :         binfo = TYPE_BINFO (scope);
    6005                 :             : 
    6006                 :     3181087 :       dependent_p = (depscope
    6007                 :     2878185 :                      || (IDENTIFIER_CONV_OP_P (lookup.name)
    6008                 :      134506 :                          && dependent_type_p (TREE_TYPE (lookup.name))));
    6009                 :             : 
    6010                 :     1590529 :       if (!dependent_p)
    6011                 :     1590529 :         lookup.value = lookup_member (binfo, lookup.name, /*protect=*/2,
    6012                 :             :                                       /*want_type=*/false, tf_none);
    6013                 :             : 
    6014                 :             :       /* If the lookup in the base contains a dependent using, this
    6015                 :             :          using is also dependent.  */
    6016                 :     1590529 :       if (!dependent_p && lookup.value && dependent_type_p (scope))
    6017                 :             :         {
    6018                 :          36 :           tree val = lookup.value;
    6019                 :          36 :           if (tree fns = maybe_get_fns (val))
    6020                 :          12 :             val = fns;
    6021                 :          64 :           for (tree f: lkp_range (val))
    6022                 :          36 :             if (TREE_CODE (f) == USING_DECL && DECL_DEPENDENT_P (f))
    6023                 :             :               {
    6024                 :             :                 dependent_p = true;
    6025                 :             :                 break;
    6026                 :             :               }
    6027                 :             :         }
    6028                 :             : 
    6029                 :     2157251 :       if (!depscope && b_kind < bk_proper_base)
    6030                 :             :         {
    6031                 :          41 :           if (cxx_dialect >= cxx20 && lookup.value
    6032                 :          15 :               && TREE_CODE (lookup.value) == CONST_DECL)
    6033                 :             :             {
    6034                 :             :               /* Using an unrelated enum; check access here rather
    6035                 :             :                  than separately for class and non-class using.  */
    6036                 :           9 :               perform_or_defer_access_check
    6037                 :           9 :                 (binfo, lookup.value, lookup.value, tf_warning_or_error);
    6038                 :             :               /* And then if this is a copy from handle_using_decl, look
    6039                 :             :                  through to the original enumerator.  */
    6040                 :           9 :               if (CONST_DECL_USING_P (lookup.value))
    6041                 :           4 :                 lookup.value = DECL_ABSTRACT_ORIGIN (lookup.value);
    6042                 :             :             }
    6043                 :          32 :           else if (!TYPE_P (current))
    6044                 :             :             {
    6045                 :           1 :               error ("using-declaration for member at non-class scope");
    6046                 :           1 :               return NULL_TREE;
    6047                 :             :             }
    6048                 :             :           else
    6049                 :             :             {
    6050                 :          31 :               auto_diagnostic_group g;
    6051                 :          31 :               error_not_base_type (scope, current);
    6052                 :          19 :               if (lookup.value && DECL_IMPLICIT_TYPEDEF_P (lookup.value)
    6053                 :          32 :                   && TREE_CODE (TREE_TYPE (lookup.value)) == ENUMERAL_TYPE)
    6054                 :           1 :                 inform (input_location,
    6055                 :             :                         "did you mean %<using enum %T::%D%>?",
    6056                 :             :                         scope, lookup.name);
    6057                 :          31 :               return NULL_TREE;
    6058                 :          31 :             }
    6059                 :             :         }
    6060                 :             :     }
    6061                 :             : 
    6062                 :             :   /* Did we find anything sane?  */
    6063                 :     2524461 :   if (dependent_p)
    6064                 :             :     ;
    6065                 :     8217682 :   else if (!lookup.value)
    6066                 :             :     {
    6067                 :          70 :       error ("%qD has not been declared in %qD", lookup.name, scope);
    6068                 :          70 :       return NULL_TREE;
    6069                 :             :     }
    6070                 :     8217612 :   else if (TREE_CODE (lookup.value) == TREE_LIST
    6071                 :             :            /* We can (independently) have ambiguous implicit typedefs.  */
    6072                 :     8217612 :            || (lookup.type && TREE_CODE (lookup.type) == TREE_LIST))
    6073                 :             :     {
    6074                 :           4 :       error ("reference to %qD is ambiguous", lookup.name);
    6075                 :           4 :       print_candidates (TREE_CODE (lookup.value) == TREE_LIST
    6076                 :             :                         ? lookup.value : lookup.type);
    6077                 :           4 :       return NULL_TREE;
    6078                 :             :     }
    6079                 :     8217608 :   else if (TREE_CODE (lookup.value) == NAMESPACE_DECL)
    6080                 :             :     {
    6081                 :           8 :       error ("using-declaration may not name namespace %qD", lookup.value);
    6082                 :           8 :       return NULL_TREE;
    6083                 :             :     }
    6084                 :             : 
    6085                 :     8784330 :   if (TYPE_P (current))
    6086                 :             :     {
    6087                 :             :       /* In class scope.  */
    6088                 :             : 
    6089                 :             :       /* Cannot introduce a constructor name.  */
    6090                 :     2420107 :       if (constructor_name_p (lookup.name, current))
    6091                 :             :         {
    6092                 :           4 :           error ("%<%T::%D%> names constructor in %qT",
    6093                 :             :                  scope, lookup.name, current);
    6094                 :           4 :           return NULL_TREE;
    6095                 :             :         }
    6096                 :             : 
    6097                 :     2420103 :       if (lookup.value && BASELINK_P (lookup.value))
    6098                 :             :         /* The binfo from which the functions came does not matter.  */
    6099                 :     1426574 :         lookup.value = BASELINK_FUNCTIONS (lookup.value);
    6100                 :             :     }
    6101                 :             : 
    6102                 :     8784326 :   tree using_decl = build_lang_decl (USING_DECL, lookup.name, NULL_TREE);
    6103                 :     8784326 :   USING_DECL_SCOPE (using_decl) = scope;
    6104                 :     8784326 :   USING_DECL_DECLS (using_decl) = lookup.value;
    6105                 :     8784326 :   DECL_DEPENDENT_P (using_decl) = dependent_p;
    6106                 :     8784326 :   DECL_CONTEXT (using_decl) = current;
    6107                 :     8784326 :   if (TYPE_P (current) && b_kind == bk_not_base)
    6108                 :      829652 :     USING_DECL_UNRELATED_P (using_decl) = true;
    6109                 :             : 
    6110                 :             :   return using_decl;
    6111                 :             : }
    6112                 :             : 
    6113                 :             : /* Process "using SCOPE::NAME" in a class scope.  Return the
    6114                 :             :    USING_DECL created.  */
    6115                 :             : 
    6116                 :             : tree
    6117                 :     2420216 : do_class_using_decl (tree scope, tree name)
    6118                 :             : {
    6119                 :     2420216 :   if (name == error_mark_node
    6120                 :     2420212 :       || scope == error_mark_node)
    6121                 :             :     return NULL_TREE;
    6122                 :             : 
    6123                 :     2420208 :   name_lookup lookup (name);
    6124                 :     2420208 :   return lookup_using_decl (scope, lookup);
    6125                 :     2420208 : }
    6126                 :             : 
    6127                 :             : 
    6128                 :             : /* Return the binding for NAME in NS in the current TU.  If NS is
    6129                 :             :    NULL, look in global_namespace.  We will not find declarations
    6130                 :             :    from imports.  Users of this who, having found nothing, push a new
    6131                 :             :    decl must be prepared for that pushing to match an existing decl.  */
    6132                 :             : 
    6133                 :             : tree
    6134                 :     8909957 : get_namespace_binding (tree ns, tree name)
    6135                 :             : {
    6136                 :     8909957 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    6137                 :     8909957 :   if (!ns)
    6138                 :     8909957 :     ns = global_namespace;
    6139                 :     8909957 :   gcc_checking_assert (!DECL_NAMESPACE_ALIAS (ns));
    6140                 :     8909957 :   tree ret = NULL_TREE;
    6141                 :             : 
    6142                 :     8909957 :   if (tree *b = find_namespace_slot (ns, name))
    6143                 :             :     {
    6144                 :     5128919 :       ret = *b;
    6145                 :             : 
    6146                 :     5128919 :       if (TREE_CODE (ret) == BINDING_VECTOR)
    6147                 :           0 :         ret = BINDING_VECTOR_CLUSTER (ret, 0).slots[0];
    6148                 :           0 :       if (ret)
    6149                 :     5128919 :         ret = MAYBE_STAT_DECL (ret);
    6150                 :             :     }
    6151                 :             : 
    6152                 :    17819914 :   return ret;
    6153                 :     8909957 : }
    6154                 :             : 
    6155                 :             : /* Push internal DECL into the global namespace.  Does not do the
    6156                 :             :    full overload fn handling and does not add it to the list of things
    6157                 :             :    in the namespace.  */
    6158                 :             : 
    6159                 :             : void
    6160                 :     3822448 : set_global_binding (tree decl)
    6161                 :             : {
    6162                 :     3822448 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    6163                 :             : 
    6164                 :     3822448 :   tree *slot = find_namespace_slot (global_namespace, DECL_NAME (decl), true);
    6165                 :             : 
    6166                 :     3822448 :   if (*slot)
    6167                 :             :     /* The user's placed something in the implementor's namespace.  */
    6168                 :           0 :     diagnose_name_conflict (decl, MAYBE_STAT_DECL (*slot));
    6169                 :             : 
    6170                 :             :   /* Force the binding, so compiler internals continue to work.  */
    6171                 :     3822448 :   *slot = decl;
    6172                 :     3822448 : }
    6173                 :             : 
    6174                 :             : /* Set the context of a declaration to scope. Complain if we are not
    6175                 :             :    outside scope.  */
    6176                 :             : 
    6177                 :             : void
    6178                 :       91046 : set_decl_namespace (tree decl, tree scope, bool friendp)
    6179                 :             : {
    6180                 :             :   /* Get rid of namespace aliases.  */
    6181                 :       91046 :   scope = ORIGINAL_NAMESPACE (scope);
    6182                 :             : 
    6183                 :             :   /* It is ok for friends to be qualified in parallel space.  */
    6184                 :       91046 :   if (!friendp && !is_nested_namespace (current_namespace, scope))
    6185                 :           8 :     error ("declaration of %qD not in a namespace surrounding %qD",
    6186                 :             :            decl, scope);
    6187                 :       91046 :   DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
    6188                 :             : 
    6189                 :             :   /* See whether this has been declared in the namespace or inline
    6190                 :             :      children.  */
    6191                 :       91046 :   tree old = NULL_TREE;
    6192                 :       91046 :   {
    6193                 :       91046 :     name_lookup lookup (DECL_NAME (decl),
    6194                 :       91046 :                         LOOK_want::NORMAL | LOOK_want::HIDDEN_FRIEND);
    6195                 :       91046 :     if (!lookup.search_qualified (scope, /*usings=*/false))
    6196                 :             :       /* No old declaration at all.  */
    6197                 :          36 :       goto not_found;
    6198                 :       91010 :     old = lookup.value;
    6199                 :       91046 :   }
    6200                 :             : 
    6201                 :             :   /* If it's a TREE_LIST, the result of the lookup was ambiguous.  */
    6202                 :       91010 :   if (TREE_CODE (old) == TREE_LIST)
    6203                 :             :     {
    6204                 :           7 :     ambiguous:
    6205                 :          13 :       DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
    6206                 :          13 :       error ("reference to %qD is ambiguous", decl);
    6207                 :          13 :       print_candidates (old);
    6208                 :          13 :       return;
    6209                 :             :     }
    6210                 :             : 
    6211                 :       91003 :   if (!DECL_DECLARES_FUNCTION_P (decl))
    6212                 :             :     {
    6213                 :             :       /* Don't compare non-function decls with decls_match here, since
    6214                 :             :          it can't check for the correct constness at this
    6215                 :             :          point.  pushdecl will find those errors later.  */
    6216                 :             : 
    6217                 :             :       /* We might have found it in an inline namespace child of SCOPE.  */
    6218                 :        2539 :       if (TREE_CODE (decl) == TREE_CODE (old))
    6219                 :          41 :         DECL_CONTEXT (decl) = DECL_CONTEXT (old);
    6220                 :             : 
    6221                 :        2498 :     found:
    6222                 :             :       /* Writing "N::i" to declare something directly in "N" is invalid.  */
    6223                 :       45237 :       if (CP_DECL_CONTEXT (decl) == current_namespace
    6224                 :       45237 :           && at_namespace_scope_p ())
    6225                 :           3 :         error_at (DECL_SOURCE_LOCATION (decl),
    6226                 :             :                   "explicit qualification in declaration of %qD", decl);
    6227                 :       45237 :       return;
    6228                 :             :     }
    6229                 :             : 
    6230                 :             :   /* Since decl is a function, old should contain a function decl.  */
    6231                 :       88464 :   if (!OVL_P (old))
    6232                 :             :     {
    6233                 :          10 :     not_found:
    6234                 :             :       /* It didn't work, go back to the explicit scope.  */
    6235                 :          54 :       DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
    6236                 :          54 :       error ("%qD should have been declared inside %qD", decl, scope);
    6237                 :             : 
    6238                 :          54 :       return;
    6239                 :             :     }
    6240                 :             :   
    6241                 :             :   /* We handle these in check_explicit_instantiation_namespace.  */
    6242                 :       88454 :   if (processing_explicit_instantiation)
    6243                 :             :     return;
    6244                 :       88369 :   if (processing_template_decl || processing_specialization)
    6245                 :             :     /* We have not yet called push_template_decl to turn a
    6246                 :             :        FUNCTION_DECL into a TEMPLATE_DECL, so the declarations won't
    6247                 :             :        match.  But, we'll check later, when we construct the
    6248                 :             :        template.  */
    6249                 :             :     return;
    6250                 :             : 
    6251                 :             :   /* Instantiations or specializations of templates may be declared as
    6252                 :             :      friends in any namespace.  */
    6253                 :       42735 :   if (friendp && DECL_USE_TEMPLATE (decl))
    6254                 :             :     return;
    6255                 :             : 
    6256                 :       42727 :   tree found = NULL_TREE;
    6257                 :       42727 :   bool hidden_p = false;
    6258                 :       42727 :   bool saw_template = false;
    6259                 :             : 
    6260                 :      104825 :   for (lkp_iterator iter (old); iter; ++iter)
    6261                 :             :     {
    6262                 :       62104 :       if (iter.using_p ())
    6263                 :           0 :         continue;
    6264                 :             : 
    6265                 :       62104 :       tree ofn = *iter;
    6266                 :             : 
    6267                 :             :       /* Adjust DECL_CONTEXT first so decls_match will return true
    6268                 :             :          if DECL will match a declaration in an inline namespace.  */
    6269                 :       62104 :       DECL_CONTEXT (decl) = DECL_CONTEXT (ofn);
    6270                 :       62104 :       if (decls_match (decl, ofn))
    6271                 :             :         {
    6272                 :       42710 :           if (found)
    6273                 :             :             {
    6274                 :             :               /* We found more than one matching declaration.  This
    6275                 :             :                  can happen if we have two inline namespace children,
    6276                 :             :                  each containing a suitable declaration.  */
    6277                 :           6 :               DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
    6278                 :           6 :               goto ambiguous;
    6279                 :             :             }
    6280                 :       42704 :           found = ofn;
    6281                 :       42704 :           hidden_p = iter.hidden_p ();
    6282                 :             :         }
    6283                 :       19394 :       else if (TREE_CODE (decl) == FUNCTION_DECL
    6284                 :       19394 :                && TREE_CODE (ofn) == TEMPLATE_DECL)
    6285                 :       62098 :         saw_template = true;
    6286                 :             :     }
    6287                 :             : 
    6288                 :       42721 :   if (!found && friendp && saw_template)
    6289                 :             :     {
    6290                 :             :       /* "[if no non-template match is found,] each remaining function template
    6291                 :             :          is replaced with the specialization chosen by deduction from the
    6292                 :             :          friend declaration or discarded if deduction fails."
    6293                 :             : 
    6294                 :             :          So tell check_explicit_specialization to look for a match.  */
    6295                 :          15 :       SET_DECL_IMPLICIT_INSTANTIATION (decl);
    6296                 :          15 :       DECL_TEMPLATE_INFO (decl) = build_template_info (old, NULL_TREE);
    6297                 :          15 :       return;
    6298                 :             :     }
    6299                 :             : 
    6300                 :       42706 :   if (found)
    6301                 :             :     {
    6302                 :       42698 :       if (hidden_p)
    6303                 :             :         {
    6304                 :           4 :           pedwarn (DECL_SOURCE_LOCATION (decl), 0,
    6305                 :             :                    "%qD has not been declared within %qD", decl, scope);
    6306                 :           4 :           inform (DECL_SOURCE_LOCATION (found),
    6307                 :             :                   "only here as a %<friend%>");
    6308                 :             :         }
    6309                 :       42698 :       DECL_CONTEXT (decl) = DECL_CONTEXT (found);
    6310                 :       42698 :       goto found;
    6311                 :             :     }
    6312                 :             : 
    6313                 :           8 :   goto not_found;
    6314                 :             : }
    6315                 :             : 
    6316                 :             : /* Return the namespace where the current declaration is declared.  */
    6317                 :             : 
    6318                 :             : tree
    6319                 :  1203196620 : current_decl_namespace (void)
    6320                 :             : {
    6321                 :  1203196620 :   tree result;
    6322                 :             :   /* If we have been pushed into a different namespace, use it.  */
    6323                 :  1203196620 :   if (!vec_safe_is_empty (decl_namespace_list))
    6324                 :    57262880 :     return decl_namespace_list->last ();
    6325                 :             : 
    6326                 :  1145933740 :   if (current_class_type)
    6327                 :   477943874 :     result = decl_namespace_context (current_class_type);
    6328                 :   667989866 :   else if (current_function_decl)
    6329                 :   241982589 :     result = decl_namespace_context (current_function_decl);
    6330                 :             :   else
    6331                 :   426007277 :     result = current_namespace;
    6332                 :             :   return result;
    6333                 :             : }
    6334                 :             : 
    6335                 :             : /* Process any ATTRIBUTES on a namespace definition.  Returns true if
    6336                 :             :    attribute visibility is seen.  */
    6337                 :             : 
    6338                 :             : bool
    6339                 :     5011054 : handle_namespace_attrs (tree ns, tree attributes)
    6340                 :             : {
    6341                 :     5011054 :   tree d;
    6342                 :     5011054 :   bool saw_vis = false;
    6343                 :             : 
    6344                 :     5011054 :   if (attributes == error_mark_node)
    6345                 :             :     return false;
    6346                 :             : 
    6347                 :     7584150 :   for (d = attributes; d; d = TREE_CHAIN (d))
    6348                 :             :     {
    6349                 :     2573096 :       tree name = get_attribute_name (d);
    6350                 :     2573096 :       tree args = TREE_VALUE (d);
    6351                 :             : 
    6352                 :     2573096 :       if (is_attribute_p ("visibility", name))
    6353                 :             :         {
    6354                 :             :           /* attribute visibility is a property of the syntactic block
    6355                 :             :              rather than the namespace as a whole, so we don't touch the
    6356                 :             :              NAMESPACE_DECL at all.  */
    6357                 :     2527468 :           tree x = args ? TREE_VALUE (args) : NULL_TREE;
    6358                 :     2527468 :           if (x == NULL_TREE || TREE_CODE (x) != STRING_CST || TREE_CHAIN (args))
    6359                 :             :             {
    6360                 :           0 :               warning (OPT_Wattributes,
    6361                 :             :                        "%qD attribute requires a single NTBS argument",
    6362                 :             :                        name);
    6363                 :           0 :               continue;
    6364                 :             :             }
    6365                 :             : 
    6366                 :     2527468 :           if (!TREE_PUBLIC (ns))
    6367                 :           0 :             warning (OPT_Wattributes,
    6368                 :             :                      "%qD attribute is meaningless since members of the "
    6369                 :             :                      "anonymous namespace get local symbols", name);
    6370                 :             : 
    6371                 :     2527468 :           push_visibility (TREE_STRING_POINTER (x), 1);
    6372                 :     2527468 :           saw_vis = true;
    6373                 :             :         }
    6374                 :       45628 :       else if (is_attribute_p ("abi_tag", name))
    6375                 :             :         {
    6376                 :       45544 :           if (!DECL_NAME (ns))
    6377                 :             :             {
    6378                 :           3 :               warning (OPT_Wattributes, "ignoring %qD attribute on anonymous "
    6379                 :             :                        "namespace", name);
    6380                 :           3 :               continue;
    6381                 :             :             }
    6382                 :       45541 :           if (!DECL_NAMESPACE_INLINE_P (ns))
    6383                 :             :             {
    6384                 :           0 :               warning (OPT_Wattributes, "ignoring %qD attribute on non-inline "
    6385                 :             :                        "namespace", name);
    6386                 :           0 :               continue;
    6387                 :             :             }
    6388                 :       45541 :           if (!args)
    6389                 :             :             {
    6390                 :          20 :               tree dn = DECL_NAME (ns);
    6391                 :          20 :               args = build_string (IDENTIFIER_LENGTH (dn) + 1,
    6392                 :          20 :                                    IDENTIFIER_POINTER (dn));
    6393                 :          20 :               TREE_TYPE (args) = char_array_type_node;
    6394                 :          20 :               args = fix_string_type (args);
    6395                 :          20 :               args = build_tree_list (NULL_TREE, args);
    6396                 :             :             }
    6397                 :       45541 :           if (check_abi_tag_args (args, name))
    6398                 :       45541 :             DECL_ATTRIBUTES (ns) = tree_cons (name, args,
    6399                 :       45541 :                                               DECL_ATTRIBUTES (ns));
    6400                 :             :         }
    6401                 :          84 :       else if (is_attribute_p ("deprecated", name))
    6402                 :             :         {
    6403                 :          63 :           if (!DECL_NAME (ns))
    6404                 :             :             {
    6405                 :           3 :               warning (OPT_Wattributes, "ignoring %qD attribute on anonymous "
    6406                 :             :                        "namespace", name);
    6407                 :           3 :               continue;
    6408                 :             :             }
    6409                 :          66 :           if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
    6410                 :             :             {
    6411                 :           0 :               error ("deprecated message is not a string");
    6412                 :           0 :               continue;
    6413                 :             :             }
    6414                 :          60 :           TREE_DEPRECATED (ns) = 1;
    6415                 :          60 :           if (args)
    6416                 :           6 :             DECL_ATTRIBUTES (ns) = tree_cons (name, args,
    6417                 :           6 :                                               DECL_ATTRIBUTES (ns));
    6418                 :             :         }
    6419                 :          21 :       else if (!attribute_ignored_p (d))
    6420                 :             :         {
    6421                 :           6 :           warning (OPT_Wattributes, "%qD attribute directive ignored",
    6422                 :             :                    name);
    6423                 :           6 :           continue;
    6424                 :             :         }
    6425                 :             :     }
    6426                 :             : 
    6427                 :             :   return saw_vis;
    6428                 :             : }
    6429                 :             : 
    6430                 :             : /* Temporarily set the namespace for the current declaration.  */
    6431                 :             : 
    6432                 :             : void
    6433                 :    68312758 : push_decl_namespace (tree decl)
    6434                 :             : {
    6435                 :    68312758 :   if (TREE_CODE (decl) != NAMESPACE_DECL)
    6436                 :           0 :     decl = decl_namespace_context (decl);
    6437                 :    68312758 :   vec_safe_push (decl_namespace_list, ORIGINAL_NAMESPACE (decl));
    6438                 :    68312758 : }
    6439                 :             : 
    6440                 :             : /* [namespace.memdef]/2 */
    6441                 :             : 
    6442                 :             : void
    6443                 :    68312755 : pop_decl_namespace (void)
    6444                 :             : {
    6445                 :    68312755 :   decl_namespace_list->pop ();
    6446                 :    68312755 : }
    6447                 :             : 
    6448                 :             : /* Process a namespace-alias declaration.  */
    6449                 :             : 
    6450                 :             : void
    6451                 :       46498 : do_namespace_alias (tree alias, tree name_space)
    6452                 :             : {
    6453                 :       46498 :   if (name_space == error_mark_node)
    6454                 :             :     return;
    6455                 :             : 
    6456                 :       46486 :   gcc_assert (TREE_CODE (name_space) == NAMESPACE_DECL);
    6457                 :             : 
    6458                 :       46486 :   name_space = ORIGINAL_NAMESPACE (name_space);
    6459                 :             : 
    6460                 :             :   /* Build the alias.  */
    6461                 :       46486 :   alias = build_lang_decl (NAMESPACE_DECL, alias, void_type_node);
    6462                 :       46486 :   DECL_NAMESPACE_ALIAS (alias) = name_space;
    6463                 :       46486 :   DECL_EXTERNAL (alias) = 1;
    6464                 :       46486 :   DECL_CONTEXT (alias) = FROB_CONTEXT (current_scope ());
    6465                 :       46486 :   set_originating_module (alias);
    6466                 :             : 
    6467                 :       46486 :   pushdecl (alias);
    6468                 :             : 
    6469                 :             :   /* Emit debug info for namespace alias.  */
    6470                 :       46486 :   if (!building_stmt_list_p ())
    6471                 :        5023 :     (*debug_hooks->early_global_decl) (alias);
    6472                 :             : }
    6473                 :             : 
    6474                 :             : /* Like pushdecl, only it places DECL in the current namespace,
    6475                 :             :    if appropriate.  */
    6476                 :             : 
    6477                 :             : tree
    6478                 :    43863173 : pushdecl_namespace_level (tree decl, bool hiding)
    6479                 :             : {
    6480                 :    43863173 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    6481                 :    43863173 :   return do_pushdecl_with_scope (decl, NAMESPACE_LEVEL (current_namespace),
    6482                 :    43863173 :                                  hiding);
    6483                 :    43863173 : }
    6484                 :             : 
    6485                 :             : /* Wrapper around push_local_binding to push the bindings for
    6486                 :             :    a non-member USING_DECL with NAME and VALUE.  LOOKUP, if non-null,
    6487                 :             :    is the result of name lookup during template parsing.  */
    6488                 :             : 
    6489                 :             : static void
    6490                 :      653608 : push_using_decl_bindings (name_lookup *lookup, tree name, tree value)
    6491                 :             : {
    6492                 :      653608 :   tree type = NULL_TREE;
    6493                 :             : 
    6494                 :      653608 :   cxx_binding *binding = find_local_binding (current_binding_level, name);
    6495                 :      653608 :   if (binding)
    6496                 :             :     {
    6497                 :         100 :       value = binding->value;
    6498                 :         100 :       type = binding->type;
    6499                 :             :     }
    6500                 :             : 
    6501                 :             :   /* DR 36 questions why using-decls at function scope may not be
    6502                 :             :      duplicates.  Disallow it, as C++11 claimed and PR 20420
    6503                 :             :      implemented.  */
    6504                 :      653608 :   if (lookup)
    6505                 :      527816 :     do_nonmember_using_decl (*lookup, true, true, &value, &type);
    6506                 :             : 
    6507                 :      653608 :   if (!value)
    6508                 :             :     ;
    6509                 :      653608 :   else if (binding && value == binding->value)
    6510                 :             :     /* Redeclaration of this USING_DECL.  */;
    6511                 :          52 :   else if (binding && binding->value && TREE_CODE (value) == OVERLOAD)
    6512                 :             :     {
    6513                 :             :       /* We already have this binding, so replace it.  */
    6514                 :          48 :       update_local_overload (IDENTIFIER_BINDING (name), value);
    6515                 :          48 :       IDENTIFIER_BINDING (name)->value = value;
    6516                 :             :     }
    6517                 :             :   else
    6518                 :             :     /* Install the new binding.  */
    6519                 :      653512 :     push_local_binding (name, value, /*using=*/true);
    6520                 :             : 
    6521                 :      653608 :   if (!type)
    6522                 :             :     ;
    6523                 :          29 :   else if (binding && type == binding->type)
    6524                 :             :     ;
    6525                 :             :   else
    6526                 :             :     {
    6527                 :          21 :       push_local_binding (name, type, /*using=*/true);
    6528                 :          21 :       set_identifier_type_value (name, type);
    6529                 :             :     }
    6530                 :      653608 : }
    6531                 :             : 
    6532                 :             : /* Overload for push_using_decl_bindings that doesn't take a name_lookup.  */
    6533                 :             : 
    6534                 :             : void
    6535                 :      125792 : push_using_decl_bindings (tree name, tree value)
    6536                 :             : {
    6537                 :      125792 :   push_using_decl_bindings (nullptr, name, value);
    6538                 :      125792 : }
    6539                 :             : 
    6540                 :             : /* Process a using declaration in non-class scope.  */
    6541                 :             : 
    6542                 :             : void
    6543                 :     6364275 : finish_nonmember_using_decl (tree scope, tree name)
    6544                 :             : {
    6545                 :     6364275 :   gcc_checking_assert (current_binding_level->kind != sk_class);
    6546                 :             : 
    6547                 :     6364275 :   if (scope == error_mark_node || name == error_mark_node)
    6548                 :          52 :     return;
    6549                 :             : 
    6550                 :     6364275 :   name_lookup lookup (name);
    6551                 :             : 
    6552                 :     6364275 :   tree using_decl = lookup_using_decl (scope, lookup);
    6553                 :     6364275 :   if (!using_decl)
    6554                 :          52 :     return;
    6555                 :             : 
    6556                 :             :   /* Emit debug info.  */
    6557                 :     6364223 :   if (!processing_template_decl)
    6558                 :    11695102 :     cp_emit_debug_info_for_using (lookup.value,
    6559                 :     5847551 :                                   current_binding_level->this_entity);
    6560                 :             : 
    6561                 :     6364223 :   if (current_binding_level->kind == sk_namespace)
    6562                 :             :     {
    6563                 :     5836407 :       tree *slot = find_namespace_slot (current_namespace, name, true);
    6564                 :     5836407 :       tree *mslot = get_fixed_binding_slot (slot, name,
    6565                 :             :                                             BINDING_SLOT_CURRENT, true);
    6566                 :     5836407 :       bool failed = false;
    6567                 :             : 
    6568                 :     5836407 :       if (mslot != slot)
    6569                 :             :         {
    6570                 :             :           /* A module vector.  I presume the binding list is going to
    6571                 :             :              be sparser than the import bitmap.  Hence iterate over
    6572                 :             :              the former checking for bits set in the bitmap.  */
    6573                 :           9 :           bitmap imports = get_import_bitmap ();
    6574                 :           9 :           binding_cluster *cluster = BINDING_VECTOR_CLUSTER_BASE (*slot);
    6575                 :             : 
    6576                 :             :           /* Scan the imported bindings.  */
    6577                 :           9 :           unsigned ix = BINDING_VECTOR_NUM_CLUSTERS (*slot);
    6578                 :           9 :           if (BINDING_VECTOR_SLOTS_PER_CLUSTER == BINDING_SLOTS_FIXED)
    6579                 :             :             {
    6580                 :           9 :               ix--;
    6581                 :           9 :               cluster++;
    6582                 :             :             }
    6583                 :             : 
    6584                 :             :           /* Do this in forward order, so we load modules in an order
    6585                 :             :              the user expects.  */
    6586                 :          18 :           for (; ix--; cluster++)
    6587                 :          27 :             for (unsigned jx = 0; jx != BINDING_VECTOR_SLOTS_PER_CLUSTER; jx++)
    6588                 :             :               {
    6589                 :             :                 /* Are we importing this module?  */
    6590                 :          18 :                 if (unsigned base = cluster->indices[jx].base)
    6591                 :           9 :                   if (unsigned span = cluster->indices[jx].span)
    6592                 :           9 :                     do
    6593                 :           9 :                       if (bitmap_bit_p (imports, base))
    6594                 :           9 :                         goto found;
    6595                 :           0 :                     while (++base, --span);
    6596                 :           9 :                 continue;
    6597                 :             : 
    6598                 :           9 :               found:;
    6599                 :             :                 /* Is it loaded?  */
    6600                 :           9 :                 if (cluster->slots[jx].is_lazy ())
    6601                 :             :                   {
    6602                 :           0 :                     gcc_assert (cluster->indices[jx].span == 1);
    6603                 :           0 :                     lazy_load_binding (cluster->indices[jx].base,
    6604                 :             :                                        scope, name, &cluster->slots[jx]);
    6605                 :             :                   }
    6606                 :             : 
    6607                 :           9 :                 tree value = cluster->slots[jx];
    6608                 :           9 :                 if (!value)
    6609                 :             :                   /* Load errors could mean there's nothing here.  */
    6610                 :           0 :                   continue;
    6611                 :             : 
    6612                 :             :                 /* Extract what we can see from here.  If there's no
    6613                 :             :                    stat_hack, then everything was exported.  */
    6614                 :           9 :                 tree type = NULL_TREE;
    6615                 :             : 
    6616                 :             :                 /* If no stat hack, everything is visible.  */
    6617                 :           9 :                 if (STAT_HACK_P (value))
    6618                 :             :                   {
    6619                 :           0 :                     if (STAT_TYPE_VISIBLE_P (value))
    6620                 :           0 :                       type = STAT_TYPE (value);
    6621                 :           0 :                     value = STAT_VISIBLE (value);
    6622                 :             :                   }
    6623                 :             : 
    6624                 :           9 :                 if (do_nonmember_using_decl (lookup, false, false,
    6625                 :             :                                              &value, &type))
    6626                 :             :                   {
    6627                 :           0 :                     failed = true;
    6628                 :           0 :                     break;
    6629                 :             :                   }
    6630                 :           9 :               }
    6631                 :             :         }
    6632                 :             : 
    6633                 :           9 :       if (!failed)
    6634                 :             :         {
    6635                 :             :           /* Now do the current slot.  */
    6636                 :     5836407 :           tree value = MAYBE_STAT_DECL (*mslot);
    6637                 :     5836407 :           tree type = MAYBE_STAT_TYPE (*mslot);
    6638                 :             : 
    6639                 :     5836407 :           do_nonmember_using_decl (lookup, false, true, &value, &type);
    6640                 :             : 
    6641                 :             :           // FIXME: Partition mergeableness?
    6642                 :     5836407 :           if (STAT_HACK_P (*mslot))
    6643                 :             :             {
    6644                 :           0 :               STAT_DECL (*mslot) = value;
    6645                 :           0 :               STAT_TYPE (*mslot) = type;
    6646                 :             :             }
    6647                 :     5836407 :           else if (type)
    6648                 :          22 :             *mslot = stat_hack (value, type);
    6649                 :             :           else
    6650                 :     5836385 :             *mslot = value;
    6651                 :             :         }
    6652                 :             :     }
    6653                 :             :   else
    6654                 :             :     {
    6655                 :      527816 :       add_decl_expr (using_decl);
    6656                 :      527816 :       if (DECL_DEPENDENT_P (using_decl))
    6657                 :           3 :         lookup.value = using_decl;
    6658                 :      527816 :       push_using_decl_bindings (&lookup, name, NULL_TREE);
    6659                 :             :     }
    6660                 :     6364275 : }
    6661                 :             : 
    6662                 :             : /* Return the declarations that are members of the namespace NS.  */
    6663                 :             : 
    6664                 :             : tree
    6665                 :          12 : cp_namespace_decls (tree ns)
    6666                 :             : {
    6667                 :          12 :   return NAMESPACE_LEVEL (ns)->names;
    6668                 :             : }
    6669                 :             : 
    6670                 :             : /* Given a lookup that returned VAL, use FLAGS to decide if we want to
    6671                 :             :    ignore it or not.  Subroutine of lookup_name_1 and lookup_type_scope.  */
    6672                 :             : 
    6673                 :             : static bool
    6674                 :  2871622990 : qualify_lookup (tree val, LOOK_want want)
    6675                 :             : {
    6676                 :  2871622990 :   if (val == NULL_TREE)
    6677                 :             :     return false;
    6678                 :             : 
    6679                 :  2871622990 :   if (bool (want & LOOK_want::TYPE))
    6680                 :             :     {
    6681                 :    38100518 :       tree target_val = strip_using_decl (val);
    6682                 :             : 
    6683                 :    38100518 :       if (TREE_CODE (STRIP_TEMPLATE (target_val)) == TYPE_DECL)
    6684                 :             :         return true;
    6685                 :             :     }
    6686                 :             : 
    6687                 :  2833735956 :   if (bool (want & LOOK_want::TYPE_NAMESPACE))
    6688                 :      350775 :     return TREE_CODE (val) == NAMESPACE_DECL;
    6689                 :             : 
    6690                 :             :   return true;
    6691                 :             : }
    6692                 :             : 
    6693                 :             : /* Is there a "using namespace std;" directive within USINGS?  */
    6694                 :             : 
    6695                 :             : static bool
    6696                 :        6035 : using_directives_contain_std_p (vec<tree, va_gc> *usings)
    6697                 :             : {
    6698                 :        6035 :   if (!usings)
    6699                 :             :     return false;
    6700                 :             : 
    6701                 :          53 :   for (unsigned ix = usings->length (); ix--;)
    6702                 :          37 :     if ((*usings)[ix] == std_node)
    6703                 :             :       return true;
    6704                 :             : 
    6705                 :             :   return false;
    6706                 :             : }
    6707                 :             : 
    6708                 :             : /* Is there a "using namespace std;" directive within the current
    6709                 :             :    namespace (or its ancestors)?
    6710                 :             :    Compare with name_lookup::search_unqualified.  */
    6711                 :             : 
    6712                 :             : static bool
    6713                 :        1924 : has_using_namespace_std_directive_p ()
    6714                 :             : {
    6715                 :        1924 :   for (cp_binding_level *level = current_binding_level;
    6716                 :        7938 :        level;
    6717                 :        6014 :        level = level->level_chain)
    6718                 :        6035 :     if (using_directives_contain_std_p (level->using_directives))
    6719                 :             :       return true;
    6720                 :             : 
    6721                 :             :   return false;
    6722                 :             : }
    6723                 :             : 
    6724                 :             : /* Subclass of deferred_diagnostic, for issuing a note when
    6725                 :             :    --param cxx-max-namespaces-for-diagnostic-help is reached.
    6726                 :             : 
    6727                 :             :    The note should be issued after the error, but before any other
    6728                 :             :    deferred diagnostics.  This is handled by decorating a wrapped
    6729                 :             :    deferred_diagnostic, and emitting a note before that wrapped note is
    6730                 :             :    deleted.  */
    6731                 :             : 
    6732                 :             : class namespace_limit_reached : public deferred_diagnostic
    6733                 :             : {
    6734                 :             :  public:
    6735                 :           3 :   namespace_limit_reached (location_t loc, unsigned limit, tree name,
    6736                 :             :                            std::unique_ptr<deferred_diagnostic> wrapped)
    6737                 :           3 :   : deferred_diagnostic (loc),
    6738                 :           3 :     m_limit (limit), m_name (name),
    6739                 :           3 :     m_wrapped (std::move (wrapped))
    6740                 :             :   {
    6741                 :             :   }
    6742                 :             : 
    6743                 :           6 :   ~namespace_limit_reached ()
    6744                 :           3 :   {
    6745                 :             :     /* Unconditionally warn that the search was truncated.  */
    6746                 :           3 :     inform (get_location (),
    6747                 :             :             "maximum limit of %d namespaces searched for %qE",
    6748                 :             :             m_limit, m_name);
    6749                 :             :     /* m_wrapped will be implicitly deleted after this, emitting any followup
    6750                 :             :        diagnostic after the above note.  */
    6751                 :           6 :   }
    6752                 :             : 
    6753                 :             :  private:
    6754                 :             :   unsigned m_limit;
    6755                 :             :   tree m_name;
    6756                 :             :   std::unique_ptr<deferred_diagnostic> m_wrapped;
    6757                 :             : };
    6758                 :             : 
    6759                 :             : /* Subclass of deferred_diagnostic, for use when issuing a single suggestion.
    6760                 :             :    Emit a note showing the location of the declaration of the suggestion.  */
    6761                 :             : 
    6762                 :             : class show_candidate_location : public deferred_diagnostic
    6763                 :             : {
    6764                 :             :  public:
    6765                 :         129 :   show_candidate_location (location_t loc, tree candidate)
    6766                 :         129 :   : deferred_diagnostic (loc),
    6767                 :         129 :     m_candidate (candidate)
    6768                 :             :   {
    6769                 :             :   }
    6770                 :             : 
    6771                 :         258 :   ~show_candidate_location ()
    6772                 :         129 :   {
    6773                 :         129 :     inform (location_of (m_candidate), "%qE declared here", m_candidate);
    6774                 :         258 :   }
    6775                 :             : 
    6776                 :             :  private:
    6777                 :             :   tree m_candidate;
    6778                 :             : };
    6779                 :             : 
    6780                 :             : /* Subclass of deferred_diagnostic, for use when there are multiple candidates
    6781                 :             :    to be suggested by suggest_alternatives_for.
    6782                 :             : 
    6783                 :             :    Emit a series of notes showing the various suggestions.  */
    6784                 :             : 
    6785                 :             : class suggest_alternatives : public deferred_diagnostic
    6786                 :             : {
    6787                 :             :  public:
    6788                 :          22 :   suggest_alternatives (location_t loc, vec<tree> candidates)
    6789                 :          22 :   : deferred_diagnostic (loc),
    6790                 :          22 :     m_candidates (candidates)
    6791                 :             :   {
    6792                 :             :   }
    6793                 :             : 
    6794                 :          44 :   ~suggest_alternatives ()
    6795                 :          22 :   {
    6796                 :          22 :     if (m_candidates.length ())
    6797                 :             :       {
    6798                 :          22 :         inform_n (get_location (), m_candidates.length (),
    6799                 :             :                   "suggested alternative:",
    6800                 :             :                   "suggested alternatives:");
    6801                 :         140 :         for (unsigned ix = 0; ix != m_candidates.length (); ix++)
    6802                 :             :           {
    6803                 :          48 :             tree val = m_candidates[ix];
    6804                 :             : 
    6805                 :          48 :             inform (location_of (val), "  %qE", val);
    6806                 :             :           }
    6807                 :             :       }
    6808                 :          22 :     m_candidates.release ();
    6809                 :          44 :   }
    6810                 :             : 
    6811                 :             :  private:
    6812                 :             :   vec<tree> m_candidates;
    6813                 :             : };
    6814                 :             : 
    6815                 :             : /* A class for encapsulating the result of a search across
    6816                 :             :    multiple namespaces (and scoped enums within them) for an
    6817                 :             :    unrecognized name seen at a given source location.  */
    6818                 :             : 
    6819                 :             : class namespace_hints
    6820                 :             : {
    6821                 :             :  public:
    6822                 :             :   namespace_hints (location_t loc, tree name);
    6823                 :             : 
    6824                 :             :   name_hint convert_candidates_to_name_hint ();
    6825                 :             :   name_hint maybe_decorate_with_limit (name_hint);
    6826                 :             : 
    6827                 :             :  private:
    6828                 :             :   void maybe_add_candidate_for_scoped_enum (tree scoped_enum, tree name);
    6829                 :             : 
    6830                 :             :   location_t m_loc;
    6831                 :             :   tree m_name;
    6832                 :             :   vec<tree> m_candidates;
    6833                 :             : 
    6834                 :             :   /* Value of "--param cxx-max-namespaces-for-diagnostic-help".  */
    6835                 :             :   unsigned m_limit;
    6836                 :             : 
    6837                 :             :   /* Was the limit reached?  */
    6838                 :             :   bool m_limited;
    6839                 :             : };
    6840                 :             : 
    6841                 :             : /* Constructor for namespace_hints.  Search namespaces and scoped enums,
    6842                 :             :    looking for an exact match for unrecognized NAME seen at LOC.  */
    6843                 :             : 
    6844                 :        2098 : namespace_hints::namespace_hints (location_t loc, tree name)
    6845                 :        2098 : : m_loc(loc), m_name (name)
    6846                 :             : {
    6847                 :        2098 :   auto_vec<tree> worklist;
    6848                 :             : 
    6849                 :        2098 :   m_candidates = vNULL;
    6850                 :        2098 :   m_limited = false;
    6851                 :        2098 :   m_limit = param_cxx_max_namespaces_for_diagnostic_help;
    6852                 :             : 
    6853                 :             :   /* Breadth-first search of namespaces.  Up to limit namespaces
    6854                 :             :      searched (limit zero == unlimited).  */
    6855                 :        2098 :   worklist.safe_push (global_namespace);
    6856                 :       18254 :   for (unsigned ix = 0; ix != worklist.length (); ix++)
    6857                 :             :     {
    6858                 :        7029 :       tree ns = worklist[ix];
    6859                 :        7029 :       name_lookup lookup (name);
    6860                 :             : 
    6861                 :        7029 :       if (lookup.search_qualified (ns, false))
    6862                 :         162 :         m_candidates.safe_push (lookup.value);
    6863                 :             : 
    6864                 :        7029 :       if (!m_limited)
    6865                 :             :         {
    6866                 :             :           /* Look for child namespaces.  We have to do this
    6867                 :             :              indirectly because they are chained in reverse order,
    6868                 :             :              which is confusing to the user.  */
    6869                 :        7017 :           auto_vec<tree> children;
    6870                 :             : 
    6871                 :        7017 :           for (tree decl = NAMESPACE_LEVEL (ns)->names;
    6872                 :     5372412 :                decl; decl = TREE_CHAIN (decl))
    6873                 :             :             {
    6874                 :     5365395 :               if (TREE_CODE (decl) == NAMESPACE_DECL
    6875                 :        5049 :                   && !DECL_NAMESPACE_ALIAS (decl)
    6876                 :     5370436 :                   && !DECL_NAMESPACE_INLINE_P (decl))
    6877                 :        4940 :                 children.safe_push (decl);
    6878                 :             : 
    6879                 :             :               /* Look for exact matches for NAME within scoped enums.
    6880                 :             :                  These aren't added to the worklist, and so don't count
    6881                 :             :                  against the search limit.  */
    6882                 :     5365395 :               if (TREE_CODE (decl) == TYPE_DECL)
    6883                 :             :                 {
    6884                 :       60194 :                   tree type = TREE_TYPE (decl);
    6885                 :       60194 :                   if (SCOPED_ENUM_P (type))
    6886                 :        1251 :                     maybe_add_candidate_for_scoped_enum (type, name);
    6887                 :             :                 }
    6888                 :             :             }
    6889                 :             : 
    6890                 :       18965 :           while (!m_limited && !children.is_empty ())
    6891                 :             :             {
    6892                 :        9868 :               if (worklist.length () == m_limit)
    6893                 :           3 :                 m_limited = true;
    6894                 :             :               else
    6895                 :        4931 :                 worklist.safe_push (children.pop ());
    6896                 :             :             }
    6897                 :        7017 :         }
    6898                 :        7029 :     }
    6899                 :        2098 : }
    6900                 :             : 
    6901                 :             : /* Drop ownership of m_candidates, using it to generate a name_hint at m_loc
    6902                 :             :    for m_name, an IDENTIFIER_NODE for which name lookup failed.
    6903                 :             : 
    6904                 :             :    If m_candidates is non-empty, use it to generate a suggestion and/or
    6905                 :             :    a deferred diagnostic that lists the possible candidate(s).
    6906                 :             : */
    6907                 :             : 
    6908                 :             : name_hint
    6909                 :        2098 : namespace_hints::convert_candidates_to_name_hint ()
    6910                 :             : {
    6911                 :             :   /* How many candidates do we have?  */
    6912                 :             : 
    6913                 :             :   /* If we have just one candidate, issue a name_hint with it as a suggestion
    6914                 :             :      (so that consumers are able to suggest it within the error message and emit
    6915                 :             :      it as a fix-it hint), and with a note showing the candidate's location.  */
    6916                 :        2098 :   if (m_candidates.length () == 1)
    6917                 :             :     {
    6918                 :         129 :       tree candidate = m_candidates[0];
    6919                 :             :       /* Clean up CANDIDATES.  */
    6920                 :         129 :       m_candidates.release ();
    6921                 :         129 :       return name_hint (expr_to_string (candidate),
    6922                 :         129 :                         new show_candidate_location (m_loc, candidate));
    6923                 :             :     }
    6924                 :        1969 :   else if (m_candidates.length () > 1)
    6925                 :             :     /* If we have more than one candidate, issue a name_hint without a single
    6926                 :             :        "suggestion", but with a deferred diagnostic that lists the
    6927                 :             :        various candidates.  This takes ownership of m_candidates.  */
    6928                 :          22 :     return name_hint (NULL, new suggest_alternatives (m_loc, m_candidates));
    6929                 :             : 
    6930                 :             :   /* Otherwise, m_candidates ought to be empty, so no cleanup is necessary.  */
    6931                 :        1947 :   gcc_assert (m_candidates.length () == 0);
    6932                 :        1947 :   gcc_assert (m_candidates == vNULL);
    6933                 :             : 
    6934                 :        1947 :   return name_hint ();
    6935                 :             : }
    6936                 :             : 
    6937                 :             : /* If --param cxx-max-namespaces-for-diagnostic-help was reached,
    6938                 :             :    then we want to emit a note about after the error, but before
    6939                 :             :    any other deferred diagnostics.
    6940                 :             : 
    6941                 :             :    Handle this by figuring out what hint is needed, then optionally
    6942                 :             :    decorating HINT with a namespace_limit_reached wrapper.  */
    6943                 :             : 
    6944                 :             : name_hint
    6945                 :        2098 : namespace_hints::maybe_decorate_with_limit (name_hint hint)
    6946                 :             : {
    6947                 :        2098 :   if (m_limited)
    6948                 :           3 :     return name_hint (hint.suggestion (),
    6949                 :             :                       new namespace_limit_reached (m_loc, m_limit,
    6950                 :             :                                                    m_name,
    6951                 :           3 :                                                    hint.take_deferred ()));
    6952                 :             :   else
    6953                 :        2095 :     return hint;
    6954                 :             : }
    6955                 :             : 
    6956                 :             : /* Look inside SCOPED_ENUM for exact matches for NAME.
    6957                 :             :    If one is found, add its CONST_DECL to m_candidates.  */
    6958                 :             : 
    6959                 :             : void
    6960                 :        1251 : namespace_hints::maybe_add_candidate_for_scoped_enum (tree scoped_enum,
    6961                 :             :                                                       tree name)
    6962                 :             : {
    6963                 :        1251 :   gcc_assert (SCOPED_ENUM_P (scoped_enum));
    6964                 :             : 
    6965                 :        2229 :   for (tree iter = TYPE_VALUES (scoped_enum); iter; iter = TREE_CHAIN (iter))
    6966                 :             :     {
    6967                 :         993 :       tree id = TREE_PURPOSE (iter);
    6968                 :         993 :       if (id == name)
    6969                 :             :         {
    6970                 :          15 :           m_candidates.safe_push (TREE_VALUE (iter));
    6971                 :          15 :           return;
    6972                 :             :         }
    6973                 :             :     }
    6974                 :             : }
    6975                 :             : 
    6976                 :             : /* Generate a name_hint at LOCATION for NAME, an IDENTIFIER_NODE for which
    6977                 :             :    name lookup failed.
    6978                 :             : 
    6979                 :             :    Search through all available namespaces and any scoped enums within them
    6980                 :             :    and generate a suggestion and/or a deferred diagnostic that lists possible
    6981                 :             :    candidate(s).
    6982                 :             : 
    6983                 :             :    If no exact matches are found, and SUGGEST_MISSPELLINGS is true, then also
    6984                 :             :    look for near-matches and suggest the best near-match, if there is one.
    6985                 :             : 
    6986                 :             :    If nothing is found, then an empty name_hint is returned.  */
    6987                 :             : 
    6988                 :             : name_hint
    6989                 :        2048 : suggest_alternatives_for (location_t location, tree name,
    6990                 :             :                           bool suggest_misspellings)
    6991                 :             : {
    6992                 :             :   /* First, search for exact matches in other namespaces.  */
    6993                 :        2048 :   namespace_hints ns_hints (location, name);
    6994                 :        2048 :   name_hint result = ns_hints.convert_candidates_to_name_hint ();
    6995                 :             : 
    6996                 :             :   /* Otherwise, try other approaches.  */
    6997                 :        2048 :   if (!result)
    6998                 :        1924 :     result = suggest_alternatives_for_1 (location, name, suggest_misspellings);
    6999                 :             : 
    7000                 :        2048 :   return ns_hints.maybe_decorate_with_limit (std::move (result));
    7001                 :        2048 : }
    7002                 :             : 
    7003                 :             : /* The second half of suggest_alternatives_for, for when no exact matches
    7004                 :             :    were found in other namespaces.  */
    7005                 :             : 
    7006                 :             : static name_hint
    7007                 :        1924 : suggest_alternatives_for_1 (location_t location, tree name,
    7008                 :             :                             bool suggest_misspellings)
    7009                 :             : {
    7010                 :             :   /* No candidates were found in the available namespaces.  */
    7011                 :             : 
    7012                 :             :   /* If there's a "using namespace std;" active, and this
    7013                 :             :      is one of the most common "std::" names, then it's probably a
    7014                 :             :      missing #include.  */
    7015                 :        1924 :   if (has_using_namespace_std_directive_p ())
    7016                 :             :     {
    7017                 :          21 :       name_hint hint = maybe_suggest_missing_std_header (location, name);
    7018                 :          21 :       if (hint)
    7019                 :          21 :         return hint;
    7020                 :          21 :     }
    7021                 :             : 
    7022                 :             :   /* Otherwise, consider misspellings.  */
    7023                 :        1903 :   if (!suggest_misspellings)
    7024                 :           0 :     return name_hint ();
    7025                 :             : 
    7026                 :        1903 :   return lookup_name_fuzzy (name, FUZZY_LOOKUP_NAME, location);
    7027                 :             : }
    7028                 :             : 
    7029                 :             : /* Generate a name_hint at LOCATION for NAME, an IDENTIFIER_NODE for which
    7030                 :             :    name lookup failed.
    7031                 :             : 
    7032                 :             :    Search through all available namespaces and generate a suggestion and/or
    7033                 :             :    a deferred diagnostic that lists possible candidate(s).
    7034                 :             : 
    7035                 :             :    This is similiar to suggest_alternatives_for, but doesn't fallback to
    7036                 :             :    the other approaches used by that function.  */
    7037                 :             : 
    7038                 :             : name_hint
    7039                 :          50 : suggest_alternatives_in_other_namespaces (location_t location, tree name)
    7040                 :             : {
    7041                 :          50 :   namespace_hints ns_hints (location, name);
    7042                 :             : 
    7043                 :          50 :   name_hint result = ns_hints.convert_candidates_to_name_hint ();
    7044                 :             : 
    7045                 :          50 :   return ns_hints.maybe_decorate_with_limit (std::move (result));
    7046                 :          50 : }
    7047                 :             : 
    7048                 :             : /* A well-known name within the C++ standard library, returned by
    7049                 :             :    get_std_name_hint.
    7050                 :             : 
    7051                 :             :    The gperf-generated file contains the definition of the class
    7052                 :             :    "std_name_hint_lookup" with a static member function which
    7053                 :             :    returns the pointer to a structure "std_name_hint" which
    7054                 :             :    is also defined in that file.  */
    7055                 :             : 
    7056                 :             : #include "std-name-hint.h"
    7057                 :             : 
    7058                 :             : /* Subroutine of maybe_suggest_missing_header for handling unrecognized names
    7059                 :             :    for some of the most common names within "std::".
    7060                 :             :    Given non-NULL NAME, return the std_name_hint for it, or NULL.  */
    7061                 :             : 
    7062                 :             : static const std_name_hint *
    7063                 :         185 : get_std_name_hint (const char *name)
    7064                 :             : {
    7065                 :         185 :   return std_name_hint_lookup::find(name, strlen(name));
    7066                 :             : }
    7067                 :             : 
    7068                 :             : /* Describe DIALECT.  */
    7069                 :             : 
    7070                 :             : const char *
    7071                 :        3145 : get_cxx_dialect_name (enum cxx_dialect dialect)
    7072                 :             : {
    7073                 :        3145 :   switch (dialect)
    7074                 :             :     {
    7075                 :           0 :     default:
    7076                 :           0 :       gcc_unreachable ();
    7077                 :             :     case cxx98:
    7078                 :             :       return "C++98";
    7079                 :           4 :     case cxx11:
    7080                 :           4 :       return "C++11";
    7081                 :           2 :     case cxx14:
    7082                 :           2 :       return "C++14";
    7083                 :        1030 :     case cxx17:
    7084                 :        1030 :       return "C++17";
    7085                 :        1075 :     case cxx20:
    7086                 :        1075 :       return "C++20";
    7087                 :        1034 :     case cxx23:
    7088                 :        1034 :       return "C++23";
    7089                 :           0 :     case cxx26:
    7090                 :           0 :       return "C++26";
    7091                 :             :     }
    7092                 :             : }
    7093                 :             : 
    7094                 :             : /* Subclass of deferred_diagnostic for use for names in the "std" namespace
    7095                 :             :    that weren't recognized, but for which we know which header it ought to be
    7096                 :             :    in.
    7097                 :             : 
    7098                 :             :    Emit a note either suggesting the header to be included, or noting that
    7099                 :             :    the current dialect is too early for the given name.  */
    7100                 :             : 
    7101                 :             : class missing_std_header : public deferred_diagnostic
    7102                 :             : {
    7103                 :             :  public:
    7104                 :         163 :   missing_std_header (location_t loc,
    7105                 :             :                       const char *name_str,
    7106                 :             :                       const std_name_hint *header_hint)
    7107                 :         163 :   : deferred_diagnostic (loc),
    7108                 :         163 :     m_name_str (name_str),
    7109                 :         163 :     m_header_hint (header_hint)
    7110                 :             :   {}
    7111                 :         326 :   ~missing_std_header ()
    7112                 :         163 :   {
    7113                 :         163 :     gcc_rich_location richloc (get_location ());
    7114                 :         163 :     if (cxx_dialect >= m_header_hint->min_dialect)
    7115                 :             :       {
    7116                 :         154 :         const char *header = m_header_hint->header;
    7117                 :         154 :         maybe_add_include_fixit (&richloc, header, true);
    7118                 :         154 :         inform (&richloc,
    7119                 :             :                 "%<std::%s%> is defined in header %qs;"
    7120                 :             :                 " this is probably fixable by adding %<#include %s%>",
    7121                 :             :                 m_name_str, header, header);
    7122                 :             :       }
    7123                 :             :     else
    7124                 :           9 :       inform (&richloc,
    7125                 :             :               "%<std::%s%> is only available from %s onwards",
    7126                 :             :               m_name_str, get_cxx_dialect_name (m_header_hint->min_dialect));
    7127                 :         326 :   }
    7128                 :             : 
    7129                 :             : private:
    7130                 :             :   const char *m_name_str;
    7131                 :             :   const std_name_hint *m_header_hint;
    7132                 :             : };
    7133                 :             : 
    7134                 :             : /* Attempt to generate a name_hint that suggests pertinent header files
    7135                 :             :    for NAME at LOCATION, for common names within the "std" namespace,
    7136                 :             :    or an empty name_hint if this isn't applicable.  */
    7137                 :             : 
    7138                 :             : static name_hint
    7139                 :         185 : maybe_suggest_missing_std_header (location_t location, tree name)
    7140                 :             : {
    7141                 :         185 :   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
    7142                 :             : 
    7143                 :         185 :   const char *name_str = IDENTIFIER_POINTER (name);
    7144                 :         185 :   const std_name_hint *header_hint = get_std_name_hint (name_str);
    7145                 :         185 :   if (!header_hint)
    7146                 :          22 :     return name_hint ();
    7147                 :             : 
    7148                 :         163 :   return name_hint (NULL, new missing_std_header (location, name_str,
    7149                 :         163 :                                                   header_hint));
    7150                 :             : }
    7151                 :             : 
    7152                 :             : /* Attempt to generate a name_hint that suggests a missing header file
    7153                 :             :    for NAME within SCOPE at LOCATION, or an empty name_hint if this isn't
    7154                 :             :    applicable.  */
    7155                 :             : 
    7156                 :             : name_hint
    7157                 :         508 : maybe_suggest_missing_header (location_t location, tree name, tree scope)
    7158                 :             : {
    7159                 :         508 :   if (scope == NULL_TREE)
    7160                 :           0 :     return name_hint ();
    7161                 :         508 :   if (TREE_CODE (scope) != NAMESPACE_DECL)
    7162                 :          43 :     return name_hint ();
    7163                 :             :   /* We only offer suggestions for the "std" namespace.  */
    7164                 :         465 :   if (scope != std_node)
    7165                 :         301 :     return name_hint ();
    7166                 :         164 :   return maybe_suggest_missing_std_header (location, name);
    7167                 :             : }
    7168                 :             : 
    7169                 :             : /* Generate a name_hint at LOCATION for NAME, an IDENTIFIER_NODE for which name
    7170                 :             :    lookup failed within the explicitly provided SCOPE.
    7171                 :             : 
    7172                 :             :    Suggest the best meaningful candidates (if any), otherwise
    7173                 :             :    an empty name_hint is returned.  */
    7174                 :             : 
    7175                 :             : name_hint
    7176                 :         299 : suggest_alternative_in_explicit_scope (location_t location, tree name,
    7177                 :             :                                        tree scope)
    7178                 :             : {
    7179                 :             :   /* Something went very wrong; don't suggest anything.  */
    7180                 :         299 :   if (name == error_mark_node)
    7181                 :           3 :     return name_hint ();
    7182                 :             : 
    7183                 :             :   /* Resolve any namespace aliases.  */
    7184                 :         296 :   scope = ORIGINAL_NAMESPACE (scope);
    7185                 :             : 
    7186                 :         296 :   name_hint hint = maybe_suggest_missing_header (location, name, scope);
    7187                 :         296 :   if (hint)
    7188                 :         127 :     return hint;
    7189                 :             : 
    7190                 :         169 :   cp_binding_level *level = NAMESPACE_LEVEL (scope);
    7191                 :             : 
    7192                 :         169 :   best_match <tree, const char *> bm (name);
    7193                 :         169 :   consider_binding_level (name, bm, level, false, FUZZY_LOOKUP_NAME);
    7194                 :             : 
    7195                 :             :   /* See if we have a good suggesion for the user.  */
    7196                 :         169 :   const char *fuzzy_name = bm.get_best_meaningful_candidate ();
    7197                 :         169 :   if (fuzzy_name)
    7198                 :          53 :     return name_hint (fuzzy_name, NULL);
    7199                 :             : 
    7200                 :         116 :   return name_hint ();
    7201                 :         296 : }
    7202                 :             : 
    7203                 :             : /* Given NAME, look within SCOPED_ENUM for possible spell-correction
    7204                 :             :    candidates.  */
    7205                 :             : 
    7206                 :             : name_hint
    7207                 :          15 : suggest_alternative_in_scoped_enum (tree name, tree scoped_enum)
    7208                 :             : {
    7209                 :          15 :   gcc_assert (SCOPED_ENUM_P (scoped_enum));
    7210                 :             : 
    7211                 :          15 :   best_match <tree, const char *> bm (name);
    7212                 :          48 :   for (tree iter = TYPE_VALUES (scoped_enum); iter; iter = TREE_CHAIN (iter))
    7213                 :             :     {
    7214                 :          33 :       tree id = TREE_PURPOSE (iter);
    7215                 :          33 :       bm.consider (IDENTIFIER_POINTER (id));
    7216                 :             :     }
    7217                 :          15 :   return name_hint (bm.get_best_meaningful_candidate (), NULL);
    7218                 :             : }
    7219                 :             : 
    7220                 :             : /* Look up NAME (an IDENTIFIER_NODE) in SCOPE (either a NAMESPACE_DECL
    7221                 :             :    or a class TYPE).
    7222                 :             : 
    7223                 :             :    WANT as for lookup_name_1.
    7224                 :             : 
    7225                 :             :    Returns a DECL (or OVERLOAD, or BASELINK) representing the
    7226                 :             :    declaration found.  If no suitable declaration can be found,
    7227                 :             :    ERROR_MARK_NODE is returned.  If COMPLAIN is true and SCOPE is
    7228                 :             :    neither a class-type nor a namespace a diagnostic is issued.  */
    7229                 :             : 
    7230                 :             : tree
    7231                 :   363397676 : lookup_qualified_name (tree scope, tree name, LOOK_want want, bool complain)
    7232                 :             : {
    7233                 :   363397676 :   tree t = NULL_TREE;
    7234                 :             : 
    7235                 :   363397676 :   if (TREE_CODE (scope) == NAMESPACE_DECL)
    7236                 :             :     {
    7237                 :   267014332 :       name_lookup lookup (name, want);
    7238                 :             : 
    7239                 :   267014332 :       if (qualified_namespace_lookup (scope, &lookup))
    7240                 :             :         {
    7241                 :   265976678 :           t = lookup.value;
    7242                 :             : 
    7243                 :             :           /* If we have a known type overload, pull it out.  This can happen
    7244                 :             :              for using decls.  */
    7245                 :   265976678 :           if (TREE_CODE (t) == OVERLOAD && TREE_TYPE (t) != unknown_type_node)
    7246                 :     1050262 :             t = OVL_FUNCTION (t);
    7247                 :             :         }
    7248                 :   267014332 :     }
    7249                 :    96383344 :   else if (cxx_dialect != cxx98 && TREE_CODE (scope) == ENUMERAL_TYPE)
    7250                 :     6338374 :     t = lookup_enumerator (scope, name);
    7251                 :    90044970 :   else if (is_class_type (scope, complain))
    7252                 :    89781303 :     t = lookup_member (scope, name, 2, bool (want & LOOK_want::TYPE),
    7253                 :             :                        tf_warning_or_error);
    7254                 :             : 
    7255                 :   363133945 :   if (!t)
    7256                 :     1374831 :     return error_mark_node;
    7257                 :             :   return t;
    7258                 :             : }
    7259                 :             : 
    7260                 :             : /* Wrapper for the above that takes a string argument.  The function name is
    7261                 :             :    not at the beginning of the line to keep this wrapper out of etags.  */
    7262                 :             : 
    7263                 :      130792 : tree lookup_qualified_name (tree t, const char *p, LOOK_want w, bool c)
    7264                 :             : {
    7265                 :      130792 :   return lookup_qualified_name (t, get_identifier (p), w, c);
    7266                 :             : }
    7267                 :             : 
    7268                 :             : /* [namespace.qual]
    7269                 :             :    Accepts the NAME to lookup and its qualifying SCOPE.
    7270                 :             :    Returns the name/type pair found into the cxx_binding *RESULT,
    7271                 :             :    or false on error.  */
    7272                 :             : 
    7273                 :             : static bool
    7274                 :   273274287 : qualified_namespace_lookup (tree scope, name_lookup *lookup)
    7275                 :             : {
    7276                 :   273274287 :   timevar_start (TV_NAME_LOOKUP);
    7277                 :   273274287 :   query_oracle (lookup->name);
    7278                 :   273274287 :   bool found = lookup->search_qualified (ORIGINAL_NAMESPACE (scope));
    7279                 :   273274287 :   timevar_stop (TV_NAME_LOOKUP);
    7280                 :   273274287 :   return found;
    7281                 :             : }
    7282                 :             : 
    7283                 :             : /* If DECL is suitably visible to the user, consider its name for
    7284                 :             :    spelling correction.  */
    7285                 :             : 
    7286                 :             : static void
    7287                 :        2241 : consider_decl (tree decl,  best_match <tree, const char *> &bm,
    7288                 :             :                bool consider_impl_names)
    7289                 :             : {
    7290                 :             :   /* Skip compiler-generated variables (e.g. __for_begin/__for_end
    7291                 :             :      within range for).  */
    7292                 :        2241 :   if (VAR_P (decl) && DECL_ARTIFICIAL (decl))
    7293                 :             :     return;
    7294                 :             : 
    7295                 :        2174 :   tree suggestion = DECL_NAME (decl);
    7296                 :        2174 :   if (!suggestion)
    7297                 :             :     return;
    7298                 :             : 
    7299                 :             :   /* Don't suggest names that are for anonymous aggregate types, as
    7300                 :             :      they are an implementation detail generated by the compiler.  */
    7301                 :        2039 :   if (IDENTIFIER_ANON_P (suggestion))
    7302                 :             :     return;
    7303                 :             : 
    7304                 :        1949 :   const char *suggestion_str = IDENTIFIER_POINTER (suggestion);
    7305                 :             : 
    7306                 :             :   /* Ignore internal names with spaces in them.  */
    7307                 :        1949 :   if (strchr (suggestion_str, ' '))
    7308                 :             :     return;
    7309                 :             : 
    7310                 :             :   /* Don't suggest names that are reserved for use by the
    7311                 :             :      implementation, unless NAME began with an underscore.  */
    7312                 :        1949 :   if (!consider_impl_names
    7313                 :        1949 :       && name_reserved_for_implementation_p (suggestion_str))
    7314                 :             :     return;
    7315                 :             : 
    7316                 :        1920 :   bm.consider (suggestion_str);
    7317                 :             : }
    7318                 :             : 
    7319                 :             : /* If DECL is suitably visible to the user, add its name to VEC and
    7320                 :             :    return true.  Otherwise return false.  */
    7321                 :             : 
    7322                 :             : static bool
    7323                 :     3550757 : maybe_add_fuzzy_decl (auto_vec<tree> &vec, tree decl)
    7324                 :             : {
    7325                 :             :   /* Skip compiler-generated variables (e.g. __for_begin/__for_end
    7326                 :             :      within range for).  */
    7327                 :     3550757 :   if (VAR_P (decl) && DECL_ARTIFICIAL (decl))
    7328                 :             :     return false;
    7329                 :             : 
    7330                 :     3549660 :   tree suggestion = DECL_NAME (decl);
    7331                 :     3549660 :   if (!suggestion)
    7332                 :             :     return false;
    7333                 :             : 
    7334                 :             :   /* Don't suggest names that are for anonymous aggregate types, as
    7335                 :             :      they are an implementation detail generated by the compiler.  */
    7336                 :     3549660 :   if (IDENTIFIER_ANON_P (suggestion))
    7337                 :             :     return false;
    7338                 :             : 
    7339                 :     3549660 :   vec.safe_push (suggestion);
    7340                 :             : 
    7341                 :     3549660 :   return true;
    7342                 :             : }
    7343                 :             : 
    7344                 :             : /* Examing the namespace binding BINDING, and add at most one instance
    7345                 :             :    of the name, if it contains a visible entity of interest.  Return
    7346                 :             :    true if we added something.  */
    7347                 :             : 
    7348                 :             : bool
    7349                 :     5551603 : maybe_add_fuzzy_binding (auto_vec<tree> &vec, tree binding,
    7350                 :             :                               lookup_name_fuzzy_kind kind)
    7351                 :             : {
    7352                 :     5551603 :   tree value = NULL_TREE;
    7353                 :             : 
    7354                 :     5551603 :   if (STAT_HACK_P (binding))
    7355                 :             :     {
    7356                 :         192 :       if (!STAT_TYPE_HIDDEN_P (binding)
    7357                 :         192 :           && STAT_TYPE (binding))
    7358                 :             :         {
    7359                 :         114 :           if (maybe_add_fuzzy_decl (vec, STAT_TYPE (binding)))
    7360                 :             :             return true;
    7361                 :             :         }
    7362                 :          78 :       else if (!STAT_DECL_HIDDEN_P (binding))
    7363                 :          42 :         value = STAT_DECL (binding);
    7364                 :             :     }
    7365                 :             :   else
    7366                 :             :     value = binding;
    7367                 :             : 
    7368                 :     5551489 :   value = ovl_skip_hidden (value);
    7369                 :     5551489 :   if (value)
    7370                 :             :     {
    7371                 :     4680610 :       value = OVL_FIRST (value);
    7372                 :     4680610 :       if (kind != FUZZY_LOOKUP_TYPENAME
    7373                 :     4680610 :           || TREE_CODE (STRIP_TEMPLATE (value)) == TYPE_DECL)
    7374                 :     3550643 :         if (maybe_add_fuzzy_decl (vec, value))
    7375                 :             :           return true;
    7376                 :             :     }
    7377                 :             : 
    7378                 :             :   /* Nothing found.  */
    7379                 :             :   return false;
    7380                 :             : }
    7381                 :             : 
    7382                 :             : /* Helper function for lookup_name_fuzzy.
    7383                 :             :    Traverse binding level LVL, looking for good name matches for NAME
    7384                 :             :    (and BM).  */
    7385                 :             : static void
    7386                 :        7308 : consider_binding_level (tree name, best_match <tree, const char *> &bm,
    7387                 :             :                         cp_binding_level *lvl, bool look_within_fields,
    7388                 :             :                         enum lookup_name_fuzzy_kind kind)
    7389                 :             : {
    7390                 :        7308 :   if (look_within_fields)
    7391                 :        1036 :     if (lvl->this_entity && TREE_CODE (lvl->this_entity) == RECORD_TYPE)
    7392                 :             :       {
    7393                 :         425 :         tree type = lvl->this_entity;
    7394                 :         425 :         bool want_type_p = (kind == FUZZY_LOOKUP_TYPENAME);
    7395                 :         425 :         tree best_matching_field
    7396                 :         425 :           = lookup_member_fuzzy (type, name, want_type_p);
    7397                 :         425 :         if (best_matching_field)
    7398                 :           8 :           bm.consider (IDENTIFIER_POINTER (best_matching_field));
    7399                 :             :       }
    7400                 :             : 
    7401                 :             :   /* Only suggest names reserved for the implementation if NAME begins
    7402                 :             :      with an underscore.  */
    7403                 :        7308 :   bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_');
    7404                 :             : 
    7405                 :        7308 :   if (lvl->kind != sk_namespace)
    7406                 :        7246 :     for (tree t = lvl->names; t; t = TREE_CHAIN (t))
    7407                 :             :       {
    7408                 :        2648 :         tree d = t;
    7409                 :             : 
    7410                 :             :         /* OVERLOADs or decls from using declaration are wrapped into
    7411                 :             :            TREE_LIST.  */
    7412                 :        2648 :         if (TREE_CODE (d) == TREE_LIST)
    7413                 :          36 :           d = OVL_FIRST (TREE_VALUE (d));
    7414                 :             : 
    7415                 :             :         /* Don't use bindings from implicitly declared functions,
    7416                 :             :            as they were likely misspellings themselves.  */
    7417                 :        2648 :         if (TREE_TYPE (d) == error_mark_node)
    7418                 :         343 :           continue;
    7419                 :             : 
    7420                 :             :         /* If we want a typename, ignore non-types.  */
    7421                 :        2369 :         if (kind == FUZZY_LOOKUP_TYPENAME
    7422                 :        2305 :             && TREE_CODE (STRIP_TEMPLATE (d)) != TYPE_DECL)
    7423                 :          64 :           continue;
    7424                 :             : 
    7425                 :        2241 :         consider_decl (d, bm, consider_implementation_names);
    7426                 :             :       }
    7427                 :             :   else
    7428                 :             :     {
    7429                 :             :       /* We need to iterate over the namespace hash table, in order to
    7430                 :             :          not mention hidden entities.  But hash table iteration is
    7431                 :             :          (essentially) unpredictable, our correction-distance measure
    7432                 :             :          is very granular, and we pick the first of equal distances.
    7433                 :             :          Hence, we need to call the distance-measurer in a predictable
    7434                 :             :          order.  So, iterate over the namespace hash, inserting
    7435                 :             :          visible names into a vector.  Then sort the vector.  Then
    7436                 :             :          determine spelling distance.  */
    7437                 :             :       
    7438                 :        2710 :       tree ns = lvl->this_entity;
    7439                 :        2710 :       auto_vec<tree> vec;
    7440                 :             : 
    7441                 :        2710 :       hash_table<named_decl_hash>::iterator end
    7442                 :        2710 :         (DECL_NAMESPACE_BINDINGS (ns)->end ());
    7443                 :     5554325 :       for (hash_table<named_decl_hash>::iterator iter
    7444                 :    11108650 :              (DECL_NAMESPACE_BINDINGS (ns)->begin ()); iter != end; ++iter)
    7445                 :             :         {
    7446                 :     5551615 :           tree binding = *iter;
    7447                 :             : 
    7448                 :     5551615 :           if (TREE_CODE (binding) == BINDING_VECTOR)
    7449                 :             :             {
    7450                 :          99 :               bitmap imports = get_import_bitmap ();
    7451                 :          99 :               binding_cluster *cluster = BINDING_VECTOR_CLUSTER_BASE (binding);
    7452                 :             : 
    7453                 :          99 :               if (tree bind = cluster->slots[BINDING_SLOT_CURRENT])
    7454                 :          15 :                 if (maybe_add_fuzzy_binding (vec, bind, kind))
    7455                 :           9 :                   continue;
    7456                 :             : 
    7457                 :             :               /* Scan the imported bindings.  */
    7458                 :          90 :               unsigned ix = BINDING_VECTOR_NUM_CLUSTERS (binding);
    7459                 :          90 :               if (BINDING_VECTOR_SLOTS_PER_CLUSTER == BINDING_SLOTS_FIXED)
    7460                 :             :                 {
    7461                 :          90 :                   ix--;
    7462                 :          90 :                   cluster++;
    7463                 :             :                 }
    7464                 :             : 
    7465                 :         180 :               for (; ix--; cluster++)
    7466                 :         162 :                 for (unsigned jx = 0; jx != BINDING_VECTOR_SLOTS_PER_CLUSTER;
    7467                 :             :                      jx++)
    7468                 :             :                   {
    7469                 :             :                     /* Are we importing this module?  */
    7470                 :         135 :                     if (unsigned base = cluster->indices[jx].base)
    7471                 :          90 :                       if (unsigned span = cluster->indices[jx].span)
    7472                 :          90 :                         do
    7473                 :          90 :                           if (bitmap_bit_p (imports, base))
    7474                 :          87 :                             goto found;
    7475                 :           3 :                         while (++base, --span);
    7476                 :          48 :                     continue;
    7477                 :             : 
    7478                 :          87 :                   found:;
    7479                 :             :                     /* Is it loaded?  */
    7480                 :          87 :                     if (cluster->slots[jx].is_lazy ())
    7481                 :             :                       /* Let's not read in everything on the first
    7482                 :             :                          spello! **/
    7483                 :          15 :                       continue;
    7484                 :          72 :                     if (tree bind = cluster->slots[jx])
    7485                 :          72 :                       if (maybe_add_fuzzy_binding (vec, bind, kind))
    7486                 :             :                         break;
    7487                 :          48 :                   }
    7488                 :             :             }
    7489                 :             :           else
    7490                 :     5551516 :             maybe_add_fuzzy_binding (vec, binding, kind);
    7491                 :             :         }
    7492                 :             :         
    7493                 :   186261404 :       vec.qsort ([] (const void *a_, const void *b_)
    7494                 :             :                  {
    7495                 :             :                    return strcmp (IDENTIFIER_POINTER (*(const tree *)a_),
    7496                 :             :                                   IDENTIFIER_POINTER (*(const tree *)b_));
    7497                 :             :                  });
    7498                 :             : 
    7499                 :             :       /* Examine longest to shortest.  */
    7500                 :     3555080 :       for (unsigned ix = vec.length (); ix--;)
    7501                 :             :         {
    7502                 :     3549660 :           const char *str = IDENTIFIER_POINTER (vec[ix]);
    7503                 :             : 
    7504                 :             :           /* Ignore internal names with spaces in them.  */
    7505                 :     3549660 :           if (strchr (str, ' '))
    7506                 :       64291 :             continue;
    7507                 :             :           
    7508                 :             :           /* Don't suggest names that are reserved for use by the
    7509                 :             :              implementation, unless NAME began with an underscore.  */
    7510                 :     6636246 :           if (!consider_implementation_names
    7511                 :     3485369 :               && name_reserved_for_implementation_p (str))
    7512                 :     3150877 :             continue;
    7513                 :             : 
    7514                 :      334492 :           bm.consider (str);
    7515                 :             :         }
    7516                 :        2710 :     }
    7517                 :        7308 : }
    7518                 :             : 
    7519                 :             : /* Subclass of deferred_diagnostic.  Notify the user that the
    7520                 :             :    given macro was used before it was defined.
    7521                 :             :    This can be done in the C++ frontend since tokenization happens
    7522                 :             :    upfront.  */
    7523                 :             : 
    7524                 :             : class macro_use_before_def : public deferred_diagnostic
    7525                 :             : {
    7526                 :             :  public:
    7527                 :             :   /* Factory function.  Return a new macro_use_before_def instance if
    7528                 :             :      appropriate, or return NULL. */
    7529                 :             :   static macro_use_before_def *
    7530                 :          57 :   maybe_make (location_t use_loc, cpp_hashnode *macro)
    7531                 :             :   {
    7532                 :          85 :     location_t def_loc = cpp_macro_definition_location (macro);
    7533                 :          57 :     if (def_loc == UNKNOWN_LOCATION)
    7534                 :             :       return NULL;
    7535                 :             : 
    7536                 :             :     /* We only want to issue a note if the macro was used *before* it was
    7537                 :             :        defined.
    7538                 :             :        We don't want to issue a note for cases where a macro was incorrectly
    7539                 :             :        used, leaving it unexpanded (e.g. by using the wrong argument
    7540                 :             :        count).  */
    7541                 :          57 :     if (!linemap_location_before_p (line_table, use_loc, def_loc))
    7542                 :             :       return NULL;
    7543                 :             : 
    7544                 :          29 :     return new macro_use_before_def (use_loc, macro);
    7545                 :             :   }
    7546                 :             : 
    7547                 :             :  private:
    7548                 :             :   /* Ctor.  LOC is the location of the usage.  MACRO is the
    7549                 :             :      macro that was used.  */
    7550                 :          29 :   macro_use_before_def (location_t loc, cpp_hashnode *macro)
    7551                 :          29 :   : deferred_diagnostic (loc), m_macro (macro)
    7552                 :             :   {
    7553                 :          29 :     gcc_assert (macro);
    7554                 :          29 :   }
    7555                 :             : 
    7556                 :          58 :   ~macro_use_before_def ()
    7557                 :          29 :   {
    7558                 :          29 :     if (is_suppressed_p ())
    7559                 :           0 :       return;
    7560                 :             : 
    7561                 :          29 :     inform (get_location (), "the macro %qs had not yet been defined",
    7562                 :          29 :             (const char *)m_macro->ident.str);
    7563                 :          58 :     inform (cpp_macro_definition_location (m_macro),
    7564                 :             :             "it was later defined here");
    7565                 :          58 :   }
    7566                 :             : 
    7567                 :             :  private:
    7568                 :             :   cpp_hashnode *m_macro;
    7569                 :             : };
    7570                 :             : 
    7571                 :             : /* Determine if it can ever make sense to offer RID as a suggestion for
    7572                 :             :    a misspelling.
    7573                 :             : 
    7574                 :             :    Subroutine of lookup_name_fuzzy.  */
    7575                 :             : 
    7576                 :             : static bool
    7577                 :      446820 : suggest_rid_p  (enum rid rid)
    7578                 :             : {
    7579                 :      446820 :   switch (rid)
    7580                 :             :     {
    7581                 :             :     /* Support suggesting function-like keywords.  */
    7582                 :             :     case RID_STATIC_ASSERT:
    7583                 :             :       return true;
    7584                 :             : 
    7585                 :      442758 :     default:
    7586                 :             :       /* Support suggesting the various decl-specifier words, to handle
    7587                 :             :          e.g. "singed" vs "signed" typos.  */
    7588                 :      442758 :       if (cp_keyword_starts_decl_specifier_p (rid))
    7589                 :             :         return true;
    7590                 :             : 
    7591                 :             :       /* Otherwise, don't offer it.  This avoids suggesting e.g. "if"
    7592                 :             :          and "do" for short misspellings, which are likely to lead to
    7593                 :             :          nonsensical results.  */
    7594                 :             :       return false;
    7595                 :             :     }
    7596                 :             : }
    7597                 :             : 
    7598                 :             : /* Search for near-matches for NAME within the current bindings, and within
    7599                 :             :    macro names, returning the best match as a const char *, or NULL if
    7600                 :             :    no reasonable match is found.
    7601                 :             : 
    7602                 :             :    Use LOC for any deferred diagnostics.  */
    7603                 :             : 
    7604                 :             : name_hint
    7605                 :        2396 : lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
    7606                 :             : {
    7607                 :        2396 :   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
    7608                 :             : 
    7609                 :             :   /* First, try some well-known names in the C++ standard library, in case
    7610                 :             :      the user forgot a #include.  */
    7611                 :        2396 :   const char *header_hint
    7612                 :        2396 :     = get_cp_stdlib_header_for_name (IDENTIFIER_POINTER (name));
    7613                 :        2396 :   if (header_hint)
    7614                 :         308 :     return name_hint (NULL,
    7615                 :             :                       new suggest_missing_header (loc,
    7616                 :         308 :                                                   IDENTIFIER_POINTER (name),
    7617                 :         308 :                                                   header_hint));
    7618                 :             : 
    7619                 :        2088 :   best_match <tree, const char *> bm (name);
    7620                 :             : 
    7621                 :        2088 :   cp_binding_level *lvl;
    7622                 :        3124 :   for (lvl = scope_chain->class_bindings; lvl; lvl = lvl->level_chain)
    7623                 :        1036 :     consider_binding_level (name, bm, lvl, true, kind);
    7624                 :             : 
    7625                 :        8191 :   for (lvl = current_binding_level; lvl; lvl = lvl->level_chain)
    7626                 :        6103 :     consider_binding_level (name, bm, lvl, false, kind);
    7627                 :             : 
    7628                 :             :   /* Consider macros: if the user misspelled a macro name e.g. "SOME_MACRO"
    7629                 :             :      as:
    7630                 :             :        x = SOME_OTHER_MACRO (y);
    7631                 :             :      then "SOME_OTHER_MACRO" will survive to the frontend and show up
    7632                 :             :      as a misspelled identifier.
    7633                 :             : 
    7634                 :             :      Use the best distance so far so that a candidate is only set if
    7635                 :             :      a macro is better than anything so far.  This allows early rejection
    7636                 :             :      (without calculating the edit distance) of macro names that must have
    7637                 :             :      distance >= bm.get_best_distance (), and means that we only get a
    7638                 :             :      non-NULL result for best_macro_match if it's better than any of
    7639                 :             :      the identifiers already checked.  */
    7640                 :        2088 :   best_macro_match bmm (name, bm.get_best_distance (), parse_in);
    7641                 :        2088 :   cpp_hashnode *best_macro = bmm.get_best_meaningful_candidate ();
    7642                 :             :   /* If a macro is the closest so far to NAME, consider it.  */
    7643                 :        2088 :   if (best_macro)
    7644                 :          32 :     bm.consider ((const char *)best_macro->ident.str);
    7645                 :        2056 :   else if (bmm.get_best_distance () == 0)
    7646                 :             :     {
    7647                 :             :       /* If we have an exact match for a macro name, then either the
    7648                 :             :          macro was used with the wrong argument count, or the macro
    7649                 :             :          has been used before it was defined.  */
    7650                 :          89 :       if (cpp_hashnode *macro = bmm.blithely_get_best_candidate ())
    7651                 :          61 :         if (cpp_user_macro_p (macro))
    7652                 :          57 :           return name_hint (NULL,
    7653                 :          57 :                             macro_use_before_def::maybe_make (loc, macro));
    7654                 :             :     }
    7655                 :             : 
    7656                 :             :   /* Try the "starts_decl_specifier_p" keywords to detect
    7657                 :             :      "singed" vs "signed" typos.  */
    7658                 :      448851 :   for (unsigned i = 0; i < num_c_common_reswords; i++)
    7659                 :             :     {
    7660                 :      446820 :       const c_common_resword *resword = &c_common_reswords[i];
    7661                 :             : 
    7662                 :      446820 :       if (!suggest_rid_p (resword->rid))
    7663                 :      322929 :         continue;
    7664                 :             : 
    7665                 :      123891 :       tree resword_identifier = ridpointers [resword->rid];
    7666                 :      123891 :       if (!resword_identifier)
    7667                 :           0 :         continue;
    7668                 :      123891 :       gcc_assert (TREE_CODE (resword_identifier) == IDENTIFIER_NODE);
    7669                 :             : 
    7670                 :             :       /* Only consider reserved words that survived the
    7671                 :             :          filtering in init_reswords (e.g. for -std).  */
    7672                 :      123891 :       if (!IDENTIFIER_KEYWORD_P (resword_identifier))
    7673                 :       13842 :         continue;
    7674                 :             : 
    7675                 :      110049 :       bm.consider (IDENTIFIER_POINTER (resword_identifier));
    7676                 :             :     }
    7677                 :             : 
    7678                 :        2031 :   return name_hint (bm.get_best_meaningful_candidate (), NULL);
    7679                 :             : }
    7680                 :             : 
    7681                 :             : /* Subroutine of outer_binding.
    7682                 :             : 
    7683                 :             :    Returns TRUE if BINDING is a binding to a template parameter of
    7684                 :             :    SCOPE.  In that case SCOPE is the scope of a primary template
    7685                 :             :    parameter -- in the sense of G++, i.e, a template that has its own
    7686                 :             :    template header.
    7687                 :             : 
    7688                 :             :    Returns FALSE otherwise.  */
    7689                 :             : 
    7690                 :             : static bool
    7691                 :   321068465 : binding_to_template_parms_of_scope_p (cxx_binding *binding,
    7692                 :             :                                       cp_binding_level *scope)
    7693                 :             : {
    7694                 :   321068465 :   tree binding_value, tmpl, tinfo;
    7695                 :   321068465 :   int level;
    7696                 :             : 
    7697                 :   321068465 :   if (!binding || !scope || !scope->this_entity)
    7698                 :             :     return false;
    7699                 :             : 
    7700                 :   190340288 :   binding_value = binding->value ?  binding->value : binding->type;
    7701                 :   190340288 :   tinfo = get_template_info (scope->this_entity);
    7702                 :             : 
    7703                 :             :   /* BINDING_VALUE must be a template parm.  */
    7704                 :   190340288 :   if (binding_value == NULL_TREE
    7705                 :   190340288 :       || (!DECL_P (binding_value)
    7706                 :   190340288 :           || !DECL_TEMPLATE_PARM_P (binding_value)))
    7707                 :             :     return false;
    7708                 :             : 
    7709                 :             :   /*  The level of BINDING_VALUE.  */
    7710                 :   380680576 :   level =
    7711                 :   190340288 :     template_type_parameter_p (binding_value)
    7712                 :   190340288 :     ? TEMPLATE_PARM_LEVEL (TEMPLATE_TYPE_PARM_INDEX
    7713                 :             :                          (TREE_TYPE (binding_value)))
    7714                 :    73407364 :     : TEMPLATE_PARM_LEVEL (DECL_INITIAL (binding_value));
    7715                 :             : 
    7716                 :             :   /* The template of the current scope, iff said scope is a primary
    7717                 :             :      template.  */
    7718                 :   661710924 :   tmpl = (tinfo
    7719                 :   174424247 :           && PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo))
    7720                 :   190340288 :           ? TI_TEMPLATE (tinfo)
    7721                 :             :           : NULL_TREE);
    7722                 :             : 
    7723                 :             :   /* If the level of the parm BINDING_VALUE equals the depth of TMPL,
    7724                 :             :      then BINDING_VALUE is a parameter of TMPL.  */
    7725                 :   150302171 :   return (tmpl && level == TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (tmpl)));
    7726                 :             : }
    7727                 :             : 
    7728                 :             : /* Return the innermost non-namespace binding for NAME from a scope
    7729                 :             :    containing BINDING, or, if BINDING is NULL, the current scope.
    7730                 :             :    Please note that for a given template, the template parameters are
    7731                 :             :    considered to be in the scope containing the current scope.
    7732                 :             :    If CLASS_P is false, then class bindings are ignored.  */
    7733                 :             : 
    7734                 :             : cxx_binding *
    7735                 :  5212176789 : outer_binding (tree name,
    7736                 :             :                cxx_binding *binding,
    7737                 :             :                bool class_p)
    7738                 :             : {
    7739                 :  5212176789 :   cxx_binding *outer;
    7740                 :  5212176789 :   cp_binding_level *scope;
    7741                 :  5212176789 :   cp_binding_level *outer_scope;
    7742                 :             : 
    7743                 :  5212176789 :   if (binding)
    7744                 :             :     {
    7745                 :     4289087 :       scope = binding->scope->level_chain;
    7746                 :     4289087 :       outer = binding->previous;
    7747                 :             :     }
    7748                 :             :   else
    7749                 :             :     {
    7750                 :  5207887702 :       scope = current_binding_level;
    7751                 :  5207887702 :       outer = IDENTIFIER_BINDING (name);
    7752                 :             :     }
    7753                 :  5212176789 :   outer_scope = outer ? outer->scope : NULL;
    7754                 :             : 
    7755                 :             :   /* Because we create class bindings lazily, we might be missing a
    7756                 :             :      class binding for NAME.  If there are any class binding levels
    7757                 :             :      between the LAST_BINDING_LEVEL and the scope in which OUTER was
    7758                 :             :      declared, we must lookup NAME in those class scopes.  */
    7759                 :  5212176789 :   if (class_p)
    7760                 : 12232697346 :     while (scope && scope != outer_scope && scope->kind != sk_namespace)
    7761                 :             :       {
    7762                 :  8937845107 :         if (scope->kind == sk_class)
    7763                 :             :           {
    7764                 :  1383987837 :             cxx_binding *class_binding;
    7765                 :             : 
    7766                 :  1383987837 :             class_binding = get_class_binding (name, scope);
    7767                 :  1383987837 :             if (class_binding)
    7768                 :             :               {
    7769                 :             :                 /* Thread this new class-scope binding onto the
    7770                 :             :                    IDENTIFIER_BINDING list so that future lookups
    7771                 :             :                    find it quickly.  */
    7772                 :   120950099 :                 if (BASELINK_P (class_binding->value))
    7773                 :             :                   /* Don't put a BASELINK in IDENTIFIER_BINDING.  */
    7774                 :    34993087 :                   class_binding->value
    7775                 :    34993087 :                     = BASELINK_FUNCTIONS (class_binding->value);
    7776                 :   120950099 :                 class_binding->previous = outer;
    7777                 :   120950099 :                 if (binding)
    7778                 :           3 :                   binding->previous = class_binding;
    7779                 :             :                 else
    7780                 :   120950096 :                   IDENTIFIER_BINDING (name) = class_binding;
    7781                 :   120950099 :                 return class_binding;
    7782                 :             :               }
    7783                 :             :           }
    7784                 :             :         /* If we are in a member template, the template parms of the member
    7785                 :             :            template are considered to be inside the scope of the containing
    7786                 :             :            class, but within G++ the class bindings are all pushed between the
    7787                 :             :            template parms and the function body.  So if the outer binding is
    7788                 :             :            a template parm for the current scope, return it now rather than
    7789                 :             :            look for a class binding.  */
    7790                 :  3853078936 :         if (outer_scope && outer_scope->kind == sk_template_parms
    7791                 :  9137963473 :             && binding_to_template_parms_of_scope_p (outer, scope))
    7792                 :             :           return outer;
    7793                 :             : 
    7794                 :  8678398028 :         scope = scope->level_chain;
    7795                 :             :       }
    7796                 :             : 
    7797                 :             :   return outer;
    7798                 :             : }
    7799                 :             : 
    7800                 :             : /* Return the innermost block-scope or class-scope value binding for
    7801                 :             :    NAME, or NULL_TREE if there is no such binding.  */
    7802                 :             : 
    7803                 :             : tree
    7804                 :   776651127 : innermost_non_namespace_value (tree name)
    7805                 :             : {
    7806                 :   776651127 :   cxx_binding *binding;
    7807                 :   776651127 :   binding = outer_binding (name, /*binding=*/NULL, /*class_p=*/true);
    7808                 :   776651127 :   return binding ? binding->value : NULL_TREE;
    7809                 :             : }
    7810                 :             : 
    7811                 :             : /* True iff current_binding_level is within the potential scope of local
    7812                 :             :    variable DECL. */
    7813                 :             : 
    7814                 :             : bool
    7815                 :         119 : decl_in_scope_p (tree decl)
    7816                 :             : {
    7817                 :         119 :   gcc_checking_assert (DECL_FUNCTION_SCOPE_P (decl));
    7818                 :             : 
    7819                 :         119 :   tree name = DECL_NAME (decl);
    7820                 :             : 
    7821                 :         119 :   for (cxx_binding *iter = NULL;
    7822                 :         127 :        (iter = outer_binding (name, iter, /*class_p=*/false)); )
    7823                 :             :     {
    7824                 :          75 :       if (!LOCAL_BINDING_P (iter))
    7825                 :             :         return false;
    7826                 :          75 :       if (iter->value == decl)
    7827                 :             :         return true;
    7828                 :             :     }
    7829                 :             : 
    7830                 :             :   return false;
    7831                 :             : }
    7832                 :             : 
    7833                 :             : /* Look up NAME in the current binding level and its superiors in the
    7834                 :             :    namespace of variables, functions and typedefs.  Return a ..._DECL
    7835                 :             :    node of some kind representing its definition if there is only one
    7836                 :             :    such declaration, or return a TREE_LIST with all the overloaded
    7837                 :             :    definitions if there are many, or return NULL_TREE if it is undefined.
    7838                 :             :    Hidden name, either friend declaration or built-in function, are
    7839                 :             :    not ignored.
    7840                 :             : 
    7841                 :             :    WHERE controls which scopes are considered.  It is a bit mask of
    7842                 :             :    LOOK_where::BLOCK (look in block scope), LOOK_where::CLASS
    7843                 :             :    (look in class scopes) & LOOK_where::NAMESPACE (look in namespace
    7844                 :             :    scopes).  It is an error for no bits to be set.  These scopes are
    7845                 :             :    searched from innermost to outermost.
    7846                 :             : 
    7847                 :             :    WANT controls what kind of entity we'd happy with.
    7848                 :             :    LOOK_want::NORMAL for normal lookup (implicit typedefs can be
    7849                 :             :    hidden).  LOOK_want::TYPE for only TYPE_DECLS, LOOK_want::NAMESPACE
    7850                 :             :    for only NAMESPACE_DECLS.  These two can be bit-ored to find
    7851                 :             :    namespace or type.
    7852                 :             : 
    7853                 :             :    WANT can also have LOOK_want::HIDDEN_FRIEND or
    7854                 :             :    LOOK_want::HIDDEN_LAMBDa added to it.  */
    7855                 :             : 
    7856                 :             : tree
    7857                 :  3934245488 : lookup_name (tree name, LOOK_where where, LOOK_want want)
    7858                 :             : {
    7859                 :  3934245488 :   tree val = NULL_TREE;
    7860                 :             : 
    7861                 :  3934245488 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    7862                 :             : 
    7863                 :  3934245488 :   gcc_checking_assert (unsigned (where) != 0);
    7864                 :             :   /* If we're looking for hidden lambda things, we shouldn't be
    7865                 :             :      looking in namespace scope.  */
    7866                 :  3934245488 :   gcc_checking_assert (!bool (want & LOOK_want::HIDDEN_LAMBDA)
    7867                 :             :                        || !bool (where & LOOK_where::NAMESPACE));
    7868                 :  3934245488 :   query_oracle (name);
    7869                 :             : 
    7870                 :             :   /* Conversion operators are handled specially because ordinary
    7871                 :             :      unqualified name lookup will not find template conversion
    7872                 :             :      operators.  */
    7873                 :  7686357403 :   if (IDENTIFIER_CONV_OP_P (name))
    7874                 :             :     {
    7875                 :      529374 :       cp_binding_level *level;
    7876                 :             : 
    7877                 :      529374 :       for (level = current_binding_level;
    7878                 :     1445688 :            level && level->kind != sk_namespace;
    7879                 :      916314 :            level = level->level_chain)
    7880                 :             :         {
    7881                 :     1001228 :           tree class_type;
    7882                 :     1001228 :           tree operators;
    7883                 :             : 
    7884                 :             :           /* A conversion operator can only be declared in a class
    7885                 :             :              scope.  */
    7886                 :     1001228 :           if (level->kind != sk_class)
    7887                 :      408598 :             continue;
    7888                 :             : 
    7889                 :             :           /* Lookup the conversion operator in the class.  */
    7890                 :      592630 :           class_type = level->this_entity;
    7891                 :      592630 :           operators = lookup_fnfields (class_type, name, /*protect=*/0,
    7892                 :             :                                        tf_warning_or_error);
    7893                 :      592630 :           if (operators)
    7894                 :       84914 :             return operators;
    7895                 :             :         }
    7896                 :             : 
    7897                 :             :       return NULL_TREE;
    7898                 :             :     }
    7899                 :             : 
    7900                 :             :   /* First, look in non-namespace scopes.  */
    7901                 :             : 
    7902                 :  3933716114 :   if (current_class_type == NULL_TREE)
    7903                 :             :     /* Maybe avoid searching the binding stack at all.  */
    7904                 :  1588908559 :     where = LOOK_where (unsigned (where) & ~unsigned (LOOK_where::CLASS));
    7905                 :             : 
    7906                 :  3933716114 :   if (bool (where & (LOOK_where::BLOCK | LOOK_where::CLASS)))
    7907                 :             :     for (cxx_binding *iter = nullptr;
    7908                 :  3937429403 :          (iter = outer_binding (name, iter, bool (where & LOOK_where::CLASS)));)
    7909                 :             :       {
    7910                 :             :         /* Skip entities we don't want.  */
    7911                 :  3583102165 :         if (!bool (where & (LOCAL_BINDING_P (iter)
    7912                 :             :                             ? LOOK_where::BLOCK : LOOK_where::CLASS)))
    7913                 :       26608 :           continue;
    7914                 :             : 
    7915                 :             :         /* If this is the kind of thing we're looking for, we're done.  */
    7916                 :  2873051902 :         if (iter->value)
    7917                 :             :           {
    7918                 :  2873051902 :             tree binding = NULL_TREE;
    7919                 :             : 
    7920                 :  2814495975 :             if (!(!iter->type && HIDDEN_TYPE_BINDING_P (iter))
    7921                 :  2873051818 :                 && (bool (want & LOOK_want::HIDDEN_LAMBDA)
    7922                 :  2872795576 :                     || !is_lambda_ignored_entity (iter->value))
    7923                 :  5741915388 :                 && qualify_lookup (iter->value, want))
    7924                 :  2868789573 :               binding = iter->value;
    7925                 :     4262329 :             else if (bool (want & LOOK_want::TYPE)
    7926                 :       73889 :                      && !HIDDEN_TYPE_BINDING_P (iter)
    7927                 :     4336198 :                      && iter->type)
    7928                 :  2873051902 :               binding = iter->type;
    7929                 :             : 
    7930                 :  2873051902 :             if (binding)
    7931                 :             :               {
    7932                 :             :                 val = binding;
    7933                 :             :                 break;
    7934                 :             :               }
    7935                 :             :           }
    7936                 :             :       }
    7937                 :             : 
    7938                 :             :   /* Now lookup in namespace scopes.  */
    7939                 :  3933716114 :   if (!val && bool (where & LOOK_where::NAMESPACE))
    7940                 :             :     {
    7941                 :  1064926243 :       name_lookup lookup (name, want);
    7942                 :  1064926243 :       if (lookup.search_unqualified
    7943                 :  1064926243 :           (current_decl_namespace (), current_binding_level))
    7944                 :   818205670 :         val = lookup.value;
    7945                 :  1064926243 :     }
    7946                 :             : 
    7947                 :             :   /* If we have a known type overload, pull it out.  This can happen
    7948                 :             :      for both using decls and unhidden functions.  */
    7949                 :  3933716114 :   if (val && TREE_CODE (val) == OVERLOAD && TREE_TYPE (val) != unknown_type_node)
    7950                 :     2604437 :     val = OVL_FUNCTION (val);
    7951                 :             : 
    7952                 :             :   return val;
    7953                 :  3934245488 : }
    7954                 :             : 
    7955                 :             : tree
    7956                 :   265099471 : lookup_name (tree name)
    7957                 :             : {
    7958                 :   265099471 :   return lookup_name (name, LOOK_where::ALL, LOOK_want::NORMAL);
    7959                 :             : }
    7960                 :             : 
    7961                 :             : /* Look up NAME for type used in elaborated name specifier in
    7962                 :             :    the scopes given by HOW.
    7963                 :             : 
    7964                 :             :    Unlike lookup_name_1, we make sure that NAME is actually
    7965                 :             :    declared in the desired scope, not from inheritance, nor using
    7966                 :             :    directive.  For using declaration, there is DR138 still waiting
    7967                 :             :    to be resolved.  Hidden name coming from an earlier friend
    7968                 :             :    declaration is also returned, and will be made visible unless HOW
    7969                 :             :    is TAG_how::HIDDEN_FRIEND.
    7970                 :             : 
    7971                 :             :    A TYPE_DECL best matching the NAME is returned.  Catching error
    7972                 :             :    and issuing diagnostics are caller's responsibility.  */
    7973                 :             : 
    7974                 :             : tree
    7975                 :    19176315 : lookup_elaborated_type (tree name, TAG_how how)
    7976                 :             : {
    7977                 :    19176315 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    7978                 :             : 
    7979                 :    19176315 :   cp_binding_level *b = current_binding_level;
    7980                 :             : 
    7981                 :    19176315 :   if (b->kind != sk_namespace)
    7982                 :             :     /* Look in non-namespace scopes.  */
    7983                 :             :     for (cxx_binding *iter = NULL;
    7984                 :    14112880 :          (iter = outer_binding (name, iter, /*class_p=*/ true)); )
    7985                 :             :       {
    7986                 :             :         /* First check we're supposed to be looking in this scope --
    7987                 :             :            if we're not, we're done.  */
    7988                 :      549157 :         for (; b != iter->scope; b = b->level_chain)
    7989                 :      348916 :           if (!(b->kind == sk_cleanup
    7990                 :      244467 :                 || b->kind == sk_template_parms
    7991                 :      104462 :                 || b->kind == sk_function_parms
    7992                 :      104422 :                 || (b->kind == sk_class && how != TAG_how::CURRENT_ONLY)))
    7993                 :             :             return NULL_TREE;
    7994                 :             : 
    7995                 :             :         /* Check if this is the kind of thing we're looking for.  If
    7996                 :             :            HOW is TAG_how::CURRENT_ONLY, also make sure it doesn't
    7997                 :             :            come from base class.  For ITER->VALUE, we can simply use
    7998                 :             :            INHERITED_VALUE_BINDING_P.  For ITER->TYPE, we have to use
    7999                 :             :            our own check.
    8000                 :             : 
    8001                 :             :            We check ITER->TYPE before ITER->VALUE in order to handle
    8002                 :             :              typedef struct C {} C;
    8003                 :             :            correctly.  */
    8004                 :             : 
    8005                 :      304687 :         if (tree type = iter->type)
    8006                 :             :           {
    8007                 :       55152 :             if (qualify_lookup (type, LOOK_want::TYPE)
    8008                 :       55152 :                 && (how != TAG_how::CURRENT_ONLY
    8009                 :         132 :                     || LOCAL_BINDING_P (iter)
    8010                 :         132 :                     || DECL_CONTEXT (type) == iter->scope->this_entity))
    8011                 :             :               {
    8012                 :       55088 :                 if (how != TAG_how::HIDDEN_FRIEND)
    8013                 :             :                   /* It is no longer a hidden binding.  */
    8014                 :          72 :                   HIDDEN_TYPE_BINDING_P (iter) = false;
    8015                 :             : 
    8016                 :       55088 :                 return type;
    8017                 :             :               }
    8018                 :             :           }
    8019                 :             :         else
    8020                 :             :           {
    8021                 :      249535 :             if (qualify_lookup (iter->value, LOOK_want::TYPE)
    8022                 :      249535 :                 && (how != TAG_how::CURRENT_ONLY
    8023                 :       45305 :                     || !INHERITED_VALUE_BINDING_P (iter)))
    8024                 :             :               {
    8025                 :      249375 :                 if (how != TAG_how::HIDDEN_FRIEND && !iter->type)
    8026                 :             :                   /* It is no longer a hidden binding.  */
    8027                 :       45313 :                   HIDDEN_TYPE_BINDING_P (iter) = false;
    8028                 :             : 
    8029                 :      249375 :                 return iter->value;
    8030                 :             :               }
    8031                 :             :           }
    8032                 :             :       }
    8033                 :             : 
    8034                 :             :   /* Now check if we can look in namespace scope.  */
    8035                 :    30766545 :   for (; b->kind != sk_namespace; b = b->level_chain)
    8036                 :             :     if (!(b->kind == sk_cleanup
    8037                 :             :           || b->kind == sk_template_parms
    8038                 :             :           || b->kind == sk_function_parms
    8039                 :     3298089 :           || (b->kind == sk_class && how != TAG_how::CURRENT_ONLY)))
    8040                 :             :       return NULL_TREE;
    8041                 :             : 
    8042                 :             :   /* Look in the innermost namespace.  */
    8043                 :    15812276 :   tree ns = b->this_entity;
    8044                 :    15812276 :   if (tree *slot = find_namespace_slot (ns, name))
    8045                 :             :     {
    8046                 :     2455035 :       tree bind = *slot;
    8047                 :     2455035 :       if (TREE_CODE (bind) == BINDING_VECTOR)
    8048                 :          85 :         bind = BINDING_VECTOR_CLUSTER (bind, 0).slots[BINDING_SLOT_CURRENT];
    8049                 :             : 
    8050                 :          85 :       if (bind)
    8051                 :             :         {
    8052                 :             :           /* If this is the kind of thing we're looking for, we're done.  */
    8053                 :     2454990 :           if (tree type = MAYBE_STAT_TYPE (bind))
    8054                 :             :             {
    8055                 :         218 :               if (how != TAG_how::HIDDEN_FRIEND)
    8056                 :             :                 /* No longer hidden.  */
    8057                 :         218 :                 STAT_TYPE_HIDDEN_P (*slot) = false;
    8058                 :             :               
    8059                 :         218 :               return type;
    8060                 :             :             }
    8061                 :     2454772 :           else if (tree decl = MAYBE_STAT_DECL (bind))
    8062                 :             :             {
    8063                 :     2454772 :               if (qualify_lookup (decl, LOOK_want::TYPE))
    8064                 :             :                 {
    8065                 :     2172806 :                   if (how != TAG_how::HIDDEN_FRIEND && STAT_HACK_P (bind)
    8066                 :     2502951 :                       && STAT_DECL_HIDDEN_P (bind))
    8067                 :             :                     {
    8068                 :       50334 :                       if (STAT_TYPE (bind))
    8069                 :           0 :                         STAT_DECL_HIDDEN_P (bind) = false;
    8070                 :             :                       else
    8071                 :             :                         {
    8072                 :             :                           /* There is no type, just remove the stat
    8073                 :             :                              hack.  */
    8074                 :       50334 :                           if (*slot == bind)
    8075                 :       50331 :                             *slot = decl;
    8076                 :             :                           else
    8077                 :           3 :                             BINDING_VECTOR_CLUSTER (*slot, 0)
    8078                 :           3 :                               .slots[BINDING_SLOT_CURRENT] = decl;
    8079                 :             :                         }
    8080                 :             :                     }
    8081                 :     2452588 :                   return decl;
    8082                 :             :                 }
    8083                 :             :             }
    8084                 :             :         }
    8085                 :             : 
    8086                 :        2229 :       if (TREE_CODE (*slot) == BINDING_VECTOR)
    8087                 :             :         {
    8088                 :             :           /* We could be redeclaring a global module entity, (from GMF
    8089                 :             :              or header unit), or from another partition, or
    8090                 :             :              specializing an imported template.  */
    8091                 :          45 :           bitmap imports = get_import_bitmap ();
    8092                 :          45 :           binding_cluster *cluster = BINDING_VECTOR_CLUSTER_BASE (*slot);
    8093                 :             : 
    8094                 :             :           /* Scan the imported bindings.  */
    8095                 :          45 :           unsigned ix = BINDING_VECTOR_NUM_CLUSTERS (*slot);
    8096                 :          45 :           if (BINDING_VECTOR_SLOTS_PER_CLUSTER == BINDING_SLOTS_FIXED)
    8097                 :             :             {
    8098                 :          45 :               ix--;
    8099                 :          45 :               cluster++;
    8100                 :             :             }
    8101                 :             : 
    8102                 :             :           /* Do this in forward order, so we load modules in an order
    8103                 :             :              the user expects.  */
    8104                 :          48 :           for (; ix--; cluster++)
    8105                 :          68 :             for (unsigned jx = 0; jx != BINDING_VECTOR_SLOTS_PER_CLUSTER; jx++)
    8106                 :             :               {
    8107                 :             :                 /* Are we importing this module?  */
    8108                 :          65 :                 if (unsigned base = cluster->indices[jx].base)
    8109                 :          41 :                   if (unsigned span = cluster->indices[jx].span)
    8110                 :          41 :                     do
    8111                 :          41 :                       if (bitmap_bit_p (imports, base))
    8112                 :          41 :                         goto found;
    8113                 :           0 :                     while (++base, --span);
    8114                 :          24 :                 continue;
    8115                 :             : 
    8116                 :          41 :               found:;
    8117                 :             :                 /* Is it loaded?  */
    8118                 :          41 :                 if (cluster->slots[jx].is_lazy ())
    8119                 :             :                   {
    8120                 :          24 :                     gcc_assert (cluster->indices[jx].span == 1);
    8121                 :          24 :                     lazy_load_binding (cluster->indices[jx].base,
    8122                 :             :                                        ns, name, &cluster->slots[jx]);
    8123                 :             :                   }
    8124                 :          41 :                 tree bind = cluster->slots[jx];
    8125                 :          41 :                 if (!bind)
    8126                 :             :                   /* Load errors could mean there's nothing here.  */
    8127                 :           0 :                   continue;
    8128                 :             : 
    8129                 :             :                 /* Extract what we can see from here.  If there's no
    8130                 :             :                    stat_hack, then everything was exported.  */
    8131                 :          41 :                 tree type = NULL_TREE;
    8132                 :             : 
    8133                 :             :                 /* If no stat hack, everything is visible.  */
    8134                 :          41 :                 if (STAT_HACK_P (bind))
    8135                 :             :                   {
    8136                 :          38 :                     if (STAT_TYPE_VISIBLE_P (bind))
    8137                 :          18 :                       type = STAT_TYPE (bind);
    8138                 :          38 :                     bind = STAT_VISIBLE (bind);
    8139                 :             :                   }
    8140                 :             : 
    8141                 :          38 :                 if (type && qualify_lookup (type, LOOK_want::TYPE))
    8142                 :           3 :                   return type;
    8143                 :             : 
    8144                 :          38 :                 if (bind && qualify_lookup (bind, LOOK_want::TYPE))
    8145                 :          38 :                   return bind;
    8146                 :          24 :               }
    8147                 :             : 
    8148                 :           4 :           if (!module_purview_p ())
    8149                 :             :             {
    8150                 :             :               /* We're in the global module, perhaps there's a tag
    8151                 :             :                  there?  */
    8152                 :             : 
    8153                 :             :               /* FIXME: In general we should probably merge global module
    8154                 :             :                  classes in check_module_override rather than here, but for
    8155                 :             :                  GCC14 let's just fix lazy declarations of __class_type_info in
    8156                 :             :                  build_dynamic_cast_1.  */
    8157                 :           4 :               if (current_namespace == abi_node)
    8158                 :             :                 {
    8159                 :           4 :                   tree g = (BINDING_VECTOR_CLUSTER (*slot, 0)
    8160                 :           4 :                             .slots[BINDING_SLOT_GLOBAL]);
    8161                 :           4 :                   for (ovl_iterator iter (g); iter; ++iter)
    8162                 :           4 :                     if (qualify_lookup (*iter, LOOK_want::TYPE))
    8163                 :           4 :                       return *iter;
    8164                 :             :                 }
    8165                 :             :             }
    8166                 :             :         }
    8167                 :             :     }
    8168                 :             : 
    8169                 :             :   return NULL_TREE;
    8170                 :    19176315 : }
    8171                 :             : 
    8172                 :             : /* The type TYPE is being declared.  If it is a class template, or a
    8173                 :             :    specialization of a class template, do any processing required and
    8174                 :             :    perform error-checking.  If IS_FRIEND is nonzero, this TYPE is
    8175                 :             :    being declared a friend.  B is the binding level at which this TYPE
    8176                 :             :    should be bound.
    8177                 :             : 
    8178                 :             :    Returns the TYPE_DECL for TYPE, which may have been altered by this
    8179                 :             :    processing.  */
    8180                 :             : 
    8181                 :             : static tree
    8182                 :    18554433 : maybe_process_template_type_declaration (tree type, int is_friend,
    8183                 :             :                                          cp_binding_level *b)
    8184                 :             : {
    8185                 :    18554433 :   tree decl = TYPE_NAME (type);
    8186                 :             : 
    8187                 :    18554433 :   if (processing_template_parmlist)
    8188                 :             :     /* You can't declare a new template type in a template parameter
    8189                 :             :        list.  But, you can declare a non-template type:
    8190                 :             : 
    8191                 :             :          template <class A*> struct S;
    8192                 :             : 
    8193                 :             :        is a forward-declaration of `A'.  */
    8194                 :             :     ;
    8195                 :    18554377 :   else if (b->kind == sk_namespace
    8196                 :     4948375 :            && current_binding_level->kind != sk_namespace)
    8197                 :             :     /* If this new type is being injected into a containing scope,
    8198                 :             :        then it's not a template type.  */
    8199                 :             :     ;
    8200                 :             :   else
    8201                 :             :     {
    8202                 :    18508961 :       gcc_assert (MAYBE_CLASS_TYPE_P (type)
    8203                 :             :                   || TREE_CODE (type) == ENUMERAL_TYPE);
    8204                 :             : 
    8205                 :    18508961 :       if (processing_template_decl)
    8206                 :             :         {
    8207                 :    11317166 :           decl = push_template_decl (decl, is_friend);
    8208                 :    11317166 :           if (decl == error_mark_node)
    8209                 :             :             return error_mark_node;
    8210                 :             : 
    8211                 :             :           /* If the current binding level is the binding level for the
    8212                 :             :              template parameters (see the comment in
    8213                 :             :              begin_template_parm_list) and the enclosing level is a class
    8214                 :             :              scope, and we're not looking at a friend, push the
    8215                 :             :              declaration of the member class into the class scope.  In the
    8216                 :             :              friend case, push_template_decl will already have put the
    8217                 :             :              friend into global scope, if appropriate.  */
    8218                 :    11317139 :           if (TREE_CODE (type) != ENUMERAL_TYPE
    8219                 :    11014230 :               && !is_friend && b->kind == sk_template_parms
    8220                 :     9333748 :               && b->level_chain->kind == sk_class)
    8221                 :             :             {
    8222                 :      635525 :               finish_member_declaration (CLASSTYPE_TI_TEMPLATE (type));
    8223                 :             : 
    8224                 :      635525 :               if (!COMPLETE_TYPE_P (current_class_type))
    8225                 :      635510 :                 maybe_add_class_template_decl_list (current_class_type,
    8226                 :             :                                                     type, /*friend_p=*/0);
    8227                 :             :             }
    8228                 :             :         }
    8229                 :             :     }
    8230                 :             : 
    8231                 :             :   return decl;
    8232                 :             : }
    8233                 :             : 
    8234                 :             : /* Push a tag name NAME for struct/class/union/enum type TYPE.  In case
    8235                 :             :    that the NAME is a class template, the tag is processed but not pushed.
    8236                 :             : 
    8237                 :             :    The pushed scope depend on the SCOPE parameter:
    8238                 :             :    - When SCOPE is TS_CURRENT, put it into the inner-most non-sk_cleanup
    8239                 :             :      scope.
    8240                 :             :    - When SCOPE is TS_GLOBAL, put it in the inner-most non-class and
    8241                 :             :      non-template-parameter scope.  This case is needed for forward
    8242                 :             :      declarations.
    8243                 :             :    - When SCOPE is TS_WITHIN_ENCLOSING_NON_CLASS, this is similar to
    8244                 :             :      TS_GLOBAL case except that names within template-parameter scopes
    8245                 :             :      are not pushed at all.
    8246                 :             : 
    8247                 :             :    Returns TYPE upon success and ERROR_MARK_NODE otherwise.  */
    8248                 :             : 
    8249                 :             : tree
    8250                 :    18554433 : pushtag (tree name, tree type, TAG_how how)
    8251                 :             : {
    8252                 :    18554433 :   tree decl;
    8253                 :             : 
    8254                 :    18554433 :   gcc_assert (identifier_p (name));
    8255                 :             : 
    8256                 :    18554433 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    8257                 :             : 
    8258                 :    18554433 :   cp_binding_level *b = current_binding_level;
    8259                 :    18600317 :   while (true)
    8260                 :             :     {
    8261                 :    18600317 :       if (/* Cleanup scopes are not scopes from the point of view of
    8262                 :             :              the language.  */
    8263                 :    18600317 :           b->kind == sk_cleanup
    8264                 :             :           /* Neither are function parameter scopes.  */
    8265                 :    18600310 :           || b->kind == sk_function_parms
    8266                 :             :           /* Neither are the scopes used to hold template parameters
    8267                 :             :              for an explicit specialization.  For an ordinary template
    8268                 :             :              declaration, these scopes are not scopes from the point of
    8269                 :             :              view of the language.  */
    8270                 :    18598496 :           || (b->kind == sk_template_parms
    8271                 :     9676382 :               && (b->explicit_spec_p || how == TAG_how::GLOBAL)))
    8272                 :        1891 :         b = b->level_chain;
    8273                 :    18598426 :       else if (b->kind == sk_class && how != TAG_how::CURRENT_ONLY)
    8274                 :             :         {
    8275                 :       43993 :           b = b->level_chain;
    8276                 :       43993 :           if (b->kind == sk_template_parms)
    8277                 :         485 :             b = b->level_chain;
    8278                 :             :         }
    8279                 :             :       else
    8280                 :             :         break;
    8281                 :             :     }
    8282                 :             : 
    8283                 :             :   /* Do C++ gratuitous typedefing.  */
    8284                 :    18554433 :   if (REAL_IDENTIFIER_TYPE_VALUE (name) != type)
    8285                 :             :     {
    8286                 :    18554433 :       tree tdef;
    8287                 :    18554433 :       tree context = TYPE_CONTEXT (type);
    8288                 :             : 
    8289                 :    18554433 :       if (! context)
    8290                 :             :         {
    8291                 :             :           cp_binding_level *cb = b;
    8292                 :    29836238 :           while (cb->kind != sk_namespace
    8293                 :    16189570 :                  && cb->kind != sk_class
    8294                 :    42779064 :                  && (cb->kind != sk_function_parms
    8295                 :     1410957 :                      || !cb->this_entity))
    8296                 :    11531869 :             cb = cb->level_chain;
    8297                 :    18304369 :           tree cs = cb->this_entity;
    8298                 :             : 
    8299                 :    18304369 :           gcc_checking_assert (TREE_CODE (cs) == FUNCTION_DECL
    8300                 :             :                                ? cs == current_function_decl
    8301                 :             :                                : TYPE_P (cs) ? cs == current_class_type
    8302                 :             :                                : cs == current_namespace);
    8303                 :             : 
    8304                 :    18304369 :           if (how == TAG_how::CURRENT_ONLY
    8305                 :      138365 :               || (cs && TREE_CODE (cs) == FUNCTION_DECL))
    8306                 :             :             context = cs;
    8307                 :      138244 :           else if (cs && TYPE_P (cs))
    8308                 :             :             /* When declaring a friend class of a local class, we want
    8309                 :             :                to inject the newly named class into the scope
    8310                 :             :                containing the local class, not the namespace
    8311                 :             :                scope.  */
    8312                 :       92441 :             context = decl_function_context (get_type_decl (cs));
    8313                 :             :         }
    8314                 :    18304248 :       if (!context)
    8315                 :      138244 :         context = current_namespace;
    8316                 :             : 
    8317                 :    18554433 :       tdef = create_implicit_typedef (name, type);
    8318                 :    18554433 :       DECL_CONTEXT (tdef) = FROB_CONTEXT (context);
    8319                 :    18554433 :       set_originating_module (tdef);
    8320                 :             : 
    8321                 :    18554433 :       decl = maybe_process_template_type_declaration
    8322                 :    18554433 :         (type, how == TAG_how::HIDDEN_FRIEND, b);
    8323                 :    18554433 :       if (decl == error_mark_node)
    8324                 :             :         return decl;
    8325                 :             : 
    8326                 :    18554406 :       if (b->kind == sk_class)
    8327                 :             :         {
    8328                 :     2518765 :           if (!TYPE_BEING_DEFINED (current_class_type))
    8329                 :             :             /* Don't push anywhere if the class is complete; a lambda in an
    8330                 :             :                NSDMI is not a member of the class.  */
    8331                 :             :             ;
    8332                 :     2518372 :           else if (!PROCESSING_REAL_TEMPLATE_DECL_P ())
    8333                 :             :             /* Put this TYPE_DECL on the TYPE_FIELDS list for the
    8334                 :             :                class.  But if it's a member template class, we want
    8335                 :             :                the TEMPLATE_DECL, not the TYPE_DECL, so this is done
    8336                 :             :                later.  */
    8337                 :     2518364 :             finish_member_declaration (decl);
    8338                 :             :           else
    8339                 :           8 :             pushdecl_class_level (decl);
    8340                 :             :         }
    8341                 :    16035641 :       else if (b->kind == sk_template_parms)
    8342                 :             :         {
    8343                 :             :           /* Do not push the tag here -- we'll want to push the
    8344                 :             :              TEMPLATE_DECL.  */
    8345                 :     9676289 :           if (b->level_chain->kind != sk_class)
    8346                 :     8698258 :             set_identifier_type_value_with_scope (name, tdef, b->level_chain);
    8347                 :             :         }
    8348                 :             :       else
    8349                 :             :         {
    8350                 :     6359352 :           decl = do_pushdecl_with_scope
    8351                 :     6359352 :             (decl, b, /*hiding=*/(how == TAG_how::HIDDEN_FRIEND));
    8352                 :     6359352 :           if (decl == error_mark_node)
    8353                 :             :             return decl;
    8354                 :             : 
    8355                 :     6359299 :           if (DECL_CONTEXT (decl) == std_node
    8356                 :     2129863 :               && init_list_identifier == DECL_NAME (TYPE_NAME (type))
    8357                 :     6359305 :               && !CLASSTYPE_TEMPLATE_INFO (type))
    8358                 :             :             {
    8359                 :           6 :               error ("declaration of %<std::initializer_list%> does not match "
    8360                 :             :                      "%<#include <initializer_list>%>, isn%'t a template");
    8361                 :           6 :               return error_mark_node;
    8362                 :             :             }
    8363                 :             :         }
    8364                 :             : 
    8365                 :    18554347 :       TYPE_CONTEXT (type) = DECL_CONTEXT (decl);
    8366                 :             : 
    8367                 :             :       /* If this is a local class, keep track of it.  We need this
    8368                 :             :          information for name-mangling, and so that it is possible to
    8369                 :             :          find all function definitions in a translation unit in a
    8370                 :             :          convenient way.  (It's otherwise tricky to find a member
    8371                 :             :          function definition it's only pointed to from within a local
    8372                 :             :          class.)  */
    8373                 :    18554347 :       if (TYPE_FUNCTION_SCOPE_P (type))
    8374                 :             :         {
    8375                 :     1410931 :           if (processing_template_decl)
    8376                 :             :             {
    8377                 :             :               /* Push a DECL_EXPR so we call pushtag at the right time in
    8378                 :             :                  template instantiation rather than in some nested context.  */
    8379                 :      623151 :               add_decl_expr (decl);
    8380                 :             :             }
    8381                 :             :           /* Lambdas use LAMBDA_EXPR_DISCRIMINATOR instead.  */
    8382                 :     1572090 :           else if (!LAMBDA_TYPE_P (type))
    8383                 :      548150 :             determine_local_discriminator (TYPE_NAME (type));
    8384                 :             :         }
    8385                 :             :     }
    8386                 :             : 
    8387                 :    18554347 :   if (b->kind == sk_class
    8388                 :    18554347 :       && !COMPLETE_TYPE_P (current_class_type))
    8389                 :     2518391 :     maybe_add_class_template_decl_list (current_class_type,
    8390                 :             :                                         type, /*friend_p=*/0);
    8391                 :             : 
    8392                 :    18554347 :   decl = TYPE_NAME (type);
    8393                 :    18554347 :   gcc_assert (TREE_CODE (decl) == TYPE_DECL);
    8394                 :             : 
    8395                 :             :   /* Set type visibility now if this is a forward declaration.  */
    8396                 :    18554347 :   TREE_PUBLIC (decl) = 1;
    8397                 :    18554347 :   determine_visibility (decl);
    8398                 :             : 
    8399                 :    18554347 :   return type;
    8400                 :    18554433 : }
    8401                 :             : 
    8402                 :             : /* Subroutines for reverting temporarily to top-level for instantiation
    8403                 :             :    of templates and such.  We actually need to clear out the class- and
    8404                 :             :    local-value slots of all identifiers, so that only the global values
    8405                 :             :    are at all visible.  Simply setting current_binding_level to the global
    8406                 :             :    scope isn't enough, because more binding levels may be pushed.  */
    8407                 :             : struct saved_scope *scope_chain;
    8408                 :             : 
    8409                 :             : /* Return true if ID has not already been marked.  */
    8410                 :             : 
    8411                 :             : static inline bool
    8412                 : >15660*10^7 : store_binding_p (tree id)
    8413                 :             : {
    8414                 : >31320*10^7 :   if (!id || !IDENTIFIER_BINDING (id))
    8415                 :             :     return false;
    8416                 :             : 
    8417                 :  1989214756 :   if (IDENTIFIER_MARKED (id))
    8418                 :           0 :     return false;
    8419                 :             : 
    8420                 :             :   return true;
    8421                 :             : }
    8422                 :             : 
    8423                 :             : /* Add an appropriate binding to *OLD_BINDINGS which needs to already
    8424                 :             :    have enough space reserved.  */
    8425                 :             : 
    8426                 :             : static void
    8427                 :   834743450 : store_binding (tree id, vec<cxx_saved_binding, va_gc> **old_bindings)
    8428                 :             : {
    8429                 :   834743450 :   cxx_saved_binding saved;
    8430                 :             : 
    8431                 :   834743450 :   gcc_checking_assert (store_binding_p (id));
    8432                 :             : 
    8433                 :   834743450 :   IDENTIFIER_MARKED (id) = 1;
    8434                 :             : 
    8435                 :   834743450 :   saved.identifier = id;
    8436                 :   834743450 :   saved.binding = IDENTIFIER_BINDING (id);
    8437                 :   834743450 :   saved.real_type_value = REAL_IDENTIFIER_TYPE_VALUE (id);
    8438                 :   834743450 :   (*old_bindings)->quick_push (saved);
    8439                 :   834743450 :   IDENTIFIER_BINDING (id) = NULL;
    8440                 :   834743450 : }
    8441                 :             : 
    8442                 :             : static void
    8443                 :   468427840 : store_bindings (tree names, vec<cxx_saved_binding, va_gc> **old_bindings)
    8444                 :             : {
    8445                 :   468427840 :   static vec<tree> bindings_need_stored;
    8446                 :   468427840 :   tree t, id;
    8447                 :   468427840 :   size_t i;
    8448                 :             : 
    8449                 :   468427840 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    8450                 : >15569*10^7 :   for (t = names; t; t = TREE_CHAIN (t))
    8451                 :             :     {
    8452                 : >15476*10^7 :       if (TREE_CODE (t) == TREE_LIST)
    8453                 :     6195359 :         id = TREE_PURPOSE (t);
    8454                 :             :       else
    8455                 : >15475*10^7 :         id = DECL_NAME (t);
    8456                 :             : 
    8457                 : >15476*10^7 :       if (store_binding_p (id))
    8458                 :   319727856 :         bindings_need_stored.safe_push (id);
    8459                 :             :     }
    8460                 :   468427840 :   if (!bindings_need_stored.is_empty ())
    8461                 :             :     {
    8462                 :   124139265 :       vec_safe_reserve_exact (*old_bindings, bindings_need_stored.length ());
    8463                 :   568006386 :       for (i = 0; bindings_need_stored.iterate (i, &id); ++i)
    8464                 :             :         {
    8465                 :             :           /* We can apparently have duplicates in NAMES.  */
    8466                 :   319727856 :           if (store_binding_p (id))
    8467                 :   319727778 :             store_binding (id, old_bindings);
    8468                 :             :         }
    8469                 :   124139265 :       bindings_need_stored.truncate (0);
    8470                 :             :     }
    8471                 :   468427840 : }
    8472                 :             : 
    8473                 :             : /* Like store_bindings, but NAMES is a vector of cp_class_binding
    8474                 :             :    objects, rather than a TREE_LIST.  */
    8475                 :             : 
    8476                 :             : static void
    8477                 :   232634124 : store_class_bindings (vec<cp_class_binding, va_gc> *names,
    8478                 :             :                       vec<cxx_saved_binding, va_gc> **old_bindings)
    8479                 :             : {
    8480                 :   232634124 :   static vec<tree> bindings_need_stored;
    8481                 :   232634124 :   size_t i;
    8482                 :   232634124 :   cp_class_binding *cb;
    8483                 :             : 
    8484                 :   918604599 :   for (i = 0; vec_safe_iterate (names, i, &cb); ++i)
    8485                 :   685970475 :     if (store_binding_p (cb->identifier))
    8486                 :   515015672 :       bindings_need_stored.safe_push (cb->identifier);
    8487                 :   232634124 :   if (!bindings_need_stored.is_empty ())
    8488                 :             :     {
    8489                 :    55466279 :       tree id;
    8490                 :    55466279 :       vec_safe_reserve_exact (*old_bindings, bindings_need_stored.length ());
    8491                 :   625948230 :       for (i = 0; bindings_need_stored.iterate (i, &id); ++i)
    8492                 :   515015672 :         store_binding (id, old_bindings);
    8493                 :    55466279 :       bindings_need_stored.truncate (0);
    8494                 :             :     }
    8495                 :   232634124 : }
    8496                 :             : 
    8497                 :             : /* A chain of saved_scope structures awaiting reuse.  */
    8498                 :             : 
    8499                 :             : static GTY((deletable)) struct saved_scope *free_saved_scope;
    8500                 :             : 
    8501                 :             : void
    8502                 :   306995104 : push_to_top_level (void)
    8503                 :             : {
    8504                 :   306995104 :   struct saved_scope *s;
    8505                 :   306995104 :   cp_binding_level *b;
    8506                 :   306995104 :   cxx_saved_binding *sb;
    8507                 :   306995104 :   size_t i;
    8508                 :   306995104 :   bool need_pop;
    8509                 :             : 
    8510                 :   306995104 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    8511                 :             : 
    8512                 :             :   /* Reuse or create a new structure for this saved scope.  */
    8513                 :   306995104 :   if (free_saved_scope != NULL)
    8514                 :             :     {
    8515                 :   305877941 :       s = free_saved_scope;
    8516                 :   305877941 :       free_saved_scope = s->prev;
    8517                 :             : 
    8518                 :   305877941 :       vec<cxx_saved_binding, va_gc> *old_bindings = s->old_bindings;
    8519                 :   305877941 :       memset (s, 0, sizeof (*s));
    8520                 :             :       /* Also reuse the structure's old_bindings vector.  */
    8521                 :   305877941 :       vec_safe_truncate (old_bindings, 0);
    8522                 :   305877941 :       s->old_bindings = old_bindings;
    8523                 :             :     }
    8524                 :             :   else
    8525                 :     1117163 :     s = ggc_cleared_alloc<saved_scope> ();
    8526                 :             : 
    8527                 :   306995104 :   b = scope_chain ? current_binding_level : 0;
    8528                 :             : 
    8529                 :             :   /* If we're in the middle of some function, save our state.  */
    8530                 :   306995104 :   if (cfun)
    8531                 :             :     {
    8532                 :    58837572 :       need_pop = true;
    8533                 :    58837572 :       push_function_context ();
    8534                 :             :     }
    8535                 :             :   else
    8536                 :             :     need_pop = false;
    8537                 :             : 
    8538                 :   306995104 :   if (scope_chain && previous_class_level)
    8539                 :    86889170 :     store_class_bindings (previous_class_level->class_shadowed,
    8540                 :             :                           &s->old_bindings);
    8541                 :             : 
    8542                 :             :   /* Have to include the global scope, because class-scope decls
    8543                 :             :      aren't listed anywhere useful.  */
    8544                 :   775422944 :   for (; b; b = b->level_chain)
    8545                 :             :     {
    8546                 :   775322321 :       tree t;
    8547                 :             : 
    8548                 :             :       /* Template IDs are inserted into the global level. If they were
    8549                 :             :          inserted into namespace level, finish_file wouldn't find them
    8550                 :             :          when doing pending instantiations. Therefore, don't stop at
    8551                 :             :          namespace level, but continue until :: .  */
    8552                 :   775322321 :       if (global_scope_p (b))
    8553                 :             :         break;
    8554                 :             : 
    8555                 :   468427840 :       store_bindings (b->names, &s->old_bindings);
    8556                 :             :       /* We also need to check class_shadowed to save class-level type
    8557                 :             :          bindings, since pushclass doesn't fill in b->names.  */
    8558                 :   468427840 :       if (b->kind == sk_class)
    8559                 :   145744954 :         store_class_bindings (b->class_shadowed, &s->old_bindings);
    8560                 :             : 
    8561                 :             :       /* Unwind type-value slots back to top level.  */
    8562                 :   794275593 :       for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
    8563                 :   325847753 :         SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
    8564                 :             :     }
    8565                 :             : 
    8566                 :  1141738554 :   FOR_EACH_VEC_SAFE_ELT (s->old_bindings, i, sb)
    8567                 :   834743450 :     IDENTIFIER_MARKED (sb->identifier) = 0;
    8568                 :             : 
    8569                 :   306995104 :   s->prev = scope_chain;
    8570                 :   306995104 :   s->bindings = b;
    8571                 :   306995104 :   s->need_pop_function_context = need_pop;
    8572                 :   306995104 :   s->function_decl = current_function_decl;
    8573                 :   306995104 :   s->unevaluated_operand = cp_unevaluated_operand;
    8574                 :   306995104 :   s->inhibit_evaluation_warnings = c_inhibit_evaluation_warnings;
    8575                 :   306995104 :   s->suppress_location_wrappers = suppress_location_wrappers;
    8576                 :   306995104 :   s->x_stmt_tree.stmts_are_full_exprs_p = true;
    8577                 :             : 
    8578                 :   306995104 :   scope_chain = s;
    8579                 :   306995104 :   current_function_decl = NULL_TREE;
    8580                 :   306995104 :   current_lang_base = NULL;
    8581                 :   306995104 :   current_lang_name = lang_name_cplusplus;
    8582                 :   306995104 :   current_namespace = global_namespace;
    8583                 :   306995104 :   push_class_stack ();
    8584                 :   306995104 :   cp_unevaluated_operand = 0;
    8585                 :   306995104 :   c_inhibit_evaluation_warnings = 0;
    8586                 :   306995104 :   suppress_location_wrappers = 0;
    8587                 :   306995104 : }
    8588                 :             : 
    8589                 :             : void
    8590                 :   306866474 : pop_from_top_level (void)
    8591                 :             : {
    8592                 :   306866474 :   struct saved_scope *s = scope_chain;
    8593                 :   306866474 :   cxx_saved_binding *saved;
    8594                 :   306866474 :   size_t i;
    8595                 :             : 
    8596                 :   306866474 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    8597                 :             : 
    8598                 :   306866474 :   pop_class_stack ();
    8599                 :             : 
    8600                 :   306866474 :   release_tree_vector (current_lang_base);
    8601                 :             : 
    8602                 :   306866474 :   scope_chain = s->prev;
    8603                 :  1141606179 :   FOR_EACH_VEC_SAFE_ELT (s->old_bindings, i, saved)
    8604                 :             :     {
    8605                 :   834739705 :       tree id = saved->identifier;
    8606                 :             : 
    8607                 :   834739705 :       IDENTIFIER_BINDING (id) = saved->binding;
    8608                 :   834739705 :       SET_IDENTIFIER_TYPE_VALUE (id, saved->real_type_value);
    8609                 :             :     }
    8610                 :             : 
    8611                 :             :   /* If we were in the middle of compiling a function, restore our
    8612                 :             :      state.  */
    8613                 :   306866474 :   if (s->need_pop_function_context)
    8614                 :    58837552 :     pop_function_context ();
    8615                 :   306866474 :   current_function_decl = s->function_decl;
    8616                 :   306866474 :   cp_unevaluated_operand = s->unevaluated_operand;
    8617                 :   306866474 :   c_inhibit_evaluation_warnings = s->inhibit_evaluation_warnings;
    8618                 :   306866474 :   suppress_location_wrappers = s->suppress_location_wrappers;
    8619                 :             : 
    8620                 :             :   /* Make this saved_scope structure available for reuse by
    8621                 :             :      push_to_top_level.  */
    8622                 :   306866474 :   s->prev = free_saved_scope;
    8623                 :   306866474 :   free_saved_scope = s;
    8624                 :   306866474 : }
    8625                 :             : 
    8626                 :             : namespace {
    8627                 :             : 
    8628                 :             : /* Helper class for saving/restoring relevant global flags for the
    8629                 :             :    function-local case of maybe_push_to_top_level.  */
    8630                 :             : 
    8631                 :             : struct local_state_t
    8632                 :             : {
    8633                 :             :   int cp_unevaluated_operand;
    8634                 :             :   int c_inhibit_evaluation_warnings;
    8635                 :             : 
    8636                 :             :   static local_state_t
    8637                 :     1809471 :   save_and_clear ()
    8638                 :             :   {
    8639                 :     1809471 :     local_state_t s;
    8640                 :     1809471 :     s.cp_unevaluated_operand = ::cp_unevaluated_operand;
    8641                 :     1809471 :     ::cp_unevaluated_operand = 0;
    8642                 :     1809471 :     s.c_inhibit_evaluation_warnings = ::c_inhibit_evaluation_warnings;
    8643                 :     1809471 :     ::c_inhibit_evaluation_warnings = 0;
    8644                 :     1809471 :     return s;
    8645                 :             :   }
    8646                 :             : 
    8647                 :             :   void
    8648                 :     1809471 :   restore () const
    8649                 :             :   {
    8650                 :     1809471 :     ::cp_unevaluated_operand = this->cp_unevaluated_operand;
    8651                 :     1809471 :     ::c_inhibit_evaluation_warnings = this->c_inhibit_evaluation_warnings;
    8652                 :             :   }
    8653                 :             : };
    8654                 :             : 
    8655                 :             : vec<local_state_t> local_state_stack;
    8656                 :             : 
    8657                 :             : } // anon namespace
    8658                 :             : 
    8659                 :             : /* Like push_to_top_level, but not if D is function-local.  Returns whether we
    8660                 :             :    did push to top.  */
    8661                 :             : 
    8662                 :             : bool
    8663                 :    46539320 : maybe_push_to_top_level (tree d)
    8664                 :             : {
    8665                 :             :   /* Push if D isn't function-local, or is a lambda function, for which name
    8666                 :             :      resolution is already done.  */
    8667                 :    46539320 :   const bool push_to_top
    8668                 :    47021386 :     = (LAMBDA_FUNCTION_P (d)
    8669                 :    46420888 :        || (TREE_CODE (d) == TYPE_DECL
    8670                 :    24332029 :            && TREE_TYPE (d)
    8671                 :    48166512 :            && LAMBDA_TYPE_P (TREE_TYPE (d)))
    8672                 :    45929826 :        || !current_function_decl
    8673                 :    59675441 :        || !decl_function_context (d));
    8674                 :             : 
    8675                 :    46539320 :   if (push_to_top)
    8676                 :    44729849 :     push_to_top_level ();
    8677                 :             :   else
    8678                 :             :     {
    8679                 :     1809471 :       gcc_assert (!processing_template_decl);
    8680                 :     1809471 :       push_function_context ();
    8681                 :     1809471 :       local_state_stack.safe_push (local_state_t::save_and_clear ());
    8682                 :             :     }
    8683                 :             : 
    8684                 :    46539320 :   return push_to_top;
    8685                 :             : }
    8686                 :             : 
    8687                 :             : /* Return from whatever maybe_push_to_top_level did.  */
    8688                 :             : 
    8689                 :             : void
    8690                 :    46539309 : maybe_pop_from_top_level (bool push_to_top)
    8691                 :             : {
    8692                 :    46539309 :   if (push_to_top)
    8693                 :    44729838 :     pop_from_top_level ();
    8694                 :             :   else
    8695                 :             :     {
    8696                 :     1809471 :       local_state_stack.pop ().restore ();
    8697                 :     1809471 :       pop_function_context ();
    8698                 :             :     }
    8699                 :    46539309 : }
    8700                 :             : 
    8701                 :             : /* Push into the scope of the namespace NS, even if it is deeply
    8702                 :             :    nested within another namespace.  */
    8703                 :             : 
    8704                 :             : void
    8705                 :    81792520 : push_nested_namespace (tree ns)
    8706                 :             : {
    8707                 :    81792520 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    8708                 :    81792520 :   if (ns == global_namespace)
    8709                 :    40736366 :     push_to_top_level ();
    8710                 :             :   else
    8711                 :             :     {
    8712                 :    81092081 :       push_nested_namespace (CP_DECL_CONTEXT (ns));
    8713                 :    41056154 :       resume_scope (NAMESPACE_LEVEL (ns));
    8714                 :    41056154 :       current_namespace = ns;
    8715                 :             :     }
    8716                 :    81792520 : }
    8717                 :             : 
    8718                 :             : /* Pop back from the scope of the namespace NS, which was previously
    8719                 :             :    entered with push_nested_namespace.  */
    8720                 :             : 
    8721                 :             : void
    8722                 :    40721974 : pop_nested_namespace (tree ns)
    8723                 :             : {
    8724                 :    40721974 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    8725                 :   122500102 :   while (ns != global_namespace)
    8726                 :             :     {
    8727                 :    41056154 :       ns = CP_DECL_CONTEXT (ns);
    8728                 :    41056154 :       current_namespace = ns;
    8729                 :    41056154 :       leave_scope ();
    8730                 :             :     }
    8731                 :             : 
    8732                 :    40721974 :   pop_from_top_level ();
    8733                 :    40721974 : }
    8734                 :             : 
    8735                 :             : /* Add TARGET to USINGS, if it does not already exist there.  We used
    8736                 :             :    to build the complete graph of usings at this point, from the POV
    8737                 :             :    of the source namespaces.  Now we build that as we perform the
    8738                 :             :    unqualified search.  */
    8739                 :             : 
    8740                 :             : static void
    8741                 :      119074 : add_using_namespace (vec<tree, va_gc> *&usings, tree target)
    8742                 :             : {
    8743                 :      119074 :   if (usings)
    8744                 :        1372 :     for (unsigned ix = usings->length (); ix--;)
    8745                 :         918 :       if ((*usings)[ix] == target)
    8746                 :             :         return;
    8747                 :             : 
    8748                 :      118627 :   vec_safe_push (usings, target);
    8749                 :             : }
    8750                 :             : 
    8751                 :             : /* Tell the debug system of a using directive.  */
    8752                 :             : 
    8753                 :             : static void
    8754                 :      172026 : emit_debug_info_using_namespace (tree from, tree target, bool implicit)
    8755                 :             : {
    8756                 :             :   /* Emit debugging info.  */
    8757                 :      172026 :   tree context = from != global_namespace ? from : NULL_TREE;
    8758                 :      172026 :   debug_hooks->imported_module_or_decl (target, NULL_TREE, context, false,
    8759                 :             :                                         implicit);
    8760                 :      172026 : }
    8761                 :             : 
    8762                 :             : /* Process a using directive.  */
    8763                 :             : 
    8764                 :             : void
    8765                 :      117775 : finish_using_directive (tree target, tree attribs)
    8766                 :             : {
    8767                 :      117775 :   if (target == error_mark_node)
    8768                 :             :     return;
    8769                 :             : 
    8770                 :      117754 :   if (current_binding_level->kind != sk_namespace)
    8771                 :       87443 :     add_stmt (build_stmt (input_location, USING_STMT, target));
    8772                 :             :   else
    8773                 :       60622 :     emit_debug_info_using_namespace (current_binding_level->this_entity,
    8774                 :       30311 :                                      ORIGINAL_NAMESPACE (target), false);
    8775                 :             : 
    8776                 :      235508 :   add_using_namespace (current_binding_level->using_directives,
    8777                 :      117754 :                        ORIGINAL_NAMESPACE (target));
    8778                 :             : 
    8779                 :      117754 :   bool diagnosed = false;
    8780                 :      117754 :   if (attribs != error_mark_node)
    8781                 :      117796 :     for (tree a = attribs; a; a = TREE_CHAIN (a))
    8782                 :             :       {
    8783                 :          42 :         tree name = get_attribute_name (a);
    8784                 :          42 :         if (current_binding_level->kind == sk_namespace
    8785                 :          42 :             && is_attribute_p ("strong", name))
    8786                 :             :           {
    8787                 :          12 :             if (warning (0, "%<strong%> using directive no longer supported")
    8788                 :          12 :                 && CP_DECL_CONTEXT (target) == current_namespace)
    8789                 :           6 :               inform (DECL_SOURCE_LOCATION (target),
    8790                 :             :                       "you can use an inline namespace instead");
    8791                 :             :           }
    8792                 :          27 :         else if ((flag_openmp || flag_openmp_simd)
    8793                 :           3 :                  && get_attribute_namespace (a) == omp_identifier
    8794                 :          33 :                  && (is_attribute_p ("directive", name)
    8795                 :           0 :                      || is_attribute_p ("sequence", name)
    8796                 :           0 :                      || is_attribute_p ("decl", name)))
    8797                 :             :           {
    8798                 :           3 :             if (!diagnosed)
    8799                 :             :               {
    8800                 :           3 :                 if (tree ar = TREE_VALUE (a))
    8801                 :             :                   {
    8802                 :           3 :                     tree d = TREE_VALUE (ar);
    8803                 :           3 :                     gcc_assert (TREE_CODE (d) == DEFERRED_PARSE);
    8804                 :           3 :                     error ("%<omp::%s%> not allowed to be specified in "
    8805                 :             :                            "this context",
    8806                 :           3 :                            TREE_PUBLIC (d) ? "decl" : "directive");
    8807                 :             :                   }
    8808                 :             :                 else
    8809                 :           0 :                   error ("%<omp::%E%> not allowed to be specified in this "
    8810                 :             :                          "context", name);
    8811                 :             :                 diagnosed = true;
    8812                 :             :               }
    8813                 :             :           }
    8814                 :          27 :         else if (!attribute_ignored_p (a))
    8815                 :          12 :           warning (OPT_Wattributes, "%qD attribute directive ignored", name);
    8816                 :             :       }
    8817                 :             : }
    8818                 :             : 
    8819                 :             : /* Pushes X into the global namespace.  */
    8820                 :             : 
    8821                 :             : tree
    8822                 :      375753 : pushdecl_top_level (tree x)
    8823                 :             : {
    8824                 :      375753 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    8825                 :      375753 :   push_to_top_level ();
    8826                 :      375753 :   gcc_checking_assert (!DECL_CONTEXT (x));
    8827                 :      375753 :   DECL_CONTEXT (x) = FROB_CONTEXT (global_namespace);
    8828                 :      375753 :   x = pushdecl_namespace_level (x);
    8829                 :      375753 :   pop_from_top_level ();
    8830                 :      751506 :   return x;
    8831                 :      375753 : }
    8832                 :             : 
    8833                 :             : /* Pushes X into the global namespace and calls cp_finish_decl to
    8834                 :             :    register the variable, initializing it with INIT.  */
    8835                 :             : 
    8836                 :             : tree
    8837                 :     2077541 : pushdecl_top_level_and_finish (tree x, tree init)
    8838                 :             : {
    8839                 :     2077541 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    8840                 :     2077541 :   push_to_top_level ();
    8841                 :     2077541 :   gcc_checking_assert (!DECL_CONTEXT (x));
    8842                 :     2077541 :   DECL_CONTEXT (x) = FROB_CONTEXT (global_namespace);
    8843                 :     2077541 :   x = pushdecl_namespace_level (x);
    8844                 :     2077541 :   cp_finish_decl (x, init, false, NULL_TREE, 0);
    8845                 :     2077541 :   pop_from_top_level ();
    8846                 :     4155082 :   return x;
    8847                 :     2077541 : }
    8848                 :             : 
    8849                 :             : /* Enter the namespaces from current_namerspace to NS.  */
    8850                 :             : 
    8851                 :             : static int
    8852                 :     4591342 : push_inline_namespaces (tree ns)
    8853                 :             : {
    8854                 :     4591342 :   int count = 0;
    8855                 :     4591342 :   if (ns != current_namespace)
    8856                 :             :     {
    8857                 :          16 :       gcc_assert (ns != global_namespace);
    8858                 :          25 :       count += push_inline_namespaces (CP_DECL_CONTEXT (ns));
    8859                 :          16 :       resume_scope (NAMESPACE_LEVEL (ns));
    8860                 :          16 :       current_namespace = ns;
    8861                 :          16 :       count++;
    8862                 :             :     }
    8863                 :     4591342 :   return count;
    8864                 :             : }
    8865                 :             : 
    8866                 :             : /* SLOT is the (possibly empty) binding slot for NAME in CTX.
    8867                 :             :    Reuse or create a namespace NAME.  NAME is null for the anonymous
    8868                 :             :    namespace.  */
    8869                 :             : 
    8870                 :             : static tree
    8871                 :        3009 : reuse_namespace (tree *slot, tree ctx, tree name)
    8872                 :             : {
    8873                 :        3009 :   if (modules_p () && *slot && TREE_PUBLIC (ctx) && name)
    8874                 :             :     {
    8875                 :             :       /* Public namespace.  Shared.  */
    8876                 :        1499 :       tree *global_slot = slot;
    8877                 :        1499 :       if (TREE_CODE (*slot) == BINDING_VECTOR)
    8878                 :         108 :         global_slot = get_fixed_binding_slot (slot, name,
    8879                 :             :                                               BINDING_SLOT_GLOBAL, false);
    8880                 :             : 
    8881                 :        1502 :       for (ovl_iterator iter (*global_slot); iter; ++iter)
    8882                 :             :         {
    8883                 :        1499 :           tree decl = *iter;
    8884                 :             : 
    8885                 :        1499 :           if (TREE_CODE (decl) == NAMESPACE_DECL && !DECL_NAMESPACE_ALIAS (decl))
    8886                 :        1496 :             return decl;
    8887                 :             :         }
    8888                 :             :     }
    8889                 :             :   return NULL_TREE;
    8890                 :             : }
    8891                 :             : 
    8892                 :             : static tree
    8893                 :      692463 : make_namespace (tree ctx, tree name, location_t loc, bool inline_p)
    8894                 :             : {
    8895                 :             :   /* Create the namespace.  */
    8896                 :      692463 :   tree ns = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
    8897                 :      692463 :   DECL_SOURCE_LOCATION (ns) = loc;
    8898                 :      692463 :   SCOPE_DEPTH (ns) = SCOPE_DEPTH (ctx) + 1;
    8899                 :      692463 :   if (!SCOPE_DEPTH (ns))
    8900                 :             :     /* We only allow depth 255. */
    8901                 :           0 :     sorry ("cannot nest more than %d namespaces", SCOPE_DEPTH (ctx));
    8902                 :      692463 :   DECL_CONTEXT (ns) = FROB_CONTEXT (ctx);
    8903                 :             : 
    8904                 :      692463 :   if (!name)
    8905                 :             :     /* Anon-namespaces in different header-unit imports are distinct.
    8906                 :             :        But that's ok as their contents all have internal linkage.
    8907                 :             :        (This is different to how they'd behave as textual includes,
    8908                 :             :        but doing this at all is really odd source.)  */
    8909                 :        1333 :     SET_DECL_ASSEMBLER_NAME (ns, anon_identifier);
    8910                 :      691130 :   else if (TREE_PUBLIC (ctx))
    8911                 :      691084 :     TREE_PUBLIC (ns) = true;
    8912                 :             : 
    8913                 :      692463 :   if (inline_p)
    8914                 :      140395 :     DECL_NAMESPACE_INLINE_P (ns) = true;
    8915                 :             : 
    8916                 :      692463 :   return ns;
    8917                 :             : }
    8918                 :             : 
    8919                 :             : /* NS was newly created, finish off making it.  */
    8920                 :             : 
    8921                 :             : static void
    8922                 :      692456 : make_namespace_finish (tree ns, tree *slot, bool from_import = false)
    8923                 :             : {
    8924                 :      692456 :   if (modules_p () && TREE_PUBLIC (ns) && (from_import || *slot != ns))
    8925                 :             :     {
    8926                 :             :       /* Merge into global slot.  */
    8927                 :        1502 :       tree *gslot = get_fixed_binding_slot (slot, DECL_NAME (ns),
    8928                 :             :                                             BINDING_SLOT_GLOBAL, true);
    8929                 :        1502 :       *gslot = ns;
    8930                 :             :     }
    8931                 :             : 
    8932                 :      692456 :   tree ctx = CP_DECL_CONTEXT (ns);
    8933                 :      692456 :   cp_binding_level *scope = ggc_cleared_alloc<cp_binding_level> ();
    8934                 :      692456 :   scope->this_entity = ns;
    8935                 :      692456 :   scope->more_cleanups_ok = true;
    8936                 :      692456 :   scope->kind = sk_namespace;
    8937                 :      692456 :   scope->level_chain = NAMESPACE_LEVEL (ctx);
    8938                 :      692456 :   NAMESPACE_LEVEL (ns) = scope;
    8939                 :             : 
    8940                 :      692456 :   if (DECL_NAMESPACE_INLINE_P (ns))
    8941                 :      140395 :     vec_safe_push (DECL_NAMESPACE_INLINEES (ctx), ns);
    8942                 :             : 
    8943                 :      692456 :   if (DECL_NAMESPACE_INLINE_P (ns) || !DECL_NAME (ns))
    8944                 :      141715 :     emit_debug_info_using_namespace (ctx, ns, true);
    8945                 :      692456 : }
    8946                 :             : 
    8947                 :             : /* Push into the scope of the NAME namespace.  If NAME is NULL_TREE,
    8948                 :             :    then we enter an anonymous namespace.  If MAKE_INLINE is true, then
    8949                 :             :    we create an inline namespace (it is up to the caller to check upon
    8950                 :             :    redefinition). Return the number of namespaces entered.  */
    8951                 :             : 
    8952                 :             : int
    8953                 :     5282305 : push_namespace (tree name, bool make_inline)
    8954                 :             : {
    8955                 :     5282305 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    8956                 :     5282305 :   int count = 0;
    8957                 :             : 
    8958                 :             :   /* We should not get here if the global_namespace is not yet constructed
    8959                 :             :      nor if NAME designates the global namespace:  The global scope is
    8960                 :             :      constructed elsewhere.  */
    8961                 :     5282305 :   gcc_checking_assert (global_namespace != NULL && name != global_identifier);
    8962                 :             : 
    8963                 :     5282305 :   tree ns = NULL_TREE;
    8964                 :     5282305 :   {
    8965                 :     5282305 :     name_lookup lookup (name);
    8966                 :     5282305 :     if (!lookup.search_qualified (current_namespace, /*usings=*/false))
    8967                 :             :       ;
    8968                 :     4591346 :     else if (TREE_CODE (lookup.value) == TREE_LIST)
    8969                 :             :       {
    8970                 :             :         /* An ambiguous lookup.  If exactly one is a namespace, we
    8971                 :             :            want that.  If more than one is a namespace, error, but
    8972                 :             :            pick one of them.  */
    8973                 :             :         /* DR2061 can cause us to find multiple namespaces of the same
    8974                 :             :            name.  We must treat that carefully and avoid thinking we
    8975                 :             :            need to push a new (possibly) duplicate namespace.  Hey,
    8976                 :             :            if you want to use the same identifier within an inline
    8977                 :             :            nest, knock yourself out.  */
    8978                 :           9 :         for (tree *chain = &lookup.value, next; (next = *chain);)
    8979                 :             :           {
    8980                 :           6 :             tree decl = TREE_VALUE (next);
    8981                 :           6 :             if (TREE_CODE (decl) == NAMESPACE_DECL)
    8982                 :             :               {
    8983                 :           6 :                 if (!ns)
    8984                 :             :                   ns = decl;
    8985                 :           3 :                 else if (SCOPE_DEPTH (ns) >= SCOPE_DEPTH (decl))
    8986                 :           6 :                   ns = decl;
    8987                 :             : 
    8988                 :             :                 /* Advance.  */
    8989                 :           6 :                 chain = &TREE_CHAIN (next);
    8990                 :             :               }
    8991                 :             :             else
    8992                 :             :               /* Stitch out.  */
    8993                 :           0 :               *chain = TREE_CHAIN (next);
    8994                 :             :           }
    8995                 :             : 
    8996                 :           3 :         if (TREE_CHAIN (lookup.value))
    8997                 :             :           {
    8998                 :           3 :             error ("%<namespace %E%> is ambiguous", name);
    8999                 :           3 :             print_candidates (lookup.value);
    9000                 :             :           }
    9001                 :             :       }
    9002                 :     4591343 :     else if (TREE_CODE (lookup.value) == NAMESPACE_DECL)
    9003                 :             :       ns = lookup.value;
    9004                 :             : 
    9005                 :     4591330 :     if (ns)
    9006                 :     4591330 :       if (tree dna = DECL_NAMESPACE_ALIAS (ns))
    9007                 :             :         {
    9008                 :             :           /* A namespace alias is not allowed here, but if the alias
    9009                 :             :              is for a namespace also inside the current scope,
    9010                 :             :              accept it with a diagnostic.  That's better than dying
    9011                 :             :              horribly.  */
    9012                 :          12 :           if (is_nested_namespace (current_namespace, CP_DECL_CONTEXT (dna)))
    9013                 :             :             {
    9014                 :           8 :               error ("namespace alias %qD not allowed here, "
    9015                 :             :                      "assuming %qD", ns, dna);
    9016                 :           8 :               ns = dna;
    9017                 :             :             }
    9018                 :             :           else
    9019                 :             :             ns = NULL_TREE;
    9020                 :             :         }
    9021                 :     5282305 :   }
    9022                 :             : 
    9023                 :     5282305 :   if (ns)
    9024                 :             :     {
    9025                 :             :       /* DR2061.  NS might be a member of an inline namespace.  We
    9026                 :             :          need to push into those namespaces.  */
    9027                 :     4591326 :       if (modules_p ())
    9028                 :             :         {
    9029                 :       53538 :           for (tree parent, ctx = ns; ctx != current_namespace;
    9030                 :             :                ctx = parent)
    9031                 :             :             {
    9032                 :       26769 :               parent = CP_DECL_CONTEXT (ctx);
    9033                 :             : 
    9034                 :       26769 :               tree bind = *find_namespace_slot (parent, DECL_NAME (ctx), false);
    9035                 :       26769 :               if (bind != ctx)
    9036                 :             :                 {
    9037                 :         252 :                   auto &cluster = BINDING_VECTOR_CLUSTER (bind, 0);
    9038                 :         252 :                   binding_slot &slot = cluster.slots[BINDING_SLOT_CURRENT];
    9039                 :         252 :                   gcc_checking_assert (!(tree)slot || (tree)slot == ctx);
    9040                 :         252 :                   slot = ctx;
    9041                 :             :                 }
    9042                 :             :             }
    9043                 :             :         }
    9044                 :             : 
    9045                 :     4591326 :       count += push_inline_namespaces (CP_DECL_CONTEXT (ns));
    9046                 :     4591326 :       if (DECL_SOURCE_LOCATION (ns) == BUILTINS_LOCATION)
    9047                 :             :         /* It's not builtin now.  */
    9048                 :       32298 :         DECL_SOURCE_LOCATION (ns) = input_location;
    9049                 :             :     }
    9050                 :             :   else
    9051                 :             :     {
    9052                 :             :       /* Before making a new namespace, see if we already have one in
    9053                 :             :          the existing partitions of the current namespace.  */
    9054                 :      690979 :       tree *slot = find_namespace_slot (current_namespace, name, false);
    9055                 :      690979 :       if (slot)
    9056                 :          29 :         ns = reuse_namespace (slot, current_namespace, name);
    9057                 :      690979 :       if (!ns)
    9058                 :      690970 :         ns = make_namespace (current_namespace, name,
    9059                 :             :                              input_location, make_inline);
    9060                 :             : 
    9061                 :      690979 :       if (pushdecl (ns) == error_mark_node)
    9062                 :             :         ns = NULL_TREE;
    9063                 :             :       else
    9064                 :             :         {
    9065                 :             :           /* Finish up making the namespace.  */
    9066                 :      690963 :           add_decl_to_level (NAMESPACE_LEVEL (current_namespace), ns);
    9067                 :      690963 :           if (!slot)
    9068                 :             :             {
    9069                 :      690950 :               slot = find_namespace_slot (current_namespace, name);
    9070                 :             :               /* This should find the slot created by pushdecl.  */
    9071                 :      690950 :               gcc_checking_assert (slot && *slot == ns);
    9072                 :             :             }
    9073                 :             :           else
    9074                 :             :             {
    9075                 :             :               /* pushdecl could have expanded the hash table, so
    9076                 :             :                  slot might be invalid.  */
    9077                 :          13 :               slot = find_namespace_slot (current_namespace, name);
    9078                 :          13 :               gcc_checking_assert (slot);
    9079                 :             :             }
    9080                 :      690963 :           make_namespace_finish (ns, slot);
    9081                 :             : 
    9082                 :             :           /* Add the anon using-directive here, we don't do it in
    9083                 :             :              make_namespace_finish.  */
    9084                 :      690963 :           if (!DECL_NAMESPACE_INLINE_P (ns) && !name)
    9085                 :        1320 :             add_using_namespace (current_binding_level->using_directives, ns);
    9086                 :             :         }
    9087                 :             :     }
    9088                 :             : 
    9089                 :     5282289 :   if (ns)
    9090                 :             :     {
    9091                 :             :       /* A public namespace is exported only if explicitly marked, or
    9092                 :             :          it contains exported entities.  */
    9093                 :     5282289 :       if (TREE_PUBLIC (ns) && module_exporting_p ())
    9094                 :       14525 :         DECL_MODULE_EXPORT_P (ns) = true;
    9095                 :     5282289 :       if (module_purview_p ())
    9096                 :       14777 :         DECL_MODULE_PURVIEW_P (ns) = true;
    9097                 :             : 
    9098                 :     5496114 :       if (make_inline && !DECL_NAMESPACE_INLINE_P (ns))
    9099                 :             :         {
    9100                 :           3 :           error_at (input_location,
    9101                 :             :                     "inline namespace must be specified at initial definition");
    9102                 :           3 :           inform (DECL_SOURCE_LOCATION (ns), "%qD defined here", ns);
    9103                 :             :         }
    9104                 :     5282289 :       resume_scope (NAMESPACE_LEVEL (ns));
    9105                 :     5282289 :       current_namespace = ns;
    9106                 :     5282289 :       count++;
    9107                 :             :     }
    9108                 :             : 
    9109                 :    10564610 :   return count;
    9110                 :     5282305 : }
    9111                 :             : 
    9112                 :             : /* Pop from the scope of the current namespace.  */
    9113                 :             : 
    9114                 :             : void
    9115                 :     5309356 : pop_namespace (void)
    9116                 :             : {
    9117                 :     5309356 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    9118                 :             : 
    9119                 :     5309356 :   gcc_assert (current_namespace != global_namespace);
    9120                 :     5309356 :   current_namespace = CP_DECL_CONTEXT (current_namespace);
    9121                 :             :   /* The binding level is not popped, as it might be re-opened later.  */
    9122                 :     5309356 :   leave_scope ();
    9123                 :     5309356 : }
    9124                 :             : 
    9125                 :             : /* An IMPORT is an import that is defining namespace NAME inside CTX.  Find or
    9126                 :             :    create that namespace and add it to the container's binding-vector.   */
    9127                 :             : 
    9128                 :             : tree
    9129                 :        2980 : add_imported_namespace (tree ctx, tree name, location_t loc, unsigned import, 
    9130                 :             :                         bool inline_p, bool visible_p)
    9131                 :             : {
    9132                 :             :   // FIXME: Something is not correct about the VISIBLE_P handling.  We
    9133                 :             :   // need to insert this namespace into
    9134                 :             :   // (a) the GLOBAL or PARTITION slot, if it is TREE_PUBLIC
    9135                 :             :   // (b) The importing module's slot (always)
    9136                 :             :   // (c) Do we need to put it in the CURRENT slot?  This is the
    9137                 :             :   // confused piece.
    9138                 :             : 
    9139                 :        2980 :   tree *slot = find_namespace_slot (ctx, name, true);
    9140                 :        2980 :   tree decl = reuse_namespace (slot, ctx, name);
    9141                 :             : 
    9142                 :             :   /* Creating and binding.  */
    9143                 :        2980 :   if (!decl)
    9144                 :             :     {
    9145                 :        1493 :       decl = make_namespace (ctx, name, loc, inline_p);
    9146                 :        1493 :       make_namespace_finish (decl, slot, true);
    9147                 :             :     }
    9148                 :        1487 :   else if (DECL_NAMESPACE_INLINE_P (decl) != inline_p)
    9149                 :             :     {
    9150                 :           0 :       error_at (loc, "%s namespace %qD conflicts with reachable definition",
    9151                 :             :                 inline_p ? "inline" : "non-inline", decl);
    9152                 :           0 :       inform (DECL_SOURCE_LOCATION (decl), "reachable %s definition here",
    9153                 :             :               inline_p ? "non-inline" : "inline");
    9154                 :             :     }
    9155                 :             : 
    9156                 :        2980 :   if (TREE_PUBLIC (decl) && TREE_CODE (*slot) == BINDING_VECTOR)
    9157                 :             :     {
    9158                 :             :       /* See if we can extend the final slot.  */
    9159                 :        1592 :       binding_cluster *last = BINDING_VECTOR_CLUSTER_LAST (*slot);
    9160                 :        1592 :       gcc_checking_assert (last->indices[0].span);
    9161                 :             :       unsigned jx = BINDING_VECTOR_SLOTS_PER_CLUSTER;
    9162                 :             : 
    9163                 :        2100 :       while (--jx)
    9164                 :        1592 :         if (last->indices[jx].span)
    9165                 :             :           break;
    9166                 :        1592 :       tree final = last->slots[jx];
    9167                 :        1592 :       if (visible_p == !STAT_HACK_P (final)
    9168                 :        1289 :           && MAYBE_STAT_DECL (final) == decl
    9169                 :         958 :           && last->indices[jx].base + last->indices[jx].span == import
    9170                 :        2524 :           && (BINDING_VECTOR_NUM_CLUSTERS (*slot) > 1
    9171                 :             :               || (BINDING_VECTOR_SLOTS_PER_CLUSTER > BINDING_SLOTS_FIXED
    9172                 :             :                   && jx >= BINDING_SLOTS_FIXED)))
    9173                 :             :         {
    9174                 :          87 :           last->indices[jx].span++;
    9175                 :          87 :           return decl;
    9176                 :             :         }
    9177                 :             :     }
    9178                 :             : 
    9179                 :             :   /* Append a new slot.  */
    9180                 :        2893 :   tree *mslot = &(tree &)*append_imported_binding_slot (slot, name, import);
    9181                 :             : 
    9182                 :        2893 :   gcc_assert (!*mslot);
    9183                 :        2893 :   *mslot = visible_p ? decl : stat_hack (decl, NULL_TREE);
    9184                 :             : 
    9185                 :        2893 :   return decl;
    9186                 :             : }
    9187                 :             : 
    9188                 :             : /* Pop off extraneous binding levels left over due to syntax errors.
    9189                 :             :    We don't pop past namespaces, as they might be valid.  */
    9190                 :             : 
    9191                 :             : void
    9192                 :       99250 : pop_everything (void)
    9193                 :             : {
    9194                 :       99250 :   if (ENABLE_SCOPE_CHECKING)
    9195                 :             :     verbatim ("XXX entering %<pop_everything ()%>");
    9196                 :       99250 :   while (!namespace_bindings_p ())
    9197                 :             :     {
    9198                 :           0 :       if (current_binding_level->kind == sk_class)
    9199                 :           0 :         pop_nested_class ();
    9200                 :             :       else
    9201                 :           0 :         poplevel (0, 0, 0);
    9202                 :             :     }
    9203                 :       99250 :   if (ENABLE_SCOPE_CHECKING)
    9204                 :             :     verbatim ("XXX leaving %<pop_everything ()%>");
    9205                 :       99250 : }
    9206                 :             : 
    9207                 :             : /* Emit debugging information for using declarations and directives.
    9208                 :             :    If input tree is overloaded fn then emit debug info for all
    9209                 :             :    candidates.  */
    9210                 :             : 
    9211                 :             : void
    9212                 :     7655954 : cp_emit_debug_info_for_using (tree t, tree context)
    9213                 :             : {
    9214                 :             :   /* Don't try to emit any debug information if we have errors.  */
    9215                 :     7655954 :   if (seen_error ())
    9216                 :             :     return;
    9217                 :             : 
    9218                 :             :   /* Do not supply context to imported_module_or_decl, if
    9219                 :             :      it is a global namespace.  */
    9220                 :     7653095 :   if (context == global_namespace)
    9221                 :      174961 :     context = NULL_TREE;
    9222                 :             : 
    9223                 :     7653095 :   t = MAYBE_BASELINK_FUNCTIONS (t);
    9224                 :             : 
    9225                 :    16547522 :   for (lkp_iterator iter (t); iter; ++iter)
    9226                 :             :     {
    9227                 :     8894427 :       tree fn = *iter;
    9228                 :             : 
    9229                 :     8894427 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    9230                 :             :         /* FIXME: Handle TEMPLATE_DECLs.  */
    9231                 :      625831 :         continue;
    9232                 :             :       
    9233                 :             :       /* Ignore this FUNCTION_DECL if it refers to a builtin declaration
    9234                 :             :          of a builtin function.  */
    9235                 :    11133860 :       if (TREE_CODE (fn) == FUNCTION_DECL
    9236                 :     7139881 :           && DECL_EXTERNAL (fn)
    9237                 :    15406192 :           && fndecl_built_in_p (fn))
    9238                 :     2865264 :         continue;
    9239                 :             : 
    9240                 :     5403332 :       if (building_stmt_list_p ())
    9241                 :         771 :         add_stmt (build_stmt (input_location, USING_STMT, fn));
    9242                 :             :       else
    9243                 :     5402561 :         debug_hooks->imported_module_or_decl (fn, NULL_TREE, context,
    9244                 :             :                                               false, false);
    9245                 :             :     }
    9246                 :             : }
    9247                 :             : 
    9248                 :             : /* True if D is a local declaration in dependent scope.  Assumes that it is
    9249                 :             :    (part of) the current lookup result for its name.  */
    9250                 :             : 
    9251                 :             : bool
    9252                 :    50709406 : dependent_local_decl_p (tree d)
    9253                 :             : {
    9254                 :    50709406 :   if (!DECL_LOCAL_DECL_P (d))
    9255                 :             :     return false;
    9256                 :             : 
    9257                 :       11624 :   cxx_binding *b = IDENTIFIER_BINDING (DECL_NAME (d));
    9258                 :       11624 :   cp_binding_level *l = b->scope;
    9259                 :       34839 :   while (!l->this_entity)
    9260                 :       23215 :     l = l->level_chain;
    9261                 :       11624 :   return uses_template_parms (l->this_entity);
    9262                 :             : }
    9263                 :             : 
    9264                 :             : 
    9265                 :             : 
    9266                 :             : #include "gt-cp-name-lookup.h"
        

Generated by: LCOV version 2.1-beta

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