LCOV - code coverage report
Current view: top level - gcc/cp - search.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.4 % 970 935
Test Date: 2026-08-22 16:33:35 Functions: 100.0 % 68 68
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Breadth-first and depth-first routines for
       2              :    searching multiple-inheritance lattice for GNU C++.
       3              :    Copyright (C) 1987-2026 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   1030459645 : dfs_lookup_base (tree binfo, void *data_)
      77              : {
      78   1030459645 :   struct lookup_base_data_s *data = (struct lookup_base_data_s *) data_;
      79              : 
      80   1030459645 :   if (data->offset != -1)
      81              :     {
      82              :       /* We're looking for the type at a particular offset.  */
      83     10345818 :       int comp = compare_tree_int (BINFO_OFFSET (binfo), data->offset);
      84     10345818 :       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     10058917 :       else if (comp != 0
      90     10071488 :                && 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   1030172741 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base))
      97              :     {
      98    471856639 :       const bool via_virtual
      99    471856639 :         = binfo_via_virtual (binfo, data->t) != NULL_TREE;
     100              : 
     101    471856639 :       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    471855947 :       if (!data->binfo)
     107              :         {
     108    471854268 :           data->binfo = binfo;
     109    471854268 :           data->via_virtual = via_virtual;
     110              : 
     111    471854268 :           if (!data->repeated_base)
     112              :             /* If there are no repeated bases, we can stop now.  */
     113              :             return binfo;
     114              : 
     115        12734 :           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         7529 :           return dfs_skip_bases;
     121              :         }
     122              :       else
     123              :         {
     124         1679 :           gcc_assert (binfo != data->binfo);
     125              : 
     126              :           /* We've found more than one matching binfo.  */
     127         1679 :           if (!data->want_any)
     128              :             {
     129              :               /* This is immediately ambiguous.  */
     130         1559 :               data->binfo = NULL_TREE;
     131         1559 :               data->ambiguous = true;
     132         1559 :               return error_mark_node;
     133              :             }
     134              : 
     135              :           /* Prefer one via a non-virtual path.  */
     136          120 :           if (!via_virtual)
     137              :             {
     138           45 :               data->binfo = binfo;
     139           45 :               data->via_virtual = false;
     140           45 :               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         1159 : get_parent_with_private_access (tree decl, tree binfo)
     166              : {
     167              :   /* Only BINFOs should come through here.  */
     168         1159 :   gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
     169              : 
     170         1258 :   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         1258 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     176              :     {
     177          281 :       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          281 :       if (RECORD_OR_UNION_TYPE_P (base_binfo_type)
     181          281 :           && 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     52997532 : accessible_base_p (tree t, tree base, bool consider_local_p)
     198              : {
     199     52997532 :   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     52997532 :   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     13281818 :   decl = TYPE_FIELDS (base);
     213    805883889 :   while (!DECL_SELF_REFERENCE_P (decl))
     214    792602071 :     decl = DECL_CHAIN (decl);
     215     13281818 :   while (ANON_AGGR_TYPE_P (t))
     216            0 :     t = TYPE_CONTEXT (t);
     217     13281818 :   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    894332346 : 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    894332346 :   tree binfo;
     235    894332346 :   tree t_binfo;
     236    894332346 :   base_kind bk;
     237              : 
     238              :   /* "Nothing" is definitely not derived from Base.  */
     239    894332346 :   if (t == NULL_TREE)
     240              :     {
     241        15263 :       if (kind_ptr)
     242            0 :         *kind_ptr = bk_not_base;
     243              :       return NULL_TREE;
     244              :     }
     245              : 
     246    894317083 :   if (t == error_mark_node || base == error_mark_node)
     247              :     {
     248            0 :       if (kind_ptr)
     249            0 :         *kind_ptr = bk_not_base;
     250              :       return error_mark_node;
     251              :     }
     252    894317083 :   gcc_assert (TYPE_P (base));
     253              : 
     254    894317083 :   if (!TYPE_P (t))
     255              :     {
     256      3963813 :       t_binfo = t;
     257      3963813 :       t = BINFO_TYPE (t);
     258              :     }
     259              :   else
     260              :     {
     261    890353270 :       t = complete_type (TYPE_MAIN_VARIANT (t));
     262    890353270 :       if (dependent_type_p (t))
     263    186960967 :         if (tree open = currently_open_class (t))
     264    890353270 :           t = open;
     265    890353270 :       t_binfo = TYPE_BINFO (t);
     266              :     }
     267              : 
     268    894317083 :   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    894317083 :   if (t_binfo && CLASS_TYPE_P (base) && COMPLETE_OR_OPEN_TYPE_P (base))
     273              :     {
     274    876970122 :       struct lookup_base_data_s data;
     275              : 
     276    876970122 :       data.t = t;
     277    876970122 :       data.base = base;
     278    876970122 :       data.binfo = NULL_TREE;
     279    876970122 :       data.ambiguous = data.via_virtual = false;
     280    876970122 :       data.repeated_base = (offset == -1) && CLASSTYPE_REPEATED_BASE_P (t);
     281    876970122 :       data.want_any = access == ba_any;
     282    876970122 :       data.offset = offset;
     283    876970122 :       data.require_virtual = (access & ba_require_virtual);
     284              : 
     285    876970122 :       dfs_walk_once (t_binfo, dfs_lookup_base, NULL, &data);
     286    876970122 :       binfo = data.binfo;
     287              : 
     288    876970122 :       if (!binfo)
     289    405117413 :         bk = data.ambiguous ? bk_ambig : bk_not_base;
     290    471852709 :       else if (binfo == t_binfo)
     291              :         bk = bk_same_type;
     292     83291901 :       else if (data.via_virtual)
     293              :         bk = bk_via_virtual;
     294              :       else
     295     82470700 :         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    894317083 :   if (access != ba_any)
     305     19200771 :     switch (bk)
     306              :       {
     307              :       case bk_not_base:
     308              :         break;
     309              : 
     310         1559 :       case bk_ambig:
     311         1559 :         if (complain & tf_error)
     312          110 :           error ("%qT is an ambiguous base of %qT", base, t);
     313         1559 :         binfo = error_mark_node;
     314         1559 :         break;
     315              : 
     316     19188244 :       default:
     317     19188244 :         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      5991017 :             && COMPLETE_TYPE_P (base)
     325     25179255 :             && !accessible_base_p (t, base, !(access & ba_ignore_scope)))
     326              :           {
     327         1145 :             if (complain & tf_error)
     328           48 :               error ("%qT is an inaccessible base of %qT", base, t);
     329         1145 :             binfo = error_mark_node;
     330         1145 :             bk = bk_inaccessible;
     331              :           }
     332              :         break;
     333              :       }
     334              : 
     335    894317083 :   if (kind_ptr)
     336      4347558 :     *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        13058 : dfs_dcast_hint_pre (tree binfo, void *data_)
     358              : {
     359        13058 :   struct dcast_data_s *data = (struct dcast_data_s *) data_;
     360              : 
     361        13058 :   if (BINFO_VIRTUAL_P (binfo))
     362          474 :     data->virt_depth++;
     363              : 
     364        13058 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->subtype))
     365              :     {
     366         5749 :       if (data->virt_depth)
     367              :         {
     368          367 :           data->offset = ssize_int (-1);
     369          367 :           return data->offset;
     370              :         }
     371         5382 :       if (data->offset)
     372           15 :         data->offset = ssize_int (-3);
     373              :       else
     374         5367 :         data->offset = BINFO_OFFSET (binfo);
     375              : 
     376         5382 :       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         1288 : dfs_dcast_hint_post (tree binfo, void *data_)
     386              : {
     387         1288 :   struct dcast_data_s *data = (struct dcast_data_s *) data_;
     388              : 
     389         1288 :   if (BINFO_VIRTUAL_P (binfo))
     390           47 :     data->virt_depth--;
     391              : 
     392         1288 :   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         6225 : dcast_base_hint (tree subtype, tree target)
     408              : {
     409         6225 :   struct dcast_data_s data;
     410              : 
     411         6225 :   data.subtype = subtype;
     412         6225 :   data.virt_depth = 0;
     413         6225 :   data.offset = NULL_TREE;
     414         6225 :   data.repeated_base = CLASSTYPE_REPEATED_BASE_P (target);
     415              : 
     416         6225 :   dfs_walk_once_accessible (TYPE_BINFO (target), /*friends=*/false,
     417              :                             dfs_dcast_hint_pre, dfs_dcast_hint_post, &data);
     418         6225 :   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   2933138129 : 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    830461882 :   if (current_function_decl && current_class_type
     449   3498303494 :       && ((DECL_FUNCTION_MEMBER_P (current_function_decl)
     450    550839640 :            && same_type_p (DECL_CONTEXT (current_function_decl),
     451              :                            current_class_type))
     452     49384552 :           || (DECL_FRIEND_CONTEXT (current_function_decl)
     453     18703558 :               && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl),
     454              :                               current_class_type))))
     455    549411987 :     return current_function_decl;
     456              : 
     457   2383726142 :   if (current_class_type)
     458              :     return current_class_type;
     459              : 
     460   1181577283 :   if (current_function_decl)
     461              :     return current_function_decl;
     462              : 
     463    916280766 :   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    552922568 : at_function_scope_p (void)
     472              : {
     473    552922568 :   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    552922568 :   return (cs && TREE_CODE (cs) == FUNCTION_DECL
     478    731387458 :           && cfun && cfun->decl == current_function_decl);
     479              : }
     480              : 
     481              : /* Returns true if the innermost active scope is a class scope.  */
     482              : 
     483              : bool
     484    909287695 : at_class_scope_p (void)
     485              : {
     486    909287695 :   tree cs = current_scope ();
     487    909287695 :   return cs && TYPE_P (cs);
     488              : }
     489              : 
     490              : /* Returns true if the innermost active scope is a namespace scope.  */
     491              : 
     492              : bool
     493    626126731 : at_namespace_scope_p (void)
     494              : {
     495    626126731 :   tree cs = current_scope ();
     496    626126731 :   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   6716652551 : 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   6716652551 :   tree context = DECL_CONTEXT (decl);
     511              : 
     512  12894581339 :   while (context && TYPE_P (context)
     513   9656366861 :          && (ANON_AGGR_TYPE_P (context) || UNSCOPED_ENUM_P (context)))
     514     55150302 :     context = TYPE_CONTEXT (context);
     515   6716652551 :   if (!context)
     516    593874065 :     context = global_namespace;
     517              : 
     518   6716652551 :   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      1563766 : type_context_for_name_lookup (tree decl)
     526              : {
     527      1563766 :   tree context = DECL_P (decl) ? DECL_CONTEXT (decl) : decl;
     528      1563766 :   gcc_checking_assert (CLASS_TYPE_P (context));
     529              : 
     530      1564109 :   while (context && TYPE_P (context) && ANON_AGGR_TYPE_P (context))
     531              :     {
     532          355 :       tree next = TYPE_CONTEXT (context);
     533          355 :       if (!TYPE_P (next))
     534              :         break;
     535              :       context = next;
     536              :     }
     537      1563766 :   return context;
     538              : }
     539              : 
     540              : /* Returns true iff DECL is declared in TYPE.  */
     541              : 
     542              : static bool
     543    580816987 : member_declared_in_type (tree decl, tree type)
     544              : {
     545              :   /* A normal declaration obviously counts.  */
     546    580816987 :   if (context_for_name_lookup (decl) == type)
     547              :     return true;
     548              :   /* So does a using or access declaration.  */
     549    176511715 :   if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl)
     550    176511715 :       && purpose_member (type, DECL_ACCESS (decl)))
     551       938179 :     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    529236685 : dfs_access_in_type_pre (tree binfo, void *data)
     562              : {
     563    529236685 :   tree decl = (tree) data;
     564    529236685 :   tree type = BINFO_TYPE (binfo);
     565    529236685 :   if (member_declared_in_type (decl, type))
     566    443304914 :     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    529236685 : dfs_access_in_type (tree binfo, void *data)
     584              : {
     585    529236685 :   tree decl = (tree) data;
     586    529236685 :   tree type = BINFO_TYPE (binfo);
     587    529236685 :   access_kind access = ak_none;
     588              : 
     589    529236685 :   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    442621361 :       if (TREE_PRIVATE (decl))
     594              :         access = ak_private;
     595    406702465 :       else if (TREE_PROTECTED (decl))
     596              :         access = ak_protected;
     597              :       else
     598    529236685 :         access = ak_public;
     599              :     }
     600              :   else
     601              :     {
     602              :       /* First, check for an access-declaration that gives us more
     603              :          access to the DECL.  */
     604     86615324 :       if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl))
     605              :         {
     606    129308013 :           tree decl_access = purpose_member (type, DECL_ACCESS (decl));
     607              : 
     608     81741041 :           if (decl_access)
     609              :             {
     610       683553 :               decl_access = TREE_VALUE (decl_access);
     611              : 
     612       683553 :               if (decl_access == access_public_node)
     613              :                 access = ak_public;
     614       254631 :               else if (decl_access == access_protected_node)
     615              :                 access = ak_protected;
     616        47910 :               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     85931771 :           int i;
     626     85931771 :           tree base_binfo;
     627     85931771 :           vec<tree, va_gc> *accesses;
     628              : 
     629              :           /* Otherwise, scan our baseclasses, and pick the most favorable
     630              :              access.  */
     631     85931771 :           accesses = BINFO_BASE_ACCESSES (binfo);
     632     92706196 :           for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     633              :             {
     634     85295731 :               tree base_access = (*accesses)[i];
     635     85295731 :               access_kind base_access_now = BINFO_ACCESS (base_binfo);
     636              : 
     637     85295731 :               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     82690614 :               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     82024094 :               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     80820628 :               if (base_access_now != ak_none
     654     82690614 :                   && (access == ak_none || base_access_now < access))
     655              :                 {
     656     82690090 :                   access = base_access_now;
     657              : 
     658              :                   /* If the new access is public, we can't do better.  */
     659     82690090 :                   if (access == ak_public)
     660              :                     break;
     661              :                 }
     662              :             }
     663              :         }
     664              :     }
     665              : 
     666              :   /* Note the access to DECL in TYPE.  */
     667    529236685 :   SET_BINFO_ACCESS (binfo, access);
     668              : 
     669    529236685 :   return NULL_TREE;
     670              : }
     671              : 
     672              : /* Return the access to DECL in TYPE.  */
     673              : 
     674              : static access_kind
     675    443304479 : access_in_type (tree type, tree decl)
     676              : {
     677    443304479 :   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    443304479 :   dfs_walk_once (binfo, dfs_access_in_type_pre, dfs_access_in_type, decl);
     691              : 
     692    443304479 :   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      9491478 : 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      9491478 :   if (!DERIVED_FROM_P (type, derived))
     712              :     return 0;
     713              : 
     714              :   /* DECL_NONSTATIC_MEMBER_P won't work for USING_DECLs.  */
     715      9356946 :   decl = strip_using_decl (decl);
     716              :   /* We don't expect or support dependent decls.  */
     717      9356946 :   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     15516329 :   if (DECL_NONSTATIC_MEMBER_P (decl)
     731     13971335 :       && !DERIVED_FROM_P (derived, otype))
     732          384 :     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     16676279 : 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     16676279 :   tree befriending_classes;
     753     16676279 :   tree t;
     754              : 
     755     16676279 :   if (!scope)
     756              :     return 0;
     757              : 
     758     16676279 :   if (is_global_friend (scope))
     759              :     return 1;
     760              : 
     761              :   /* Is SCOPE itself a suitable P?  */
     762     16676279 :   if (TYPE_P (scope) && protected_accessible_p (decl, scope, type, otype))
     763              :     return 1;
     764              : 
     765      7331202 :   if (DECL_DECLARES_FUNCTION_P (scope))
     766      7240932 :     befriending_classes = DECL_BEFRIENDING_CLASSES (scope);
     767        90270 :   else if (TYPE_P (scope))
     768        87239 :     befriending_classes = CLASSTYPE_BEFRIENDING_CLASSES (scope);
     769              :   else
     770              :     return 0;
     771              : 
     772      7375848 :   for (t = befriending_classes; t; t = TREE_CHAIN (t))
     773        59162 :     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      7316686 :   if (TYPE_P (scope))
     779        76347 :     if (friend_accessible_p (TYPE_CONTEXT (scope), decl, type, otype))
     780              :       return 1;
     781              : 
     782      7241441 :   if (DECL_DECLARES_FUNCTION_P (scope))
     783              :     {
     784              :       /* Perhaps this SCOPE is a member of a class which is a
     785              :          friend.  */
     786     14480678 :       if (DECL_CLASS_SCOPE_P (scope)
     787     14480300 :           && 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          954 :       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         1576 :   if (tree tinfo = get_template_info (scope))
     798              :     {
     799         1305 :       tree tmpl = TI_TEMPLATE (tinfo);
     800         1305 :       if (DECL_CLASS_TEMPLATE_P (tmpl))
     801         1037 :         tmpl = TREE_TYPE (tmpl);
     802              :       else
     803          268 :         tmpl = DECL_TEMPLATE_RESULT (tmpl);
     804         1305 :       if (tmpl != scope)
     805              :         {
     806              :           /* Increment processing_template_decl to make sure that
     807              :              dependent_type_p works correctly.  */
     808         1161 :           ++processing_template_decl;
     809         1161 :           int ret = friend_accessible_p (tmpl, decl, type, otype);
     810         1161 :           --processing_template_decl;
     811         1161 :           if (ret)
     812              :             return 1;
     813              :         }
     814              :     }
     815              : 
     816              :   /* If is_friend is true, we should have found a befriending class.  */
     817          445 :   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     51580302 : dfs_accessible_pre (tree binfo, void *data)
     832              : {
     833     51580302 :   dfs_accessible_data *d = (dfs_accessible_data *)data;
     834     51580302 :   tree type = BINFO_TYPE (binfo);
     835     51580302 :   if (member_declared_in_type (d->decl, type))
     836     46781201 :     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     47324041 : dfs_accessible_post (tree binfo, void *data)
     844              : {
     845              :   /* access_in_type already set BINFO_ACCESS for us.  */
     846     47324041 :   access_kind access = BINFO_ACCESS (binfo);
     847     47324041 :   tree N = BINFO_TYPE (binfo);
     848     47324041 :   dfs_accessible_data *d = (dfs_accessible_data *)data;
     849     47324041 :   tree decl = d->decl;
     850     47324041 :   tree scope = current_nonlambda_scope ();
     851              : 
     852              :   /* A member m is accessible at the point R when named in class N if */
     853     47324041 :   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     35967051 :     case ak_private:
     863     35967051 :       {
     864              :         /* m as a member of N is private, and R occurs in a member or friend of
     865              :            class N, or */
     866     35967051 :         if (scope && TREE_CODE (scope) != NAMESPACE_DECL
     867     71931948 :             && is_friend (N, scope))
     868              :           return binfo;
     869              :         return NULL_TREE;
     870              :       }
     871              : 
     872      9358807 :     case ak_protected:
     873      9358807 :       {
     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      9358807 :         if (friend_accessible_p (scope, decl, N, d->object_type))
     878              :           return binfo;
     879              :         return NULL_TREE;
     880              :       }
     881              : 
     882            0 :     default:
     883            0 :       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      4386643 : accessible_in_template_p (tree type, tree decl)
     892              : {
     893      4386643 :   int save_ptd = processing_template_decl;
     894      4386643 :   processing_template_decl = 0;
     895      4386643 :   int val = accessible_p (type, decl, false);
     896      4386643 :   processing_template_decl = save_ptd;
     897      4386643 :   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    443304257 : accessible_p (tree type, tree decl, bool consider_local_p)
     910              : {
     911    443304257 :   tree binfo;
     912    443304257 :   access_kind access;
     913              : 
     914              :   /* If this declaration is in a block or namespace scope, there's no
     915              :      access control.  */
     916    443304257 :   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    443304201 :   if (current_function_decl && DECL_THUNK_P (current_function_decl))
     921              :     return 1;
     922              : 
     923    443304201 :   tree otype = NULL_TREE;
     924    443304201 :   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    870103697 :       for (tree b = type; b; b = BINFO_INHERITANCE_CHAIN (b))
     930    444531043 :         otype = BINFO_TYPE (b);
     931    425572654 :       type = BINFO_TYPE (type);
     932              :     }
     933              :   else
     934              :     otype = type;
     935              : 
     936              :   /* Anonymous unions don't have their own access.  */
     937    443304201 :   if (ANON_AGGR_TYPE_P (type))
     938          150 :     type = type_context_for_name_lookup (type);
     939    443304201 :   if (ANON_AGGR_TYPE_P (otype))
     940          150 :     otype = type_context_for_name_lookup (otype);
     941              : 
     942              :   /* [class.access.base]
     943              : 
     944              :      A member m is accessible when named in class N if
     945              : 
     946              :      --m as a member of N is public, or
     947              : 
     948              :      --m as a member of N is private, and the reference occurs in a
     949              :        member or friend of class N, or
     950              : 
     951              :      --m as a member of N is protected, and the reference occurs in a
     952              :        member or friend of class N, or in a member or friend of a
     953              :        class P derived from N, where m as a member of P is public, private or
     954              :        protected, or
     955              : 
     956              :      --there exists a base class B of N that is accessible at the point
     957              :        of reference, and m is accessible when named in class B.
     958              : 
     959              :     We walk the base class hierarchy, checking these conditions.  */
     960              : 
     961              :   /* We walk using TYPE_BINFO (type) because access_in_type will set
     962              :      BINFO_ACCESS on it and its bases.  */
     963    443304201 :   binfo = TYPE_BINFO (type);
     964              : 
     965              :   /* Compute the accessibility of DECL in the class hierarchy
     966              :      dominated by type.  */
     967    443304201 :   access = access_in_type (type, decl);
     968    443304201 :   if (access == ak_public)
     969              :     return 1;
     970              : 
     971              :   /* If we aren't considering the point of reference, only the first bullet
     972              :      applies.  */
     973     46783680 :   if (!consider_local_p)
     974              :     return 0;
     975              : 
     976     46782679 :   dfs_accessible_data d = { decl, otype };
     977              : 
     978              :   /* Walk the hierarchy again, looking for a base class that allows
     979              :      access.  */
     980     46782679 :   return dfs_walk_once_accessible (binfo, /*friends=*/true,
     981              :                                    dfs_accessible_pre,
     982              :                                    dfs_accessible_post, &d)
     983     46782679 :     != NULL_TREE;
     984              : }
     985              : 
     986              : struct lookup_field_info {
     987              :   /* The type in which we're looking.  */
     988              :   tree type;
     989              :   /* The name of the field for which we're looking.  */
     990              :   tree name;
     991              :   /* If non-NULL, the current result of the lookup.  */
     992              :   tree rval;
     993              :   /* The path to RVAL.  */
     994              :   tree rval_binfo;
     995              :   /* If non-NULL, the lookup was ambiguous, and this is a list of the
     996              :      candidates.  */
     997              :   tree ambiguous;
     998              :   /* If nonzero, we are looking for types, not data members.  */
     999              :   int want_type;
    1000              : };
    1001              : 
    1002              : /* True for a class member means that it is shared between all objects
    1003              :    of that class.
    1004              : 
    1005              :    [class.member.lookup]:If the resulting set of declarations are not all
    1006              :    from sub-objects of the same type, or the set has a non-static member
    1007              :    and  includes members from distinct sub-objects, there is an ambiguity
    1008              :    and the program is ill-formed.
    1009              : 
    1010              :    This function checks that T contains no non-static members.  */
    1011              : 
    1012              : bool
    1013     47711324 : shared_member_p (tree t)
    1014              : {
    1015     47711324 :   if (VAR_P (t) || TREE_CODE (t) == TYPE_DECL
    1016     45818873 :       || TREE_CODE (t) == CONST_DECL)
    1017              :     return true;
    1018     45815243 :   if (is_overloaded_fn (t))
    1019              :     {
    1020     73994194 :       for (ovl_iterator iter (get_fns (t)); iter; ++iter)
    1021              :         {
    1022     49828015 :           tree decl = strip_using_decl (*iter);
    1023     49828015 :           if (TREE_CODE (decl) == USING_DECL)
    1024              :             /* Conservatively assume a dependent using-declaration
    1025              :                might resolve to a non-static member.  */
    1026     30480819 :             return false;
    1027     49828012 :           if (DECL_OBJECT_MEMBER_FUNCTION_P (decl))
    1028              :             return false;
    1029              :         }
    1030     15333970 :       return true;
    1031              :     }
    1032              :   return false;
    1033              : }
    1034              : 
    1035              : /* Routine to see if the sub-object denoted by the binfo PARENT can be
    1036              :    found as a base class and sub-object of the object denoted by
    1037              :    BINFO.  */
    1038              : 
    1039              : static int
    1040      4741868 : is_subobject_of_p (tree parent, tree binfo)
    1041              : {
    1042      4741868 :   tree probe;
    1043              : 
    1044     10840118 :   for (probe = parent; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
    1045              :     {
    1046      7846877 :       if (probe == binfo)
    1047              :         return 1;
    1048      7804765 :       if (BINFO_VIRTUAL_P (probe))
    1049      1706515 :         return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (binfo))
    1050      1706515 :                 != NULL_TREE);
    1051              :     }
    1052              :   return 0;
    1053              : }
    1054              : 
    1055              : /* DATA is really a struct lookup_field_info.  Look for a field with
    1056              :    the name indicated there in BINFO.  If this function returns a
    1057              :    non-NULL value it is the result of the lookup.  Called from
    1058              :    lookup_field via breadth_first_search.  */
    1059              : 
    1060              : static tree
    1061   7257812384 : lookup_field_r (tree binfo, void *data)
    1062              : {
    1063   7257812384 :   struct lookup_field_info *lfi = (struct lookup_field_info *) data;
    1064   7257812384 :   tree type = BINFO_TYPE (binfo);
    1065   7257812384 :   tree nval = NULL_TREE;
    1066              : 
    1067              :   /* If this is a dependent base, don't look in it.  */
    1068   7257812384 :   if (BINFO_DEPENDENT_BASE_P (binfo))
    1069              :     return NULL_TREE;
    1070              : 
    1071              :   /* If this base class is hidden by the best-known value so far, we
    1072              :      don't need to look.  */
    1073     74432097 :   if (lfi->rval_binfo && BINFO_INHERITANCE_CHAIN (binfo) == lfi->rval_binfo
    1074   5960641477 :       && !BINFO_VIRTUAL_P (binfo))
    1075              :     return dfs_skip_bases;
    1076              : 
    1077   5831755925 :   nval = get_class_binding (type, lfi->name, lfi->want_type);
    1078              : 
    1079              :   /* If there is no declaration with the indicated name in this type,
    1080              :      then there's nothing to do.  */
    1081   5831755925 :   if (!nval)
    1082   5090101124 :     goto done;
    1083              : 
    1084              :   /* If the lookup already found a match, and the new value doesn't
    1085              :      hide the old one, we might have an ambiguity.  */
    1086    741654801 :   if (lfi->rval_binfo
    1087    741654801 :       && !is_subobject_of_p (lfi->rval_binfo, binfo))
    1088              : 
    1089              :     {
    1090      2349963 :       if (nval == lfi->rval && shared_member_p (nval))
    1091              :         /* The two things are really the same.  */
    1092              :         ;
    1093      2349753 :       else if (is_subobject_of_p (binfo, lfi->rval_binfo))
    1094              :         /* The previous value hides the new one.  */
    1095              :         ;
    1096              :       else
    1097              :         {
    1098              :           /* We have a real ambiguity.  We keep a chain of all the
    1099              :              candidates.  */
    1100       687395 :           if (!lfi->ambiguous && lfi->rval)
    1101              :             {
    1102              :               /* This is the first time we noticed an ambiguity.  Add
    1103              :                  what we previously thought was a reasonable candidate
    1104              :                  to the list.  */
    1105       544436 :               lfi->ambiguous = tree_cons (NULL_TREE, lfi->rval, NULL_TREE);
    1106       544436 :               TREE_TYPE (lfi->ambiguous) = error_mark_node;
    1107              :             }
    1108              : 
    1109              :           /* Add the new value.  */
    1110       687395 :           if (TREE_CODE (nval) == TREE_LIST)
    1111            8 :             lfi->ambiguous = chainon (nval, lfi->ambiguous);
    1112              :           else
    1113              :             {
    1114       687387 :               lfi->ambiguous = tree_cons (NULL_TREE, nval, lfi->ambiguous);
    1115       687387 :               TREE_TYPE (lfi->ambiguous) = error_mark_node;
    1116              :             }
    1117              :         }
    1118              :     }
    1119              :   else
    1120              :     {
    1121    739304838 :       if (TREE_CODE (nval) == TREE_LIST)
    1122              :         {
    1123          101 :           lfi->ambiguous = chainon (nval, lfi->ambiguous);
    1124          101 :           lfi->rval = TREE_VALUE (nval);
    1125              :         }
    1126              :       else
    1127    739304737 :         lfi->rval = nval;
    1128    739304838 :       lfi->rval_binfo = binfo;
    1129              :     }
    1130              : 
    1131   5831755925 :  done:
    1132              :   /* Don't look for constructors or destructors in base classes.  */
    1133   5831755925 :   if (IDENTIFIER_CDTOR_P (lfi->name))
    1134    198810625 :     return dfs_skip_bases;
    1135              :   return NULL_TREE;
    1136              : }
    1137              : 
    1138              : /* Return a "baselink" with BASELINK_BINFO, BASELINK_ACCESS_BINFO,
    1139              :    BASELINK_FUNCTIONS, and BASELINK_OPTYPE set to BINFO, ACCESS_BINFO,
    1140              :    FUNCTIONS, and OPTYPE respectively.  */
    1141              : 
    1142              : tree
    1143    231168965 : build_baselink (tree binfo, tree access_binfo, tree functions, tree optype)
    1144              : {
    1145    231168965 :   tree baselink;
    1146              : 
    1147    231168965 :   gcc_checking_assert (binfo && access_binfo);
    1148    231168965 :   gcc_assert (OVL_P (functions) || TREE_CODE (functions) == TEMPLATE_ID_EXPR);
    1149    231168965 :   gcc_assert (!optype || TYPE_P (optype));
    1150    231168965 :   gcc_assert (TREE_TYPE (functions));
    1151              : 
    1152    231168965 :   baselink = make_node (BASELINK);
    1153    231168965 :   TREE_TYPE (baselink) = TREE_TYPE (functions);
    1154    231168965 :   BASELINK_BINFO (baselink) = binfo;
    1155    231168965 :   BASELINK_ACCESS_BINFO (baselink) = access_binfo;
    1156    231168965 :   BASELINK_FUNCTIONS (baselink) = functions;
    1157    231168965 :   BASELINK_OPTYPE (baselink) = optype;
    1158              : 
    1159    231168965 :   if (binfo == access_binfo
    1160    451068132 :       && TYPE_BEING_DEFINED (BINFO_TYPE (access_binfo)))
    1161      6741307 :     BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (baselink) = true;
    1162              : 
    1163    231168965 :   return baselink;
    1164              : }
    1165              : 
    1166              : /* Look for a member named NAME in an inheritance lattice dominated by
    1167              :    XBASETYPE.  If PROTECT is 0 or two, we do not check access.  If it
    1168              :    is 1, we enforce accessibility.  If PROTECT is zero, then, for an
    1169              :    ambiguous lookup, we return NULL.  If PROTECT is 1, we issue error
    1170              :    messages about inaccessible or ambiguous lookup.  If PROTECT is 2,
    1171              :    we return a TREE_LIST whose TREE_TYPE is error_mark_node and whose
    1172              :    TREE_VALUEs are the list of ambiguous candidates.
    1173              : 
    1174              :    WANT_TYPE is 1 when we should only return TYPE_DECLs.
    1175              : 
    1176              :    If nothing can be found return NULL_TREE and do not issue an error.
    1177              : 
    1178              :    If non-NULL, failure information is written back to AFI.  */
    1179              : 
    1180              : tree
    1181   5152241972 : lookup_member (tree xbasetype, tree name, int protect, bool want_type,
    1182              :                tsubst_flags_t complain, access_failure_info *afi /* = NULL */)
    1183              : {
    1184   5152241972 :   tree rval, rval_binfo = NULL_TREE;
    1185   5152241972 :   tree type = NULL_TREE, basetype_path = NULL_TREE;
    1186   5152241972 :   struct lookup_field_info lfi;
    1187              : 
    1188              :   /* rval_binfo is the binfo associated with the found member, note,
    1189              :      this can be set with useful information, even when rval is not
    1190              :      set, because it must deal with ALL members, not just non-function
    1191              :      members.  It is used for ambiguity checking and the hidden
    1192              :      checks.  Whereas rval is only set if a proper (not hidden)
    1193              :      non-function member is found.  */
    1194              : 
    1195   5152241972 :   if (name == error_mark_node
    1196   5152241972 :       || xbasetype == NULL_TREE
    1197   5152241966 :       || xbasetype == error_mark_node)
    1198              :     return NULL_TREE;
    1199              : 
    1200   5152241966 :   gcc_assert (identifier_p (name));
    1201              : 
    1202   5152241966 :   if (TREE_CODE (xbasetype) == TREE_BINFO)
    1203              :     {
    1204    112531704 :       type = BINFO_TYPE (xbasetype);
    1205    112531704 :       basetype_path = xbasetype;
    1206              :     }
    1207              :   else
    1208              :     {
    1209   5039710262 :       if (!RECORD_OR_UNION_CODE_P (TREE_CODE (xbasetype)))
    1210              :         return NULL_TREE;
    1211              :       type = xbasetype;
    1212   5152241930 :       xbasetype = NULL_TREE;
    1213              :     }
    1214              : 
    1215   5152241930 :   type = complete_type (type);
    1216              : 
    1217              :   /* Make sure we're looking for a member of the current instantiation in the
    1218              :      right partial specialization.  */
    1219   5152241876 :   if (dependent_type_p (type))
    1220   3287086249 :     if (tree t = currently_open_class (type))
    1221   5152241876 :       type = t;
    1222              : 
    1223   5152241876 :   if (!basetype_path)
    1224   5039710172 :     basetype_path = TYPE_BINFO (type);
    1225              : 
    1226   5039710172 :   if (!basetype_path)
    1227              :     return NULL_TREE;
    1228              : 
    1229   5067588842 :   memset (&lfi, 0, sizeof (lfi));
    1230   5067588842 :   lfi.type = type;
    1231   5067588842 :   lfi.name = name;
    1232   5067588842 :   lfi.want_type = want_type;
    1233   5067588842 :   dfs_walk_all (basetype_path, &lookup_field_r, NULL, &lfi);
    1234   5067588842 :   rval = lfi.rval;
    1235   5067588842 :   rval_binfo = lfi.rval_binfo;
    1236   5067588842 :   if (rval_binfo)
    1237    739262686 :     type = BINFO_TYPE (rval_binfo);
    1238              : 
    1239   5067588842 :   if (lfi.ambiguous)
    1240              :     {
    1241       544537 :       if (protect == 0)
    1242              :         return NULL_TREE;
    1243       544537 :       else if (protect == 1)
    1244              :         {
    1245           84 :           if (complain & tf_error)
    1246              :             {
    1247           71 :               auto_diagnostic_group d;
    1248           71 :               error ("request for member %qD is ambiguous", name);
    1249           71 :               print_candidates (input_location, lfi.ambiguous);
    1250           71 :             }
    1251           84 :           return error_mark_node;
    1252              :         }
    1253       544453 :       else if (protect == 2)
    1254              :         return lfi.ambiguous;
    1255              :     }
    1256              : 
    1257   5067044305 :   if (!rval)
    1258              :     return NULL_TREE;
    1259              : 
    1260              :   /* [class.access]
    1261              : 
    1262              :      In the case of overloaded function names, access control is
    1263              :      applied to the function selected by overloaded resolution.
    1264              : 
    1265              :      We cannot check here, even if RVAL is only a single non-static
    1266              :      member function, since we do not know what the "this" pointer
    1267              :      will be.  For:
    1268              : 
    1269              :         class A { protected: void f(); };
    1270              :         class B : public A {
    1271              :           void g(A *p) {
    1272              :             f(); // OK
    1273              :             p->f(); // Not OK.
    1274              :           }
    1275              :         };
    1276              : 
    1277              :     only the first call to "f" is valid.  However, if the function is
    1278              :     static, we can check.  */
    1279    738718149 :   if (protect == 1 && !really_overloaded_fn (rval))
    1280              :     {
    1281    109787693 :       tree decl = is_overloaded_fn (rval) ? get_first_fn (rval) : rval;
    1282    109787693 :       decl = strip_using_decl (decl);
    1283              :       /* A dependent declaration will be checked after tsubsting.  */
    1284    109787693 :       if (!dependent_scope_p (DECL_CONTEXT (decl))
    1285    109214821 :           && !(DECL_DECLARES_FUNCTION_P (decl)
    1286     60003249 :                && DECL_IOBJ_MEMBER_FUNCTION_P (decl))
    1287    162453388 :           && !perform_or_defer_access_check (basetype_path, decl, decl,
    1288              :                                              complain, afi))
    1289           72 :         return error_mark_node;
    1290              :     }
    1291              : 
    1292    738718077 :   if (is_overloaded_fn (rval)
    1293              :       /* Don't use a BASELINK for class-scope deduction guides since
    1294              :          they're not actually member functions.  */
    1295    738718077 :       && !dguide_name_p (name))
    1296    213727469 :     rval = build_baselink (rval_binfo, basetype_path, rval,
    1297    213727469 :                            (IDENTIFIER_CONV_OP_P (name)
    1298       483103 :                             ? TREE_TYPE (name) : NULL_TREE));
    1299              :   return rval;
    1300              : }
    1301              : 
    1302              : /* Helper class for lookup_member_fuzzy.  */
    1303              : 
    1304          781 : class lookup_field_fuzzy_info
    1305              : {
    1306              :  public:
    1307          781 :   lookup_field_fuzzy_info (bool want_type_p) :
    1308          781 :     m_want_type_p (want_type_p), m_candidates () {}
    1309              : 
    1310              :   void fuzzy_lookup_field (tree type);
    1311              : 
    1312              :   /* If true, we are looking for types, not data members.  */
    1313              :   bool m_want_type_p;
    1314              :   /* The result: a vec of identifiers.  */
    1315              :   auto_vec<tree> m_candidates;
    1316              : };
    1317              : 
    1318              : /* Locate all fields within TYPE, append them to m_candidates.  */
    1319              : 
    1320              : void
    1321          876 : lookup_field_fuzzy_info::fuzzy_lookup_field (tree type)
    1322              : {
    1323          876 :   if (!CLASS_TYPE_P (type))
    1324              :     return;
    1325              : 
    1326         4423 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    1327              :     {
    1328         3553 :       if (m_want_type_p && !DECL_DECLARES_TYPE_P (field))
    1329          146 :         continue;
    1330              : 
    1331         3407 :       if (!DECL_NAME (field))
    1332           72 :         continue;
    1333              : 
    1334         3335 :       if (is_lambda_ignored_entity (field))
    1335           36 :         continue;
    1336              : 
    1337              :       /* Ignore special identifiers with space at the end like cdtor or
    1338              :          conversion op identifiers.  */
    1339         3299 :       if (TREE_CODE (DECL_NAME (field)) == IDENTIFIER_NODE)
    1340         3299 :         if (unsigned int len = IDENTIFIER_LENGTH (DECL_NAME (field)))
    1341         3299 :           if (IDENTIFIER_POINTER (DECL_NAME (field))[len - 1] == ' ')
    1342         1457 :             continue;
    1343              : 
    1344         1842 :       m_candidates.safe_push (DECL_NAME (field));
    1345              :     }
    1346              : }
    1347              : 
    1348              : 
    1349              : /* Helper function for lookup_member_fuzzy, called via dfs_walk_all
    1350              :    DATA is really a lookup_field_fuzzy_info.  Look for a field with
    1351              :    the name indicated there in BINFO.  Gathers pertinent identifiers into
    1352              :    m_candidates.  */
    1353              : 
    1354              : static tree
    1355          876 : lookup_field_fuzzy_r (tree binfo, void *data)
    1356              : {
    1357          876 :   lookup_field_fuzzy_info *lffi = (lookup_field_fuzzy_info *) data;
    1358          876 :   tree type = BINFO_TYPE (binfo);
    1359              : 
    1360          876 :   lffi->fuzzy_lookup_field (type);
    1361              : 
    1362          876 :   return NULL_TREE;
    1363              : }
    1364              : 
    1365              : /* Like lookup_member, but try to find the closest match for NAME,
    1366              :    rather than an exact match, and return an identifier (or NULL_TREE).
    1367              :    Do not complain.  */
    1368              : 
    1369              : tree
    1370          781 : lookup_member_fuzzy (tree xbasetype, tree name, bool want_type_p)
    1371              : {
    1372          781 :   tree type = NULL_TREE, basetype_path = NULL_TREE;
    1373          781 :   class lookup_field_fuzzy_info lffi (want_type_p);
    1374              : 
    1375              :   /* rval_binfo is the binfo associated with the found member, note,
    1376              :      this can be set with useful information, even when rval is not
    1377              :      set, because it must deal with ALL members, not just non-function
    1378              :      members.  It is used for ambiguity checking and the hidden
    1379              :      checks.  Whereas rval is only set if a proper (not hidden)
    1380              :      non-function member is found.  */
    1381              : 
    1382          781 :   if (name == error_mark_node
    1383          781 :       || xbasetype == NULL_TREE
    1384          781 :       || xbasetype == error_mark_node)
    1385              :     return NULL_TREE;
    1386              : 
    1387          781 :   gcc_assert (identifier_p (name));
    1388              : 
    1389          781 :   if (TREE_CODE (xbasetype) == TREE_BINFO)
    1390              :     {
    1391            6 :       type = BINFO_TYPE (xbasetype);
    1392            6 :       basetype_path = xbasetype;
    1393              :     }
    1394              :   else
    1395              :     {
    1396          775 :       if (!RECORD_OR_UNION_CODE_P (TREE_CODE (xbasetype)))
    1397              :         return NULL_TREE;
    1398              :       type = xbasetype;
    1399          781 :       xbasetype = NULL_TREE;
    1400              :     }
    1401              : 
    1402          781 :   type = complete_type (type);
    1403              : 
    1404              :   /* Make sure we're looking for a member of the current instantiation in the
    1405              :      right partial specialization.  */
    1406          781 :   if (flag_concepts && dependent_type_p (type))
    1407          137 :     type = currently_open_class (type);
    1408              : 
    1409          781 :   if (!basetype_path)
    1410          775 :     basetype_path = TYPE_BINFO (type);
    1411              : 
    1412          775 :   if (!basetype_path)
    1413              :     return NULL_TREE;
    1414              : 
    1415              :   /* Populate lffi.m_candidates.  */
    1416          775 :   dfs_walk_all (basetype_path, &lookup_field_fuzzy_r, NULL, &lffi);
    1417              : 
    1418          775 :   return find_closest_identifier (name, &lffi.m_candidates);
    1419          781 : }
    1420              : 
    1421              : /* Like lookup_member, except that if we find a function member we
    1422              :    return NULL_TREE.  */
    1423              : 
    1424              : tree
    1425     27785541 : lookup_field (tree xbasetype, tree name, int protect, bool want_type)
    1426              : {
    1427     27785541 :   tree rval = lookup_member (xbasetype, name, protect, want_type,
    1428              :                              tf_warning_or_error);
    1429              : 
    1430              :   /* Ignore functions, but propagate the ambiguity list.  */
    1431     27785541 :   if (!error_operand_p (rval)
    1432     27785541 :       && (rval && BASELINK_P (rval)))
    1433            0 :     return NULL_TREE;
    1434              : 
    1435              :   return rval;
    1436              : }
    1437              : 
    1438              : /* Like lookup_member, except that if we find a non-function member we
    1439              :    return NULL_TREE.  */
    1440              : 
    1441              : tree
    1442    147249427 : lookup_fnfields (tree xbasetype, tree name, int protect,
    1443              :                  tsubst_flags_t complain)
    1444              : {
    1445    147249427 :   tree rval = lookup_member (xbasetype, name, protect, /*want_type=*/false,
    1446              :                              complain);
    1447              : 
    1448              :   /* Ignore non-functions, but propagate the ambiguity list.  */
    1449    147249427 :   if (!error_operand_p (rval)
    1450    147249427 :       && (rval && !BASELINK_P (rval)))
    1451            0 :     return NULL_TREE;
    1452              : 
    1453              :   return rval;
    1454              : }
    1455              : 
    1456              : /* DECL is the result of a qualified name lookup.  QUALIFYING_SCOPE is
    1457              :    the class or namespace used to qualify the name.  CONTEXT_CLASS is
    1458              :    the class corresponding to the object in which DECL will be used.
    1459              :    Return a possibly modified version of DECL that takes into account
    1460              :    the CONTEXT_CLASS.
    1461              : 
    1462              :    In particular, consider an expression like `B::m' in the context of
    1463              :    a derived class `D'.  If `B::m' has been resolved to a BASELINK,
    1464              :    then the most derived class indicated by the BASELINK_BINFO will be
    1465              :    `B', not `D'.  This function makes that adjustment.  */
    1466              : 
    1467              : tree
    1468    176590840 : adjust_result_of_qualified_name_lookup (tree decl,
    1469              :                                         tree qualifying_scope,
    1470              :                                         tree context_class)
    1471              : {
    1472    176590840 :   if (!BASELINK_P (decl))
    1473              :     return decl;
    1474              : 
    1475     12667517 :   const bool qualified_p = qualifying_scope != NULL_TREE;
    1476     12667517 :   if (!qualified_p)
    1477         1756 :     qualifying_scope = BINFO_TYPE (BASELINK_ACCESS_BINFO (decl));
    1478              : 
    1479     12667517 :   if (context_class
    1480      8825032 :       && context_class != error_mark_node
    1481      8825023 :       && CLASS_TYPE_P (context_class)
    1482      8825017 :       && CLASS_TYPE_P (qualifying_scope)
    1483     21492534 :       && DERIVED_FROM_P (qualifying_scope, context_class))
    1484              :     {
    1485              :       /* Look for the QUALIFYING_SCOPE as a base of the CONTEXT_CLASS.
    1486              :          Because we do not yet know which function will be chosen by
    1487              :          overload resolution, we cannot yet check either accessibility
    1488              :          or ambiguity -- in either case, the choice of a static member
    1489              :          function might make the usage valid.  */
    1490      3777762 :       tree base = lookup_base (context_class, qualifying_scope,
    1491              :                                ba_unique, NULL, tf_none);
    1492      3777762 :       if (base && base != error_mark_node)
    1493              :         {
    1494      3777754 :           BASELINK_ACCESS_BINFO (decl) = base;
    1495      3777754 :           tree decl_binfo
    1496      3777754 :             = lookup_base (base, BINFO_TYPE (BASELINK_BINFO (decl)),
    1497              :                            ba_unique, NULL, tf_none);
    1498      3777754 :           if (decl_binfo && decl_binfo != error_mark_node)
    1499      3777748 :             BASELINK_BINFO (decl) = decl_binfo;
    1500              :         }
    1501              :     }
    1502              : 
    1503     12667517 :   BASELINK_QUALIFIED_P (decl) = qualified_p;
    1504              : 
    1505     12667517 :   return decl;
    1506              : }
    1507              : 
    1508              : 
    1509              : /* Walk the class hierarchy within BINFO, in a depth-first traversal.
    1510              :    PRE_FN is called in preorder, while POST_FN is called in postorder.
    1511              :    If PRE_FN returns DFS_SKIP_BASES, child binfos will not be
    1512              :    walked.  If PRE_FN or POST_FN returns a different non-NULL value,
    1513              :    that value is immediately returned and the walk is terminated.  One
    1514              :    of PRE_FN and POST_FN can be NULL.  At each node, PRE_FN and
    1515              :    POST_FN are passed the binfo to examine and the caller's DATA
    1516              :    value.  All paths are walked, thus virtual and morally virtual
    1517              :    binfos can be multiply walked.  */
    1518              : 
    1519              : tree
    1520   8924849980 : dfs_walk_all (tree binfo, tree (*pre_fn) (tree, void *),
    1521              :               tree (*post_fn) (tree, void *), void *data)
    1522              : {
    1523   8924849980 :   tree rval;
    1524   8924849980 :   unsigned ix;
    1525   8924849980 :   tree base_binfo;
    1526              : 
    1527              :   /* Call the pre-order walking function.  */
    1528   8924849980 :   if (pre_fn)
    1529              :     {
    1530   8919976096 :       rval = pre_fn (binfo, data);
    1531   8919976096 :       if (rval)
    1532              :         {
    1533   1238166895 :           if (rval == dfs_skip_bases)
    1534    766845439 :             goto skip_bases;
    1535              :           return rval;
    1536              :         }
    1537              :     }
    1538              : 
    1539              :   /* Find the next child binfo to walk.  */
    1540  10061704613 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    1541              :     {
    1542   2464595726 :       rval = dfs_walk_all (base_binfo, pre_fn, post_fn, data);
    1543   2464595726 :       if (rval)
    1544              :         return rval;
    1545              :     }
    1546              : 
    1547   8363954326 :  skip_bases:
    1548              :   /* Call the post-order walking function.  */
    1549   8363954326 :   if (post_fn)
    1550              :     {
    1551    564580126 :       rval = post_fn (binfo, data);
    1552    564580126 :       gcc_assert (rval != dfs_skip_bases);
    1553              :       return rval;
    1554              :     }
    1555              : 
    1556              :   return NULL_TREE;
    1557              : }
    1558              : 
    1559              : /* Worker for dfs_walk_once.  This behaves as dfs_walk_all, except
    1560              :    that binfos are walked at most once.  */
    1561              : 
    1562              : static tree
    1563      3701993 : dfs_walk_once_r (tree binfo, tree (*pre_fn) (tree, void *),
    1564              :                  tree (*post_fn) (tree, void *), hash_set<tree> *pset,
    1565              :                  void *data)
    1566              : {
    1567      3701993 :   tree rval;
    1568      3701993 :   unsigned ix;
    1569      3701993 :   tree base_binfo;
    1570              : 
    1571              :   /* Call the pre-order walking function.  */
    1572      3701993 :   if (pre_fn)
    1573              :     {
    1574      3354507 :       rval = pre_fn (binfo, data);
    1575      3354507 :       if (rval)
    1576              :         {
    1577       738644 :           if (rval == dfs_skip_bases)
    1578       211694 :             goto skip_bases;
    1579              : 
    1580              :           return rval;
    1581              :         }
    1582              :     }
    1583              : 
    1584              :   /* Find the next child binfo to walk.  */
    1585      5551034 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    1586              :     {
    1587      3351536 :       if (BINFO_VIRTUAL_P (base_binfo))
    1588      1611332 :         if (pset->add (base_binfo))
    1589       607318 :           continue;
    1590              : 
    1591      2744218 :       rval = dfs_walk_once_r (base_binfo, pre_fn, post_fn, pset, data);
    1592      2744218 :       if (rval)
    1593              :         return rval;
    1594              :     }
    1595              : 
    1596      2411192 :  skip_bases:
    1597              :   /* Call the post-order walking function.  */
    1598      2411192 :   if (post_fn)
    1599              :     {
    1600       979843 :       rval = post_fn (binfo, data);
    1601       979843 :       gcc_assert (rval != dfs_skip_bases);
    1602              :       return rval;
    1603              :     }
    1604              : 
    1605              :   return NULL_TREE;
    1606              : }
    1607              : 
    1608              : /* Like dfs_walk_all, except that binfos are not multiply walked.  For
    1609              :    non-diamond shaped hierarchies this is the same as dfs_walk_all.
    1610              :    For diamond shaped hierarchies we must mark the virtual bases, to
    1611              :    avoid multiple walks.  */
    1612              : 
    1613              : tree
    1614   1383493192 : dfs_walk_once (tree binfo, tree (*pre_fn) (tree, void *),
    1615              :                tree (*post_fn) (tree, void *), void *data)
    1616              : {
    1617   1383493192 :   static int active = 0;  /* We must not be called recursively. */
    1618   1383493192 :   tree rval;
    1619              : 
    1620   1383493192 :   gcc_assert (pre_fn || post_fn);
    1621   1383493192 :   gcc_assert (!active);
    1622   1383493192 :   active++;
    1623              : 
    1624   1383493192 :   if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
    1625              :     /* We are not diamond shaped, and therefore cannot encounter the
    1626              :        same binfo twice.  */
    1627   1382535417 :     rval = dfs_walk_all (binfo, pre_fn, post_fn, data);
    1628              :   else
    1629              :     {
    1630       957775 :       hash_set<tree> pset;
    1631       957775 :       rval = dfs_walk_once_r (binfo, pre_fn, post_fn, &pset, data);
    1632       957775 :     }
    1633              : 
    1634   1383493192 :   active--;
    1635              : 
    1636   1383493192 :   return rval;
    1637              : }
    1638              : 
    1639              : /* Worker function for dfs_walk_once_accessible.  Behaves like
    1640              :    dfs_walk_once_r, except (a) FRIENDS_P is true if special
    1641              :    access given by the current context should be considered, (b) ONCE
    1642              :    indicates whether bases should be marked during traversal.  */
    1643              : 
    1644              : static tree
    1645     51593814 : dfs_walk_once_accessible_r (tree binfo, bool friends_p, hash_set<tree> *pset,
    1646              :                             tree (*pre_fn) (tree, void *),
    1647              :                             tree (*post_fn) (tree, void *), void *data)
    1648              : {
    1649     51593814 :   tree rval = NULL_TREE;
    1650     51593814 :   unsigned ix;
    1651     51593814 :   tree base_binfo;
    1652              : 
    1653              :   /* Call the pre-order walking function.  */
    1654     51593814 :   if (pre_fn)
    1655              :     {
    1656     51593814 :       rval = pre_fn (binfo, data);
    1657     51593814 :       if (rval)
    1658              :         {
    1659     46787111 :           if (rval == dfs_skip_bases)
    1660     46781324 :             goto skip_bases;
    1661              : 
    1662              :           return rval;
    1663              :         }
    1664              :     }
    1665              : 
    1666              :   /* Find the next child binfo to walk.  */
    1667      5358959 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    1668              :     {
    1669      4814682 :       bool mark = pset && BINFO_VIRTUAL_P (base_binfo);
    1670              : 
    1671         9195 :       if (mark && pset->contains (base_binfo))
    1672          116 :         continue;
    1673              : 
    1674              :       /* If the base is inherited via private or protected
    1675              :          inheritance, then we can't see it, unless we are a friend of
    1676              :          the current binfo.  */
    1677      4814566 :       if (BINFO_BASE_ACCESS (binfo, ix) != access_public_node)
    1678              :         {
    1679      2015032 :           tree scope;
    1680      2015032 :           if (!friends_p)
    1681          574 :             continue;
    1682      2014458 :           scope = current_scope ();
    1683      2023952 :           if (!scope
    1684      2014458 :               || TREE_CODE (scope) == NAMESPACE_DECL
    1685      4027777 :               || !is_friend (BINFO_TYPE (binfo), scope))
    1686         9494 :             continue;
    1687              :         }
    1688              : 
    1689      4804498 :       if (mark)
    1690         1068 :         pset->add (base_binfo);
    1691              : 
    1692      4804498 :       rval = dfs_walk_once_accessible_r (base_binfo, friends_p, pset,
    1693              :                                          pre_fn, post_fn, data);
    1694      4804498 :       if (rval)
    1695              :         return rval;
    1696              :     }
    1697              : 
    1698     47325601 :  skip_bases:
    1699              :   /* Call the post-order walking function.  */
    1700     47325601 :   if (post_fn)
    1701              :     {
    1702     47325329 :       rval = post_fn (binfo, data);
    1703     47325329 :       gcc_assert (rval != dfs_skip_bases);
    1704              :       return rval;
    1705              :     }
    1706              : 
    1707              :   return NULL_TREE;
    1708              : }
    1709              : 
    1710              : /* Like dfs_walk_once except that only accessible bases are walked.
    1711              :    FRIENDS_P indicates whether friendship of the local context
    1712              :    should be considered when determining accessibility.  */
    1713              : 
    1714              : static tree
    1715     46789316 : dfs_walk_once_accessible (tree binfo, bool friends_p,
    1716              :                             tree (*pre_fn) (tree, void *),
    1717              :                             tree (*post_fn) (tree, void *), void *data)
    1718              : {
    1719     46789316 :   hash_set<tree> *pset = NULL;
    1720     46789316 :   if (CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
    1721         1796 :     pset = new hash_set<tree>;
    1722     46789316 :   tree rval = dfs_walk_once_accessible_r (binfo, friends_p, pset,
    1723              :                                           pre_fn, post_fn, data);
    1724              : 
    1725     46789316 :   if (pset)
    1726         1796 :     delete pset;
    1727     46789316 :   return rval;
    1728              : }
    1729              : 
    1730              : /* Return true iff the code of T is CODE, and it has compatible
    1731              :    type with TYPE.  */
    1732              : 
    1733              : static bool
    1734          448 : matches_code_and_type_p (tree t, enum tree_code code, tree type)
    1735              : {
    1736          448 :   if (TREE_CODE (t) != code)
    1737              :     return false;
    1738          434 :   if (!cxx_types_compatible_p (TREE_TYPE (t), type))
    1739            0 :     return false;
    1740              :   return true;
    1741              : }
    1742              : 
    1743              : /* Subroutine of direct_accessor_p and reference_accessor_p.
    1744              :    Determine if COMPONENT_REF is a simple field lookup of this->FIELD_DECL.
    1745              :    We expect a tree of the form:
    1746              :              <component_ref:
    1747              :                <indirect_ref:S>
    1748              :                  <nop_expr:P*
    1749              :                    <parm_decl (this)>
    1750              :                  <field_decl (FIELD_DECL)>>>.  */
    1751              : 
    1752              : static bool
    1753          203 : field_access_p (tree component_ref, tree field_decl, tree field_type)
    1754              : {
    1755          203 :   if (!matches_code_and_type_p (component_ref, COMPONENT_REF, field_type))
    1756              :     return false;
    1757              : 
    1758          189 :   tree indirect_ref = TREE_OPERAND (component_ref, 0);
    1759          189 :   if (!INDIRECT_REF_P (indirect_ref))
    1760              :     return false;
    1761              : 
    1762          189 :   tree ptr = STRIP_NOPS (TREE_OPERAND (indirect_ref, 0));
    1763          189 :   if (!is_object_parameter (ptr))
    1764              :     return false;
    1765              : 
    1766              :   /* Must access the correct field.  */
    1767          189 :   if (TREE_OPERAND (component_ref, 1) != field_decl)
    1768           28 :     return false;
    1769              :   return true;
    1770              : }
    1771              : 
    1772              : /* Subroutine of field_accessor_p.
    1773              : 
    1774              :    Assuming that INIT_EXPR has already had its code and type checked,
    1775              :    determine if it is a simple accessor for FIELD_DECL
    1776              :    (of type FIELD_TYPE).
    1777              : 
    1778              :    Specifically, a simple accessor within struct S of the form:
    1779              :        T get_field () { return m_field; }
    1780              :    should have a constexpr_fn_retval (saved_tree) of the form:
    1781              :          <init_expr:T
    1782              :            <result_decl:T
    1783              :            <nop_expr:T
    1784              :              <component_ref:
    1785              :                <indirect_ref:S>
    1786              :                  <nop_expr:P*
    1787              :                    <parm_decl (this)>
    1788              :                  <field_decl (FIELD_DECL)>>>>>.  */
    1789              : 
    1790              : static bool
    1791          161 : direct_accessor_p (tree init_expr, tree field_decl, tree field_type)
    1792              : {
    1793          161 :   tree result_decl = TREE_OPERAND (init_expr, 0);
    1794          161 :   if (!matches_code_and_type_p (result_decl, RESULT_DECL, field_type))
    1795              :     return false;
    1796              : 
    1797          161 :   tree component_ref = STRIP_NOPS (TREE_OPERAND (init_expr, 1));
    1798          161 :   if (!field_access_p (component_ref, field_decl, field_type))
    1799              :     return false;
    1800              : 
    1801              :   return true;
    1802              : }
    1803              : 
    1804              : /* Subroutine of field_accessor_p.
    1805              : 
    1806              :    Assuming that INIT_EXPR has already had its code and type checked,
    1807              :    determine if it is a "reference" accessor for FIELD_DECL
    1808              :    (of type FIELD_REFERENCE_TYPE).
    1809              : 
    1810              :    Specifically, a simple accessor within struct S of the form:
    1811              :        T& get_field () { return m_field; }
    1812              :    should have a constexpr_fn_retval (saved_tree) of the form:
    1813              :          <init_expr:T&
    1814              :            <result_decl:T&
    1815              :            <nop_expr: T&
    1816              :              <addr_expr: T*
    1817              :                <component_ref:T
    1818              :                  <indirect_ref:S
    1819              :                    <nop_expr
    1820              :                      <parm_decl (this)>>
    1821              :                    <field (FIELD_DECL)>>>>>>.  */
    1822              : static bool
    1823           42 : reference_accessor_p (tree init_expr, tree field_decl, tree field_type,
    1824              :                       tree field_reference_type)
    1825              : {
    1826           42 :   tree result_decl = TREE_OPERAND (init_expr, 0);
    1827           42 :   if (!matches_code_and_type_p (result_decl, RESULT_DECL, field_reference_type))
    1828              :     return false;
    1829              : 
    1830           42 :   tree field_pointer_type = build_pointer_type (field_type);
    1831           42 :   tree addr_expr = STRIP_NOPS (TREE_OPERAND (init_expr, 1));
    1832           42 :   if (!matches_code_and_type_p (addr_expr, ADDR_EXPR, field_pointer_type))
    1833              :     return false;
    1834              : 
    1835           42 :   tree component_ref = STRIP_NOPS (TREE_OPERAND (addr_expr, 0));
    1836              : 
    1837           42 :   if (!field_access_p (component_ref, field_decl, field_type))
    1838              :     return false;
    1839              : 
    1840              :   return true;
    1841              : }
    1842              : 
    1843              : /* Return the class of the `this' or explicit object parameter of FN.  */
    1844              : 
    1845              : static tree
    1846           61 : class_of_object_parm (const_tree fn)
    1847              : {
    1848           61 :   tree fntype = TREE_TYPE (fn);
    1849           61 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    1850            0 :     return non_reference (TREE_VALUE (TYPE_ARG_TYPES (fntype)));
    1851           61 :   return class_of_this_parm (fntype);
    1852              : }
    1853              : 
    1854              : /* Return true if FN is an accessor method for FIELD_DECL.
    1855              :    i.e. a method of the form { return FIELD; }, with no
    1856              :    conversions.
    1857              : 
    1858              :    If CONST_P, then additionally require that FN be a const
    1859              :    method.  */
    1860              : 
    1861              : static bool
    1862         2417 : field_accessor_p (tree fn, tree field_decl, bool const_p)
    1863              : {
    1864         2417 :   if (TREE_CODE (fn) != FUNCTION_DECL)
    1865              :     return false;
    1866              : 
    1867              :   /* We don't yet support looking up static data, just fields.  */
    1868          648 :   if (TREE_CODE (field_decl) != FIELD_DECL)
    1869              :     return false;
    1870              : 
    1871          639 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (fn))
    1872              :     return false;
    1873              : 
    1874              :   /* If the field is accessed via a const "this" argument, verify
    1875              :      that the "this" parameter is const.  */
    1876          639 :   if (const_p)
    1877              :     {
    1878           61 :       tree this_class = class_of_object_parm (fn);
    1879           61 :       if (!TYPE_READONLY (this_class))
    1880              :         return false;
    1881              :     }
    1882              : 
    1883          601 :   tree saved_tree = DECL_SAVED_TREE (fn);
    1884              : 
    1885          601 :   if (saved_tree == NULL_TREE)
    1886              :     return false;
    1887              : 
    1888              :   /* Attempt to extract a single return value from the function,
    1889              :      if it has one.  */
    1890          235 :   tree retval = constexpr_fn_retval (saved_tree);
    1891          235 :   if (retval == NULL_TREE || retval == error_mark_node)
    1892              :     return false;
    1893              :   /* Require an INIT_EXPR.  */
    1894          209 :   if (TREE_CODE (retval) != INIT_EXPR)
    1895              :     return false;
    1896          209 :   tree init_expr = retval;
    1897              : 
    1898              :   /* Determine if this is a simple accessor within struct S of the form:
    1899              :        T get_field () { return m_field; }.  */
    1900          209 :   tree field_type = TREE_TYPE (field_decl);
    1901          209 :   if (cxx_types_compatible_p (TREE_TYPE (init_expr), field_type))
    1902          161 :     return direct_accessor_p (init_expr, field_decl, field_type);
    1903              : 
    1904              :   /* Failing that, determine if it is an accessor of the form:
    1905              :        T& get_field () { return m_field; }.  */
    1906           48 :   tree field_reference_type = cp_build_reference_type (field_type, false);
    1907           48 :   if (cxx_types_compatible_p (TREE_TYPE (init_expr), field_reference_type))
    1908           42 :     return reference_accessor_p (init_expr, field_decl, field_type,
    1909           42 :                                  field_reference_type);
    1910              : 
    1911              :   return false;
    1912              : }
    1913              : 
    1914              : /* Callback data for dfs_locate_field_accessor_pre.  */
    1915              : 
    1916              : class locate_field_data
    1917              : {
    1918              : public:
    1919          412 :   locate_field_data (tree field_decl_, bool const_p_)
    1920          412 :   : field_decl (field_decl_), const_p (const_p_) {}
    1921              : 
    1922              :   tree field_decl;
    1923              :   bool const_p;
    1924              : };
    1925              : 
    1926              : /* Return a FUNCTION_DECL that is an "accessor" method for DATA, a FIELD_DECL,
    1927              :    callable via binfo, if one exists, otherwise return NULL_TREE.
    1928              : 
    1929              :    Callback for dfs_walk_once_accessible for use within
    1930              :    locate_field_accessor.  */
    1931              : 
    1932              : static tree
    1933          454 : dfs_locate_field_accessor_pre (tree binfo, void *data)
    1934              : {
    1935          454 :   locate_field_data *lfd = (locate_field_data *)data;
    1936          454 :   tree type = BINFO_TYPE (binfo);
    1937              : 
    1938          454 :   vec<tree, va_gc> *member_vec;
    1939          454 :   tree fn;
    1940          454 :   size_t i;
    1941              : 
    1942          454 :   if (!CLASS_TYPE_P (type))
    1943              :     return NULL_TREE;
    1944              : 
    1945          454 :   member_vec = CLASSTYPE_MEMBER_VEC (type);
    1946          454 :   if (!member_vec)
    1947              :     return NULL_TREE;
    1948              : 
    1949         2594 :   for (i = 0; vec_safe_iterate (member_vec, i, &fn); ++i)
    1950         2417 :     if (fn)
    1951         2417 :       if (field_accessor_p (fn, lfd->field_decl, lfd->const_p))
    1952              :         return fn;
    1953              : 
    1954              :   return NULL_TREE;
    1955              : }
    1956              : 
    1957              : /* Return a FUNCTION_DECL that is an "accessor" method for FIELD_DECL,
    1958              :    callable via BASETYPE_PATH, if one exists, otherwise return NULL_TREE.  */
    1959              : 
    1960              : tree
    1961          412 : locate_field_accessor (tree basetype_path, tree field_decl, bool const_p)
    1962              : {
    1963          412 :   if (TREE_CODE (basetype_path) != TREE_BINFO)
    1964              :     return NULL_TREE;
    1965              : 
    1966              :   /* Walk the hierarchy, looking for a method of some base class that allows
    1967              :      access to the field.  */
    1968          412 :   locate_field_data lfd (field_decl, const_p);
    1969          412 :   return dfs_walk_once_accessible (basetype_path, /*friends=*/true,
    1970              :                                    dfs_locate_field_accessor_pre,
    1971          412 :                                    NULL, &lfd);
    1972              : }
    1973              : 
    1974              : /* Check throw specifier of OVERRIDER is at least as strict as
    1975              :    the one of BASEFN.  This is due to [except.spec]: "If a virtual function
    1976              :    has a non-throwing exception specification, all declarations, including
    1977              :    the definition, of any function that overrides that virtual function in
    1978              :    any derived class shall have a non-throwing exception specification,
    1979              :    unless the overriding function is defined as deleted."  */
    1980              : 
    1981              : bool
    1982      3682257 : maybe_check_overriding_exception_spec (tree overrider, tree basefn)
    1983              : {
    1984      3682257 :   maybe_instantiate_noexcept (basefn);
    1985      3682257 :   maybe_instantiate_noexcept (overrider);
    1986      3682257 :   tree base_throw = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (basefn));
    1987      3682257 :   tree over_throw = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (overrider));
    1988              : 
    1989      3682257 :   if (DECL_INVALID_OVERRIDER_P (overrider)
    1990              :       /* CWG 1351 added the "unless the overriding function is defined as
    1991              :          deleted" wording.  */
    1992      3682257 :       || DECL_DELETED_FN (overrider))
    1993              :     return true;
    1994              : 
    1995              :   /* Can't check this yet.  Pretend this is fine and let
    1996              :      noexcept_override_late_checks check this later.  */
    1997      2354609 :   if (UNPARSED_NOEXCEPT_SPEC_P (base_throw)
    1998      8391564 :       || UNPARSED_NOEXCEPT_SPEC_P (over_throw))
    1999              :     return true;
    2000              : 
    2001              :   /* We also have to defer checking when we're in a template and couldn't
    2002              :      instantiate & evaluate the noexcept to true/false.  */
    2003      3682242 :   if (processing_template_decl)
    2004            6 :     if ((base_throw
    2005            3 :          && base_throw != noexcept_true_spec
    2006            0 :          && base_throw != noexcept_false_spec)
    2007            6 :         || (over_throw
    2008            6 :             && over_throw != noexcept_true_spec
    2009            6 :             && over_throw != noexcept_false_spec))
    2010              :       return true;
    2011              : 
    2012      3682236 :   if (!comp_except_specs (base_throw, over_throw, ce_derived))
    2013              :     {
    2014           41 :       auto_diagnostic_group d;
    2015           41 :       error ("looser exception specification on overriding virtual function "
    2016              :              "%q+#F", overrider);
    2017           41 :       inform (DECL_SOURCE_LOCATION (basefn),
    2018              :               "overridden function is %q#F", basefn);
    2019           41 :       DECL_INVALID_OVERRIDER_P (overrider) = 1;
    2020           41 :       return false;
    2021           41 :     }
    2022              :   return true;
    2023              : }
    2024              : 
    2025              : /* Check that virtual overrider OVERRIDER is acceptable for base function
    2026              :    BASEFN. Issue diagnostic, and return zero, if unacceptable.  */
    2027              : 
    2028              : static int
    2029      3682302 : check_final_overrider (tree overrider, tree basefn)
    2030              : {
    2031      3682302 :   tree over_type = TREE_TYPE (overrider);
    2032      3682302 :   tree base_type = TREE_TYPE (basefn);
    2033      3682302 :   tree over_return = fndecl_declared_return_type (overrider);
    2034      3682302 :   tree base_return = fndecl_declared_return_type (basefn);
    2035              : 
    2036      3682302 :   int fail = 0;
    2037              : 
    2038      3682302 :   if (DECL_INVALID_OVERRIDER_P (overrider))
    2039              :     return 0;
    2040              : 
    2041      3682296 :   if (same_type_p (base_return, over_return))
    2042              :     /* OK */;
    2043            0 :   else if ((CLASS_TYPE_P (over_return) && CLASS_TYPE_P (base_return))
    2044          307 :            || (TREE_CODE (base_return) == TREE_CODE (over_return)
    2045          292 :                && INDIRECT_TYPE_P (base_return)))
    2046              :     {
    2047              :       /* Potentially covariant.  */
    2048          292 :       unsigned base_quals, over_quals;
    2049              : 
    2050          292 :       fail = !INDIRECT_TYPE_P (base_return);
    2051          292 :       if (!fail)
    2052              :         {
    2053          292 :           if (cp_type_quals (base_return) != cp_type_quals (over_return))
    2054            0 :             fail = 1;
    2055              : 
    2056          292 :           if (TYPE_REF_P (base_return)
    2057          292 :               && (TYPE_REF_IS_RVALUE (base_return)
    2058           60 :                   != TYPE_REF_IS_RVALUE (over_return)))
    2059              :             fail = 1;
    2060              : 
    2061          292 :           base_return = TREE_TYPE (base_return);
    2062          292 :           over_return = TREE_TYPE (over_return);
    2063              :         }
    2064          292 :       base_quals = cp_type_quals (base_return);
    2065          292 :       over_quals = cp_type_quals (over_return);
    2066              : 
    2067          292 :       if ((base_quals & over_quals) != over_quals)
    2068            3 :         fail = 1;
    2069              : 
    2070          292 :       if (CLASS_TYPE_P (base_return) && CLASS_TYPE_P (over_return))
    2071              :         {
    2072              :           /* Strictly speaking, the standard requires the return type to be
    2073              :              complete even if it only differs in cv-quals, but that seems
    2074              :              like a bug in the wording.  */
    2075          283 :           if (!same_type_ignoring_top_level_qualifiers_p (base_return,
    2076              :                                                           over_return))
    2077              :             {
    2078          273 :               tree binfo = lookup_base (over_return, base_return,
    2079              :                                         ba_check, NULL, tf_none);
    2080              : 
    2081          273 :               if (!binfo || binfo == error_mark_node)
    2082              :                 fail = 1;
    2083              :             }
    2084              :         }
    2085            9 :       else if (can_convert_standard (TREE_TYPE (base_type),
    2086            9 :                                      TREE_TYPE (over_type),
    2087              :                                      tf_warning_or_error))
    2088              :         /* GNU extension, allow trivial pointer conversions such as
    2089              :            converting to void *, or qualification conversion.  */
    2090              :         {
    2091            0 :           auto_diagnostic_group d;
    2092            0 :           if (pedwarn (DECL_SOURCE_LOCATION (overrider), 0,
    2093              :                        "invalid covariant return type for %q#D", overrider))
    2094            0 :             inform (DECL_SOURCE_LOCATION (basefn),
    2095              :                     "overridden function is %q#D", basefn);
    2096            0 :         }
    2097              :       else
    2098              :         fail = 2;
    2099              :     }
    2100              :   else
    2101              :     fail = 2;
    2102          268 :   if (!fail)
    2103              :     /* OK */;
    2104              :   else
    2105              :     {
    2106           45 :       auto_diagnostic_group d;
    2107           45 :       if (fail == 1)
    2108           21 :         error ("invalid covariant return type for %q+#D", overrider);
    2109              :       else
    2110           24 :         error ("conflicting return type specified for %q+#D", overrider);
    2111           45 :       inform (DECL_SOURCE_LOCATION (basefn),
    2112              :               "overridden function is %q#D", basefn);
    2113           45 :       DECL_INVALID_OVERRIDER_P (overrider) = 1;
    2114           45 :       return 0;
    2115           45 :     }
    2116              : 
    2117      3682251 :   if (!maybe_check_overriding_exception_spec (overrider, basefn))
    2118              :     return 0;
    2119              : 
    2120              :   /* Check for conflicting type attributes.  But leave transaction_safe for
    2121              :      set_one_vmethod_tm_attributes.  */
    2122      3682210 :   if (!comp_type_attributes (over_type, base_type)
    2123           63 :       && !tx_safe_fn_type_p (base_type)
    2124      3682217 :       && !tx_safe_fn_type_p (over_type))
    2125              :     {
    2126            0 :       auto_diagnostic_group d;
    2127            0 :       error ("conflicting type attributes specified for %q+#D", overrider);
    2128            0 :       inform (DECL_SOURCE_LOCATION (basefn),
    2129              :               "overridden function is %q#D", basefn);
    2130            0 :       DECL_INVALID_OVERRIDER_P (overrider) = 1;
    2131            0 :       return 0;
    2132            0 :     }
    2133              : 
    2134              :   /* A class with a consteval virtual function that overrides a virtual
    2135              :      function that is not consteval shall have consteval-only type (CWG 3117).
    2136              :      A consteval virtual function shall not be overridden by a virtual
    2137              :      function that is not consteval.  */
    2138      7364420 :   if ((DECL_IMMEDIATE_FUNCTION_P (basefn)
    2139           80 :        && !DECL_IMMEDIATE_FUNCTION_P (overrider))
    2140      3682243 :       || (!DECL_IMMEDIATE_FUNCTION_P (basefn)
    2141      7364340 :           && DECL_IMMEDIATE_FUNCTION_P (overrider)
    2142          845 :           && !consteval_only_p (overrider)))
    2143              :     {
    2144           12 :       auto_diagnostic_group d;
    2145           24 :       if (DECL_IMMEDIATE_FUNCTION_P (overrider))
    2146            5 :         error ("%<consteval%> function %q+D overriding non-%<consteval%> "
    2147              :                "function", overrider);
    2148              :       else
    2149            7 :         error ("non-%<consteval%> function %q+D overriding %<consteval%> "
    2150              :                "function", overrider);
    2151           12 :       inform (DECL_SOURCE_LOCATION (basefn),
    2152              :               "overridden function is %qD", basefn);
    2153           12 :       DECL_INVALID_OVERRIDER_P (overrider) = 1;
    2154           12 :       return 0;
    2155           12 :     }
    2156              : 
    2157              :   /* A function declared transaction_safe_dynamic that overrides a function
    2158              :      declared transaction_safe (but not transaction_safe_dynamic) is
    2159              :      ill-formed.  */
    2160      3682198 :   if (tx_safe_fn_type_p (base_type)
    2161           72 :       && lookup_attribute ("transaction_safe_dynamic",
    2162           72 :                            DECL_ATTRIBUTES (overrider))
    2163      3682211 :       && !lookup_attribute ("transaction_safe_dynamic",
    2164           13 :                             DECL_ATTRIBUTES (basefn)))
    2165              :     {
    2166            1 :       auto_diagnostic_group d;
    2167            1 :       error_at (DECL_SOURCE_LOCATION (overrider),
    2168              :                 "%qD declared %<transaction_safe_dynamic%>", overrider);
    2169            1 :       inform (DECL_SOURCE_LOCATION (basefn),
    2170              :               "overriding %qD declared %<transaction_safe%>", basefn);
    2171            1 :     }
    2172              : 
    2173      3682198 :   if (DECL_DELETED_FN (basefn) != DECL_DELETED_FN (overrider))
    2174              :     {
    2175           15 :       if (DECL_DELETED_FN (overrider))
    2176              :         {
    2177           12 :           auto_diagnostic_group d;
    2178           12 :           error ("deleted function %q+D overriding non-deleted function",
    2179              :                  overrider);
    2180           12 :           inform (DECL_SOURCE_LOCATION (basefn),
    2181              :                   "overridden function is %qD", basefn);
    2182           12 :           maybe_explain_implicit_delete (overrider);
    2183           12 :         }
    2184              :       else
    2185              :         {
    2186            3 :           auto_diagnostic_group d;
    2187            3 :           error ("non-deleted function %q+D overriding deleted function",
    2188              :                  overrider);
    2189            3 :           inform (DECL_SOURCE_LOCATION (basefn),
    2190              :                   "overridden function is %qD", basefn);
    2191            3 :         }
    2192              :       return 0;
    2193              :     }
    2194              : 
    2195      3682183 :   if (DECL_FINAL_P (basefn))
    2196              :     {
    2197            6 :       auto_diagnostic_group d;
    2198            6 :       error ("virtual function %q+D overriding final function", overrider);
    2199            6 :       inform (DECL_SOURCE_LOCATION (basefn),
    2200              :               "overridden function is %qD", basefn);
    2201            6 :       return 0;
    2202            6 :     }
    2203              :   return 1;
    2204              : }
    2205              : 
    2206              : /* Given a class TYPE, and a function decl FNDECL, look for
    2207              :    virtual functions in TYPE's hierarchy which FNDECL overrides.
    2208              :    We do not look in TYPE itself, only its bases.
    2209              : 
    2210              :    Returns nonzero, if we find any. Set FNDECL's DECL_VIRTUAL_P, if we
    2211              :    find that it overrides anything.
    2212              : 
    2213              :    We check that every function which is overridden, is correctly
    2214              :    overridden.  */
    2215              : 
    2216              : int
    2217     18702226 : look_for_overrides (tree type, tree fndecl)
    2218              : {
    2219     18702226 :   tree binfo = TYPE_BINFO (type);
    2220     18702226 :   tree base_binfo;
    2221     18702226 :   int ix;
    2222     18702226 :   int found = 0;
    2223              : 
    2224              :   /* A constructor for a class T does not override a function T
    2225              :      in a base class.  */
    2226     37404452 :   if (DECL_CONSTRUCTOR_P (fndecl))
    2227              :     return 0;
    2228              : 
    2229     27808645 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    2230              :     {
    2231      9106419 :       tree basetype = BINFO_TYPE (base_binfo);
    2232              : 
    2233      9106419 :       if (TYPE_POLYMORPHIC_P (basetype))
    2234      5507676 :         found += look_for_overrides_r (basetype, fndecl);
    2235              :     }
    2236              :   return found;
    2237              : }
    2238              : 
    2239              : /* Look in TYPE for virtual functions with the same signature as
    2240              :    FNDECL.  */
    2241              : 
    2242              : tree
    2243     26515485 : look_for_overrides_here (tree type, tree fndecl)
    2244              : {
    2245     26515485 :   tree ovl = get_class_binding (type, DECL_NAME (fndecl));
    2246              : 
    2247     27394603 :   for (ovl_iterator iter (ovl); iter; ++iter)
    2248              :     {
    2249     20449479 :       tree fn = *iter;
    2250              : 
    2251     20449479 :       if (!DECL_VIRTUAL_P (fn))
    2252              :         /* Not a virtual.  */;
    2253     20352579 :       else if (DECL_CONTEXT (fn) != type)
    2254              :         /* Introduced with a using declaration.  */;
    2255     20352419 :       else if (DECL_STATIC_FUNCTION_P (fndecl)
    2256     20352419 :                || DECL_XOBJ_MEMBER_FUNCTION_P (fndecl))
    2257              :         {
    2258           36 :           tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
    2259           36 :           tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
    2260           36 :           dtypes = DECL_XOBJ_MEMBER_FUNCTION_P (fndecl) ? TREE_CHAIN (dtypes)
    2261              :                                                         : dtypes;
    2262           36 :           if (compparms (TREE_CHAIN (btypes), dtypes))
    2263     19960516 :             return fn;
    2264              :         }
    2265     20352383 :       else if (same_signature_p (fndecl, fn))
    2266              :         return fn;
    2267              :     }
    2268              : 
    2269      6554969 :   return NULL_TREE;
    2270              : }
    2271              : 
    2272              : /* Look in TYPE for virtual functions overridden by FNDECL. Check both
    2273              :    TYPE itself and its bases.  */
    2274              : 
    2275              : static int
    2276      5507676 : look_for_overrides_r (tree type, tree fndecl)
    2277              : {
    2278      5507676 :   tree fn = look_for_overrides_here (type, fndecl);
    2279      5507676 :   if (fn)
    2280              :     {
    2281      3682332 :       if (DECL_STATIC_FUNCTION_P (fndecl))
    2282              :         {
    2283              :           /* A static member function cannot match an inherited
    2284              :              virtual member function.  */
    2285            6 :           auto_diagnostic_group d;
    2286            6 :           error ("%q+#D cannot be declared", fndecl);
    2287            6 :           error ("  since %q+#D declared in base class", fn);
    2288            6 :         }
    2289      3682326 :       else if (DECL_XOBJ_MEMBER_FUNCTION_P (fndecl))
    2290              :         {
    2291           24 :           auto_diagnostic_group d;
    2292           24 :           error_at (DECL_SOURCE_LOCATION (fndecl),
    2293              :                     "explicit object member function "
    2294              :                     "overrides virtual function");
    2295           24 :           inform (DECL_SOURCE_LOCATION (fn),
    2296              :                   "virtual function declared here");
    2297           24 :         }
    2298              :       else
    2299              :         {
    2300              :           /* It's definitely virtual, even if not explicitly set.  */
    2301      3682302 :           DECL_VIRTUAL_P (fndecl) = 1;
    2302      3682302 :           check_final_overrider (fndecl, fn);
    2303              :         }
    2304              :       return 1;
    2305              :     }
    2306              : 
    2307              :   /* We failed to find one declared in this class. Look in its bases.  */
    2308      1825344 :   return look_for_overrides (type, fndecl);
    2309              : }
    2310              : 
    2311              : /* Called via dfs_walk from dfs_get_pure_virtuals.  */
    2312              : 
    2313              : static tree
    2314      5221370 : dfs_get_pure_virtuals (tree binfo, void *data)
    2315              : {
    2316      5221370 :   tree type = (tree) data;
    2317              : 
    2318              :   /* We're not interested in primary base classes; the derived class
    2319              :      of which they are a primary base will contain the information we
    2320              :      need.  */
    2321      5221370 :   if (!BINFO_PRIMARY_P (binfo))
    2322              :     {
    2323      2516812 :       tree virtuals;
    2324              : 
    2325      2516812 :       for (virtuals = BINFO_VIRTUALS (binfo);
    2326     12540243 :            virtuals;
    2327     10023431 :            virtuals = TREE_CHAIN (virtuals))
    2328     10023431 :         if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals)))
    2329       662830 :           vec_safe_push (CLASSTYPE_PURE_VIRTUALS (type), BV_FN (virtuals));
    2330              :     }
    2331              : 
    2332      5221370 :   return NULL_TREE;
    2333              : }
    2334              : 
    2335              : /* Set CLASSTYPE_PURE_VIRTUALS for TYPE.  */
    2336              : 
    2337              : void
    2338      1630880 : get_pure_virtuals (tree type)
    2339              : {
    2340              :   /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
    2341              :      is going to be overridden.  */
    2342      1630880 :   CLASSTYPE_PURE_VIRTUALS (type) = NULL;
    2343              :   /* Now, run through all the bases which are not primary bases, and
    2344              :      collect the pure virtual functions.  We look at the vtable in
    2345              :      each class to determine what pure virtual functions are present.
    2346              :      (A primary base is not interesting because the derived class of
    2347              :      which it is a primary base will contain vtable entries for the
    2348              :      pure virtuals in the base class.  */
    2349      1630880 :   dfs_walk_once (TYPE_BINFO (type), NULL, dfs_get_pure_virtuals, type);
    2350      1630880 : }
    2351              : 
    2352              : /* Debug info for C++ classes can get very large; try to avoid
    2353              :    emitting it everywhere.
    2354              : 
    2355              :    Note that this optimization wins even when the target supports
    2356              :    BINCL (if only slightly), and reduces the amount of work for the
    2357              :    linker.  */
    2358              : 
    2359              : void
    2360     53320001 : maybe_suppress_debug_info (tree t)
    2361              : {
    2362     53320001 :   if (write_symbols == NO_DEBUG)
    2363              :     return;
    2364              : 
    2365              :   /* We might have set this earlier in cp_finish_decl.  */
    2366     49505225 :   TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 0;
    2367              : 
    2368              :   /* Always emit the information for each class every time. */
    2369     49505225 :   if (flag_emit_class_debug_always)
    2370              :     return;
    2371              : 
    2372              :   /* If we already know how we're handling this class, handle debug info
    2373              :      the same way.  */
    2374     49505225 :   if (CLASSTYPE_INTERFACE_KNOWN (t))
    2375              :     {
    2376            1 :       if (CLASSTYPE_INTERFACE_ONLY (t))
    2377            1 :         TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
    2378              :       /* else don't set it.  */
    2379              :     }
    2380              :   /* If the class has a vtable, write out the debug info along with
    2381              :      the vtable.  */
    2382     49505224 :   else if (TYPE_CONTAINS_VPTR_P (t))
    2383      1729842 :     TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
    2384              : 
    2385              :   /* Otherwise, just emit the debug info normally.  */
    2386              : }
    2387              : 
    2388              : /* Note that we want debugging information for a base class of a class
    2389              :    whose vtable is being emitted.  Normally, this would happen because
    2390              :    calling the constructor for a derived class implies calling the
    2391              :    constructors for all bases, which involve initializing the
    2392              :    appropriate vptr with the vtable for the base class; but in the
    2393              :    presence of optimization, this initialization may be optimized
    2394              :    away, so we tell finish_vtable_vardecl that we want the debugging
    2395              :    information anyway.  */
    2396              : 
    2397              : static tree
    2398       876144 : dfs_debug_mark (tree binfo, void * /*data*/)
    2399              : {
    2400       876144 :   tree t = BINFO_TYPE (binfo);
    2401              : 
    2402       876144 :   if (CLASSTYPE_DEBUG_REQUESTED (t))
    2403              :     return dfs_skip_bases;
    2404              : 
    2405       533212 :   CLASSTYPE_DEBUG_REQUESTED (t) = 1;
    2406              : 
    2407       533212 :   return NULL_TREE;
    2408              : }
    2409              : 
    2410              : /* Write out the debugging information for TYPE, whose vtable is being
    2411              :    emitted.  Also walk through our bases and note that we want to
    2412              :    write out information for them.  This avoids the problem of not
    2413              :    writing any debug info for intermediate basetypes whose
    2414              :    constructors, and thus the references to their vtables, and thus
    2415              :    the vtables themselves, were optimized away.  */
    2416              : 
    2417              : void
    2418       397437 : note_debug_info_needed (tree type)
    2419              : {
    2420       397437 :   if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
    2421              :     {
    2422       349874 :       TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)) = 0;
    2423       349874 :       rest_of_type_compilation (type, namespace_bindings_p ());
    2424              :     }
    2425              : 
    2426       397437 :   dfs_walk_all (TYPE_BINFO (type), dfs_debug_mark, NULL, 0);
    2427       397437 : }
    2428              : 
    2429              : /* Helper for lookup_conversions_r.  TO_TYPE is the type converted to
    2430              :    by a conversion op in base BINFO.  VIRTUAL_DEPTH is nonzero if
    2431              :    BINFO is morally virtual, and VIRTUALNESS is nonzero if virtual
    2432              :    bases have been encountered already in the tree walk.  PARENT_CONVS
    2433              :    is the list of lists of conversion functions that could hide CONV
    2434              :    and OTHER_CONVS is the list of lists of conversion functions that
    2435              :    could hide or be hidden by CONV, should virtualness be involved in
    2436              :    the hierarchy.  Merely checking the conversion op's name is not
    2437              :    enough because two conversion operators to the same type can have
    2438              :    different names.  Return nonzero if we are visible.  */
    2439              : 
    2440              : static int
    2441     42134190 : check_hidden_convs (tree binfo, int virtual_depth, int virtualness,
    2442              :                     tree to_type, tree parent_convs, tree other_convs)
    2443              : {
    2444     42134190 :   tree level, probe;
    2445              : 
    2446              :   /* See if we are hidden by a parent conversion.  */
    2447     42136316 :   for (level = parent_convs; level; level = TREE_CHAIN (level))
    2448       104852 :     for (probe = TREE_VALUE (level); probe; probe = TREE_CHAIN (probe))
    2449       102726 :       if (same_type_p (to_type, TREE_TYPE (probe)))
    2450              :         return 0;
    2451              : 
    2452     42074220 :   if (virtual_depth || virtualness)
    2453              :     {
    2454              :      /* In a virtual hierarchy, we could be hidden, or could hide a
    2455              :         conversion function on the other_convs list.  */
    2456       110463 :       for (level = other_convs; level; level = TREE_CHAIN (level))
    2457              :         {
    2458         1735 :           int we_hide_them;
    2459         1735 :           int they_hide_us;
    2460         1735 :           tree *prev, other;
    2461              : 
    2462         1735 :           if (!(virtual_depth || TREE_STATIC (level)))
    2463              :             /* Neither is morally virtual, so cannot hide each other.  */
    2464            0 :             continue;
    2465              : 
    2466         1735 :           if (!TREE_VALUE (level))
    2467              :             /* They evaporated away already.  */
    2468            0 :             continue;
    2469              : 
    2470         3470 :           they_hide_us = (virtual_depth
    2471         1735 :                           && original_binfo (binfo, TREE_PURPOSE (level)));
    2472            6 :           we_hide_them = (!they_hide_us && TREE_STATIC (level)
    2473            6 :                           && original_binfo (TREE_PURPOSE (level), binfo));
    2474              : 
    2475         1729 :           if (!(we_hide_them || they_hide_us))
    2476              :             /* Neither is within the other, so no hiding can occur.  */
    2477            0 :             continue;
    2478              : 
    2479         1741 :           for (prev = &TREE_VALUE (level), other = *prev; other;)
    2480              :             {
    2481         1735 :               if (same_type_p (to_type, TREE_TYPE (other)))
    2482              :                 {
    2483         1735 :                   if (they_hide_us)
    2484              :                     /* We are hidden.  */
    2485              :                     return 0;
    2486              : 
    2487            6 :                   if (we_hide_them)
    2488              :                     {
    2489              :                       /* We hide the other one.  */
    2490            6 :                       other = TREE_CHAIN (other);
    2491            6 :                       *prev = other;
    2492            6 :                       continue;
    2493              :                     }
    2494              :                 }
    2495            0 :               prev = &TREE_CHAIN (other);
    2496            0 :               other = *prev;
    2497              :             }
    2498              :         }
    2499              :     }
    2500              :   return 1;
    2501              : }
    2502              : 
    2503              : /* Helper for lookup_conversions_r.  PARENT_CONVS is a list of lists
    2504              :    of conversion functions, the first slot will be for the current
    2505              :    binfo, if MY_CONVS is non-NULL.  CHILD_CONVS is the list of lists
    2506              :    of conversion functions from children of the current binfo,
    2507              :    concatenated with conversions from elsewhere in the hierarchy --
    2508              :    that list begins with OTHER_CONVS.  Return a single list of lists
    2509              :    containing only conversions from the current binfo and its
    2510              :    children.  */
    2511              : 
    2512              : static tree
    2513     36037993 : split_conversions (tree my_convs, tree parent_convs,
    2514              :                    tree child_convs, tree other_convs)
    2515              : {
    2516     36037993 :   tree t;
    2517     36037993 :   tree prev;
    2518              : 
    2519              :   /* Remove the original other_convs portion from child_convs.  */
    2520     36037993 :   for (prev = NULL, t = child_convs;
    2521     37052999 :        t != other_convs; prev = t, t = TREE_CHAIN (t))
    2522      1015006 :     continue;
    2523              : 
    2524     36037993 :   if (prev)
    2525      1014913 :     TREE_CHAIN (prev) = NULL_TREE;
    2526              :   else
    2527              :     child_convs = NULL_TREE;
    2528              : 
    2529              :   /* Attach the child convs to any we had at this level.  */
    2530     36037993 :   if (my_convs)
    2531              :     {
    2532     34963014 :       my_convs = parent_convs;
    2533     34963014 :       TREE_CHAIN (my_convs) = child_convs;
    2534              :     }
    2535              :   else
    2536              :     my_convs = child_convs;
    2537              : 
    2538     36037993 :   return my_convs;
    2539      1015006 : }
    2540              : 
    2541              : /* Worker for lookup_conversions.  Lookup conversion functions in
    2542              :    BINFO and its children.  VIRTUAL_DEPTH is nonzero, if BINFO is in a
    2543              :    morally virtual base, and VIRTUALNESS is nonzero, if we've
    2544              :    encountered virtual bases already in the tree walk.  PARENT_CONVS
    2545              :    is a list of conversions within parent binfos.  OTHER_CONVS are
    2546              :    conversions found elsewhere in the tree.  Return the conversions
    2547              :    found within this portion of the graph in CONVS.  Return nonzero if
    2548              :    we encountered virtualness.  We keep template and non-template
    2549              :    conversions separate, to avoid unnecessary type comparisons.
    2550              : 
    2551              :    The located conversion functions are held in lists of lists.  The
    2552              :    TREE_VALUE of the outer list is the list of conversion functions
    2553              :    found in a particular binfo.  The TREE_PURPOSE of both the outer
    2554              :    and inner lists is the binfo at which those conversions were
    2555              :    found.  TREE_STATIC is set for those lists within of morally
    2556              :    virtual binfos.  The TREE_VALUE of the inner list is the conversion
    2557              :    function or overload itself.  The TREE_TYPE of each inner list node
    2558              :    is the converted-to type.  */
    2559              : 
    2560              : static int
    2561     83175479 : lookup_conversions_r (tree binfo, int virtual_depth, int virtualness,
    2562              :                       tree parent_convs, tree other_convs, tree *convs)
    2563              : {
    2564     83175479 :   int my_virtualness = 0;
    2565     83175479 :   tree my_convs = NULL_TREE;
    2566     83175479 :   tree child_convs = NULL_TREE;
    2567              : 
    2568              :   /* If we have no conversion operators, then don't look.  */
    2569     83175479 :   if (!TYPE_HAS_CONVERSION (BINFO_TYPE (binfo)))
    2570              :     {
    2571     47137486 :       *convs = NULL_TREE;
    2572              : 
    2573     47137486 :       return 0;
    2574              :     }
    2575              : 
    2576     36037993 :   if (BINFO_VIRTUAL_P (binfo))
    2577       110463 :     virtual_depth++;
    2578              : 
    2579              :   /* First, locate the unhidden ones at this level.  */
    2580     36037993 :   if (tree conv = get_class_binding (BINFO_TYPE (binfo), conv_op_identifier))
    2581     87888505 :   for (ovl_iterator iter (conv); iter; ++iter)
    2582              :     {
    2583     42134190 :       tree fn = *iter;
    2584     42134190 :       tree type = DECL_CONV_FN_TYPE (fn);
    2585              : 
    2586     42134190 :       if (TREE_CODE (fn) != TEMPLATE_DECL && type_uses_auto (type))
    2587              :         {
    2588            3 :           mark_used (fn);
    2589            3 :           type = DECL_CONV_FN_TYPE (fn);
    2590              :         }
    2591              : 
    2592     42134190 :       if (check_hidden_convs (binfo, virtual_depth, virtualness,
    2593              :                               type, parent_convs, other_convs))
    2594              :         {
    2595     42072491 :           my_convs = tree_cons (binfo, fn, my_convs);
    2596     42072491 :           TREE_TYPE (my_convs) = type;
    2597     42072491 :           if (virtual_depth)
    2598              :             {
    2599       108722 :               TREE_STATIC (my_convs) = 1;
    2600       108722 :               my_virtualness = 1;
    2601              :             }
    2602              :         }
    2603              :     }
    2604              : 
    2605     35022497 :   if (my_convs)
    2606              :     {
    2607     34963014 :       parent_convs = tree_cons (binfo, my_convs, parent_convs);
    2608     34963014 :       if (virtual_depth)
    2609       108722 :         TREE_STATIC (parent_convs) = 1;
    2610              :     }
    2611              : 
    2612     36037993 :   child_convs = other_convs;
    2613              : 
    2614              :   /* Now iterate over each base, looking for more conversions.  */
    2615     36037993 :   unsigned i;
    2616     36037993 :   tree base_binfo;
    2617     38158628 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    2618              :     {
    2619      2120635 :       tree base_convs;
    2620      2120635 :       unsigned base_virtualness;
    2621              : 
    2622      2120635 :       base_virtualness = lookup_conversions_r (base_binfo,
    2623              :                                                virtual_depth, virtualness,
    2624              :                                                parent_convs, child_convs,
    2625              :                                                &base_convs);
    2626      2120635 :       if (base_virtualness)
    2627       126347 :         my_virtualness = virtualness = 1;
    2628      2120635 :       child_convs = chainon (base_convs, child_convs);
    2629              :     }
    2630              : 
    2631     36037993 :   *convs = split_conversions (my_convs, parent_convs,
    2632              :                               child_convs, other_convs);
    2633              : 
    2634     36037993 :   return my_virtualness;
    2635              : }
    2636              : 
    2637              : /* Return a TREE_LIST containing all the non-hidden user-defined
    2638              :    conversion functions for TYPE (and its base-classes).  The
    2639              :    TREE_VALUE of each node is the FUNCTION_DECL of the conversion
    2640              :    function.  The TREE_PURPOSE is the BINFO from which the conversion
    2641              :    functions in this node were selected.  This function is effectively
    2642              :    performing a set of member lookups as lookup_fnfield does, but
    2643              :    using the type being converted to as the unique key, rather than the
    2644              :    field name.  */
    2645              : 
    2646              : tree
    2647     81055254 : lookup_conversions (tree type)
    2648              : {
    2649     81055254 :   tree convs;
    2650              : 
    2651     81055254 :   complete_type (type);
    2652     81055254 :   if (!CLASS_TYPE_P (type) || !TYPE_BINFO (type))
    2653              :     return NULL_TREE;
    2654              : 
    2655     81054844 :   lookup_conversions_r (TYPE_BINFO (type), 0, 0, NULL_TREE, NULL_TREE, &convs);
    2656              : 
    2657     81054844 :   tree list = NULL_TREE;
    2658              : 
    2659              :   /* Flatten the list-of-lists */
    2660    197072702 :   for (; convs; convs = TREE_CHAIN (convs))
    2661              :     {
    2662     34963014 :       tree probe, next;
    2663              : 
    2664     77035499 :       for (probe = TREE_VALUE (convs); probe; probe = next)
    2665              :         {
    2666     42072485 :           next = TREE_CHAIN (probe);
    2667              : 
    2668     42072485 :           TREE_CHAIN (probe) = list;
    2669     42072485 :           list = probe;
    2670              :         }
    2671              :     }
    2672              : 
    2673              :   return list;
    2674              : }
    2675              : 
    2676              : /* Returns the binfo of the first direct or indirect virtual base derived
    2677              :    from BINFO, or NULL if binfo is not via virtual.  */
    2678              : 
    2679              : tree
    2680           78 : binfo_from_vbase (tree binfo)
    2681              : {
    2682          123 :   for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
    2683              :     {
    2684          123 :       if (BINFO_VIRTUAL_P (binfo))
    2685              :         return binfo;
    2686              :     }
    2687              :   return NULL_TREE;
    2688              : }
    2689              : 
    2690              : /* Returns the binfo of the first direct or indirect virtual base derived
    2691              :    from BINFO up to the TREE_TYPE, LIMIT, or NULL if binfo is not
    2692              :    via virtual.  */
    2693              : 
    2694              : tree
    2695    473190433 : binfo_via_virtual (tree binfo, tree limit)
    2696              : {
    2697    473190433 :   if (limit && !CLASSTYPE_VBASECLASSES (limit))
    2698              :     /* LIMIT has no virtual bases, so BINFO cannot be via one.  */
    2699              :     return NULL_TREE;
    2700              : 
    2701     13657051 :   for (; binfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), limit);
    2702      1905711 :        binfo = BINFO_INHERITANCE_CHAIN (binfo))
    2703              :     {
    2704      4061772 :       if (BINFO_VIRTUAL_P (binfo))
    2705              :         return binfo;
    2706              :     }
    2707              :   return NULL_TREE;
    2708              : }
    2709              : 
    2710              : /* BINFO is for a base class in some hierarchy.  Return true iff it is a
    2711              :    direct base.  */
    2712              : 
    2713              : bool
    2714       110206 : binfo_direct_p (tree binfo)
    2715              : {
    2716       110206 :   tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
    2717       110206 :   if (BINFO_INHERITANCE_CHAIN (d_binfo))
    2718              :     /* A second inheritance chain means indirect.  */
    2719              :     return false;
    2720       110200 :   if (!BINFO_VIRTUAL_P (binfo))
    2721              :     /* Non-virtual, so only one inheritance chain means direct.  */
    2722              :     return true;
    2723              :   /* A virtual base looks like a direct base, so we need to look through the
    2724              :      direct bases to see if it's there.  */
    2725              :   tree b_binfo;
    2726           27 :   for (int i = 0; BINFO_BASE_ITERATE (d_binfo, i, b_binfo); ++i)
    2727           24 :     if (b_binfo == binfo)
    2728              :       return true;
    2729              :   return false;
    2730              : }
    2731              : 
    2732              : /* BINFO is a base binfo in the complete type BINFO_TYPE (HERE).
    2733              :    Find the equivalent binfo within whatever graph HERE is located.
    2734              :    This is the inverse of original_binfo.  */
    2735              : 
    2736              : tree
    2737     29408081 : copied_binfo (tree binfo, tree here)
    2738              : {
    2739     29408081 :   tree result = NULL_TREE;
    2740              : 
    2741     29408081 :   if (BINFO_VIRTUAL_P (binfo))
    2742              :     {
    2743              :       tree t;
    2744              : 
    2745      6623441 :       for (t = here; BINFO_INHERITANCE_CHAIN (t);
    2746      3440644 :            t = BINFO_INHERITANCE_CHAIN (t))
    2747      3440644 :         continue;
    2748              : 
    2749      3182797 :       result = binfo_for_vbase (BINFO_TYPE (binfo), BINFO_TYPE (t));
    2750      3440644 :     }
    2751     26225284 :   else if (BINFO_INHERITANCE_CHAIN (binfo))
    2752              :     {
    2753     13112642 :       tree cbinfo;
    2754     13112642 :       tree base_binfo;
    2755     13112642 :       int ix;
    2756              : 
    2757     13112642 :       cbinfo = copied_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
    2758     26251188 :       for (ix = 0; BINFO_BASE_ITERATE (cbinfo, ix, base_binfo); ix++)
    2759     13138546 :         if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo)))
    2760              :           {
    2761              :             result = base_binfo;
    2762              :             break;
    2763              :           }
    2764              :     }
    2765              :   else
    2766              :     {
    2767     13112642 :       gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (here), BINFO_TYPE (binfo)));
    2768              :       result = here;
    2769              :     }
    2770              : 
    2771     29408081 :   gcc_assert (result);
    2772     29408081 :   return result;
    2773              : }
    2774              : 
    2775              : tree
    2776      6525807 : binfo_for_vbase (tree base, tree t)
    2777              : {
    2778      6525807 :   unsigned ix;
    2779      6525807 :   tree binfo;
    2780      6525807 :   vec<tree, va_gc> *vbases;
    2781              : 
    2782      6525807 :   for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
    2783     67797060 :        vec_safe_iterate (vbases, ix, &binfo); ix++)
    2784     66253353 :     if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), base))
    2785              :       return binfo;
    2786              :   return NULL;
    2787              : }
    2788              : 
    2789              : /* BINFO is some base binfo of HERE, within some other
    2790              :    hierarchy. Return the equivalent binfo, but in the hierarchy
    2791              :    dominated by HERE.  This is the inverse of copied_binfo.  If BINFO
    2792              :    is not a base binfo of HERE, returns NULL_TREE.  */
    2793              : 
    2794              : tree
    2795         1735 : original_binfo (tree binfo, tree here)
    2796              : {
    2797         1735 :   tree result = NULL;
    2798              : 
    2799         1735 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (here)))
    2800              :     result = here;
    2801           12 :   else if (BINFO_VIRTUAL_P (binfo))
    2802           12 :     result = (CLASSTYPE_VBASECLASSES (BINFO_TYPE (here))
    2803           12 :               ? binfo_for_vbase (BINFO_TYPE (binfo), BINFO_TYPE (here))
    2804              :               : NULL_TREE);
    2805            0 :   else if (BINFO_INHERITANCE_CHAIN (binfo))
    2806              :     {
    2807            0 :       tree base_binfos;
    2808              : 
    2809            0 :       base_binfos = original_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
    2810            0 :       if (base_binfos)
    2811              :         {
    2812              :           int ix;
    2813              :           tree base_binfo;
    2814              : 
    2815            0 :           for (ix = 0; (base_binfo = BINFO_BASE_BINFO (base_binfos, ix)); ix++)
    2816            0 :             if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
    2817              :                                    BINFO_TYPE (binfo)))
    2818              :               {
    2819              :                 result = base_binfo;
    2820              :                 break;
    2821              :               }
    2822              :         }
    2823              :     }
    2824              : 
    2825         1735 :   return result;
    2826              : }
    2827              : 
    2828              : /* True iff TYPE has any dependent bases (and therefore we can't say
    2829              :    definitively that another class is not a base of an instantiation of
    2830              :    TYPE).  */
    2831              : 
    2832              : bool
    2833    169018926 : any_dependent_bases_p (tree type /* = current_nonlambda_class_type () */)
    2834              : {
    2835    169018926 :   if (!type || !CLASS_TYPE_P (type) || !uses_template_parms (type))
    2836              :     return false;
    2837              : 
    2838              :   /* If we haven't set TYPE_BINFO yet, we don't know anything about the bases.
    2839              :      Return false because in this situation we aren't actually looking up names
    2840              :      in the scope of the class, so it doesn't matter whether it has dependent
    2841              :      bases.  */
    2842     49219322 :   if (!TYPE_BINFO (type))
    2843              :     return false;
    2844              : 
    2845              :   unsigned i;
    2846              :   tree base_binfo;
    2847     51473073 :   FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_BINFOS (TYPE_BINFO (type)), i, base_binfo)
    2848     33423860 :     if (BINFO_DEPENDENT_BASE_P (base_binfo)
    2849              :         /* Recurse to also consider possibly dependent bases of a base that
    2850              :            is part of the current instantiation.  */
    2851     33423860 :         || any_dependent_bases_p (BINFO_TYPE (base_binfo)))
    2852              :       return true;
    2853              : 
    2854              :   return false;
    2855              : }
        

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