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

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.