LCOV - code coverage report
Current view: top level - gcc/cp - search.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 870 903 96.3 %
Date: 2020-03-28 11:57:23 Functions: 65 65 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.0

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 --enable-host-shared. GCC test suite is run with the built compiler.