LCOV - code coverage report
Current view: top level - gcc/cp - search.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.0 % 967 928
Test Date: 2024-12-21 13:15:12 Functions: 100.0 % 68 68
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Breadth-first and depth-first routines for
       2                 :             :    searching multiple-inheritance lattice for GNU C++.
       3                 :             :    Copyright (C) 1987-2024 Free Software Foundation, Inc.
       4                 :             :    Contributed by Michael Tiemann (tiemann@cygnus.com)
       5                 :             : 
       6                 :             : This file is part of GCC.
       7                 :             : 
       8                 :             : GCC is free software; you can redistribute it and/or modify
       9                 :             : it under the terms of the GNU General Public License as published by
      10                 :             : the Free Software Foundation; either version 3, or (at your option)
      11                 :             : any later version.
      12                 :             : 
      13                 :             : GCC is distributed in the hope that it will be useful,
      14                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16                 :             : GNU General Public License for more details.
      17                 :             : 
      18                 :             : You should have received a copy of the GNU General Public License
      19                 :             : along with GCC; see the file COPYING3.  If not see
      20                 :             : <http://www.gnu.org/licenses/>.  */
      21                 :             : 
      22                 :             : /* High-level class interface.  */
      23                 :             : 
      24                 :             : #include "config.h"
      25                 :             : #include "system.h"
      26                 :             : #include "coretypes.h"
      27                 :             : #include "cp-tree.h"
      28                 :             : #include "intl.h"
      29                 :             : #include "toplev.h"
      30                 :             : #include "spellcheck-tree.h"
      31                 :             : #include "stringpool.h"
      32                 :             : #include "attribs.h"
      33                 :             : #include "tree-inline.h"
      34                 :             : 
      35                 :             : static int is_subobject_of_p (tree, tree);
      36                 :             : static tree dfs_lookup_base (tree, void *);
      37                 :             : static tree dfs_dcast_hint_pre (tree, void *);
      38                 :             : static tree dfs_dcast_hint_post (tree, void *);
      39                 :             : static tree dfs_debug_mark (tree, void *);
      40                 :             : static int check_hidden_convs (tree, int, int, tree, tree, tree);
      41                 :             : static tree split_conversions (tree, tree, tree, tree);
      42                 :             : static int lookup_conversions_r (tree, int, int, tree, tree, tree *);
      43                 :             : static int look_for_overrides_r (tree, tree);
      44                 :             : static tree lookup_field_r (tree, void *);
      45                 :             : static tree dfs_accessible_post (tree, void *);
      46                 :             : static tree dfs_walk_once_accessible (tree, bool,
      47                 :             :                                       tree (*pre_fn) (tree, void *),
      48                 :             :                                       tree (*post_fn) (tree, void *),
      49                 :             :                                       void *data);
      50                 :             : static tree dfs_access_in_type (tree, void *);
      51                 :             : static access_kind access_in_type (tree, tree);
      52                 :             : static tree dfs_get_pure_virtuals (tree, void *);
      53                 :             : 
      54                 :             : 
      55                 :             : /* Data for lookup_base and its workers.  */
      56                 :             : 
      57                 :             : struct lookup_base_data_s
      58                 :             : {
      59                 :             :   HOST_WIDE_INT offset; /* Offset we want, or -1 if any.  */
      60                 :             :   tree t;               /* type being searched.  */
      61                 :             :   tree base;            /* The base type we're looking for.  */
      62                 :             :   tree binfo;           /* Found binfo.  */
      63                 :             :   bool via_virtual;     /* Found via a virtual path.  */
      64                 :             :   bool ambiguous;       /* Found multiply ambiguous */
      65                 :             :   bool repeated_base;   /* Whether there are repeated bases in the
      66                 :             :                             hierarchy.  */
      67                 :             :   bool want_any;        /* Whether we want any matching binfo.  */
      68                 :             :   bool require_virtual; /* Whether we require a virtual path.  */
      69                 :             : };
      70                 :             : 
      71                 :             : /* Worker function for lookup_base.  See if we've found the desired
      72                 :             :    base and update DATA_ (a pointer to LOOKUP_BASE_DATA_S).  */
      73                 :             : 
      74                 :             : static tree
      75                 :   748523585 : dfs_lookup_base (tree binfo, void *data_)
      76                 :             : {
      77                 :   748523585 :   struct lookup_base_data_s *data = (struct lookup_base_data_s *) data_;
      78                 :             : 
      79                 :   748523585 :   if (data->offset != -1)
      80                 :             :     {
      81                 :             :       /* We're looking for the type at a particular offset.  */
      82                 :     6196653 :       int comp = compare_tree_int (BINFO_OFFSET (binfo), data->offset);
      83                 :     6196653 :       if (comp > 0)
      84                 :             :         /* Don't bother looking into bases laid out later; even if they
      85                 :             :            do virtually inherit from the base we want, we can get there
      86                 :             :            by another path.  */
      87                 :             :         return dfs_skip_bases;
      88                 :     6193656 :       else if (comp != 0
      89                 :     6194965 :                && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base))
      90                 :             :         /* Right type, wrong offset.  */
      91                 :             :         return dfs_skip_bases;
      92                 :             :       /* Fall through.  */
      93                 :             :     }
      94                 :             : 
      95                 :   748520585 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base))
      96                 :             :     {
      97                 :   357593578 :       const bool via_virtual
      98                 :   357593578 :         = binfo_via_virtual (binfo, data->t) != NULL_TREE;
      99                 :             : 
     100                 :   357593578 :       if (data->require_virtual && !via_virtual)
     101                 :             :         /* Skip this result if we require virtual inheritance
     102                 :             :            and this is not a virtual base.  */
     103                 :             :         return dfs_skip_bases;
     104                 :             : 
     105                 :   357593386 :       if (!data->binfo)
     106                 :             :         {
     107                 :   357592224 :           data->binfo = binfo;
     108                 :   357592224 :           data->via_virtual = via_virtual;
     109                 :             : 
     110                 :   357592224 :           if (!data->repeated_base)
     111                 :             :             /* If there are no repeated bases, we can stop now.  */
     112                 :             :             return binfo;
     113                 :             : 
     114                 :       11057 :           if (data->want_any && !data->via_virtual)
     115                 :             :             /* If this is a non-virtual base, then we can't do
     116                 :             :                better.  */
     117                 :             :             return binfo;
     118                 :             : 
     119                 :             :           return dfs_skip_bases;
     120                 :             :         }
     121                 :             :       else
     122                 :             :         {
     123                 :        1162 :           gcc_assert (binfo != data->binfo);
     124                 :             : 
     125                 :             :           /* We've found more than one matching binfo.  */
     126                 :        1162 :           if (!data->want_any)
     127                 :             :             {
     128                 :             :               /* This is immediately ambiguous.  */
     129                 :        1066 :               data->binfo = NULL_TREE;
     130                 :        1066 :               data->ambiguous = true;
     131                 :        1066 :               return error_mark_node;
     132                 :             :             }
     133                 :             : 
     134                 :             :           /* Prefer one via a non-virtual path.  */
     135                 :          96 :           if (!via_virtual)
     136                 :             :             {
     137                 :          27 :               data->binfo = binfo;
     138                 :          27 :               data->via_virtual = false;
     139                 :          27 :               return binfo;
     140                 :             :             }
     141                 :             : 
     142                 :             :           /* There must be repeated bases, otherwise we'd have stopped
     143                 :             :              on the first base we found.  */
     144                 :             :           return dfs_skip_bases;
     145                 :             :         }
     146                 :             :     }
     147                 :             : 
     148                 :             :   return NULL_TREE;
     149                 :             : }
     150                 :             : 
     151                 :             : /* This deals with bug PR17314.
     152                 :             : 
     153                 :             :    DECL is a declaration and BINFO represents a class that has attempted (but
     154                 :             :    failed) to access DECL.
     155                 :             : 
     156                 :             :    Examine the parent binfos of BINFO and determine whether any of them had
     157                 :             :    private access to DECL.  If they did, return the parent binfo.  This helps
     158                 :             :    in figuring out the correct error message to show (if the parents had
     159                 :             :    access, it's their fault for not giving sufficient access to BINFO).
     160                 :             : 
     161                 :             :    If no parents had access, return NULL_TREE.  */
     162                 :             : 
     163                 :             : tree
     164                 :        1106 : get_parent_with_private_access (tree decl, tree binfo)
     165                 :             : {
     166                 :             :   /* Only BINFOs should come through here.  */
     167                 :        1106 :   gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
     168                 :             : 
     169                 :        1205 :   tree base_binfo = NULL_TREE;
     170                 :             : 
     171                 :             :   /* Iterate through immediate parent classes.
     172                 :             :      Note that the base list might contain WILDCARD_TYPE_P types, that
     173                 :             :      should be ignored here.  */
     174                 :        1205 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     175                 :             :     {
     176                 :         281 :       tree base_binfo_type = BINFO_TYPE (base_binfo);
     177                 :             :       /* This parent had private access.  Therefore that's why BINFO can't
     178                 :             :           access DECL.  */
     179                 :         281 :       if (RECORD_OR_UNION_TYPE_P (base_binfo_type)
     180                 :         281 :           && access_in_type (base_binfo_type, decl) == ak_private)
     181                 :             :         return base_binfo;
     182                 :             :     }
     183                 :             : 
     184                 :             :   /* None of the parents had access.  Note: it's impossible for one of the
     185                 :             :      parents to have had public or protected access to DECL, since then
     186                 :             :      BINFO would have been able to access DECL too.  */
     187                 :             :   return NULL_TREE;
     188                 :             : }
     189                 :             : 
     190                 :             : /* Returns true if type BASE is accessible in T.  (BASE is known to be
     191                 :             :    a (possibly non-proper) base class of T.)  If CONSIDER_LOCAL_P is
     192                 :             :    true, consider any special access of the current scope, or access
     193                 :             :    bestowed by friendship.  */
     194                 :             : 
     195                 :             : bool
     196                 :    35864324 : accessible_base_p (tree t, tree base, bool consider_local_p)
     197                 :             : {
     198                 :    35864324 :   tree decl;
     199                 :             : 
     200                 :             :   /* [class.access.base]
     201                 :             : 
     202                 :             :      A base class is said to be accessible if an invented public
     203                 :             :      member of the base class is accessible.
     204                 :             : 
     205                 :             :      If BASE is a non-proper base, this condition is trivially
     206                 :             :      true.  */
     207                 :    35864324 :   if (same_type_p (t, base))
     208                 :             :     return true;
     209                 :             :   /* Rather than inventing a public member, we use the implicit
     210                 :             :      public typedef created in the scope of every class.  */
     211                 :     8453411 :   decl = TYPE_FIELDS (base);
     212                 :   569449990 :   while (!DECL_SELF_REFERENCE_P (decl))
     213                 :   560996579 :     decl = DECL_CHAIN (decl);
     214                 :     8453411 :   while (ANON_AGGR_TYPE_P (t))
     215                 :           0 :     t = TYPE_CONTEXT (t);
     216                 :     8453411 :   return accessible_p (t, decl, consider_local_p);
     217                 :             : }
     218                 :             : 
     219                 :             : /* Lookup BASE in the hierarchy dominated by T.  Do access checking as
     220                 :             :    ACCESS specifies.  Return the binfo we discover.  If KIND_PTR is
     221                 :             :    non-NULL, fill with information about what kind of base we
     222                 :             :    discovered.  If OFFSET is other than -1, only match at that offset.
     223                 :             : 
     224                 :             :    If the base is inaccessible, or ambiguous, then error_mark_node is
     225                 :             :    returned.  If the tf_error bit of COMPLAIN is not set, no error
     226                 :             :    is issued.  */
     227                 :             : 
     228                 :             : tree
     229                 :   601685797 : lookup_base (tree t, tree base, base_access access,
     230                 :             :              base_kind *kind_ptr, tsubst_flags_t complain,
     231                 :             :              HOST_WIDE_INT offset /* = -1 */)
     232                 :             : {
     233                 :   601685797 :   tree binfo;
     234                 :   601685797 :   tree t_binfo;
     235                 :   601685797 :   base_kind bk;
     236                 :             : 
     237                 :             :   /* "Nothing" is definitely not derived from Base.  */
     238                 :   601685797 :   if (t == NULL_TREE)
     239                 :             :     {
     240                 :        4614 :       if (kind_ptr)
     241                 :           0 :         *kind_ptr = bk_not_base;
     242                 :        4614 :       return NULL_TREE;
     243                 :             :     }
     244                 :             : 
     245                 :   601681183 :   if (t == error_mark_node || base == error_mark_node)
     246                 :             :     {
     247                 :           0 :       if (kind_ptr)
     248                 :           0 :         *kind_ptr = bk_not_base;
     249                 :           0 :       return error_mark_node;
     250                 :             :     }
     251                 :   601681183 :   gcc_assert (TYPE_P (base));
     252                 :             : 
     253                 :   601681183 :   if (!TYPE_P (t))
     254                 :             :     {
     255                 :     3028228 :       t_binfo = t;
     256                 :     3028228 :       t = BINFO_TYPE (t);
     257                 :             :     }
     258                 :             :   else
     259                 :             :     {
     260                 :   598652955 :       t = complete_type (TYPE_MAIN_VARIANT (t));
     261                 :   598652955 :       if (dependent_type_p (t))
     262                 :   147439660 :         if (tree open = currently_open_class (t))
     263                 :   598652955 :           t = open;
     264                 :   598652955 :       t_binfo = TYPE_BINFO (t);
     265                 :             :     }
     266                 :             : 
     267                 :   601681183 :   base = TYPE_MAIN_VARIANT (base);
     268                 :             : 
     269                 :             :   /* If BASE is incomplete, it can't be a base of T--and instantiating it
     270                 :             :      might cause an error.  */
     271                 :   601681183 :   if (t_binfo && CLASS_TYPE_P (base) && COMPLETE_OR_OPEN_TYPE_P (base))
     272                 :             :     {
     273                 :   598824341 :       struct lookup_base_data_s data;
     274                 :             : 
     275                 :   598824341 :       data.t = t;
     276                 :   598824341 :       data.base = base;
     277                 :   598824341 :       data.binfo = NULL_TREE;
     278                 :   598824341 :       data.ambiguous = data.via_virtual = false;
     279                 :   598824341 :       data.repeated_base = (offset == -1) && CLASSTYPE_REPEATED_BASE_P (t);
     280                 :   598824341 :       data.want_any = access == ba_any;
     281                 :   598824341 :       data.offset = offset;
     282                 :   598824341 :       data.require_virtual = (access & ba_require_virtual);
     283                 :             : 
     284                 :   598824341 :       dfs_walk_once (t_binfo, dfs_lookup_base, NULL, &data);
     285                 :   598824341 :       binfo = data.binfo;
     286                 :             : 
     287                 :   598824341 :       if (!binfo)
     288                 :   241233183 :         bk = data.ambiguous ? bk_ambig : bk_not_base;
     289                 :   357591158 :       else if (binfo == t_binfo)
     290                 :             :         bk = bk_same_type;
     291                 :    66812554 :       else if (data.via_virtual)
     292                 :             :         bk = bk_via_virtual;
     293                 :             :       else
     294                 :    66207374 :         bk = bk_proper_base;
     295                 :             :     }
     296                 :             :   else
     297                 :             :     {
     298                 :             :       binfo = NULL_TREE;
     299                 :             :       bk = bk_not_base;
     300                 :             :     }
     301                 :             : 
     302                 :             :   /* Check that the base is unambiguous and accessible.  */
     303                 :   601681183 :   if (access != ba_any)
     304                 :    13688288 :     switch (bk)
     305                 :             :       {
     306                 :             :       case bk_not_base:
     307                 :             :         break;
     308                 :             : 
     309                 :        1066 :       case bk_ambig:
     310                 :        1066 :         if (complain & tf_error)
     311                 :          84 :           error ("%qT is an ambiguous base of %qT", base, t);
     312                 :        1066 :         binfo = error_mark_node;
     313                 :        1066 :         break;
     314                 :             : 
     315                 :    13675358 :       default:
     316                 :    13675358 :         if ((access & ba_check_bit)
     317                 :             :             /* If BASE is incomplete, then BASE and TYPE are probably
     318                 :             :                the same, in which case BASE is accessible.  If they
     319                 :             :                are not the same, then TYPE is invalid.  In that case,
     320                 :             :                there's no need to issue another error here, and
     321                 :             :                there's no implicit typedef to use in the code that
     322                 :             :                follows, so we skip the check.  */
     323                 :     3552510 :             && COMPLETE_TYPE_P (base)
     324                 :    17227862 :             && !accessible_base_p (t, base, !(access & ba_ignore_scope)))
     325                 :             :           {
     326                 :         320 :             if (complain & tf_error)
     327                 :          48 :               error ("%qT is an inaccessible base of %qT", base, t);
     328                 :         320 :             binfo = error_mark_node;
     329                 :         320 :             bk = bk_inaccessible;
     330                 :             :           }
     331                 :             :         break;
     332                 :             :       }
     333                 :             : 
     334                 :   601681183 :   if (kind_ptr)
     335                 :     3282467 :     *kind_ptr = bk;
     336                 :             : 
     337                 :             :   return binfo;
     338                 :             : }
     339                 :             : 
     340                 :             : /* Data for dcast_base_hint walker.  */
     341                 :             : 
     342                 :             : struct dcast_data_s
     343                 :             : {
     344                 :             :   tree subtype;   /* The base type we're looking for.  */
     345                 :             :   int virt_depth; /* Number of virtual bases encountered from most
     346                 :             :                      derived.  */
     347                 :             :   tree offset;    /* Best hint offset discovered so far.  */
     348                 :             :   bool repeated_base;  /* Whether there are repeated bases in the
     349                 :             :                           hierarchy.  */
     350                 :             : };
     351                 :             : 
     352                 :             : /* Worker for dcast_base_hint.  Search for the base type being cast
     353                 :             :    from.  */
     354                 :             : 
     355                 :             : static tree
     356                 :       16184 : dfs_dcast_hint_pre (tree binfo, void *data_)
     357                 :             : {
     358                 :       16184 :   struct dcast_data_s *data = (struct dcast_data_s *) data_;
     359                 :             : 
     360                 :       16184 :   if (BINFO_VIRTUAL_P (binfo))
     361                 :         135 :     data->virt_depth++;
     362                 :             : 
     363                 :       16184 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->subtype))
     364                 :             :     {
     365                 :        7471 :       if (data->virt_depth)
     366                 :             :         {
     367                 :         120 :           data->offset = ssize_int (-1);
     368                 :         120 :           return data->offset;
     369                 :             :         }
     370                 :        7351 :       if (data->offset)
     371                 :          12 :         data->offset = ssize_int (-3);
     372                 :             :       else
     373                 :        7339 :         data->offset = BINFO_OFFSET (binfo);
     374                 :             : 
     375                 :        7351 :       return data->repeated_base ? dfs_skip_bases : data->offset;
     376                 :             :     }
     377                 :             : 
     378                 :             :   return NULL_TREE;
     379                 :             : }
     380                 :             : 
     381                 :             : /* Worker for dcast_base_hint.  Track the virtual depth.  */
     382                 :             : 
     383                 :             : static tree
     384                 :        1015 : dfs_dcast_hint_post (tree binfo, void *data_)
     385                 :             : {
     386                 :        1015 :   struct dcast_data_s *data = (struct dcast_data_s *) data_;
     387                 :             : 
     388                 :        1015 :   if (BINFO_VIRTUAL_P (binfo))
     389                 :           3 :     data->virt_depth--;
     390                 :             : 
     391                 :        1015 :   return NULL_TREE;
     392                 :             : }
     393                 :             : 
     394                 :             : /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
     395                 :             :    started from is related to the required TARGET type, in order to optimize
     396                 :             :    the inheritance graph search. This information is independent of the
     397                 :             :    current context, and ignores private paths, hence get_base_distance is
     398                 :             :    inappropriate. Return a TREE specifying the base offset, BOFF.
     399                 :             :    BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
     400                 :             :       and there are no public virtual SUBTYPE bases.
     401                 :             :    BOFF == -1, SUBTYPE occurs as multiple public virtual or non-virtual bases.
     402                 :             :    BOFF == -2, SUBTYPE is not a public base.
     403                 :             :    BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases.  */
     404                 :             : 
     405                 :             : tree
     406                 :        7751 : dcast_base_hint (tree subtype, tree target)
     407                 :             : {
     408                 :        7751 :   struct dcast_data_s data;
     409                 :             : 
     410                 :        7751 :   data.subtype = subtype;
     411                 :        7751 :   data.virt_depth = 0;
     412                 :        7751 :   data.offset = NULL_TREE;
     413                 :        7751 :   data.repeated_base = CLASSTYPE_REPEATED_BASE_P (target);
     414                 :             : 
     415                 :        7751 :   dfs_walk_once_accessible (TYPE_BINFO (target), /*friends=*/false,
     416                 :             :                             dfs_dcast_hint_pre, dfs_dcast_hint_post, &data);
     417                 :        7751 :   return data.offset ? data.offset : ssize_int (-2);
     418                 :             : }
     419                 :             : 
     420                 :             : /* Search for a member with name NAME in a multiple inheritance
     421                 :             :    lattice specified by TYPE.  If it does not exist, return NULL_TREE.
     422                 :             :    If the member is ambiguously referenced, return `error_mark_node'.
     423                 :             :    Otherwise, return a DECL with the indicated name.  If WANT_TYPE is
     424                 :             :    true, type declarations are preferred.  */
     425                 :             : 
     426                 :             : /* Return the FUNCTION_DECL, RECORD_TYPE, UNION_TYPE, or
     427                 :             :    NAMESPACE_DECL corresponding to the innermost non-block scope.  */
     428                 :             : 
     429                 :             : tree
     430                 :  1742821347 : current_scope (void)
     431                 :             : {
     432                 :             :   /* There are a number of cases we need to be aware of here:
     433                 :             :                          current_class_type     current_function_decl
     434                 :             :      global                     NULL                    NULL
     435                 :             :      fn-local                   NULL                    SET
     436                 :             :      class-local                SET                     NULL
     437                 :             :      class->fn                       SET                     SET
     438                 :             :      fn->class                       SET                     SET
     439                 :             : 
     440                 :             :      Those last two make life interesting.  If we're in a function which is
     441                 :             :      itself inside a class, we need decls to go into the fn's decls (our
     442                 :             :      second case below).  But if we're in a class and the class itself is
     443                 :             :      inside a function, we need decls to go into the decls for the class.  To
     444                 :             :      achieve this last goal, we must see if, when both current_class_ptr and
     445                 :             :      current_function_decl are set, the class was declared inside that
     446                 :             :      function.  If so, we know to put the decls into the class's scope.  */
     447                 :   424519729 :   if (current_function_decl && current_class_type
     448                 :  2020092874 :       && ((DECL_FUNCTION_MEMBER_P (current_function_decl)
     449                 :   271000706 :            && same_type_p (DECL_CONTEXT (current_function_decl),
     450                 :             :                            current_class_type))
     451                 :    21417908 :           || (DECL_FRIEND_CONTEXT (current_function_decl)
     452                 :     4270089 :               && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl),
     453                 :             :                               current_class_type))))
     454                 :   270621637 :     return current_function_decl;
     455                 :             : 
     456                 :  1472199710 :   if (current_class_type)
     457                 :             :     return current_class_type;
     458                 :             : 
     459                 :   722086609 :   if (current_function_decl)
     460                 :             :     return current_function_decl;
     461                 :             : 
     462                 :   574838407 :   return current_namespace;
     463                 :             : }
     464                 :             : 
     465                 :             : /* Returns nonzero if we are currently in a function scope.  Note
     466                 :             :    that this function returns zero if we are within a local class, but
     467                 :             :    not within a member function body of the local class.  */
     468                 :             : 
     469                 :             : int
     470                 :   408482105 : at_function_scope_p (void)
     471                 :             : {
     472                 :   408482105 :   tree cs = current_scope ();
     473                 :             :   /* Also check cfun to make sure that we're really compiling
     474                 :             :      this function (as opposed to having set current_function_decl
     475                 :             :      for access checking or some such).  */
     476                 :   408482105 :   return (cs && TREE_CODE (cs) == FUNCTION_DECL
     477                 :   545527529 :           && cfun && cfun->decl == current_function_decl);
     478                 :             : }
     479                 :             : 
     480                 :             : /* Returns true if the innermost active scope is a class scope.  */
     481                 :             : 
     482                 :             : bool
     483                 :   591544802 : at_class_scope_p (void)
     484                 :             : {
     485                 :   591544802 :   tree cs = current_scope ();
     486                 :   591544802 :   return cs && TYPE_P (cs);
     487                 :             : }
     488                 :             : 
     489                 :             : /* Returns true if the innermost active scope is a namespace scope.  */
     490                 :             : 
     491                 :             : bool
     492                 :   293049290 : at_namespace_scope_p (void)
     493                 :             : {
     494                 :   293049290 :   tree cs = current_scope ();
     495                 :   293049290 :   return cs && TREE_CODE (cs) == NAMESPACE_DECL;
     496                 :             : }
     497                 :             : 
     498                 :             : /* Return the scope of DECL, as appropriate when doing name-lookup.  */
     499                 :             : 
     500                 :             : tree
     501                 :  4827550826 : context_for_name_lookup (tree decl)
     502                 :             : {
     503                 :             :   /* [class.union]
     504                 :             : 
     505                 :             :      For the purposes of name lookup, after the anonymous union
     506                 :             :      definition, the members of the anonymous union are considered to
     507                 :             :      have been defined in the scope in which the anonymous union is
     508                 :             :      declared.  */
     509                 :  4827550826 :   tree context = DECL_CONTEXT (decl);
     510                 :             : 
     511                 :  9245450102 :   while (context && TYPE_P (context)
     512                 :  6836714453 :          && (ANON_AGGR_TYPE_P (context) || UNSCOPED_ENUM_P (context)))
     513                 :    54667514 :     context = TYPE_CONTEXT (context);
     514                 :  4827550826 :   if (!context)
     515                 :   464319064 :     context = global_namespace;
     516                 :             : 
     517                 :  4827550826 :   return context;
     518                 :             : }
     519                 :             : 
     520                 :             : /* Like the above, but always return a type, because it's simpler for member
     521                 :             :    handling to refer to the anonymous aggr rather than a function.  */
     522                 :             : 
     523                 :             : tree
     524                 :     1112571 : type_context_for_name_lookup (tree decl)
     525                 :             : {
     526                 :     1112571 :   tree context = DECL_P (decl) ? DECL_CONTEXT (decl) : decl;
     527                 :     1112571 :   gcc_checking_assert (CLASS_TYPE_P (context));
     528                 :             : 
     529                 :     1114911 :   while (context && TYPE_P (context) && ANON_AGGR_TYPE_P (context))
     530                 :             :     {
     531                 :        2352 :       tree next = TYPE_CONTEXT (context);
     532                 :        2352 :       if (!TYPE_P (next))
     533                 :             :         break;
     534                 :             :       context = next;
     535                 :             :     }
     536                 :     1112571 :   return context;
     537                 :             : }
     538                 :             : 
     539                 :             : /* Returns true iff DECL is declared in TYPE.  */
     540                 :             : 
     541                 :             : static bool
     542                 :   368560962 : member_declared_in_type (tree decl, tree type)
     543                 :             : {
     544                 :             :   /* A normal declaration obviously counts.  */
     545                 :   368560962 :   if (context_for_name_lookup (decl) == type)
     546                 :             :     return true;
     547                 :             :   /* So does a using or access declaration.  */
     548                 :   107473113 :   if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl)
     549                 :   107473113 :       && purpose_member (type, DECL_ACCESS (decl)))
     550                 :             :     return true;
     551                 :             :   return false;
     552                 :             : }
     553                 :             : 
     554                 :             : /* The accessibility routines use BINFO_ACCESS for scratch space
     555                 :             :    during the computation of the accessibility of some declaration.  */
     556                 :             : 
     557                 :             : /* Avoid walking up past a declaration of the member.  */
     558                 :             : 
     559                 :             : static tree
     560                 :   325742016 : dfs_access_in_type_pre (tree binfo, void *data)
     561                 :             : {
     562                 :   325742016 :   tree decl = (tree) data;
     563                 :   325742016 :   tree type = BINFO_TYPE (binfo);
     564                 :   325742016 :   if (member_declared_in_type (decl, type))
     565                 :   273652035 :     return dfs_skip_bases;
     566                 :             :   return NULL_TREE;
     567                 :             : }
     568                 :             : 
     569                 :             : #define BINFO_ACCESS(NODE) \
     570                 :             :   ((access_kind) ((TREE_PUBLIC (NODE) << 1) | TREE_PRIVATE (NODE)))
     571                 :             : 
     572                 :             : /* Set the access associated with NODE to ACCESS.  */
     573                 :             : 
     574                 :             : #define SET_BINFO_ACCESS(NODE, ACCESS)                  \
     575                 :             :   ((TREE_PUBLIC (NODE) = ((ACCESS) & 2) != 0),      \
     576                 :             :    (TREE_PRIVATE (NODE) = ((ACCESS) & 1) != 0))
     577                 :             : 
     578                 :             : /* Called from access_in_type via dfs_walk.  Calculate the access to
     579                 :             :    DATA (which is really a DECL) in BINFO.  */
     580                 :             : 
     581                 :             : static tree
     582                 :   325742016 : dfs_access_in_type (tree binfo, void *data)
     583                 :             : {
     584                 :   325742016 :   tree decl = (tree) data;
     585                 :   325742016 :   tree type = BINFO_TYPE (binfo);
     586                 :   325742016 :   access_kind access = ak_none;
     587                 :             : 
     588                 :   325742016 :   if (context_for_name_lookup (decl) == type)
     589                 :             :     {
     590                 :             :       /* If we have descended to the scope of DECL, just note the
     591                 :             :          appropriate access.  */
     592                 :   273091648 :       if (TREE_PRIVATE (decl))
     593                 :             :         access = ak_private;
     594                 :   243767560 :       else if (TREE_PROTECTED (decl))
     595                 :             :         access = ak_protected;
     596                 :             :       else
     597                 :   281819888 :         access = ak_public;
     598                 :             :     }
     599                 :             :   else
     600                 :             :     {
     601                 :             :       /* First, check for an access-declaration that gives us more
     602                 :             :          access to the DECL.  */
     603                 :    52650368 :       if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl))
     604                 :             :         {
     605                 :    74049436 :           tree decl_access = purpose_member (type, DECL_ACCESS (decl));
     606                 :             : 
     607                 :    48169402 :           if (decl_access)
     608                 :             :             {
     609                 :      560387 :               decl_access = TREE_VALUE (decl_access);
     610                 :             : 
     611                 :      560387 :               if (decl_access == access_public_node)
     612                 :             :                 access = ak_public;
     613                 :      205676 :               else if (decl_access == access_protected_node)
     614                 :             :                 access = ak_protected;
     615                 :       35557 :               else if (decl_access == access_private_node)
     616                 :             :                 access = ak_private;
     617                 :             :               else
     618                 :           0 :                 gcc_unreachable ();
     619                 :             :             }
     620                 :             :         }
     621                 :             : 
     622                 :             :       if (!access)
     623                 :             :         {
     624                 :    52089981 :           int i;
     625                 :    52089981 :           tree base_binfo;
     626                 :    52089981 :           vec<tree, va_gc> *accesses;
     627                 :             : 
     628                 :             :           /* Otherwise, scan our baseclasses, and pick the most favorable
     629                 :             :              access.  */
     630                 :    52089981 :           accesses = BINFO_BASE_ACCESSES (binfo);
     631                 :    57812001 :           for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     632                 :             :             {
     633                 :    51425955 :               tree base_access = (*accesses)[i];
     634                 :    51425955 :               access_kind base_access_now = BINFO_ACCESS (base_binfo);
     635                 :             : 
     636                 :    51425955 :               if (base_access_now == ak_none || base_access_now == ak_private)
     637                 :             :                 /* If it was not accessible in the base, or only
     638                 :             :                    accessible as a private member, we can't access it
     639                 :             :                    all.  */
     640                 :             :                 base_access_now = ak_none;
     641                 :    49112309 :               else if (base_access == access_protected_node)
     642                 :             :                 /* Public and protected members in the base become
     643                 :             :                    protected here.  */
     644                 :             :                 base_access_now = ak_protected;
     645                 :    48669181 :               else if (base_access == access_private_node)
     646                 :             :                 /* Public and protected members in the base become
     647                 :             :                    private here.  */
     648                 :             :                 base_access_now = ak_private;
     649                 :             : 
     650                 :             :               /* See if the new access, via this base, gives more
     651                 :             :                  access than our previous best access.  */
     652                 :    47507954 :               if (base_access_now != ak_none
     653                 :    49112309 :                   && (access == ak_none || base_access_now < access))
     654                 :             :                 {
     655                 :    49111971 :                   access = base_access_now;
     656                 :             : 
     657                 :             :                   /* If the new access is public, we can't do better.  */
     658                 :    49111971 :                   if (access == ak_public)
     659                 :             :                     break;
     660                 :             :                 }
     661                 :             :             }
     662                 :             :         }
     663                 :             :     }
     664                 :             : 
     665                 :             :   /* Note the access to DECL in TYPE.  */
     666                 :   325742016 :   SET_BINFO_ACCESS (binfo, access);
     667                 :             : 
     668                 :   325742016 :   return NULL_TREE;
     669                 :             : }
     670                 :             : 
     671                 :             : /* Return the access to DECL in TYPE.  */
     672                 :             : 
     673                 :             : static access_kind
     674                 :   273651883 : access_in_type (tree type, tree decl)
     675                 :             : {
     676                 :   273651883 :   tree binfo = TYPE_BINFO (type);
     677                 :             : 
     678                 :             :   /* We must take into account
     679                 :             : 
     680                 :             :        [class.paths]
     681                 :             : 
     682                 :             :        If a name can be reached by several paths through a multiple
     683                 :             :        inheritance graph, the access is that of the path that gives
     684                 :             :        most access.
     685                 :             : 
     686                 :             :     The algorithm we use is to make a post-order depth-first traversal
     687                 :             :     of the base-class hierarchy.  As we come up the tree, we annotate
     688                 :             :     each node with the most lenient access.  */
     689                 :   273651883 :   dfs_walk_once (binfo, dfs_access_in_type_pre, dfs_access_in_type, decl);
     690                 :             : 
     691                 :   273651883 :   return BINFO_ACCESS (binfo);
     692                 :             : }
     693                 :             : 
     694                 :             : /* Returns nonzero if it is OK to access DECL named in TYPE through an object
     695                 :             :    of OTYPE in the context of DERIVED.  */
     696                 :             : 
     697                 :             : static int
     698                 :     8237158 : protected_accessible_p (tree decl, tree derived, tree type, tree otype)
     699                 :             : {
     700                 :             :   /* We're checking this clause from [class.access.base]
     701                 :             : 
     702                 :             :        m as a member of N is protected, and the reference occurs in a
     703                 :             :        member or friend of class N, or in a member or friend of a
     704                 :             :        class P derived from N, where m as a member of P is public, private
     705                 :             :        or protected.
     706                 :             : 
     707                 :             :     Here DERIVED is a possible P, DECL is m and TYPE is N.  */
     708                 :             : 
     709                 :             :   /* If DERIVED isn't derived from N, then it can't be a P.  */
     710                 :     8237158 :   if (!DERIVED_FROM_P (type, derived))
     711                 :             :     return 0;
     712                 :             : 
     713                 :             :   /* DECL_NONSTATIC_MEMBER_P won't work for USING_DECLs.  */
     714                 :     8176706 :   decl = strip_using_decl (decl);
     715                 :             :   /* We don't expect or support dependent decls.  */
     716                 :     8176706 :   gcc_assert (TREE_CODE (decl) != USING_DECL);
     717                 :             : 
     718                 :             :   /* [class.protected]
     719                 :             : 
     720                 :             :      When a friend or a member function of a derived class references
     721                 :             :      a protected non-static member of a base class, an access check
     722                 :             :      applies in addition to those described earlier in clause
     723                 :             :      _class.access_) Except when forming a pointer to member
     724                 :             :      (_expr.unary.op_), the access must be through a pointer to,
     725                 :             :      reference to, or object of the derived class itself (or any class
     726                 :             :      derived from that class) (_expr.ref_).  If the access is to form
     727                 :             :      a pointer to member, the nested-name-specifier shall name the
     728                 :             :      derived class (or any class derived from that class).  */
     729                 :    13776573 :   if (DECL_NONSTATIC_MEMBER_P (decl)
     730                 :    12430920 :       && !DERIVED_FROM_P (derived, otype))
     731                 :             :     return 0;
     732                 :             : 
     733                 :             :   return 1;
     734                 :             : }
     735                 :             : 
     736                 :             : /* Returns nonzero if SCOPE is a type or a friend of a type which would be able
     737                 :             :    to access DECL through TYPE.  OTYPE is the type of the object.  */
     738                 :             : 
     739                 :             : static int
     740                 :    14543049 : friend_accessible_p (tree scope, tree decl, tree type, tree otype)
     741                 :             : {
     742                 :             :   /* We're checking this clause from [class.access.base]
     743                 :             : 
     744                 :             :        m as a member of N is protected, and the reference occurs in a
     745                 :             :        member or friend of class N, or in a member or friend of a
     746                 :             :        class P derived from N, where m as a member of P is public, private
     747                 :             :        or protected.
     748                 :             : 
     749                 :             :     Here DECL is m and TYPE is N.  SCOPE is the current context,
     750                 :             :     and we check all its possible Ps.  */
     751                 :    14543049 :   tree befriending_classes;
     752                 :    14543049 :   tree t;
     753                 :             : 
     754                 :    14543049 :   if (!scope)
     755                 :             :     return 0;
     756                 :             : 
     757                 :    14543049 :   if (is_global_friend (scope))
     758                 :             :     return 1;
     759                 :             : 
     760                 :             :   /* Is SCOPE itself a suitable P?  */
     761                 :    14543049 :   if (TYPE_P (scope) && protected_accessible_p (decl, scope, type, otype))
     762                 :             :     return 1;
     763                 :             : 
     764                 :     6378793 :   if (DECL_DECLARES_FUNCTION_P (scope))
     765                 :     6317971 :     befriending_classes = DECL_BEFRIENDING_CLASSES (scope);
     766                 :       60822 :   else if (TYPE_P (scope))
     767                 :       59985 :     befriending_classes = CLASSTYPE_BEFRIENDING_CLASSES (scope);
     768                 :             :   else
     769                 :             :     return 0;
     770                 :             : 
     771                 :     6378506 :   for (t = befriending_classes; t; t = TREE_CHAIN (t))
     772                 :       12917 :     if (protected_accessible_p (decl, TREE_VALUE (t), type, otype))
     773                 :             :       return 1;
     774                 :             : 
     775                 :             :   /* Nested classes have the same access as their enclosing types, as
     776                 :             :      per DR 45 (this is a change from C++98).  */
     777                 :     6365589 :   if (TYPE_P (scope))
     778                 :       48145 :     if (friend_accessible_p (TYPE_CONTEXT (scope), decl, type, otype))
     779                 :             :       return 1;
     780                 :             : 
     781                 :     6317988 :   if (DECL_DECLARES_FUNCTION_P (scope))
     782                 :             :     {
     783                 :             :       /* Perhaps this SCOPE is a member of a class which is a
     784                 :             :          friend.  */
     785                 :    12634888 :       if (DECL_CLASS_SCOPE_P (scope)
     786                 :    12634540 :           && friend_accessible_p (DECL_CONTEXT (scope), decl, type, otype))
     787                 :             :         return 1;
     788                 :             :       /* Perhaps SCOPE is a friend function defined inside a class from which
     789                 :             :          DECL is accessible.  */
     790                 :         910 :       if (tree fctx = DECL_FRIEND_CONTEXT (scope))
     791                 :           3 :         if (friend_accessible_p (fctx, decl, type, otype))
     792                 :             :           return 1;
     793                 :             :     }
     794                 :             : 
     795                 :             :   /* Maybe scope's template is a friend.  */
     796                 :         996 :   if (tree tinfo = get_template_info (scope))
     797                 :             :     {
     798                 :         747 :       tree tmpl = TI_TEMPLATE (tinfo);
     799                 :         747 :       if (DECL_CLASS_TEMPLATE_P (tmpl))
     800                 :         479 :         tmpl = TREE_TYPE (tmpl);
     801                 :             :       else
     802                 :         268 :         tmpl = DECL_TEMPLATE_RESULT (tmpl);
     803                 :         747 :       if (tmpl != scope)
     804                 :             :         {
     805                 :             :           /* Increment processing_template_decl to make sure that
     806                 :             :              dependent_type_p works correctly.  */
     807                 :         599 :           ++processing_template_decl;
     808                 :         599 :           int ret = friend_accessible_p (tmpl, decl, type, otype);
     809                 :         599 :           --processing_template_decl;
     810                 :         599 :           if (ret)
     811                 :             :             return 1;
     812                 :             :         }
     813                 :             :     }
     814                 :             : 
     815                 :             :   /* If is_friend is true, we should have found a befriending class.  */
     816                 :         431 :   gcc_checking_assert (!is_friend (type, scope));
     817                 :             : 
     818                 :             :   return 0;
     819                 :             : }
     820                 :             : 
     821                 :             : struct dfs_accessible_data
     822                 :             : {
     823                 :             :   tree decl;
     824                 :             :   tree object_type;
     825                 :             : };
     826                 :             : 
     827                 :             : /* Avoid walking up past a declaration of the member.  */
     828                 :             : 
     829                 :             : static tree
     830                 :    42818946 : dfs_accessible_pre (tree binfo, void *data)
     831                 :             : {
     832                 :    42818946 :   dfs_accessible_data *d = (dfs_accessible_data *)data;
     833                 :    42818946 :   tree type = BINFO_TYPE (binfo);
     834                 :    42818946 :   if (member_declared_in_type (d->decl, type))
     835                 :    38771852 :     return dfs_skip_bases;
     836                 :             :   return NULL_TREE;
     837                 :             : }
     838                 :             : 
     839                 :             : /* Called via dfs_walk_once_accessible from accessible_p */
     840                 :             : 
     841                 :             : static tree
     842                 :    39329669 : dfs_accessible_post (tree binfo, void *data)
     843                 :             : {
     844                 :             :   /* access_in_type already set BINFO_ACCESS for us.  */
     845                 :    39329669 :   access_kind access = BINFO_ACCESS (binfo);
     846                 :    39329669 :   tree N = BINFO_TYPE (binfo);
     847                 :    39329669 :   dfs_accessible_data *d = (dfs_accessible_data *)data;
     848                 :    39329669 :   tree decl = d->decl;
     849                 :    39329669 :   tree scope = current_nonlambda_scope ();
     850                 :             : 
     851                 :             :   /* A member m is accessible at the point R when named in class N if */
     852                 :    39329669 :   switch (access)
     853                 :             :     {
     854                 :             :     case ak_none:
     855                 :             :       return NULL_TREE;
     856                 :             : 
     857                 :             :     case ak_public:
     858                 :             :       /* m as a member of N is public, or */
     859                 :             :       return binfo;
     860                 :             : 
     861                 :    29359557 :     case ak_private:
     862                 :    29359557 :       {
     863                 :             :         /* m as a member of N is private, and R occurs in a member or friend of
     864                 :             :            class N, or */
     865                 :    29359557 :         if (scope && TREE_CODE (scope) != NAMESPACE_DECL
     866                 :    58718745 :             && is_friend (N, scope))
     867                 :             :           return binfo;
     868                 :             :         return NULL_TREE;
     869                 :             :       }
     870                 :             : 
     871                 :     8177206 :     case ak_protected:
     872                 :     8177206 :       {
     873                 :             :         /* m as a member of N is protected, and R occurs in a member or friend
     874                 :             :            of class N, or in a member or friend of a class P derived from N,
     875                 :             :            where m as a member of P is public, private, or protected  */
     876                 :     8177206 :         if (friend_accessible_p (scope, decl, N, d->object_type))
     877                 :             :           return binfo;
     878                 :             :         return NULL_TREE;
     879                 :             :       }
     880                 :             : 
     881                 :             :     default:
     882                 :             :       gcc_unreachable ();
     883                 :             :     }
     884                 :             : }
     885                 :             : 
     886                 :             : /* Like accessible_p below, but within a template returns true iff DECL is
     887                 :             :    accessible in TYPE to all possible instantiations of the template.  */
     888                 :             : 
     889                 :             : int
     890                 :     5119909 : accessible_in_template_p (tree type, tree decl)
     891                 :             : {
     892                 :     5119909 :   int save_ptd = processing_template_decl;
     893                 :     5119909 :   processing_template_decl = 0;
     894                 :     5119909 :   int val = accessible_p (type, decl, false);
     895                 :     5119909 :   processing_template_decl = save_ptd;
     896                 :     5119909 :   return val;
     897                 :             : }
     898                 :             : 
     899                 :             : /* DECL is a declaration from a base class of TYPE, which was the
     900                 :             :    class used to name DECL.  Return nonzero if, in the current
     901                 :             :    context, DECL is accessible.  If TYPE is actually a BINFO node,
     902                 :             :    then we can tell in what context the access is occurring by looking
     903                 :             :    at the most derived class along the path indicated by BINFO.  If
     904                 :             :    CONSIDER_LOCAL is true, do consider special access the current
     905                 :             :    scope or friendship thereof we might have.  */
     906                 :             : 
     907                 :             : int
     908                 :   273651662 : accessible_p (tree type, tree decl, bool consider_local_p)
     909                 :             : {
     910                 :   273651662 :   tree binfo;
     911                 :   273651662 :   access_kind access;
     912                 :             : 
     913                 :             :   /* If this declaration is in a block or namespace scope, there's no
     914                 :             :      access control.  */
     915                 :   273651662 :   if (!TYPE_P (context_for_name_lookup (decl)))
     916                 :             :     return 1;
     917                 :             : 
     918                 :             :   /* There is no need to perform access checks inside a thunk.  */
     919                 :   273651605 :   if (current_function_decl && DECL_THUNK_P (current_function_decl))
     920                 :             :     return 1;
     921                 :             : 
     922                 :   273651605 :   tree otype = NULL_TREE;
     923                 :   273651605 :   if (!TYPE_P (type))
     924                 :             :     {
     925                 :             :       /* When accessing a non-static member, the most derived type in the
     926                 :             :          binfo chain is the type of the object; remember that type for
     927                 :             :          protected_accessible_p.  */
     928                 :   534989446 :       for (tree b = type; b; b = BINFO_INHERITANCE_CHAIN (b))
     929                 :   274948105 :         otype = BINFO_TYPE (b);
     930                 :   260041341 :       type = BINFO_TYPE (type);
     931                 :             :     }
     932                 :             :   else
     933                 :             :     otype = type;
     934                 :             : 
     935                 :             :   /* Anonymous unions don't have their own access.  */
     936                 :   273651605 :   if (ANON_AGGR_TYPE_P (type))
     937                 :           3 :     type = type_context_for_name_lookup (type);
     938                 :             : 
     939                 :             :   /* [class.access.base]
     940                 :             : 
     941                 :             :      A member m is accessible when named in class N if
     942                 :             : 
     943                 :             :      --m as a member of N is public, or
     944                 :             : 
     945                 :             :      --m as a member of N is private, and the reference occurs in a
     946                 :             :        member or friend of class N, or
     947                 :             : 
     948                 :             :      --m as a member of N is protected, and the reference occurs in a
     949                 :             :        member or friend of class N, or in a member or friend of a
     950                 :             :        class P derived from N, where m as a member of P is public, private or
     951                 :             :        protected, or
     952                 :             : 
     953                 :             :      --there exists a base class B of N that is accessible at the point
     954                 :             :        of reference, and m is accessible when named in class B.
     955                 :             : 
     956                 :             :     We walk the base class hierarchy, checking these conditions.  */
     957                 :             : 
     958                 :             :   /* We walk using TYPE_BINFO (type) because access_in_type will set
     959                 :             :      BINFO_ACCESS on it and its bases.  */
     960                 :   273651605 :   binfo = TYPE_BINFO (type);
     961                 :             : 
     962                 :             :   /* Compute the accessibility of DECL in the class hierarchy
     963                 :             :      dominated by type.  */
     964                 :   273651605 :   access = access_in_type (type, decl);
     965                 :   273651605 :   if (access == ak_public)
     966                 :             :     return 1;
     967                 :             : 
     968                 :             :   /* If we aren't considering the point of reference, only the first bullet
     969                 :             :      applies.  */
     970                 :    38773361 :   if (!consider_local_p)
     971                 :             :     return 0;
     972                 :             : 
     973                 :    38772991 :   dfs_accessible_data d = { decl, otype };
     974                 :             : 
     975                 :             :   /* Walk the hierarchy again, looking for a base class that allows
     976                 :             :      access.  */
     977                 :    38772991 :   return dfs_walk_once_accessible (binfo, /*friends=*/true,
     978                 :             :                                    dfs_accessible_pre,
     979                 :             :                                    dfs_accessible_post, &d)
     980                 :    38772991 :     != NULL_TREE;
     981                 :             : }
     982                 :             : 
     983                 :             : struct lookup_field_info {
     984                 :             :   /* The type in which we're looking.  */
     985                 :             :   tree type;
     986                 :             :   /* The name of the field for which we're looking.  */
     987                 :             :   tree name;
     988                 :             :   /* If non-NULL, the current result of the lookup.  */
     989                 :             :   tree rval;
     990                 :             :   /* The path to RVAL.  */
     991                 :             :   tree rval_binfo;
     992                 :             :   /* If non-NULL, the lookup was ambiguous, and this is a list of the
     993                 :             :      candidates.  */
     994                 :             :   tree ambiguous;
     995                 :             :   /* If nonzero, we are looking for types, not data members.  */
     996                 :             :   int want_type;
     997                 :             : };
     998                 :             : 
     999                 :             : /* True for a class member means that it is shared between all objects
    1000                 :             :    of that class.
    1001                 :             : 
    1002                 :             :    [class.member.lookup]:If the resulting set of declarations are not all
    1003                 :             :    from sub-objects of the same type, or the set has a non-static member
    1004                 :             :    and  includes members from distinct sub-objects, there is an ambiguity
    1005                 :             :    and the program is ill-formed.
    1006                 :             : 
    1007                 :             :    This function checks that T contains no non-static members.  */
    1008                 :             : 
    1009                 :             : bool
    1010                 :    41180535 : shared_member_p (tree t)
    1011                 :             : {
    1012                 :    41180535 :   if (VAR_P (t) || TREE_CODE (t) == TYPE_DECL
    1013                 :    38182248 :       || TREE_CODE (t) == CONST_DECL)
    1014                 :             :     return true;
    1015                 :    38178764 :   if (is_overloaded_fn (t))
    1016                 :             :     {
    1017                 :    65178448 :       for (ovl_iterator iter (get_fns (t)); iter; ++iter)
    1018                 :             :         {
    1019                 :    41773916 :           tree decl = strip_using_decl (*iter);
    1020                 :    41773916 :           if (TREE_CODE (decl) == USING_DECL)
    1021                 :             :             /* Conservatively assume a dependent using-declaration
    1022                 :             :                might resolve to a non-static member.  */
    1023                 :    24224047 :             return false;
    1024                 :    41773913 :           if (DECL_OBJECT_MEMBER_FUNCTION_P (decl))
    1025                 :             :             return false;
    1026                 :             :         }
    1027                 :    13954284 :       return true;
    1028                 :             :     }
    1029                 :             :   return false;
    1030                 :             : }
    1031                 :             : 
    1032                 :             : /* Routine to see if the sub-object denoted by the binfo PARENT can be
    1033                 :             :    found as a base class and sub-object of the object denoted by
    1034                 :             :    BINFO.  */
    1035                 :             : 
    1036                 :             : static int
    1037                 :     4554003 : is_subobject_of_p (tree parent, tree binfo)
    1038                 :             : {
    1039                 :     4554003 :   tree probe;
    1040                 :             : 
    1041                 :    10355913 :   for (probe = parent; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
    1042                 :             :     {
    1043                 :     7510563 :       if (probe == binfo)
    1044                 :             :         return 1;
    1045                 :     7470708 :       if (BINFO_VIRTUAL_P (probe))
    1046                 :     1668798 :         return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (binfo))
    1047                 :     1668798 :                 != NULL_TREE);
    1048                 :             :     }
    1049                 :             :   return 0;
    1050                 :             : }
    1051                 :             : 
    1052                 :             : /* DATA is really a struct lookup_field_info.  Look for a field with
    1053                 :             :    the name indicated there in BINFO.  If this function returns a
    1054                 :             :    non-NULL value it is the result of the lookup.  Called from
    1055                 :             :    lookup_field via breadth_first_search.  */
    1056                 :             : 
    1057                 :             : static tree
    1058                 :  5378707500 : lookup_field_r (tree binfo, void *data)
    1059                 :             : {
    1060                 :  5378707500 :   struct lookup_field_info *lfi = (struct lookup_field_info *) data;
    1061                 :  5378707500 :   tree type = BINFO_TYPE (binfo);
    1062                 :  5378707500 :   tree nval = NULL_TREE;
    1063                 :             : 
    1064                 :             :   /* If this is a dependent base, don't look in it.  */
    1065                 :  5378707500 :   if (BINFO_DEPENDENT_BASE_P (binfo))
    1066                 :             :     return NULL_TREE;
    1067                 :             : 
    1068                 :             :   /* If this base class is hidden by the best-known value so far, we
    1069                 :             :      don't need to look.  */
    1070                 :    63919090 :   if (lfi->rval_binfo && BINFO_INHERITANCE_CHAIN (binfo) == lfi->rval_binfo
    1071                 :  4352312548 :       && !BINFO_VIRTUAL_P (binfo))
    1072                 :             :     return dfs_skip_bases;
    1073                 :             : 
    1074                 :  4243354922 :   nval = get_class_binding (type, lfi->name, lfi->want_type);
    1075                 :             : 
    1076                 :             :   /* If there is no declaration with the indicated name in this type,
    1077                 :             :      then there's nothing to do.  */
    1078                 :  4243354922 :   if (!nval)
    1079                 :  3733496302 :     goto done;
    1080                 :             : 
    1081                 :             :   /* If the lookup already found a match, and the new value doesn't
    1082                 :             :      hide the old one, we might have an ambiguity.  */
    1083                 :   509858620 :   if (lfi->rval_binfo
    1084                 :   509858620 :       && !is_subobject_of_p (lfi->rval_binfo, binfo))
    1085                 :             : 
    1086                 :             :     {
    1087                 :     2257162 :       if (nval == lfi->rval && shared_member_p (nval))
    1088                 :             :         /* The two things are really the same.  */
    1089                 :             :         ;
    1090                 :     2256952 :       else if (is_subobject_of_p (binfo, lfi->rval_binfo))
    1091                 :             :         /* The previous value hides the new one.  */
    1092                 :             :         ;
    1093                 :             :       else
    1094                 :             :         {
    1095                 :             :           /* We have a real ambiguity.  We keep a chain of all the
    1096                 :             :              candidates.  */
    1097                 :      632305 :           if (!lfi->ambiguous && lfi->rval)
    1098                 :             :             {
    1099                 :             :               /* This is the first time we noticed an ambiguity.  Add
    1100                 :             :                  what we previously thought was a reasonable candidate
    1101                 :             :                  to the list.  */
    1102                 :      492292 :               lfi->ambiguous = tree_cons (NULL_TREE, lfi->rval, NULL_TREE);
    1103                 :      492292 :               TREE_TYPE (lfi->ambiguous) = error_mark_node;
    1104                 :             :             }
    1105                 :             : 
    1106                 :             :           /* Add the new value.  */
    1107                 :      632305 :           if (TREE_CODE (nval) == TREE_LIST)
    1108                 :           6 :             lfi->ambiguous = chainon (nval, lfi->ambiguous);
    1109                 :             :           else
    1110                 :             :             {
    1111                 :      632299 :               lfi->ambiguous = tree_cons (NULL_TREE, nval, lfi->ambiguous);
    1112                 :      632299 :               TREE_TYPE (lfi->ambiguous) = error_mark_node;
    1113                 :             :             }
    1114                 :             :         }
    1115                 :             :     }
    1116                 :             :   else
    1117                 :             :     {
    1118                 :   507601458 :       if (TREE_CODE (nval) == TREE_LIST)
    1119                 :             :         {
    1120                 :          97 :           lfi->ambiguous = chainon (nval, lfi->ambiguous);
    1121                 :          97 :           lfi->rval = TREE_VALUE (nval);
    1122                 :             :         }
    1123                 :             :       else
    1124                 :   507601361 :         lfi->rval = nval;
    1125                 :   507601458 :       lfi->rval_binfo = binfo;
    1126                 :             :     }
    1127                 :             : 
    1128                 :  4243354922 :  done:
    1129                 :             :   /* Don't look for constructors or destructors in base classes.  */
    1130                 :  4243354922 :   if (IDENTIFIER_CDTOR_P (lfi->name))
    1131                 :             :     return dfs_skip_bases;
    1132                 :             :   return NULL_TREE;
    1133                 :             : }
    1134                 :             : 
    1135                 :             : /* Return a "baselink" with BASELINK_BINFO, BASELINK_ACCESS_BINFO,
    1136                 :             :    BASELINK_FUNCTIONS, and BASELINK_OPTYPE set to BINFO, ACCESS_BINFO,
    1137                 :             :    FUNCTIONS, and OPTYPE respectively.  */
    1138                 :             : 
    1139                 :             : tree
    1140                 :   168704252 : build_baselink (tree binfo, tree access_binfo, tree functions, tree optype)
    1141                 :             : {
    1142                 :   168704252 :   tree baselink;
    1143                 :             : 
    1144                 :   168704252 :   gcc_assert (OVL_P (functions) || TREE_CODE (functions) == TEMPLATE_ID_EXPR);
    1145                 :   168704252 :   gcc_assert (!optype || TYPE_P (optype));
    1146                 :   168704252 :   gcc_assert (TREE_TYPE (functions));
    1147                 :             : 
    1148                 :   168704252 :   baselink = make_node (BASELINK);
    1149                 :   168704252 :   TREE_TYPE (baselink) = TREE_TYPE (functions);
    1150                 :   168704252 :   BASELINK_BINFO (baselink) = binfo;
    1151                 :   168704252 :   BASELINK_ACCESS_BINFO (baselink) = access_binfo;
    1152                 :   168704252 :   BASELINK_FUNCTIONS (baselink) = functions;
    1153                 :   168704252 :   BASELINK_OPTYPE (baselink) = optype;
    1154                 :             : 
    1155                 :   168704252 :   if (binfo == access_binfo
    1156                 :   328343743 :       && TYPE_BEING_DEFINED (BINFO_TYPE (access_binfo)))
    1157                 :     3673906 :     BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (baselink) = true;
    1158                 :             : 
    1159                 :   168704252 :   return baselink;
    1160                 :             : }
    1161                 :             : 
    1162                 :             : /* Look for a member named NAME in an inheritance lattice dominated by
    1163                 :             :    XBASETYPE.  If PROTECT is 0 or two, we do not check access.  If it
    1164                 :             :    is 1, we enforce accessibility.  If PROTECT is zero, then, for an
    1165                 :             :    ambiguous lookup, we return NULL.  If PROTECT is 1, we issue error
    1166                 :             :    messages about inaccessible or ambiguous lookup.  If PROTECT is 2,
    1167                 :             :    we return a TREE_LIST whose TREE_TYPE is error_mark_node and whose
    1168                 :             :    TREE_VALUEs are the list of ambiguous candidates.
    1169                 :             : 
    1170                 :             :    WANT_TYPE is 1 when we should only return TYPE_DECLs.
    1171                 :             : 
    1172                 :             :    If nothing can be found return NULL_TREE and do not issue an error.
    1173                 :             : 
    1174                 :             :    If non-NULL, failure information is written back to AFI.  */
    1175                 :             : 
    1176                 :             : tree
    1177                 :  3699005274 : lookup_member (tree xbasetype, tree name, int protect, bool want_type,
    1178                 :             :                tsubst_flags_t complain, access_failure_info *afi /* = NULL */)
    1179                 :             : {
    1180                 :  3699005274 :   tree rval, rval_binfo = NULL_TREE;
    1181                 :  3699005274 :   tree type = NULL_TREE, basetype_path = NULL_TREE;
    1182                 :  3699005274 :   struct lookup_field_info lfi;
    1183                 :             : 
    1184                 :             :   /* rval_binfo is the binfo associated with the found member, note,
    1185                 :             :      this can be set with useful information, even when rval is not
    1186                 :             :      set, because it must deal with ALL members, not just non-function
    1187                 :             :      members.  It is used for ambiguity checking and the hidden
    1188                 :             :      checks.  Whereas rval is only set if a proper (not hidden)
    1189                 :             :      non-function member is found.  */
    1190                 :             : 
    1191                 :  3699005274 :   if (name == error_mark_node
    1192                 :  3699005274 :       || xbasetype == NULL_TREE
    1193                 :  3699005268 :       || xbasetype == error_mark_node)
    1194                 :             :     return NULL_TREE;
    1195                 :             : 
    1196                 :  3699005268 :   gcc_assert (identifier_p (name));
    1197                 :             : 
    1198                 :  3699005268 :   if (TREE_CODE (xbasetype) == TREE_BINFO)
    1199                 :             :     {
    1200                 :    75653998 :       type = BINFO_TYPE (xbasetype);
    1201                 :    75653998 :       basetype_path = xbasetype;
    1202                 :             :     }
    1203                 :             :   else
    1204                 :             :     {
    1205                 :  3623351270 :       if (!RECORD_OR_UNION_CODE_P (TREE_CODE (xbasetype)))
    1206                 :             :         return NULL_TREE;
    1207                 :             :       type = xbasetype;
    1208                 :  3699005244 :       xbasetype = NULL_TREE;
    1209                 :             :     }
    1210                 :             : 
    1211                 :  3699005244 :   type = complete_type (type);
    1212                 :             : 
    1213                 :             :   /* Make sure we're looking for a member of the current instantiation in the
    1214                 :             :      right partial specialization.  */
    1215                 :  3699005190 :   if (dependent_type_p (type))
    1216                 :  2552016839 :     if (tree t = currently_open_class (type))
    1217                 :  3699005190 :       type = t;
    1218                 :             : 
    1219                 :  3699005190 :   if (!basetype_path)
    1220                 :  3623351192 :     basetype_path = TYPE_BINFO (type);
    1221                 :             : 
    1222                 :  3623351192 :   if (!basetype_path)
    1223                 :             :     return NULL_TREE;
    1224                 :             : 
    1225                 :  3623985795 :   memset (&lfi, 0, sizeof (lfi));
    1226                 :  3623985795 :   lfi.type = type;
    1227                 :  3623985795 :   lfi.name = name;
    1228                 :  3623985795 :   lfi.want_type = want_type;
    1229                 :  3623985795 :   dfs_walk_all (basetype_path, &lookup_field_r, NULL, &lfi);
    1230                 :  3623985795 :   rval = lfi.rval;
    1231                 :  3623985795 :   rval_binfo = lfi.rval_binfo;
    1232                 :  3623985795 :   if (rval_binfo)
    1233                 :   507561569 :     type = BINFO_TYPE (rval_binfo);
    1234                 :             : 
    1235                 :  3623985795 :   if (lfi.ambiguous)
    1236                 :             :     {
    1237                 :      492389 :       if (protect == 0)
    1238                 :             :         return NULL_TREE;
    1239                 :      492371 :       else if (protect == 1)
    1240                 :             :         {
    1241                 :          82 :           if (complain & tf_error)
    1242                 :             :             {
    1243                 :          69 :               auto_diagnostic_group d;
    1244                 :          69 :               error ("request for member %qD is ambiguous", name);
    1245                 :          69 :               print_candidates (lfi.ambiguous);
    1246                 :          69 :             }
    1247                 :          82 :           return error_mark_node;
    1248                 :             :         }
    1249                 :      492289 :       else if (protect == 2)
    1250                 :             :         return lfi.ambiguous;
    1251                 :             :     }
    1252                 :             : 
    1253                 :  3623493406 :   if (!rval)
    1254                 :             :     return NULL_TREE;
    1255                 :             : 
    1256                 :             :   /* [class.access]
    1257                 :             : 
    1258                 :             :      In the case of overloaded function names, access control is
    1259                 :             :      applied to the function selected by overloaded resolution.
    1260                 :             : 
    1261                 :             :      We cannot check here, even if RVAL is only a single non-static
    1262                 :             :      member function, since we do not know what the "this" pointer
    1263                 :             :      will be.  For:
    1264                 :             : 
    1265                 :             :         class A { protected: void f(); };
    1266                 :             :         class B : public A {
    1267                 :             :           void g(A *p) {
    1268                 :             :             f(); // OK
    1269                 :             :             p->f(); // Not OK.
    1270                 :             :           }
    1271                 :             :         };
    1272                 :             : 
    1273                 :             :     only the first call to "f" is valid.  However, if the function is
    1274                 :             :     static, we can check.  */
    1275                 :   507069180 :   if (protect == 1 && !really_overloaded_fn (rval))
    1276                 :             :     {
    1277                 :    83727028 :       tree decl = is_overloaded_fn (rval) ? get_first_fn (rval) : rval;
    1278                 :    83727028 :       decl = strip_using_decl (decl);
    1279                 :             :       /* A dependent USING_DECL will be checked after tsubsting.  */
    1280                 :    83727028 :       if (TREE_CODE (decl) != USING_DECL
    1281                 :    78566755 :           && !DECL_IOBJ_MEMBER_FUNCTION_P (decl)
    1282                 :   121544533 :           && !perform_or_defer_access_check (basetype_path, decl, decl,
    1283                 :             :                                              complain, afi))
    1284                 :          72 :         return error_mark_node;
    1285                 :             :     }
    1286                 :             : 
    1287                 :   507069108 :   if (is_overloaded_fn (rval)
    1288                 :             :       /* Don't use a BASELINK for class-scope deduction guides since
    1289                 :             :          they're not actually member functions.  */
    1290                 :   507069108 :       && !dguide_name_p (name))
    1291                 :   157003328 :     rval = build_baselink (rval_binfo, basetype_path, rval,
    1292                 :   157003328 :                            (IDENTIFIER_CONV_OP_P (name)
    1293                 :      296586 :                             ? TREE_TYPE (name) : NULL_TREE));
    1294                 :             :   return rval;
    1295                 :             : }
    1296                 :             : 
    1297                 :             : /* Helper class for lookup_member_fuzzy.  */
    1298                 :             : 
    1299                 :         688 : class lookup_field_fuzzy_info
    1300                 :             : {
    1301                 :             :  public:
    1302                 :         688 :   lookup_field_fuzzy_info (bool want_type_p) :
    1303                 :         688 :     m_want_type_p (want_type_p), m_candidates () {}
    1304                 :             : 
    1305                 :             :   void fuzzy_lookup_field (tree type);
    1306                 :             : 
    1307                 :             :   /* If true, we are looking for types, not data members.  */
    1308                 :             :   bool m_want_type_p;
    1309                 :             :   /* The result: a vec of identifiers.  */
    1310                 :             :   auto_vec<tree> m_candidates;
    1311                 :             : };
    1312                 :             : 
    1313                 :             : /* Locate all fields within TYPE, append them to m_candidates.  */
    1314                 :             : 
    1315                 :             : void
    1316                 :         783 : lookup_field_fuzzy_info::fuzzy_lookup_field (tree type)
    1317                 :             : {
    1318                 :         783 :   if (!CLASS_TYPE_P (type))
    1319                 :             :     return;
    1320                 :             : 
    1321                 :        3999 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    1322                 :             :     {
    1323                 :        3222 :       if (m_want_type_p && !DECL_DECLARES_TYPE_P (field))
    1324                 :         146 :         continue;
    1325                 :             : 
    1326                 :        3076 :       if (!DECL_NAME (field))
    1327                 :          72 :         continue;
    1328                 :             : 
    1329                 :        3004 :       if (is_lambda_ignored_entity (field))
    1330                 :          36 :         continue;
    1331                 :             : 
    1332                 :             :       /* Ignore special identifiers with space at the end like cdtor or
    1333                 :             :          conversion op identifiers.  */
    1334                 :        2968 :       if (TREE_CODE (DECL_NAME (field)) == IDENTIFIER_NODE)
    1335                 :        2968 :         if (unsigned int len = IDENTIFIER_LENGTH (DECL_NAME (field)))
    1336                 :        2968 :           if (IDENTIFIER_POINTER (DECL_NAME (field))[len - 1] == ' ')
    1337                 :        1328 :             continue;
    1338                 :             : 
    1339                 :        1640 :       m_candidates.safe_push (DECL_NAME (field));
    1340                 :             :     }
    1341                 :             : }
    1342                 :             : 
    1343                 :             : 
    1344                 :             : /* Helper function for lookup_member_fuzzy, called via dfs_walk_all
    1345                 :             :    DATA is really a lookup_field_fuzzy_info.  Look for a field with
    1346                 :             :    the name indicated there in BINFO.  Gathers pertinent identifiers into
    1347                 :             :    m_candidates.  */
    1348                 :             : 
    1349                 :             : static tree
    1350                 :         783 : lookup_field_fuzzy_r (tree binfo, void *data)
    1351                 :             : {
    1352                 :         783 :   lookup_field_fuzzy_info *lffi = (lookup_field_fuzzy_info *) data;
    1353                 :         783 :   tree type = BINFO_TYPE (binfo);
    1354                 :             : 
    1355                 :         783 :   lffi->fuzzy_lookup_field (type);
    1356                 :             : 
    1357                 :         783 :   return NULL_TREE;
    1358                 :             : }
    1359                 :             : 
    1360                 :             : /* Like lookup_member, but try to find the closest match for NAME,
    1361                 :             :    rather than an exact match, and return an identifier (or NULL_TREE).
    1362                 :             :    Do not complain.  */
    1363                 :             : 
    1364                 :             : tree
    1365                 :         688 : lookup_member_fuzzy (tree xbasetype, tree name, bool want_type_p)
    1366                 :             : {
    1367                 :         688 :   tree type = NULL_TREE, basetype_path = NULL_TREE;
    1368                 :         688 :   class lookup_field_fuzzy_info lffi (want_type_p);
    1369                 :             : 
    1370                 :             :   /* rval_binfo is the binfo associated with the found member, note,
    1371                 :             :      this can be set with useful information, even when rval is not
    1372                 :             :      set, because it must deal with ALL members, not just non-function
    1373                 :             :      members.  It is used for ambiguity checking and the hidden
    1374                 :             :      checks.  Whereas rval is only set if a proper (not hidden)
    1375                 :             :      non-function member is found.  */
    1376                 :             : 
    1377                 :         688 :   if (name == error_mark_node
    1378                 :         688 :       || xbasetype == NULL_TREE
    1379                 :         688 :       || xbasetype == error_mark_node)
    1380                 :             :     return NULL_TREE;
    1381                 :             : 
    1382                 :         688 :   gcc_assert (identifier_p (name));
    1383                 :             : 
    1384                 :         688 :   if (TREE_CODE (xbasetype) == TREE_BINFO)
    1385                 :             :     {
    1386                 :           6 :       type = BINFO_TYPE (xbasetype);
    1387                 :           6 :       basetype_path = xbasetype;
    1388                 :             :     }
    1389                 :             :   else
    1390                 :             :     {
    1391                 :         682 :       if (!RECORD_OR_UNION_CODE_P (TREE_CODE (xbasetype)))
    1392                 :             :         return NULL_TREE;
    1393                 :             :       type = xbasetype;
    1394                 :         688 :       xbasetype = NULL_TREE;
    1395                 :             :     }
    1396                 :             : 
    1397                 :         688 :   type = complete_type (type);
    1398                 :             : 
    1399                 :             :   /* Make sure we're looking for a member of the current instantiation in the
    1400                 :             :      right partial specialization.  */
    1401                 :         688 :   if (flag_concepts && dependent_type_p (type))
    1402                 :          64 :     type = currently_open_class (type);
    1403                 :             : 
    1404                 :         688 :   if (!basetype_path)
    1405                 :         682 :     basetype_path = TYPE_BINFO (type);
    1406                 :             : 
    1407                 :         682 :   if (!basetype_path)
    1408                 :             :     return NULL_TREE;
    1409                 :             : 
    1410                 :             :   /* Populate lffi.m_candidates.  */
    1411                 :         682 :   dfs_walk_all (basetype_path, &lookup_field_fuzzy_r, NULL, &lffi);
    1412                 :             : 
    1413                 :         682 :   return find_closest_identifier (name, &lffi.m_candidates);
    1414                 :         688 : }
    1415                 :             : 
    1416                 :             : /* Like lookup_member, except that if we find a function member we
    1417                 :             :    return NULL_TREE.  */
    1418                 :             : 
    1419                 :             : tree
    1420                 :    22096080 : lookup_field (tree xbasetype, tree name, int protect, bool want_type)
    1421                 :             : {
    1422                 :    22096080 :   tree rval = lookup_member (xbasetype, name, protect, want_type,
    1423                 :             :                              tf_warning_or_error);
    1424                 :             : 
    1425                 :             :   /* Ignore functions, but propagate the ambiguity list.  */
    1426                 :    22096080 :   if (!error_operand_p (rval)
    1427                 :    22096080 :       && (rval && BASELINK_P (rval)))
    1428                 :           0 :     return NULL_TREE;
    1429                 :             : 
    1430                 :             :   return rval;
    1431                 :             : }
    1432                 :             : 
    1433                 :             : /* Like lookup_member, except that if we find a non-function member we
    1434                 :             :    return NULL_TREE.  */
    1435                 :             : 
    1436                 :             : tree
    1437                 :    93960163 : lookup_fnfields (tree xbasetype, tree name, int protect,
    1438                 :             :                  tsubst_flags_t complain)
    1439                 :             : {
    1440                 :    93960163 :   tree rval = lookup_member (xbasetype, name, protect, /*want_type=*/false,
    1441                 :             :                              complain);
    1442                 :             : 
    1443                 :             :   /* Ignore non-functions, but propagate the ambiguity list.  */
    1444                 :    93960163 :   if (!error_operand_p (rval)
    1445                 :    93960163 :       && (rval && !BASELINK_P (rval)))
    1446                 :           0 :     return NULL_TREE;
    1447                 :             : 
    1448                 :             :   return rval;
    1449                 :             : }
    1450                 :             : 
    1451                 :             : /* DECL is the result of a qualified name lookup.  QUALIFYING_SCOPE is
    1452                 :             :    the class or namespace used to qualify the name.  CONTEXT_CLASS is
    1453                 :             :    the class corresponding to the object in which DECL will be used.
    1454                 :             :    Return a possibly modified version of DECL that takes into account
    1455                 :             :    the CONTEXT_CLASS.
    1456                 :             : 
    1457                 :             :    In particular, consider an expression like `B::m' in the context of
    1458                 :             :    a derived class `D'.  If `B::m' has been resolved to a BASELINK,
    1459                 :             :    then the most derived class indicated by the BASELINK_BINFO will be
    1460                 :             :    `B', not `D'.  This function makes that adjustment.  */
    1461                 :             : 
    1462                 :             : tree
    1463                 :   121324942 : adjust_result_of_qualified_name_lookup (tree decl,
    1464                 :             :                                         tree qualifying_scope,
    1465                 :             :                                         tree context_class)
    1466                 :             : {
    1467                 :    84658321 :   if (context_class && context_class != error_mark_node
    1468                 :    84658312 :       && CLASS_TYPE_P (context_class)
    1469                 :    84658306 :       && CLASS_TYPE_P (qualifying_scope)
    1470                 :    47739596 :       && DERIVED_FROM_P (qualifying_scope, context_class)
    1471                 :   124330195 :       && BASELINK_P (decl))
    1472                 :             :     {
    1473                 :     2909655 :       tree base;
    1474                 :             : 
    1475                 :             :       /* Look for the QUALIFYING_SCOPE as a base of the CONTEXT_CLASS.
    1476                 :             :          Because we do not yet know which function will be chosen by
    1477                 :             :          overload resolution, we cannot yet check either accessibility
    1478                 :             :          or ambiguity -- in either case, the choice of a static member
    1479                 :             :          function might make the usage valid.  */
    1480                 :     2909655 :       base = lookup_base (context_class, qualifying_scope,
    1481                 :             :                           ba_unique, NULL, tf_none);
    1482                 :     2909655 :       if (base && base != error_mark_node)
    1483                 :             :         {
    1484                 :     2909649 :           BASELINK_ACCESS_BINFO (decl) = base;
    1485                 :     2909649 :           tree decl_binfo
    1486                 :     2909649 :             = lookup_base (base, BINFO_TYPE (BASELINK_BINFO (decl)),
    1487                 :             :                            ba_unique, NULL, tf_none);
    1488                 :     2909649 :           if (decl_binfo && decl_binfo != error_mark_node)
    1489                 :     2909643 :             BASELINK_BINFO (decl) = decl_binfo;
    1490                 :             :         }
    1491                 :             :     }
    1492                 :             : 
    1493                 :   121324942 :   if (BASELINK_P (decl))
    1494                 :    16821445 :     BASELINK_QUALIFIED_P (decl) = true;
    1495                 :             : 
    1496                 :   121324942 :   return decl;
    1497                 :             : }
    1498                 :             : 
    1499                 :             : 
    1500                 :             : /* Walk the class hierarchy within BINFO, in a depth-first traversal.
    1501                 :             :    PRE_FN is called in preorder, while POST_FN is called in postorder.
    1502                 :             :    If PRE_FN returns DFS_SKIP_BASES, child binfos will not be
    1503                 :             :    walked.  If PRE_FN or POST_FN returns a different non-NULL value,
    1504                 :             :    that value is immediately returned and the walk is terminated.  One
    1505                 :             :    of PRE_FN and POST_FN can be NULL.  At each node, PRE_FN and
    1506                 :             :    POST_FN are passed the binfo to examine and the caller's DATA
    1507                 :             :    value.  All paths are walked, thus virtual and morally virtual
    1508                 :             :    binfos can be multiply walked.  */
    1509                 :             : 
    1510                 :             : tree
    1511                 :  6535927036 : dfs_walk_all (tree binfo, tree (*pre_fn) (tree, void *),
    1512                 :             :               tree (*post_fn) (tree, void *), void *data)
    1513                 :             : {
    1514                 :  6535927036 :   tree rval;
    1515                 :  6535927036 :   unsigned ix;
    1516                 :  6535927036 :   tree base_binfo;
    1517                 :             : 
    1518                 :             :   /* Call the pre-order walking function.  */
    1519                 :  6535927036 :   if (pre_fn)
    1520                 :             :     {
    1521                 :  6531620319 :       rval = pre_fn (binfo, data);
    1522                 :  6531620319 :       if (rval)
    1523                 :             :         {
    1524                 :   882683863 :           if (rval == dfs_skip_bases)
    1525                 :   525487868 :             goto skip_bases;
    1526                 :             :           return rval;
    1527                 :             :         }
    1528                 :             :     }
    1529                 :             : 
    1530                 :             :   /* Find the next child binfo to walk.  */
    1531                 :  7569329477 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    1532                 :             :     {
    1533                 :  1988291056 :       rval = dfs_walk_all (base_binfo, pre_fn, post_fn, data);
    1534                 :  1988291056 :       if (rval)
    1535                 :             :         return rval;
    1536                 :             :     }
    1537                 :             : 
    1538                 :  6106526289 :  skip_bases:
    1539                 :             :   /* Call the post-order walking function.  */
    1540                 :  6106526289 :   if (post_fn)
    1541                 :             :     {
    1542                 :   357904143 :       rval = post_fn (binfo, data);
    1543                 :   357904143 :       gcc_assert (rval != dfs_skip_bases);
    1544                 :             :       return rval;
    1545                 :             :     }
    1546                 :             : 
    1547                 :             :   return NULL_TREE;
    1548                 :             : }
    1549                 :             : 
    1550                 :             : /* Worker for dfs_walk_once.  This behaves as dfs_walk_all, except
    1551                 :             :    that binfos are walked at most once.  */
    1552                 :             : 
    1553                 :             : static tree
    1554                 :     2658358 : dfs_walk_once_r (tree binfo, tree (*pre_fn) (tree, void *),
    1555                 :             :                  tree (*post_fn) (tree, void *), hash_set<tree> *pset,
    1556                 :             :                  void *data)
    1557                 :             : {
    1558                 :     2658358 :   tree rval;
    1559                 :     2658358 :   unsigned ix;
    1560                 :     2658358 :   tree base_binfo;
    1561                 :             : 
    1562                 :             :   /* Call the pre-order walking function.  */
    1563                 :     2658358 :   if (pre_fn)
    1564                 :             :     {
    1565                 :     2319495 :       rval = pre_fn (binfo, data);
    1566                 :     2319495 :       if (rval)
    1567                 :             :         {
    1568                 :      528935 :           if (rval == dfs_skip_bases)
    1569                 :      137562 :             goto skip_bases;
    1570                 :             : 
    1571                 :             :           return rval;
    1572                 :             :         }
    1573                 :             :     }
    1574                 :             : 
    1575                 :             :   /* Find the next child binfo to walk.  */
    1576                 :     3927966 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    1577                 :             :     {
    1578                 :     2294301 :       if (BINFO_VIRTUAL_P (base_binfo))
    1579                 :      899049 :         if (pset->add (base_binfo))
    1580                 :      378993 :           continue;
    1581                 :             : 
    1582                 :     1915308 :       rval = dfs_walk_once_r (base_binfo, pre_fn, post_fn, pset, data);
    1583                 :     1915308 :       if (rval)
    1584                 :             :         return rval;
    1585                 :             :     }
    1586                 :             : 
    1587                 :     1771227 :  skip_bases:
    1588                 :             :   /* Call the post-order walking function.  */
    1589                 :     1771227 :   if (post_fn)
    1590                 :             :     {
    1591                 :      490566 :       rval = post_fn (binfo, data);
    1592                 :      490566 :       gcc_assert (rval != dfs_skip_bases);
    1593                 :             :       return rval;
    1594                 :             :     }
    1595                 :             : 
    1596                 :             :   return NULL_TREE;
    1597                 :             : }
    1598                 :             : 
    1599                 :             : /* Like dfs_walk_all, except that binfos are not multiply walked.  For
    1600                 :             :    non-diamond shaped hierarchies this is the same as dfs_walk_all.
    1601                 :             :    For diamond shaped hierarchies we must mark the virtual bases, to
    1602                 :             :    avoid multiple walks.  */
    1603                 :             : 
    1604                 :             : tree
    1605                 :   915437810 : dfs_walk_once (tree binfo, tree (*pre_fn) (tree, void *),
    1606                 :             :                tree (*post_fn) (tree, void *), void *data)
    1607                 :             : {
    1608                 :   915437810 :   static int active = 0;  /* We must not be called recursively. */
    1609                 :   915437810 :   tree rval;
    1610                 :             : 
    1611                 :   915437810 :   gcc_assert (pre_fn || post_fn);
    1612                 :   915437810 :   gcc_assert (!active);
    1613                 :   915437810 :   active++;
    1614                 :             : 
    1615                 :   915437810 :   if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
    1616                 :             :     /* We are not diamond shaped, and therefore cannot encounter the
    1617                 :             :        same binfo twice.  */
    1618                 :   914694760 :     rval = dfs_walk_all (binfo, pre_fn, post_fn, data);
    1619                 :             :   else
    1620                 :             :     {
    1621                 :      743050 :       hash_set<tree> pset;
    1622                 :      743050 :       rval = dfs_walk_once_r (binfo, pre_fn, post_fn, &pset, data);
    1623                 :      743050 :     }
    1624                 :             : 
    1625                 :   915437810 :   active--;
    1626                 :             : 
    1627                 :   915437810 :   return rval;
    1628                 :             : }
    1629                 :             : 
    1630                 :             : /* Worker function for dfs_walk_once_accessible.  Behaves like
    1631                 :             :    dfs_walk_once_r, except (a) FRIENDS_P is true if special
    1632                 :             :    access given by the current context should be considered, (b) ONCE
    1633                 :             :    indicates whether bases should be marked during traversal.  */
    1634                 :             : 
    1635                 :             : static tree
    1636                 :    42835578 : dfs_walk_once_accessible_r (tree binfo, bool friends_p, hash_set<tree> *pset,
    1637                 :             :                             tree (*pre_fn) (tree, void *),
    1638                 :             :                             tree (*post_fn) (tree, void *), void *data)
    1639                 :             : {
    1640                 :    42835578 :   tree rval = NULL_TREE;
    1641                 :    42835578 :   unsigned ix;
    1642                 :    42835578 :   tree base_binfo;
    1643                 :             : 
    1644                 :             :   /* Call the pre-order walking function.  */
    1645                 :    42835578 :   if (pre_fn)
    1646                 :             :     {
    1647                 :    42835578 :       rval = pre_fn (binfo, data);
    1648                 :    42835578 :       if (rval)
    1649                 :             :         {
    1650                 :    38779484 :           if (rval == dfs_skip_bases)
    1651                 :    38771969 :             goto skip_bases;
    1652                 :             : 
    1653                 :             :           return rval;
    1654                 :             :         }
    1655                 :             :     }
    1656                 :             : 
    1657                 :             :   /* Find the next child binfo to walk.  */
    1658                 :     4622299 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    1659                 :             :     {
    1660                 :     4063318 :       bool mark = pset && BINFO_VIRTUAL_P (base_binfo);
    1661                 :             : 
    1662                 :        7742 :       if (mark && pset->contains (base_binfo))
    1663                 :           0 :         continue;
    1664                 :             : 
    1665                 :             :       /* If the base is inherited via private or protected
    1666                 :             :          inheritance, then we can't see it, unless we are a friend of
    1667                 :             :          the current binfo.  */
    1668                 :     4063318 :       if (BINFO_BASE_ACCESS (binfo, ix) != access_public_node)
    1669                 :             :         {
    1670                 :     1735772 :           tree scope;
    1671                 :     1735772 :           if (!friends_p)
    1672                 :         228 :             continue;
    1673                 :     1735544 :           scope = current_scope ();
    1674                 :     1744204 :           if (!scope
    1675                 :     1735544 :               || TREE_CODE (scope) == NAMESPACE_DECL
    1676                 :     3470933 :               || !is_friend (BINFO_TYPE (binfo), scope))
    1677                 :        8660 :             continue;
    1678                 :             :         }
    1679                 :             : 
    1680                 :     4054430 :       if (mark)
    1681                 :         389 :         pset->add (base_binfo);
    1682                 :             : 
    1683                 :     4054430 :       rval = dfs_walk_once_accessible_r (base_binfo, friends_p, pset,
    1684                 :             :                                          pre_fn, post_fn, data);
    1685                 :     4054430 :       if (rval)
    1686                 :             :         return rval;
    1687                 :             :     }
    1688                 :             : 
    1689                 :    39330950 :  skip_bases:
    1690                 :             :   /* Call the post-order walking function.  */
    1691                 :    39330950 :   if (post_fn)
    1692                 :             :     {
    1693                 :    39330684 :       rval = post_fn (binfo, data);
    1694                 :    39330684 :       gcc_assert (rval != dfs_skip_bases);
    1695                 :             :       return rval;
    1696                 :             :     }
    1697                 :             : 
    1698                 :             :   return NULL_TREE;
    1699                 :             : }
    1700                 :             : 
    1701                 :             : /* Like dfs_walk_once except that only accessible bases are walked.
    1702                 :             :    FRIENDS_P indicates whether friendship of the local context
    1703                 :             :    should be considered when determining accessibility.  */
    1704                 :             : 
    1705                 :             : static tree
    1706                 :    38781148 : dfs_walk_once_accessible (tree binfo, bool friends_p,
    1707                 :             :                             tree (*pre_fn) (tree, void *),
    1708                 :             :                             tree (*post_fn) (tree, void *), void *data)
    1709                 :             : {
    1710                 :    38781148 :   hash_set<tree> *pset = NULL;
    1711                 :    38781148 :   if (CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
    1712                 :        1862 :     pset = new hash_set<tree>;
    1713                 :    38781148 :   tree rval = dfs_walk_once_accessible_r (binfo, friends_p, pset,
    1714                 :             :                                           pre_fn, post_fn, data);
    1715                 :             : 
    1716                 :    38781148 :   if (pset)
    1717                 :        1862 :     delete pset;
    1718                 :    38781148 :   return rval;
    1719                 :             : }
    1720                 :             : 
    1721                 :             : /* Return true iff the code of T is CODE, and it has compatible
    1722                 :             :    type with TYPE.  */
    1723                 :             : 
    1724                 :             : static bool
    1725                 :         448 : matches_code_and_type_p (tree t, enum tree_code code, tree type)
    1726                 :             : {
    1727                 :         448 :   if (TREE_CODE (t) != code)
    1728                 :             :     return false;
    1729                 :         434 :   if (!cxx_types_compatible_p (TREE_TYPE (t), type))
    1730                 :             :     return false;
    1731                 :             :   return true;
    1732                 :             : }
    1733                 :             : 
    1734                 :             : /* Subroutine of direct_accessor_p and reference_accessor_p.
    1735                 :             :    Determine if COMPONENT_REF is a simple field lookup of this->FIELD_DECL.
    1736                 :             :    We expect a tree of the form:
    1737                 :             :              <component_ref:
    1738                 :             :                <indirect_ref:S>
    1739                 :             :                  <nop_expr:P*
    1740                 :             :                    <parm_decl (this)>
    1741                 :             :                  <field_decl (FIELD_DECL)>>>.  */
    1742                 :             : 
    1743                 :             : static bool
    1744                 :         203 : field_access_p (tree component_ref, tree field_decl, tree field_type)
    1745                 :             : {
    1746                 :         203 :   if (!matches_code_and_type_p (component_ref, COMPONENT_REF, field_type))
    1747                 :             :     return false;
    1748                 :             : 
    1749                 :         189 :   tree indirect_ref = TREE_OPERAND (component_ref, 0);
    1750                 :         189 :   if (!INDIRECT_REF_P (indirect_ref))
    1751                 :             :     return false;
    1752                 :             : 
    1753                 :         189 :   tree ptr = STRIP_NOPS (TREE_OPERAND (indirect_ref, 0));
    1754                 :         189 :   if (!is_object_parameter (ptr))
    1755                 :             :     return false;
    1756                 :             : 
    1757                 :             :   /* Must access the correct field.  */
    1758                 :         189 :   if (TREE_OPERAND (component_ref, 1) != field_decl)
    1759                 :             :     return false;
    1760                 :             :   return true;
    1761                 :             : }
    1762                 :             : 
    1763                 :             : /* Subroutine of field_accessor_p.
    1764                 :             : 
    1765                 :             :    Assuming that INIT_EXPR has already had its code and type checked,
    1766                 :             :    determine if it is a simple accessor for FIELD_DECL
    1767                 :             :    (of type FIELD_TYPE).
    1768                 :             : 
    1769                 :             :    Specifically, a simple accessor within struct S of the form:
    1770                 :             :        T get_field () { return m_field; }
    1771                 :             :    should have a constexpr_fn_retval (saved_tree) of the form:
    1772                 :             :          <init_expr:T
    1773                 :             :            <result_decl:T
    1774                 :             :            <nop_expr:T
    1775                 :             :              <component_ref:
    1776                 :             :                <indirect_ref:S>
    1777                 :             :                  <nop_expr:P*
    1778                 :             :                    <parm_decl (this)>
    1779                 :             :                  <field_decl (FIELD_DECL)>>>>>.  */
    1780                 :             : 
    1781                 :             : static bool
    1782                 :         161 : direct_accessor_p (tree init_expr, tree field_decl, tree field_type)
    1783                 :             : {
    1784                 :         161 :   tree result_decl = TREE_OPERAND (init_expr, 0);
    1785                 :         161 :   if (!matches_code_and_type_p (result_decl, RESULT_DECL, field_type))
    1786                 :             :     return false;
    1787                 :             : 
    1788                 :         161 :   tree component_ref = STRIP_NOPS (TREE_OPERAND (init_expr, 1));
    1789                 :         161 :   if (!field_access_p (component_ref, field_decl, field_type))
    1790                 :             :     return false;
    1791                 :             : 
    1792                 :             :   return true;
    1793                 :             : }
    1794                 :             : 
    1795                 :             : /* Subroutine of field_accessor_p.
    1796                 :             : 
    1797                 :             :    Assuming that INIT_EXPR has already had its code and type checked,
    1798                 :             :    determine if it is a "reference" accessor for FIELD_DECL
    1799                 :             :    (of type FIELD_REFERENCE_TYPE).
    1800                 :             : 
    1801                 :             :    Specifically, a simple accessor within struct S of the form:
    1802                 :             :        T& get_field () { return m_field; }
    1803                 :             :    should have a constexpr_fn_retval (saved_tree) of the form:
    1804                 :             :          <init_expr:T&
    1805                 :             :            <result_decl:T&
    1806                 :             :            <nop_expr: T&
    1807                 :             :              <addr_expr: T*
    1808                 :             :                <component_ref:T
    1809                 :             :                  <indirect_ref:S
    1810                 :             :                    <nop_expr
    1811                 :             :                      <parm_decl (this)>>
    1812                 :             :                    <field (FIELD_DECL)>>>>>>.  */
    1813                 :             : static bool
    1814                 :          42 : reference_accessor_p (tree init_expr, tree field_decl, tree field_type,
    1815                 :             :                       tree field_reference_type)
    1816                 :             : {
    1817                 :          42 :   tree result_decl = TREE_OPERAND (init_expr, 0);
    1818                 :          42 :   if (!matches_code_and_type_p (result_decl, RESULT_DECL, field_reference_type))
    1819                 :             :     return false;
    1820                 :             : 
    1821                 :          42 :   tree field_pointer_type = build_pointer_type (field_type);
    1822                 :          42 :   tree addr_expr = STRIP_NOPS (TREE_OPERAND (init_expr, 1));
    1823                 :          42 :   if (!matches_code_and_type_p (addr_expr, ADDR_EXPR, field_pointer_type))
    1824                 :             :     return false;
    1825                 :             : 
    1826                 :          42 :   tree component_ref = STRIP_NOPS (TREE_OPERAND (addr_expr, 0));
    1827                 :             : 
    1828                 :          42 :   if (!field_access_p (component_ref, field_decl, field_type))
    1829                 :             :     return false;
    1830                 :             : 
    1831                 :             :   return true;
    1832                 :             : }
    1833                 :             : 
    1834                 :             : /* Return the class of the `this' or explicit object parameter of FN.  */
    1835                 :             : 
    1836                 :             : static tree
    1837                 :          61 : class_of_object_parm (const_tree fn)
    1838                 :             : {
    1839                 :          61 :   tree fntype = TREE_TYPE (fn);
    1840                 :          61 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    1841                 :           0 :     return non_reference (TREE_VALUE (TYPE_ARG_TYPES (fntype)));
    1842                 :          61 :   return class_of_this_parm (fntype);
    1843                 :             : }
    1844                 :             : 
    1845                 :             : /* Return true if FN is an accessor method for FIELD_DECL.
    1846                 :             :    i.e. a method of the form { return FIELD; }, with no
    1847                 :             :    conversions.
    1848                 :             : 
    1849                 :             :    If CONST_P, then additionally require that FN be a const
    1850                 :             :    method.  */
    1851                 :             : 
    1852                 :             : static bool
    1853                 :        2363 : field_accessor_p (tree fn, tree field_decl, bool const_p)
    1854                 :             : {
    1855                 :        2363 :   if (TREE_CODE (fn) != FUNCTION_DECL)
    1856                 :             :     return false;
    1857                 :             : 
    1858                 :             :   /* We don't yet support looking up static data, just fields.  */
    1859                 :         624 :   if (TREE_CODE (field_decl) != FIELD_DECL)
    1860                 :             :     return false;
    1861                 :             : 
    1862                 :         615 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (fn))
    1863                 :             :     return false;
    1864                 :             : 
    1865                 :             :   /* If the field is accessed via a const "this" argument, verify
    1866                 :             :      that the "this" parameter is const.  */
    1867                 :         615 :   if (const_p)
    1868                 :             :     {
    1869                 :          61 :       tree this_class = class_of_object_parm (fn);
    1870                 :          61 :       if (!TYPE_READONLY (this_class))
    1871                 :             :         return false;
    1872                 :             :     }
    1873                 :             : 
    1874                 :         577 :   tree saved_tree = DECL_SAVED_TREE (fn);
    1875                 :             : 
    1876                 :         577 :   if (saved_tree == NULL_TREE)
    1877                 :             :     return false;
    1878                 :             : 
    1879                 :             :   /* Attempt to extract a single return value from the function,
    1880                 :             :      if it has one.  */
    1881                 :         229 :   tree retval = constexpr_fn_retval (saved_tree);
    1882                 :         229 :   if (retval == NULL_TREE || retval == error_mark_node)
    1883                 :             :     return false;
    1884                 :             :   /* Require an INIT_EXPR.  */
    1885                 :         203 :   if (TREE_CODE (retval) != INIT_EXPR)
    1886                 :             :     return false;
    1887                 :         203 :   tree init_expr = retval;
    1888                 :             : 
    1889                 :             :   /* Determine if this is a simple accessor within struct S of the form:
    1890                 :             :        T get_field () { return m_field; }.  */
    1891                 :         203 :   tree field_type = TREE_TYPE (field_decl);
    1892                 :         203 :   if (cxx_types_compatible_p (TREE_TYPE (init_expr), field_type))
    1893                 :         161 :     return direct_accessor_p (init_expr, field_decl, field_type);
    1894                 :             : 
    1895                 :             :   /* Failing that, determine if it is an accessor of the form:
    1896                 :             :        T& get_field () { return m_field; }.  */
    1897                 :          42 :   tree field_reference_type = cp_build_reference_type (field_type, false);
    1898                 :          42 :   if (cxx_types_compatible_p (TREE_TYPE (init_expr), field_reference_type))
    1899                 :          42 :     return reference_accessor_p (init_expr, field_decl, field_type,
    1900                 :          42 :                                  field_reference_type);
    1901                 :             : 
    1902                 :             :   return false;
    1903                 :             : }
    1904                 :             : 
    1905                 :             : /* Callback data for dfs_locate_field_accessor_pre.  */
    1906                 :             : 
    1907                 :             : class locate_field_data
    1908                 :             : {
    1909                 :             : public:
    1910                 :         406 :   locate_field_data (tree field_decl_, bool const_p_)
    1911                 :         406 :   : field_decl (field_decl_), const_p (const_p_) {}
    1912                 :             : 
    1913                 :             :   tree field_decl;
    1914                 :             :   bool const_p;
    1915                 :             : };
    1916                 :             : 
    1917                 :             : /* Return a FUNCTION_DECL that is an "accessor" method for DATA, a FIELD_DECL,
    1918                 :             :    callable via binfo, if one exists, otherwise return NULL_TREE.
    1919                 :             : 
    1920                 :             :    Callback for dfs_walk_once_accessible for use within
    1921                 :             :    locate_field_accessor.  */
    1922                 :             : 
    1923                 :             : static tree
    1924                 :         448 : dfs_locate_field_accessor_pre (tree binfo, void *data)
    1925                 :             : {
    1926                 :         448 :   locate_field_data *lfd = (locate_field_data *)data;
    1927                 :         448 :   tree type = BINFO_TYPE (binfo);
    1928                 :             : 
    1929                 :         448 :   vec<tree, va_gc> *member_vec;
    1930                 :         448 :   tree fn;
    1931                 :         448 :   size_t i;
    1932                 :             : 
    1933                 :         448 :   if (!CLASS_TYPE_P (type))
    1934                 :             :     return NULL_TREE;
    1935                 :             : 
    1936                 :         448 :   member_vec = CLASSTYPE_MEMBER_VEC (type);
    1937                 :         448 :   if (!member_vec)
    1938                 :             :     return NULL_TREE;
    1939                 :             : 
    1940                 :        2534 :   for (i = 0; vec_safe_iterate (member_vec, i, &fn); ++i)
    1941                 :        2363 :     if (fn)
    1942                 :        2363 :       if (field_accessor_p (fn, lfd->field_decl, lfd->const_p))
    1943                 :             :         return fn;
    1944                 :             : 
    1945                 :             :   return NULL_TREE;
    1946                 :             : }
    1947                 :             : 
    1948                 :             : /* Return a FUNCTION_DECL that is an "accessor" method for FIELD_DECL,
    1949                 :             :    callable via BASETYPE_PATH, if one exists, otherwise return NULL_TREE.  */
    1950                 :             : 
    1951                 :             : tree
    1952                 :         406 : locate_field_accessor (tree basetype_path, tree field_decl, bool const_p)
    1953                 :             : {
    1954                 :         406 :   if (TREE_CODE (basetype_path) != TREE_BINFO)
    1955                 :             :     return NULL_TREE;
    1956                 :             : 
    1957                 :             :   /* Walk the hierarchy, looking for a method of some base class that allows
    1958                 :             :      access to the field.  */
    1959                 :         406 :   locate_field_data lfd (field_decl, const_p);
    1960                 :         406 :   return dfs_walk_once_accessible (basetype_path, /*friends=*/true,
    1961                 :             :                                    dfs_locate_field_accessor_pre,
    1962                 :         406 :                                    NULL, &lfd);
    1963                 :             : }
    1964                 :             : 
    1965                 :             : /* Check throw specifier of OVERRIDER is at least as strict as
    1966                 :             :    the one of BASEFN.  This is due to [except.spec]: "If a virtual function
    1967                 :             :    has a non-throwing exception specification, all declarations, including
    1968                 :             :    the definition, of any function that overrides that virtual function in
    1969                 :             :    any derived class shall have a non-throwing exception specification,
    1970                 :             :    unless the overriding function is defined as deleted."  */
    1971                 :             : 
    1972                 :             : bool
    1973                 :     3295264 : maybe_check_overriding_exception_spec (tree overrider, tree basefn)
    1974                 :             : {
    1975                 :     3295264 :   maybe_instantiate_noexcept (basefn);
    1976                 :     3295264 :   maybe_instantiate_noexcept (overrider);
    1977                 :     3295264 :   tree base_throw = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (basefn));
    1978                 :     3295264 :   tree over_throw = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (overrider));
    1979                 :             : 
    1980                 :     3295264 :   if (DECL_INVALID_OVERRIDER_P (overrider)
    1981                 :             :       /* CWG 1351 added the "unless the overriding function is defined as
    1982                 :             :          deleted" wording.  */
    1983                 :     3295264 :       || DECL_DELETED_FN (overrider))
    1984                 :             :     return true;
    1985                 :             : 
    1986                 :             :   /* Can't check this yet.  Pretend this is fine and let
    1987                 :             :      noexcept_override_late_checks check this later.  */
    1988                 :     2156827 :   if (UNPARSED_NOEXCEPT_SPEC_P (base_throw)
    1989                 :     7609006 :       || UNPARSED_NOEXCEPT_SPEC_P (over_throw))
    1990                 :             :     return true;
    1991                 :             : 
    1992                 :             :   /* We also have to defer checking when we're in a template and couldn't
    1993                 :             :      instantiate & evaluate the noexcept to true/false.  */
    1994                 :     3295249 :   if (processing_template_decl)
    1995                 :           6 :     if ((base_throw
    1996                 :           3 :          && base_throw != noexcept_true_spec
    1997                 :           0 :          && base_throw != noexcept_false_spec)
    1998                 :           6 :         || (over_throw
    1999                 :           6 :             && over_throw != noexcept_true_spec
    2000                 :           6 :             && over_throw != noexcept_false_spec))
    2001                 :             :       return true;
    2002                 :             : 
    2003                 :     3295243 :   if (!comp_except_specs (base_throw, over_throw, ce_derived))
    2004                 :             :     {
    2005                 :          42 :       auto_diagnostic_group d;
    2006                 :          42 :       error ("looser exception specification on overriding virtual function "
    2007                 :             :              "%q+#F", overrider);
    2008                 :          42 :       inform (DECL_SOURCE_LOCATION (basefn),
    2009                 :             :               "overridden function is %q#F", basefn);
    2010                 :          42 :       DECL_INVALID_OVERRIDER_P (overrider) = 1;
    2011                 :          42 :       return false;
    2012                 :          42 :     }
    2013                 :             :   return true;
    2014                 :             : }
    2015                 :             : 
    2016                 :             : /* Check that virtual overrider OVERRIDER is acceptable for base function
    2017                 :             :    BASEFN. Issue diagnostic, and return zero, if unacceptable.  */
    2018                 :             : 
    2019                 :             : static int
    2020                 :     3295309 : check_final_overrider (tree overrider, tree basefn)
    2021                 :             : {
    2022                 :     3295309 :   tree over_type = TREE_TYPE (overrider);
    2023                 :     3295309 :   tree base_type = TREE_TYPE (basefn);
    2024                 :     3295309 :   tree over_return = fndecl_declared_return_type (overrider);
    2025                 :     3295309 :   tree base_return = fndecl_declared_return_type (basefn);
    2026                 :             : 
    2027                 :     3295309 :   int fail = 0;
    2028                 :             : 
    2029                 :     3295309 :   if (DECL_INVALID_OVERRIDER_P (overrider))
    2030                 :             :     return 0;
    2031                 :             : 
    2032                 :     3295303 :   if (same_type_p (base_return, over_return))
    2033                 :             :     /* OK */;
    2034                 :           0 :   else if ((CLASS_TYPE_P (over_return) && CLASS_TYPE_P (base_return))
    2035                 :         295 :            || (TREE_CODE (base_return) == TREE_CODE (over_return)
    2036                 :         280 :                && INDIRECT_TYPE_P (base_return)))
    2037                 :             :     {
    2038                 :             :       /* Potentially covariant.  */
    2039                 :         280 :       unsigned base_quals, over_quals;
    2040                 :             : 
    2041                 :         280 :       fail = !INDIRECT_TYPE_P (base_return);
    2042                 :         280 :       if (!fail)
    2043                 :             :         {
    2044                 :         280 :           if (cp_type_quals (base_return) != cp_type_quals (over_return))
    2045                 :           0 :             fail = 1;
    2046                 :             : 
    2047                 :         280 :           if (TYPE_REF_P (base_return)
    2048                 :         280 :               && (TYPE_REF_IS_RVALUE (base_return)
    2049                 :          60 :                   != TYPE_REF_IS_RVALUE (over_return)))
    2050                 :             :             fail = 1;
    2051                 :             : 
    2052                 :         280 :           base_return = TREE_TYPE (base_return);
    2053                 :         280 :           over_return = TREE_TYPE (over_return);
    2054                 :             :         }
    2055                 :         280 :       base_quals = cp_type_quals (base_return);
    2056                 :         280 :       over_quals = cp_type_quals (over_return);
    2057                 :             : 
    2058                 :         280 :       if ((base_quals & over_quals) != over_quals)
    2059                 :           3 :         fail = 1;
    2060                 :             : 
    2061                 :         280 :       if (CLASS_TYPE_P (base_return) && CLASS_TYPE_P (over_return))
    2062                 :             :         {
    2063                 :             :           /* Strictly speaking, the standard requires the return type to be
    2064                 :             :              complete even if it only differs in cv-quals, but that seems
    2065                 :             :              like a bug in the wording.  */
    2066                 :         271 :           if (!same_type_ignoring_top_level_qualifiers_p (base_return,
    2067                 :             :                                                           over_return))
    2068                 :             :             {
    2069                 :         261 :               tree binfo = lookup_base (over_return, base_return,
    2070                 :             :                                         ba_check, NULL, tf_none);
    2071                 :             : 
    2072                 :         261 :               if (!binfo || binfo == error_mark_node)
    2073                 :             :                 fail = 1;
    2074                 :             :             }
    2075                 :             :         }
    2076                 :           9 :       else if (can_convert_standard (TREE_TYPE (base_type),
    2077                 :           9 :                                      TREE_TYPE (over_type),
    2078                 :             :                                      tf_warning_or_error))
    2079                 :             :         /* GNU extension, allow trivial pointer conversions such as
    2080                 :             :            converting to void *, or qualification conversion.  */
    2081                 :             :         {
    2082                 :           0 :           auto_diagnostic_group d;
    2083                 :           0 :           if (pedwarn (DECL_SOURCE_LOCATION (overrider), 0,
    2084                 :             :                        "invalid covariant return type for %q#D", overrider))
    2085                 :           0 :             inform (DECL_SOURCE_LOCATION (basefn),
    2086                 :             :                     "overridden function is %q#D", basefn);
    2087                 :           0 :         }
    2088                 :             :       else
    2089                 :             :         fail = 2;
    2090                 :             :     }
    2091                 :             :   else
    2092                 :             :     fail = 2;
    2093                 :         256 :   if (!fail)
    2094                 :             :     /* OK */;
    2095                 :             :   else
    2096                 :             :     {
    2097                 :          45 :       auto_diagnostic_group d;
    2098                 :          45 :       if (fail == 1)
    2099                 :          21 :         error ("invalid covariant return type for %q+#D", overrider);
    2100                 :             :       else
    2101                 :          24 :         error ("conflicting return type specified for %q+#D", overrider);
    2102                 :          45 :       inform (DECL_SOURCE_LOCATION (basefn),
    2103                 :             :               "overridden function is %q#D", basefn);
    2104                 :          45 :       DECL_INVALID_OVERRIDER_P (overrider) = 1;
    2105                 :          45 :       return 0;
    2106                 :          45 :     }
    2107                 :             : 
    2108                 :     3295258 :   if (!maybe_check_overriding_exception_spec (overrider, basefn))
    2109                 :             :     return 0;
    2110                 :             : 
    2111                 :             :   /* Check for conflicting type attributes.  But leave transaction_safe for
    2112                 :             :      set_one_vmethod_tm_attributes.  */
    2113                 :     3295216 :   if (!comp_type_attributes (over_type, base_type)
    2114                 :          63 :       && !tx_safe_fn_type_p (base_type)
    2115                 :     3295223 :       && !tx_safe_fn_type_p (over_type))
    2116                 :             :     {
    2117                 :           0 :       auto_diagnostic_group d;
    2118                 :           0 :       error ("conflicting type attributes specified for %q+#D", overrider);
    2119                 :           0 :       inform (DECL_SOURCE_LOCATION (basefn),
    2120                 :             :               "overridden function is %q#D", basefn);
    2121                 :           0 :       DECL_INVALID_OVERRIDER_P (overrider) = 1;
    2122                 :           0 :       return 0;
    2123                 :           0 :     }
    2124                 :             : 
    2125                 :             :   /* A consteval virtual function shall not override a virtual function that is
    2126                 :             :      not consteval. A consteval virtual function shall not be overridden by a
    2127                 :             :      virtual function that is not consteval.  */
    2128                 :     9885648 :   if (DECL_IMMEDIATE_FUNCTION_P (overrider)
    2129                 :     6590432 :       != DECL_IMMEDIATE_FUNCTION_P (basefn))
    2130                 :             :     {
    2131                 :           6 :       auto_diagnostic_group d;
    2132                 :          12 :       if (DECL_IMMEDIATE_FUNCTION_P (overrider))
    2133                 :           3 :         error ("%<consteval%> function %q+D overriding non-%<consteval%> "
    2134                 :             :                "function", overrider);
    2135                 :             :       else
    2136                 :           3 :         error ("non-%<consteval%> function %q+D overriding %<consteval%> "
    2137                 :             :                "function", overrider);
    2138                 :           6 :       inform (DECL_SOURCE_LOCATION (basefn),
    2139                 :             :               "overridden function is %qD", basefn);
    2140                 :           6 :       DECL_INVALID_OVERRIDER_P (overrider) = 1;
    2141                 :           6 :       return 0;
    2142                 :           6 :     }
    2143                 :             : 
    2144                 :             :   /* A function declared transaction_safe_dynamic that overrides a function
    2145                 :             :      declared transaction_safe (but not transaction_safe_dynamic) is
    2146                 :             :      ill-formed.  */
    2147                 :     3295210 :   if (tx_safe_fn_type_p (base_type)
    2148                 :          72 :       && lookup_attribute ("transaction_safe_dynamic",
    2149                 :          72 :                            DECL_ATTRIBUTES (overrider))
    2150                 :     3295223 :       && !lookup_attribute ("transaction_safe_dynamic",
    2151                 :          13 :                             DECL_ATTRIBUTES (basefn)))
    2152                 :             :     {
    2153                 :           1 :       auto_diagnostic_group d;
    2154                 :           1 :       error_at (DECL_SOURCE_LOCATION (overrider),
    2155                 :             :                 "%qD declared %<transaction_safe_dynamic%>", overrider);
    2156                 :           1 :       inform (DECL_SOURCE_LOCATION (basefn),
    2157                 :             :               "overriding %qD declared %<transaction_safe%>", basefn);
    2158                 :           1 :     }
    2159                 :             : 
    2160                 :     3295210 :   if (DECL_DELETED_FN (basefn) != DECL_DELETED_FN (overrider))
    2161                 :             :     {
    2162                 :          15 :       if (DECL_DELETED_FN (overrider))
    2163                 :             :         {
    2164                 :          12 :           auto_diagnostic_group d;
    2165                 :          12 :           error ("deleted function %q+D overriding non-deleted function",
    2166                 :             :                  overrider);
    2167                 :          12 :           inform (DECL_SOURCE_LOCATION (basefn),
    2168                 :             :                   "overridden function is %qD", basefn);
    2169                 :          12 :           maybe_explain_implicit_delete (overrider);
    2170                 :          12 :         }
    2171                 :             :       else
    2172                 :             :         {
    2173                 :           3 :           auto_diagnostic_group d;
    2174                 :           3 :           error ("non-deleted function %q+D overriding deleted function",
    2175                 :             :                  overrider);
    2176                 :           3 :           inform (DECL_SOURCE_LOCATION (basefn),
    2177                 :             :                   "overridden function is %qD", basefn);
    2178                 :           3 :         }
    2179                 :          15 :       return 0;
    2180                 :             :     }
    2181                 :             : 
    2182                 :     3295195 :   if (!DECL_HAS_CONTRACTS_P (basefn) && DECL_HAS_CONTRACTS_P (overrider))
    2183                 :             :     {
    2184                 :           0 :       auto_diagnostic_group d;
    2185                 :           0 :       error ("function with contracts %q+D overriding contractless function",
    2186                 :             :              overrider);
    2187                 :           0 :       inform (DECL_SOURCE_LOCATION (basefn),
    2188                 :             :               "overridden function is %qD", basefn);
    2189                 :           0 :       return 0;
    2190                 :           0 :     }
    2191                 :     3295195 :   else if (DECL_HAS_CONTRACTS_P (basefn) && !DECL_HAS_CONTRACTS_P (overrider))
    2192                 :             :     {
    2193                 :             :       /* We're inheriting basefn's contracts; create a copy of them but
    2194                 :             :          replace references to their parms to our parms.  */
    2195                 :          12 :       inherit_base_contracts (overrider, basefn);
    2196                 :             :     }
    2197                 :     3295183 :   else if (DECL_HAS_CONTRACTS_P (basefn) && DECL_HAS_CONTRACTS_P (overrider))
    2198                 :             :     {
    2199                 :             :       /* We're in the process of completing the overrider's class, which means
    2200                 :             :          our conditions definitely are not parsed so simply chain on the
    2201                 :             :          basefn for later checking.
    2202                 :             : 
    2203                 :             :          Note that OVERRIDER's contracts will have been fully parsed at the
    2204                 :             :          point the deferred match is run.  */
    2205                 :          20 :       defer_guarded_contract_match (overrider, basefn, DECL_CONTRACTS (basefn));
    2206                 :             :     }
    2207                 :             : 
    2208                 :     3295195 :   if (DECL_FINAL_P (basefn))
    2209                 :             :     {
    2210                 :           6 :       auto_diagnostic_group d;
    2211                 :           6 :       error ("virtual function %q+D overriding final function", overrider);
    2212                 :           6 :       inform (DECL_SOURCE_LOCATION (basefn),
    2213                 :             :               "overridden function is %qD", basefn);
    2214                 :           6 :       return 0;
    2215                 :           6 :     }
    2216                 :             :   return 1;
    2217                 :             : }
    2218                 :             : 
    2219                 :             : /* Given a class TYPE, and a function decl FNDECL, look for
    2220                 :             :    virtual functions in TYPE's hierarchy which FNDECL overrides.
    2221                 :             :    We do not look in TYPE itself, only its bases.
    2222                 :             : 
    2223                 :             :    Returns nonzero, if we find any. Set FNDECL's DECL_VIRTUAL_P, if we
    2224                 :             :    find that it overrides anything.
    2225                 :             : 
    2226                 :             :    We check that every function which is overridden, is correctly
    2227                 :             :    overridden.  */
    2228                 :             : 
    2229                 :             : int
    2230                 :    14079150 : look_for_overrides (tree type, tree fndecl)
    2231                 :             : {
    2232                 :    14079150 :   tree binfo = TYPE_BINFO (type);
    2233                 :    14079150 :   tree base_binfo;
    2234                 :    14079150 :   int ix;
    2235                 :    14079150 :   int found = 0;
    2236                 :             : 
    2237                 :             :   /* A constructor for a class T does not override a function T
    2238                 :             :      in a base class.  */
    2239                 :    28158300 :   if (DECL_CONSTRUCTOR_P (fndecl))
    2240                 :             :     return 0;
    2241                 :             : 
    2242                 :    21868966 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    2243                 :             :     {
    2244                 :     7789816 :       tree basetype = BINFO_TYPE (base_binfo);
    2245                 :             : 
    2246                 :     7789816 :       if (TYPE_POLYMORPHIC_P (basetype))
    2247                 :     4853168 :         found += look_for_overrides_r (basetype, fndecl);
    2248                 :             :     }
    2249                 :             :   return found;
    2250                 :             : }
    2251                 :             : 
    2252                 :             : /* Look in TYPE for virtual functions with the same signature as
    2253                 :             :    FNDECL.  */
    2254                 :             : 
    2255                 :             : tree
    2256                 :    23276848 : look_for_overrides_here (tree type, tree fndecl)
    2257                 :             : {
    2258                 :    23276848 :   tree ovl = get_class_binding (type, DECL_NAME (fndecl));
    2259                 :             : 
    2260                 :    24063809 :   for (ovl_iterator iter (ovl); iter; ++iter)
    2261                 :             :     {
    2262                 :    18201466 :       tree fn = *iter;
    2263                 :             : 
    2264                 :    18201466 :       if (!DECL_VIRTUAL_P (fn))
    2265                 :             :         /* Not a virtual.  */;
    2266                 :    18151113 :       else if (DECL_CONTEXT (fn) != type)
    2267                 :             :         /* Introduced with a using declaration.  */;
    2268                 :    18150959 :       else if (DECL_STATIC_FUNCTION_P (fndecl)
    2269                 :    18150959 :                || DECL_XOBJ_MEMBER_FUNCTION_P (fndecl))
    2270                 :             :         {
    2271                 :          28 :           tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
    2272                 :          28 :           tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
    2273                 :          28 :           dtypes = DECL_XOBJ_MEMBER_FUNCTION_P (fndecl) ? TREE_CHAIN (dtypes)
    2274                 :             :                                                         : dtypes;
    2275                 :          28 :           if (compparms (TREE_CHAIN (btypes), dtypes))
    2276                 :    17782187 :             return fn;
    2277                 :             :         }
    2278                 :    18150931 :       else if (same_signature_p (fndecl, fn))
    2279                 :             :         return fn;
    2280                 :             :     }
    2281                 :             : 
    2282                 :     5494661 :   return NULL_TREE;
    2283                 :             : }
    2284                 :             : 
    2285                 :             : /* Look in TYPE for virtual functions overridden by FNDECL. Check both
    2286                 :             :    TYPE itself and its bases.  */
    2287                 :             : 
    2288                 :             : static int
    2289                 :     4853168 : look_for_overrides_r (tree type, tree fndecl)
    2290                 :             : {
    2291                 :     4853168 :   tree fn = look_for_overrides_here (type, fndecl);
    2292                 :     4853168 :   if (fn)
    2293                 :             :     {
    2294                 :     3295331 :       if (DECL_STATIC_FUNCTION_P (fndecl))
    2295                 :             :         {
    2296                 :             :           /* A static member function cannot match an inherited
    2297                 :             :              virtual member function.  */
    2298                 :           6 :           auto_diagnostic_group d;
    2299                 :           6 :           error ("%q+#D cannot be declared", fndecl);
    2300                 :           6 :           error ("  since %q+#D declared in base class", fn);
    2301                 :           6 :         }
    2302                 :     3295325 :       else if (DECL_XOBJ_MEMBER_FUNCTION_P (fndecl))
    2303                 :             :         {
    2304                 :          16 :           auto_diagnostic_group d;
    2305                 :          16 :           error_at (DECL_SOURCE_LOCATION (fndecl),
    2306                 :             :                     "explicit object member function "
    2307                 :             :                     "overrides virtual function");
    2308                 :          16 :           inform (DECL_SOURCE_LOCATION (fn),
    2309                 :             :                   "virtual function declared here");
    2310                 :          16 :         }
    2311                 :             :       else
    2312                 :             :         {
    2313                 :             :           /* It's definitely virtual, even if not explicitly set.  */
    2314                 :     3295309 :           DECL_VIRTUAL_P (fndecl) = 1;
    2315                 :     3295309 :           check_final_overrider (fndecl, fn);
    2316                 :             :         }
    2317                 :     3295331 :       return 1;
    2318                 :             :     }
    2319                 :             : 
    2320                 :             :   /* We failed to find one declared in this class. Look in its bases.  */
    2321                 :     1557837 :   return look_for_overrides (type, fndecl);
    2322                 :             : }
    2323                 :             : 
    2324                 :             : /* Called via dfs_walk from dfs_get_pure_virtuals.  */
    2325                 :             : 
    2326                 :             : static tree
    2327                 :     4645580 : dfs_get_pure_virtuals (tree binfo, void *data)
    2328                 :             : {
    2329                 :     4645580 :   tree type = (tree) data;
    2330                 :             : 
    2331                 :             :   /* We're not interested in primary base classes; the derived class
    2332                 :             :      of which they are a primary base will contain the information we
    2333                 :             :      need.  */
    2334                 :     4645580 :   if (!BINFO_PRIMARY_P (binfo))
    2335                 :             :     {
    2336                 :     2261245 :       tree virtuals;
    2337                 :             : 
    2338                 :     2261245 :       for (virtuals = BINFO_VIRTUALS (binfo);
    2339                 :    11203855 :            virtuals;
    2340                 :     8942610 :            virtuals = TREE_CHAIN (virtuals))
    2341                 :     8942610 :         if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals)))
    2342                 :      516756 :           vec_safe_push (CLASSTYPE_PURE_VIRTUALS (type), BV_FN (virtuals));
    2343                 :             :     }
    2344                 :             : 
    2345                 :     4645580 :   return NULL_TREE;
    2346                 :             : }
    2347                 :             : 
    2348                 :             : /* Set CLASSTYPE_PURE_VIRTUALS for TYPE.  */
    2349                 :             : 
    2350                 :             : void
    2351                 :     1443584 : get_pure_virtuals (tree type)
    2352                 :             : {
    2353                 :             :   /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
    2354                 :             :      is going to be overridden.  */
    2355                 :     1443584 :   CLASSTYPE_PURE_VIRTUALS (type) = NULL;
    2356                 :             :   /* Now, run through all the bases which are not primary bases, and
    2357                 :             :      collect the pure virtual functions.  We look at the vtable in
    2358                 :             :      each class to determine what pure virtual functions are present.
    2359                 :             :      (A primary base is not interesting because the derived class of
    2360                 :             :      which it is a primary base will contain vtable entries for the
    2361                 :             :      pure virtuals in the base class.  */
    2362                 :     1443584 :   dfs_walk_once (TYPE_BINFO (type), NULL, dfs_get_pure_virtuals, type);
    2363                 :     1443584 : }
    2364                 :             : 
    2365                 :             : /* Debug info for C++ classes can get very large; try to avoid
    2366                 :             :    emitting it everywhere.
    2367                 :             : 
    2368                 :             :    Note that this optimization wins even when the target supports
    2369                 :             :    BINCL (if only slightly), and reduces the amount of work for the
    2370                 :             :    linker.  */
    2371                 :             : 
    2372                 :             : void
    2373                 :    35009030 : maybe_suppress_debug_info (tree t)
    2374                 :             : {
    2375                 :    35009030 :   if (write_symbols == NO_DEBUG)
    2376                 :             :     return;
    2377                 :             : 
    2378                 :             :   /* We might have set this earlier in cp_finish_decl.  */
    2379                 :    33460495 :   TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 0;
    2380                 :             : 
    2381                 :             :   /* Always emit the information for each class every time. */
    2382                 :    33460495 :   if (flag_emit_class_debug_always)
    2383                 :             :     return;
    2384                 :             : 
    2385                 :             :   /* If we already know how we're handling this class, handle debug info
    2386                 :             :      the same way.  */
    2387                 :    33460495 :   if (CLASSTYPE_INTERFACE_KNOWN (t))
    2388                 :             :     {
    2389                 :           1 :       if (CLASSTYPE_INTERFACE_ONLY (t))
    2390                 :           1 :         TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
    2391                 :             :       /* else don't set it.  */
    2392                 :             :     }
    2393                 :             :   /* If the class has a vtable, write out the debug info along with
    2394                 :             :      the vtable.  */
    2395                 :    33460494 :   else if (TYPE_CONTAINS_VPTR_P (t))
    2396                 :     1546842 :     TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
    2397                 :             : 
    2398                 :             :   /* Otherwise, just emit the debug info normally.  */
    2399                 :             : }
    2400                 :             : 
    2401                 :             : /* Note that we want debugging information for a base class of a class
    2402                 :             :    whose vtable is being emitted.  Normally, this would happen because
    2403                 :             :    calling the constructor for a derived class implies calling the
    2404                 :             :    constructors for all bases, which involve initializing the
    2405                 :             :    appropriate vptr with the vtable for the base class; but in the
    2406                 :             :    presence of optimization, this initialization may be optimized
    2407                 :             :    away, so we tell finish_vtable_vardecl that we want the debugging
    2408                 :             :    information anyway.  */
    2409                 :             : 
    2410                 :             : static tree
    2411                 :      669062 : dfs_debug_mark (tree binfo, void * /*data*/)
    2412                 :             : {
    2413                 :      669062 :   tree t = BINFO_TYPE (binfo);
    2414                 :             : 
    2415                 :      669062 :   if (CLASSTYPE_DEBUG_REQUESTED (t))
    2416                 :             :     return dfs_skip_bases;
    2417                 :             : 
    2418                 :      417302 :   CLASSTYPE_DEBUG_REQUESTED (t) = 1;
    2419                 :             : 
    2420                 :      417302 :   return NULL_TREE;
    2421                 :             : }
    2422                 :             : 
    2423                 :             : /* Write out the debugging information for TYPE, whose vtable is being
    2424                 :             :    emitted.  Also walk through our bases and note that we want to
    2425                 :             :    write out information for them.  This avoids the problem of not
    2426                 :             :    writing any debug info for intermediate basetypes whose
    2427                 :             :    constructors, and thus the references to their vtables, and thus
    2428                 :             :    the vtables themselves, were optimized away.  */
    2429                 :             : 
    2430                 :             : void
    2431                 :      308347 : note_debug_info_needed (tree type)
    2432                 :             : {
    2433                 :      308347 :   if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
    2434                 :             :     {
    2435                 :      265284 :       TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)) = 0;
    2436                 :      265284 :       rest_of_type_compilation (type, namespace_bindings_p ());
    2437                 :             :     }
    2438                 :             : 
    2439                 :      308347 :   dfs_walk_all (TYPE_BINFO (type), dfs_debug_mark, NULL, 0);
    2440                 :      308347 : }
    2441                 :             : 
    2442                 :             : /* Helper for lookup_conversions_r.  TO_TYPE is the type converted to
    2443                 :             :    by a conversion op in base BINFO.  VIRTUAL_DEPTH is nonzero if
    2444                 :             :    BINFO is morally virtual, and VIRTUALNESS is nonzero if virtual
    2445                 :             :    bases have been encountered already in the tree walk.  PARENT_CONVS
    2446                 :             :    is the list of lists of conversion functions that could hide CONV
    2447                 :             :    and OTHER_CONVS is the list of lists of conversion functions that
    2448                 :             :    could hide or be hidden by CONV, should virtualness be involved in
    2449                 :             :    the hierarchy.  Merely checking the conversion op's name is not
    2450                 :             :    enough because two conversion operators to the same type can have
    2451                 :             :    different names.  Return nonzero if we are visible.  */
    2452                 :             : 
    2453                 :             : static int
    2454                 :    15774580 : check_hidden_convs (tree binfo, int virtual_depth, int virtualness,
    2455                 :             :                     tree to_type, tree parent_convs, tree other_convs)
    2456                 :             : {
    2457                 :    15774580 :   tree level, probe;
    2458                 :             : 
    2459                 :             :   /* See if we are hidden by a parent conversion.  */
    2460                 :    15776337 :   for (level = parent_convs; level; level = TREE_CHAIN (level))
    2461                 :        7820 :     for (probe = TREE_VALUE (level); probe; probe = TREE_CHAIN (probe))
    2462                 :        6063 :       if (same_type_p (to_type, TREE_TYPE (probe)))
    2463                 :             :         return 0;
    2464                 :             : 
    2465                 :    15770340 :   if (virtual_depth || virtualness)
    2466                 :             :     {
    2467                 :             :      /* In a virtual hierarchy, we could be hidden, or could hide a
    2468                 :             :         conversion function on the other_convs list.  */
    2469                 :       79497 :       for (level = other_convs; level; level = TREE_CHAIN (level))
    2470                 :             :         {
    2471                 :        1507 :           int we_hide_them;
    2472                 :        1507 :           int they_hide_us;
    2473                 :        1507 :           tree *prev, other;
    2474                 :             : 
    2475                 :        1507 :           if (!(virtual_depth || TREE_STATIC (level)))
    2476                 :             :             /* Neither is morally virtual, so cannot hide each other.  */
    2477                 :           0 :             continue;
    2478                 :             : 
    2479                 :        1507 :           if (!TREE_VALUE (level))
    2480                 :             :             /* They evaporated away already.  */
    2481                 :           0 :             continue;
    2482                 :             : 
    2483                 :        3014 :           they_hide_us = (virtual_depth
    2484                 :        1507 :                           && original_binfo (binfo, TREE_PURPOSE (level)));
    2485                 :           6 :           we_hide_them = (!they_hide_us && TREE_STATIC (level)
    2486                 :           6 :                           && original_binfo (TREE_PURPOSE (level), binfo));
    2487                 :             : 
    2488                 :        1501 :           if (!(we_hide_them || they_hide_us))
    2489                 :             :             /* Neither is within the other, so no hiding can occur.  */
    2490                 :           0 :             continue;
    2491                 :             : 
    2492                 :        1513 :           for (prev = &TREE_VALUE (level), other = *prev; other;)
    2493                 :             :             {
    2494                 :        1507 :               if (same_type_p (to_type, TREE_TYPE (other)))
    2495                 :             :                 {
    2496                 :        1507 :                   if (they_hide_us)
    2497                 :             :                     /* We are hidden.  */
    2498                 :             :                     return 0;
    2499                 :             : 
    2500                 :           6 :                   if (we_hide_them)
    2501                 :             :                     {
    2502                 :             :                       /* We hide the other one.  */
    2503                 :           6 :                       other = TREE_CHAIN (other);
    2504                 :           6 :                       *prev = other;
    2505                 :           6 :                       continue;
    2506                 :             :                     }
    2507                 :             :                 }
    2508                 :           0 :               prev = &TREE_CHAIN (other);
    2509                 :           0 :               other = *prev;
    2510                 :             :             }
    2511                 :             :         }
    2512                 :             :     }
    2513                 :             :   return 1;
    2514                 :             : }
    2515                 :             : 
    2516                 :             : /* Helper for lookup_conversions_r.  PARENT_CONVS is a list of lists
    2517                 :             :    of conversion functions, the first slot will be for the current
    2518                 :             :    binfo, if MY_CONVS is non-NULL.  CHILD_CONVS is the list of lists
    2519                 :             :    of conversion functions from children of the current binfo,
    2520                 :             :    concatenated with conversions from elsewhere in the hierarchy --
    2521                 :             :    that list begins with OTHER_CONVS.  Return a single list of lists
    2522                 :             :    containing only conversions from the current binfo and its
    2523                 :             :    children.  */
    2524                 :             : 
    2525                 :             : static tree
    2526                 :    14834478 : split_conversions (tree my_convs, tree parent_convs,
    2527                 :             :                    tree child_convs, tree other_convs)
    2528                 :             : {
    2529                 :    14834478 :   tree t;
    2530                 :    14834478 :   tree prev;
    2531                 :             : 
    2532                 :             :   /* Remove the original other_convs portion from child_convs.  */
    2533                 :    14834478 :   for (prev = NULL, t = child_convs;
    2534                 :    15662692 :        t != other_convs; prev = t, t = TREE_CHAIN (t))
    2535                 :      828214 :     continue;
    2536                 :             : 
    2537                 :    14834478 :   if (prev)
    2538                 :      828113 :     TREE_CHAIN (prev) = NULL_TREE;
    2539                 :             :   else
    2540                 :             :     child_convs = NULL_TREE;
    2541                 :             : 
    2542                 :             :   /* Attach the child convs to any we had at this level.  */
    2543                 :    14834478 :   if (my_convs)
    2544                 :             :     {
    2545                 :    14002161 :       my_convs = parent_convs;
    2546                 :    14002161 :       TREE_CHAIN (my_convs) = child_convs;
    2547                 :             :     }
    2548                 :             :   else
    2549                 :             :     my_convs = child_convs;
    2550                 :             : 
    2551                 :    14834478 :   return my_convs;
    2552                 :      828214 : }
    2553                 :             : 
    2554                 :             : /* Worker for lookup_conversions.  Lookup conversion functions in
    2555                 :             :    BINFO and its children.  VIRTUAL_DEPTH is nonzero, if BINFO is in a
    2556                 :             :    morally virtual base, and VIRTUALNESS is nonzero, if we've
    2557                 :             :    encountered virtual bases already in the tree walk.  PARENT_CONVS
    2558                 :             :    is a list of conversions within parent binfos.  OTHER_CONVS are
    2559                 :             :    conversions found elsewhere in the tree.  Return the conversions
    2560                 :             :    found within this portion of the graph in CONVS.  Return nonzero if
    2561                 :             :    we encountered virtualness.  We keep template and non-template
    2562                 :             :    conversions separate, to avoid unnecessary type comparisons.
    2563                 :             : 
    2564                 :             :    The located conversion functions are held in lists of lists.  The
    2565                 :             :    TREE_VALUE of the outer list is the list of conversion functions
    2566                 :             :    found in a particular binfo.  The TREE_PURPOSE of both the outer
    2567                 :             :    and inner lists is the binfo at which those conversions were
    2568                 :             :    found.  TREE_STATIC is set for those lists within of morally
    2569                 :             :    virtual binfos.  The TREE_VALUE of the inner list is the conversion
    2570                 :             :    function or overload itself.  The TREE_TYPE of each inner list node
    2571                 :             :    is the converted-to type.  */
    2572                 :             : 
    2573                 :             : static int
    2574                 :    39768626 : lookup_conversions_r (tree binfo, int virtual_depth, int virtualness,
    2575                 :             :                       tree parent_convs, tree other_convs, tree *convs)
    2576                 :             : {
    2577                 :    39768626 :   int my_virtualness = 0;
    2578                 :    39768626 :   tree my_convs = NULL_TREE;
    2579                 :    39768626 :   tree child_convs = NULL_TREE;
    2580                 :             : 
    2581                 :             :   /* If we have no conversion operators, then don't look.  */
    2582                 :    39768626 :   if (!TYPE_HAS_CONVERSION (BINFO_TYPE (binfo)))
    2583                 :             :     {
    2584                 :    24934148 :       *convs = NULL_TREE;
    2585                 :             : 
    2586                 :    24934148 :       return 0;
    2587                 :             :     }
    2588                 :             : 
    2589                 :    14834478 :   if (BINFO_VIRTUAL_P (binfo))
    2590                 :       79497 :     virtual_depth++;
    2591                 :             : 
    2592                 :             :   /* First, locate the unhidden ones at this level.  */
    2593                 :    14834478 :   if (tree conv = get_class_binding (BINFO_TYPE (binfo), conv_op_identifier))
    2594                 :    32322304 :   for (ovl_iterator iter (conv); iter; ++iter)
    2595                 :             :     {
    2596                 :    15774580 :       tree fn = *iter;
    2597                 :    15774580 :       tree type = DECL_CONV_FN_TYPE (fn);
    2598                 :             : 
    2599                 :    15774580 :       if (TREE_CODE (fn) != TEMPLATE_DECL && type_uses_auto (type))
    2600                 :             :         {
    2601                 :           3 :           mark_used (fn);
    2602                 :           3 :           type = DECL_CONV_FN_TYPE (fn);
    2603                 :             :         }
    2604                 :             : 
    2605                 :    15774580 :       if (check_hidden_convs (binfo, virtual_depth, virtualness,
    2606                 :             :                               type, parent_convs, other_convs))
    2607                 :             :         {
    2608                 :    15768839 :           my_convs = tree_cons (binfo, fn, my_convs);
    2609                 :    15768839 :           TREE_TYPE (my_convs) = type;
    2610                 :    15768839 :           if (virtual_depth)
    2611                 :             :             {
    2612                 :       77984 :               TREE_STATIC (my_convs) = 1;
    2613                 :       77984 :               my_virtualness = 1;
    2614                 :             :             }
    2615                 :             :         }
    2616                 :             :     }
    2617                 :             : 
    2618                 :    14005843 :   if (my_convs)
    2619                 :             :     {
    2620                 :    14002161 :       parent_convs = tree_cons (binfo, my_convs, parent_convs);
    2621                 :    14002161 :       if (virtual_depth)
    2622                 :       77984 :         TREE_STATIC (parent_convs) = 1;
    2623                 :             :     }
    2624                 :             : 
    2625                 :    14834478 :   child_convs = other_convs;
    2626                 :             : 
    2627                 :             :   /* Now iterate over each base, looking for more conversions.  */
    2628                 :    14834478 :   unsigned i;
    2629                 :    14834478 :   tree base_binfo;
    2630                 :    16328138 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    2631                 :             :     {
    2632                 :     1493660 :       tree base_convs;
    2633                 :     1493660 :       unsigned base_virtualness;
    2634                 :             : 
    2635                 :     1493660 :       base_virtualness = lookup_conversions_r (base_binfo,
    2636                 :             :                                                virtual_depth, virtualness,
    2637                 :             :                                                parent_convs, child_convs,
    2638                 :             :                                                &base_convs);
    2639                 :     1493660 :       if (base_virtualness)
    2640                 :       97975 :         my_virtualness = virtualness = 1;
    2641                 :     1493660 :       child_convs = chainon (base_convs, child_convs);
    2642                 :             :     }
    2643                 :             : 
    2644                 :    14834478 :   *convs = split_conversions (my_convs, parent_convs,
    2645                 :             :                               child_convs, other_convs);
    2646                 :             : 
    2647                 :    14834478 :   return my_virtualness;
    2648                 :             : }
    2649                 :             : 
    2650                 :             : /* Return a TREE_LIST containing all the non-hidden user-defined
    2651                 :             :    conversion functions for TYPE (and its base-classes).  The
    2652                 :             :    TREE_VALUE of each node is the FUNCTION_DECL of the conversion
    2653                 :             :    function.  The TREE_PURPOSE is the BINFO from which the conversion
    2654                 :             :    functions in this node were selected.  This function is effectively
    2655                 :             :    performing a set of member lookups as lookup_fnfield does, but
    2656                 :             :    using the type being converted to as the unique key, rather than the
    2657                 :             :    field name.  */
    2658                 :             : 
    2659                 :             : tree
    2660                 :    38275126 : lookup_conversions (tree type)
    2661                 :             : {
    2662                 :    38275126 :   tree convs;
    2663                 :             : 
    2664                 :    38275126 :   complete_type (type);
    2665                 :    38275126 :   if (!CLASS_TYPE_P (type) || !TYPE_BINFO (type))
    2666                 :             :     return NULL_TREE;
    2667                 :             : 
    2668                 :    38274966 :   lookup_conversions_r (TYPE_BINFO (type), 0, 0, NULL_TREE, NULL_TREE, &convs);
    2669                 :             : 
    2670                 :    38274966 :   tree list = NULL_TREE;
    2671                 :             : 
    2672                 :             :   /* Flatten the list-of-lists */
    2673                 :    52277127 :   for (; convs; convs = TREE_CHAIN (convs))
    2674                 :             :     {
    2675                 :    14002161 :       tree probe, next;
    2676                 :             : 
    2677                 :    29770994 :       for (probe = TREE_VALUE (convs); probe; probe = next)
    2678                 :             :         {
    2679                 :    15768833 :           next = TREE_CHAIN (probe);
    2680                 :             : 
    2681                 :    15768833 :           TREE_CHAIN (probe) = list;
    2682                 :    15768833 :           list = probe;
    2683                 :             :         }
    2684                 :             :     }
    2685                 :             : 
    2686                 :             :   return list;
    2687                 :             : }
    2688                 :             : 
    2689                 :             : /* Returns the binfo of the first direct or indirect virtual base derived
    2690                 :             :    from BINFO, or NULL if binfo is not via virtual.  */
    2691                 :             : 
    2692                 :             : tree
    2693                 :          78 : binfo_from_vbase (tree binfo)
    2694                 :             : {
    2695                 :         123 :   for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
    2696                 :             :     {
    2697                 :         123 :       if (BINFO_VIRTUAL_P (binfo))
    2698                 :             :         return binfo;
    2699                 :             :     }
    2700                 :             :   return NULL_TREE;
    2701                 :             : }
    2702                 :             : 
    2703                 :             : /* Returns the binfo of the first direct or indirect virtual base derived
    2704                 :             :    from BINFO up to the TREE_TYPE, LIMIT, or NULL if binfo is not
    2705                 :             :    via virtual.  */
    2706                 :             : 
    2707                 :             : tree
    2708                 :   358898951 : binfo_via_virtual (tree binfo, tree limit)
    2709                 :             : {
    2710                 :   358898951 :   if (limit && !CLASSTYPE_VBASECLASSES (limit))
    2711                 :             :     /* LIMIT has no virtual bases, so BINFO cannot be via one.  */
    2712                 :             :     return NULL_TREE;
    2713                 :             : 
    2714                 :    12912679 :   for (; binfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), limit);
    2715                 :     1893415 :        binfo = BINFO_INHERITANCE_CHAIN (binfo))
    2716                 :             :     {
    2717                 :     3804143 :       if (BINFO_VIRTUAL_P (binfo))
    2718                 :             :         return binfo;
    2719                 :             :     }
    2720                 :             :   return NULL_TREE;
    2721                 :             : }
    2722                 :             : 
    2723                 :             : /* BINFO is for a base class in some hierarchy.  Return true iff it is a
    2724                 :             :    direct base.  */
    2725                 :             : 
    2726                 :             : bool
    2727                 :       50748 : binfo_direct_p (tree binfo)
    2728                 :             : {
    2729                 :       50748 :   tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
    2730                 :       50748 :   if (BINFO_INHERITANCE_CHAIN (d_binfo))
    2731                 :             :     /* A second inheritance chain means indirect.  */
    2732                 :             :     return false;
    2733                 :       50742 :   if (!BINFO_VIRTUAL_P (binfo))
    2734                 :             :     /* Non-virtual, so only one inheritance chain means direct.  */
    2735                 :             :     return true;
    2736                 :             :   /* A virtual base looks like a direct base, so we need to look through the
    2737                 :             :      direct bases to see if it's there.  */
    2738                 :             :   tree b_binfo;
    2739                 :          27 :   for (int i = 0; BINFO_BASE_ITERATE (d_binfo, i, b_binfo); ++i)
    2740                 :          24 :     if (b_binfo == binfo)
    2741                 :             :       return true;
    2742                 :             :   return false;
    2743                 :             : }
    2744                 :             : 
    2745                 :             : /* BINFO is a base binfo in the complete type BINFO_TYPE (HERE).
    2746                 :             :    Find the equivalent binfo within whatever graph HERE is located.
    2747                 :             :    This is the inverse of original_binfo.  */
    2748                 :             : 
    2749                 :             : tree
    2750                 :    26345460 : copied_binfo (tree binfo, tree here)
    2751                 :             : {
    2752                 :    26345460 :   tree result = NULL_TREE;
    2753                 :             : 
    2754                 :    26345460 :   if (BINFO_VIRTUAL_P (binfo))
    2755                 :             :     {
    2756                 :             :       tree t;
    2757                 :             : 
    2758                 :     6570984 :       for (t = here; BINFO_INHERITANCE_CHAIN (t);
    2759                 :     3413576 :            t = BINFO_INHERITANCE_CHAIN (t))
    2760                 :     3413576 :         continue;
    2761                 :             : 
    2762                 :     3157408 :       result = binfo_for_vbase (BINFO_TYPE (binfo), BINFO_TYPE (t));
    2763                 :     3413576 :     }
    2764                 :    23188052 :   else if (BINFO_INHERITANCE_CHAIN (binfo))
    2765                 :             :     {
    2766                 :    11594026 :       tree cbinfo;
    2767                 :    11594026 :       tree base_binfo;
    2768                 :    11594026 :       int ix;
    2769                 :             : 
    2770                 :    11594026 :       cbinfo = copied_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
    2771                 :    23213898 :       for (ix = 0; BINFO_BASE_ITERATE (cbinfo, ix, base_binfo); ix++)
    2772                 :    11619872 :         if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo)))
    2773                 :             :           {
    2774                 :             :             result = base_binfo;
    2775                 :             :             break;
    2776                 :             :           }
    2777                 :             :     }
    2778                 :             :   else
    2779                 :             :     {
    2780                 :    11594026 :       gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (here), BINFO_TYPE (binfo)));
    2781                 :             :       result = here;
    2782                 :             :     }
    2783                 :             : 
    2784                 :    26345460 :   gcc_assert (result);
    2785                 :    26345460 :   return result;
    2786                 :             : }
    2787                 :             : 
    2788                 :             : tree
    2789                 :     6206524 : binfo_for_vbase (tree base, tree t)
    2790                 :             : {
    2791                 :     6206524 :   unsigned ix;
    2792                 :     6206524 :   tree binfo;
    2793                 :     6206524 :   vec<tree, va_gc> *vbases;
    2794                 :             : 
    2795                 :    67471510 :   for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
    2796                 :    67471510 :        vec_safe_iterate (vbases, ix, &binfo); ix++)
    2797                 :    66181897 :     if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), base))
    2798                 :             :       return binfo;
    2799                 :             :   return NULL;
    2800                 :             : }
    2801                 :             : 
    2802                 :             : /* BINFO is some base binfo of HERE, within some other
    2803                 :             :    hierarchy. Return the equivalent binfo, but in the hierarchy
    2804                 :             :    dominated by HERE.  This is the inverse of copied_binfo.  If BINFO
    2805                 :             :    is not a base binfo of HERE, returns NULL_TREE.  */
    2806                 :             : 
    2807                 :             : tree
    2808                 :        1507 : original_binfo (tree binfo, tree here)
    2809                 :             : {
    2810                 :        1507 :   tree result = NULL;
    2811                 :             : 
    2812                 :        1507 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (here)))
    2813                 :             :     result = here;
    2814                 :          12 :   else if (BINFO_VIRTUAL_P (binfo))
    2815                 :          12 :     result = (CLASSTYPE_VBASECLASSES (BINFO_TYPE (here))
    2816                 :          12 :               ? binfo_for_vbase (BINFO_TYPE (binfo), BINFO_TYPE (here))
    2817                 :             :               : NULL_TREE);
    2818                 :           0 :   else if (BINFO_INHERITANCE_CHAIN (binfo))
    2819                 :             :     {
    2820                 :           0 :       tree base_binfos;
    2821                 :             : 
    2822                 :           0 :       base_binfos = original_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
    2823                 :           0 :       if (base_binfos)
    2824                 :             :         {
    2825                 :             :           int ix;
    2826                 :             :           tree base_binfo;
    2827                 :             : 
    2828                 :           0 :           for (ix = 0; (base_binfo = BINFO_BASE_BINFO (base_binfos, ix)); ix++)
    2829                 :           0 :             if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
    2830                 :             :                                    BINFO_TYPE (binfo)))
    2831                 :             :               {
    2832                 :             :                 result = base_binfo;
    2833                 :             :                 break;
    2834                 :             :               }
    2835                 :             :         }
    2836                 :             :     }
    2837                 :             : 
    2838                 :        1507 :   return result;
    2839                 :             : }
    2840                 :             : 
    2841                 :             : /* True iff TYPE has any dependent bases (and therefore we can't say
    2842                 :             :    definitively that another class is not a base of an instantiation of
    2843                 :             :    TYPE).  */
    2844                 :             : 
    2845                 :             : bool
    2846                 :   123318853 : any_dependent_bases_p (tree type)
    2847                 :             : {
    2848                 :   123318853 :   if (!type || !CLASS_TYPE_P (type) || !uses_template_parms (type))
    2849                 :    81305119 :     return false;
    2850                 :             : 
    2851                 :             :   /* If we haven't set TYPE_BINFO yet, we don't know anything about the bases.
    2852                 :             :      Return false because in this situation we aren't actually looking up names
    2853                 :             :      in the scope of the class, so it doesn't matter whether it has dependent
    2854                 :             :      bases.  */
    2855                 :    42013734 :   if (!TYPE_BINFO (type))
    2856                 :             :     return false;
    2857                 :             : 
    2858                 :             :   unsigned i;
    2859                 :             :   tree base_binfo;
    2860                 :    44145929 :   FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_BINFOS (TYPE_BINFO (type)), i, base_binfo)
    2861                 :    28595964 :     if (BINFO_DEPENDENT_BASE_P (base_binfo))
    2862                 :             :       return true;
    2863                 :             : 
    2864                 :             :   return false;
    2865                 :             : }
        

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.