LCOV - code coverage report
Current view: top level - gcc/cp - class.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.5 % 4385 4231
Test Date: 2025-06-21 16:26:05 Functions: 97.6 % 206 201
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Functions related to building -*- C++ -*- classes and their related objects.
       2                 :             :    Copyright (C) 1987-2025 Free Software Foundation, Inc.
       3                 :             :    Contributed by Michael Tiemann (tiemann@cygnus.com)
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify
       8                 :             : it under the terms of the GNU General Public License as published by
       9                 :             : the Free Software Foundation; either version 3, or (at your option)
      10                 :             : any later version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful,
      13                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :             : GNU General Public License for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : 
      22                 :             : /* High-level class interface.  */
      23                 :             : 
      24                 :             : #include "config.h"
      25                 :             : #include "system.h"
      26                 :             : #include "coretypes.h"
      27                 :             : #include "target.h"
      28                 :             : #include "cp-tree.h"
      29                 :             : #include "stringpool.h"
      30                 :             : #include "cgraph.h"
      31                 :             : #include "stor-layout.h"
      32                 :             : #include "attribs.h"
      33                 :             : #include "flags.h"
      34                 :             : #include "toplev.h"
      35                 :             : #include "convert.h"
      36                 :             : #include "dumpfile.h"
      37                 :             : #include "gimplify.h"
      38                 :             : #include "intl.h"
      39                 :             : #include "asan.h"
      40                 :             : 
      41                 :             : /* Id for dumping the class hierarchy.  */
      42                 :             : int class_dump_id;
      43                 :             : 
      44                 :             : /* The number of nested classes being processed.  If we are not in the
      45                 :             :    scope of any class, this is zero.  */
      46                 :             : 
      47                 :             : int current_class_depth;
      48                 :             : 
      49                 :             : /* In order to deal with nested classes, we keep a stack of classes.
      50                 :             :    The topmost entry is the innermost class, and is the entry at index
      51                 :             :    CURRENT_CLASS_DEPTH  */
      52                 :             : 
      53                 :             : typedef struct class_stack_node {
      54                 :             :   /* The name of the class.  */
      55                 :             :   tree name;
      56                 :             : 
      57                 :             :   /* The _TYPE node for the class.  */
      58                 :             :   tree type;
      59                 :             : 
      60                 :             :   /* The access specifier pending for new declarations in the scope of
      61                 :             :      this class.  */
      62                 :             :   tree access;
      63                 :             : 
      64                 :             :   /* If were defining TYPE, the names used in this class.  */
      65                 :             :   splay_tree names_used;
      66                 :             : 
      67                 :             :   /* Nonzero if this class is no longer open, because of a call to
      68                 :             :      push_to_top_level.  */
      69                 :             :   size_t hidden;
      70                 :             : }* class_stack_node_t;
      71                 :             : 
      72                 :             : struct vtbl_init_data
      73                 :             : {
      74                 :             :   /* The base for which we're building initializers.  */
      75                 :             :   tree binfo;
      76                 :             :   /* The type of the most-derived type.  */
      77                 :             :   tree derived;
      78                 :             :   /* The binfo for the dynamic type. This will be TYPE_BINFO (derived),
      79                 :             :      unless ctor_vtbl_p is true.  */
      80                 :             :   tree rtti_binfo;
      81                 :             :   /* The negative-index vtable initializers built up so far.  These
      82                 :             :      are in order from least negative index to most negative index.  */
      83                 :             :   vec<constructor_elt, va_gc> *inits;
      84                 :             :   /* The binfo for the virtual base for which we're building
      85                 :             :      vcall offset initializers.  */
      86                 :             :   tree vbase;
      87                 :             :   /* The functions in vbase for which we have already provided vcall
      88                 :             :      offsets.  */
      89                 :             :   vec<tree, va_gc> *fns;
      90                 :             :   /* The vtable index of the next vcall or vbase offset.  */
      91                 :             :   tree index;
      92                 :             :   /* Nonzero if we are building the initializer for the primary
      93                 :             :      vtable.  */
      94                 :             :   int primary_vtbl_p;
      95                 :             :   /* Nonzero if we are building the initializer for a construction
      96                 :             :      vtable.  */
      97                 :             :   int ctor_vtbl_p;
      98                 :             :   /* True when adding vcall offset entries to the vtable.  False when
      99                 :             :      merely computing the indices.  */
     100                 :             :   bool generate_vcall_entries;
     101                 :             : };
     102                 :             : 
     103                 :             : /* The type of a function passed to walk_subobject_offsets.  */
     104                 :             : typedef int (*subobject_offset_fn) (tree, tree, splay_tree);
     105                 :             : 
     106                 :             : /* The stack itself.  This is a dynamically resized array.  The
     107                 :             :    number of elements allocated is CURRENT_CLASS_STACK_SIZE.  */
     108                 :             : static int current_class_stack_size;
     109                 :             : static class_stack_node_t current_class_stack;
     110                 :             : 
     111                 :             : /* The size of the largest empty class seen in this translation unit.  */
     112                 :             : static GTY (()) tree sizeof_biggest_empty_class;
     113                 :             : 
     114                 :             : static tree get_vfield_name (tree);
     115                 :             : static void finish_struct_anon (tree);
     116                 :             : static tree get_vtable_name (tree);
     117                 :             : static void get_basefndecls (tree, tree, vec<tree> *);
     118                 :             : static int build_primary_vtable (tree, tree);
     119                 :             : static int build_secondary_vtable (tree);
     120                 :             : static void finish_vtbls (tree);
     121                 :             : static void modify_vtable_entry (tree, tree, tree, tree, tree *);
     122                 :             : static void finish_struct_bits (tree);
     123                 :             : static int alter_access (tree, tree, tree);
     124                 :             : static void handle_using_decl (tree, tree);
     125                 :             : static tree dfs_modify_vtables (tree, void *);
     126                 :             : static tree modify_all_vtables (tree, tree);
     127                 :             : static void determine_primary_bases (tree);
     128                 :             : static void maybe_warn_about_overly_private_class (tree);
     129                 :             : static void add_implicitly_declared_members (tree, tree*, int, int);
     130                 :             : static tree fixed_type_or_null (tree, int *, int *);
     131                 :             : static tree build_simple_base_path (tree expr, tree binfo);
     132                 :             : static void build_vtbl_initializer (tree, tree, tree, tree, int *,
     133                 :             :                                     vec<constructor_elt, va_gc> **);
     134                 :             : static bool check_bitfield_decl (tree);
     135                 :             : static bool check_field_decl (tree, tree, int *, int *);
     136                 :             : static void check_field_decls (tree, tree *, int *, int *);
     137                 :             : static void build_base_fields (record_layout_info, splay_tree, tree *);
     138                 :             : static void check_methods (tree);
     139                 :             : static bool accessible_nvdtor_p (tree);
     140                 :             : 
     141                 :             : /* Used by find_flexarrays and related functions.  */
     142                 :             : struct flexmems_t;
     143                 :             : static void diagnose_flexarrays (tree, const flexmems_t *);
     144                 :             : static void find_flexarrays (tree, flexmems_t *, bool, bool = false,
     145                 :             :                              bool = false, tree = NULL_TREE);
     146                 :             : static void check_flexarrays (tree, flexmems_t * = NULL, bool = false);
     147                 :             : static void check_bases (tree, int *, int *);
     148                 :             : static void check_bases_and_members (tree);
     149                 :             : static tree create_vtable_ptr (tree, tree *);
     150                 :             : static void include_empty_classes (record_layout_info);
     151                 :             : static void layout_class_type (tree, tree *);
     152                 :             : static void propagate_binfo_offsets (tree, tree);
     153                 :             : static void layout_virtual_bases (record_layout_info, splay_tree);
     154                 :             : static void build_vbase_offset_vtbl_entries (tree, vtbl_init_data *);
     155                 :             : static void add_vcall_offset_vtbl_entries_r (tree, vtbl_init_data *);
     156                 :             : static void add_vcall_offset_vtbl_entries_1 (tree, vtbl_init_data *);
     157                 :             : static void build_vcall_offset_vtbl_entries (tree, vtbl_init_data *);
     158                 :             : static void add_vcall_offset (tree, tree, vtbl_init_data *);
     159                 :             : static void layout_vtable_decl (tree, int);
     160                 :             : static tree dfs_find_final_overrider_pre (tree, void *);
     161                 :             : static tree dfs_find_final_overrider_post (tree, void *);
     162                 :             : static tree find_final_overrider (tree, tree, tree);
     163                 :             : static int make_new_vtable (tree, tree);
     164                 :             : static tree get_primary_binfo (tree);
     165                 :             : static int maybe_indent_hierarchy (FILE *, int, int);
     166                 :             : static tree dump_class_hierarchy_r (FILE *, dump_flags_t, tree, tree, int);
     167                 :             : static void dump_class_hierarchy (tree);
     168                 :             : static void dump_class_hierarchy_1 (FILE *, dump_flags_t, tree);
     169                 :             : static void dump_array (FILE *, tree);
     170                 :             : static void dump_vtable (tree, tree, tree);
     171                 :             : static void dump_vtt (tree, tree);
     172                 :             : static void dump_thunk (FILE *, int, tree);
     173                 :             : static tree build_vtable (tree, tree, tree);
     174                 :             : static void initialize_vtable (tree, vec<constructor_elt, va_gc> *);
     175                 :             : static void layout_nonempty_base_or_field (record_layout_info,
     176                 :             :                                            tree, tree, splay_tree);
     177                 :             : static void accumulate_vtbl_inits (tree, tree, tree, tree, tree,
     178                 :             :                                    vec<constructor_elt, va_gc> **);
     179                 :             : static void dfs_accumulate_vtbl_inits (tree, tree, tree, tree, tree,
     180                 :             :                                        vec<constructor_elt, va_gc> **);
     181                 :             : static void build_rtti_vtbl_entries (tree, vtbl_init_data *);
     182                 :             : static void build_vcall_and_vbase_vtbl_entries (tree, vtbl_init_data *);
     183                 :             : static void clone_constructors_and_destructors (tree);
     184                 :             : static void update_vtable_entry_for_fn (tree, tree, tree, tree *, unsigned);
     185                 :             : static void build_ctor_vtbl_group (tree, tree);
     186                 :             : static void build_vtt (tree);
     187                 :             : static tree binfo_ctor_vtable (tree);
     188                 :             : static void build_vtt_inits (tree, tree, vec<constructor_elt, va_gc> **,
     189                 :             :                              tree *);
     190                 :             : static tree dfs_build_secondary_vptr_vtt_inits (tree, void *);
     191                 :             : static tree dfs_fixup_binfo_vtbls (tree, void *);
     192                 :             : static int record_subobject_offset (tree, tree, splay_tree);
     193                 :             : static int check_subobject_offset (tree, tree, splay_tree);
     194                 :             : static int walk_subobject_offsets (tree, subobject_offset_fn,
     195                 :             :                                    tree, splay_tree, tree, int);
     196                 :             : static int layout_conflict_p (tree, tree, splay_tree, int);
     197                 :             : static int splay_tree_compare_integer_csts (splay_tree_key k1,
     198                 :             :                                             splay_tree_key k2);
     199                 :             : static void maybe_warn_about_inaccessible_bases (tree);
     200                 :             : static bool type_requires_array_cookie (tree);
     201                 :             : static bool base_derived_from (tree, tree);
     202                 :             : static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree);
     203                 :             : static tree end_of_base (tree);
     204                 :             : static tree get_vcall_index (tree, tree);
     205                 :             : static bool type_maybe_constexpr_default_constructor (tree);
     206                 :             : static bool type_maybe_constexpr_destructor (tree);
     207                 :             : static bool field_poverlapping_p (tree);
     208                 :             : static void propagate_class_warmth_attribute (tree);
     209                 :             : 
     210                 :             : /* Set CURRENT_ACCESS_SPECIFIER based on the protection of DECL.  */
     211                 :             : 
     212                 :             : void
     213                 :   168966638 : set_current_access_from_decl (tree decl)
     214                 :             : {
     215                 :   168966638 :   if (TREE_PRIVATE (decl))
     216                 :    15654496 :     current_access_specifier = access_private_node;
     217                 :   153312142 :   else if (TREE_PROTECTED (decl))
     218                 :    10457446 :     current_access_specifier = access_protected_node;
     219                 :             :   else
     220                 :   142854696 :     current_access_specifier = access_public_node;
     221                 :   168966638 : }
     222                 :             : 
     223                 :             : /* Return a COND_EXPR that executes TRUE_STMT if this execution of the
     224                 :             :    'structor is in charge of 'structing virtual bases, or FALSE_STMT
     225                 :             :    otherwise.  */
     226                 :             : 
     227                 :             : tree
     228                 :      176588 : build_if_in_charge (tree true_stmt, tree false_stmt)
     229                 :             : {
     230                 :      176588 :   gcc_assert (DECL_HAS_IN_CHARGE_PARM_P (current_function_decl));
     231                 :      353176 :   tree cmp = build2 (NE_EXPR, boolean_type_node,
     232                 :      176588 :                      current_in_charge_parm, integer_zero_node);
     233                 :      176588 :   tree type = unlowered_expr_type (true_stmt);
     234                 :      176588 :   if (VOID_TYPE_P (type))
     235                 :       17572 :     type = unlowered_expr_type (false_stmt);
     236                 :      176588 :   tree cond = build3 (COND_EXPR, type,
     237                 :             :                       cmp, true_stmt, false_stmt);
     238                 :      176588 :   return cond;
     239                 :             : }
     240                 :             : 
     241                 :             : /* Convert to or from a base subobject.  EXPR is an expression of type
     242                 :             :    `A' or `A*', an expression of type `B' or `B*' is returned.  To
     243                 :             :    convert A to a base B, CODE is PLUS_EXPR and BINFO is the binfo for
     244                 :             :    the B base instance within A.  To convert base A to derived B, CODE
     245                 :             :    is MINUS_EXPR and BINFO is the binfo for the A instance within B.
     246                 :             :    In this latter case, A must not be a morally virtual base of B.
     247                 :             :    NONNULL is true if EXPR is known to be non-NULL (this is only
     248                 :             :    needed when EXPR is of pointer type).  CV qualifiers are preserved
     249                 :             :    from EXPR.  */
     250                 :             : 
     251                 :             : tree
     252                 :    47637626 : build_base_path (enum tree_code code,
     253                 :             :                  tree expr,
     254                 :             :                  tree binfo,
     255                 :             :                  int nonnull,
     256                 :             :                  tsubst_flags_t complain)
     257                 :             : {
     258                 :    47637626 :   tree v_binfo = NULL_TREE;
     259                 :    47637626 :   tree d_binfo = NULL_TREE;
     260                 :    47637626 :   tree probe;
     261                 :    47637626 :   tree offset;
     262                 :    47637626 :   tree target_type;
     263                 :    47637626 :   tree null_test = NULL;
     264                 :    47637626 :   tree ptr_target_type;
     265                 :    47637626 :   int fixed_type_p;
     266                 :    47637626 :   int want_pointer = TYPE_PTR_P (TREE_TYPE (expr));
     267                 :    47637626 :   bool has_empty = false;
     268                 :    47637626 :   bool virtual_access;
     269                 :    47637626 :   bool rvalue = false;
     270                 :             : 
     271                 :    47637626 :   if (expr == error_mark_node || binfo == error_mark_node || !binfo)
     272                 :             :     return error_mark_node;
     273                 :             : 
     274                 :   102952643 :   for (probe = binfo; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
     275                 :             :     {
     276                 :    55315032 :       d_binfo = probe;
     277                 :    55315032 :       if (is_empty_class (BINFO_TYPE (probe)))
     278                 :     7871376 :         has_empty = true;
     279                 :   110523294 :       if (!v_binfo && BINFO_VIRTUAL_P (probe))
     280                 :             :         v_binfo = probe;
     281                 :             :     }
     282                 :             : 
     283                 :    47637611 :   probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
     284                 :    47637611 :   if (want_pointer)
     285                 :    44443235 :     probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
     286                 :    47637611 :   if (dependent_type_p (probe))
     287                 :      298677 :     if (tree open = currently_open_class (probe))
     288                 :    47637611 :       probe = open;
     289                 :             : 
     290                 :    47637611 :   if (code == PLUS_EXPR
     291                 :    92813994 :       && !SAME_BINFO_TYPE_P (BINFO_TYPE (d_binfo), probe))
     292                 :             :     {
     293                 :             :       /* This can happen when adjust_result_of_qualified_name_lookup can't
     294                 :             :          find a unique base binfo in a call to a member function.  We
     295                 :             :          couldn't give the diagnostic then since we might have been calling
     296                 :             :          a static member function, so we do it now.  In other cases, eg.
     297                 :             :          during error recovery (c++/71979), we may not have a base at all.  */
     298                 :           6 :       if (complain & tf_error)
     299                 :             :         {
     300                 :           6 :           tree base = lookup_base (probe, BINFO_TYPE (d_binfo),
     301                 :             :                                    ba_unique, NULL, complain);
     302                 :           6 :           gcc_assert (base == error_mark_node || !base);
     303                 :             :         }
     304                 :           6 :       return error_mark_node;
     305                 :             :     }
     306                 :             : 
     307                 :    50098833 :   gcc_assert ((code == MINUS_EXPR
     308                 :             :                && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), probe))
     309                 :             :               || code == PLUS_EXPR);
     310                 :             : 
     311                 :    47637605 :   if (binfo == d_binfo)
     312                 :             :     /* Nothing to do.  */
     313                 :             :     return expr;
     314                 :             : 
     315                 :     7139189 :   if (code == MINUS_EXPR && v_binfo)
     316                 :             :     {
     317                 :          12 :       if (complain & tf_error)
     318                 :             :         {
     319                 :           9 :           if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (v_binfo)))
     320                 :             :             {
     321                 :           9 :               if (want_pointer)
     322                 :          18 :                 error ("cannot convert from pointer to base class %qT to "
     323                 :             :                        "pointer to derived class %qT because the base is "
     324                 :           9 :                        "virtual", BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
     325                 :             :               else
     326                 :           0 :                 error ("cannot convert from base class %qT to derived "
     327                 :             :                        "class %qT because the base is virtual",
     328                 :           0 :                        BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
     329                 :             :             }
     330                 :             :           else
     331                 :             :             {
     332                 :           0 :               if (want_pointer)
     333                 :           0 :                 error ("cannot convert from pointer to base class %qT to "
     334                 :             :                        "pointer to derived class %qT via virtual base %qT",
     335                 :           0 :                        BINFO_TYPE (binfo), BINFO_TYPE (d_binfo),
     336                 :           0 :                        BINFO_TYPE (v_binfo));
     337                 :             :               else
     338                 :           0 :                 error ("cannot convert from base class %qT to derived "
     339                 :           0 :                        "class %qT via virtual base %qT", BINFO_TYPE (binfo),
     340                 :           0 :                        BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo));
     341                 :             :             }
     342                 :             :         }
     343                 :          12 :       return error_mark_node;
     344                 :             :     }
     345                 :             : 
     346                 :    14278354 :   bool uneval = (cp_unevaluated_operand != 0
     347                 :     6844562 :                  || processing_template_decl
     348                 :    13626371 :                  || in_template_context);
     349                 :             : 
     350                 :             :   /* For a non-pointer simple base reference, express it as a COMPONENT_REF
     351                 :             :      without taking its address (and so causing lambda capture, 91933).  */
     352                 :     7139177 :   if (code == PLUS_EXPR && !v_binfo && !want_pointer && !has_empty && !uneval)
     353                 :     2086257 :     return build_simple_base_path (expr, binfo);
     354                 :             : 
     355                 :     5052920 :   if (!want_pointer)
     356                 :             :     {
     357                 :     1107834 :       rvalue = !lvalue_p (expr);
     358                 :             :       /* This must happen before the call to save_expr.  */
     359                 :     1107834 :       expr = cp_build_addr_expr (expr, complain);
     360                 :             :     }
     361                 :             :   else
     362                 :     3945086 :     expr = mark_rvalue_use (expr);
     363                 :             : 
     364                 :     5052920 :   offset = BINFO_OFFSET (binfo);
     365                 :     5052920 :   fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
     366                 :    10105840 :   target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo);
     367                 :             :   /* TARGET_TYPE has been extracted from BINFO, and, is therefore always
     368                 :             :      cv-unqualified.  Extract the cv-qualifiers from EXPR so that the
     369                 :             :      expression returned matches the input.  */
     370                 :     5052920 :   target_type = cp_build_qualified_type
     371                 :     5052920 :     (target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr))));
     372                 :     5052920 :   ptr_target_type = build_pointer_type (target_type);
     373                 :             : 
     374                 :             :   /* Do we need to look in the vtable for the real offset?  */
     375                 :     5052920 :   virtual_access = (v_binfo && fixed_type_p <= 0);
     376                 :             : 
     377                 :             :   /* Don't bother with the calculations inside sizeof; they'll ICE if the
     378                 :             :      source type is incomplete and the pointer value doesn't matter.  In a
     379                 :             :      template (even in instantiate_non_dependent_expr), we don't have vtables
     380                 :             :      set up properly yet, and the value doesn't matter there either; we're
     381                 :             :      just interested in the result of overload resolution.  */
     382                 :     5052920 :   if (uneval)
     383                 :             :     {
     384                 :      652013 :       expr = build_nop (ptr_target_type, expr);
     385                 :      652013 :       goto indout;
     386                 :             :     }
     387                 :             : 
     388                 :     4400907 :   if (!COMPLETE_TYPE_P (probe))
     389                 :             :     {
     390                 :           6 :       if (complain & tf_error)
     391                 :          18 :         error ("cannot convert from %qT to base class %qT because %qT is "
     392                 :           6 :                "incomplete", BINFO_TYPE (d_binfo), BINFO_TYPE (binfo),
     393                 :           6 :                BINFO_TYPE (d_binfo));
     394                 :           6 :       return error_mark_node;
     395                 :             :     }
     396                 :             : 
     397                 :             :   /* If we're in an NSDMI, we don't have the full constructor context yet
     398                 :             :      that we need for converting to a virtual base, so just build a stub
     399                 :             :      CONVERT_EXPR and expand it later in bot_replace.  */
     400                 :     4400901 :   if (virtual_access && fixed_type_p < 0
     401                 :     4400901 :       && current_scope () != current_function_decl)
     402                 :             :     {
     403                 :          33 :       expr = build1 (CONVERT_EXPR, ptr_target_type, expr);
     404                 :          33 :       CONVERT_EXPR_VBASE_PATH (expr) = true;
     405                 :          33 :       goto indout;
     406                 :             :     }
     407                 :             : 
     408                 :             :   /* Do we need to check for a null pointer?  */
     409                 :     4400868 :   if (want_pointer && !nonnull)
     410                 :             :     {
     411                 :             :       /* If we know the conversion will not actually change the value
     412                 :             :          of EXPR, then we can avoid testing the expression for NULL.
     413                 :             :          We have to avoid generating a COMPONENT_REF for a base class
     414                 :             :          field, because other parts of the compiler know that such
     415                 :             :          expressions are always non-NULL.  */
     416                 :       71218 :       if (!virtual_access && integer_zerop (offset))
     417                 :       69435 :         return build_nop (ptr_target_type, expr);
     418                 :        1783 :       null_test = error_mark_node;
     419                 :             :     }
     420                 :             : 
     421                 :             :   /* Protect against multiple evaluation if necessary.  */
     422                 :     4331433 :   if (TREE_SIDE_EFFECTS (expr) && (null_test || virtual_access))
     423                 :         776 :     expr = save_expr (expr);
     424                 :             : 
     425                 :             :   /* Store EXPR and build the real null test just before returning.  */
     426                 :     4331433 :   if (null_test)
     427                 :        1783 :     null_test = expr;
     428                 :             : 
     429                 :             :   /* If this is a simple base reference, express it as a COMPONENT_REF.  */
     430                 :     4331433 :   if (code == PLUS_EXPR && !virtual_access
     431                 :             :       /* We don't build base fields for empty bases, and they aren't very
     432                 :             :          interesting to the optimizers anyway.  */
     433                 :     4193727 :       && !has_empty)
     434                 :             :     {
     435                 :     2488596 :       expr = cp_build_fold_indirect_ref (expr);
     436                 :     2488596 :       expr = build_simple_base_path (expr, binfo);
     437                 :     2488596 :       if (rvalue && lvalue_p (expr))
     438                 :           0 :         expr = move (expr);
     439                 :     2488596 :       if (want_pointer)
     440                 :     2486701 :         expr = build_address (expr);
     441                 :     2488596 :       target_type = TREE_TYPE (expr);
     442                 :     2488596 :       goto out;
     443                 :             :     }
     444                 :             : 
     445                 :     1842837 :   if (virtual_access)
     446                 :             :     {
     447                 :             :       /* Going via virtual base V_BINFO.  We need the static offset
     448                 :             :          from V_BINFO to BINFO, and the dynamic offset from D_BINFO to
     449                 :             :          V_BINFO.  That offset is an entry in D_BINFO's vtable.  */
     450                 :       86566 :       tree v_offset;
     451                 :             : 
     452                 :       86566 :       if (fixed_type_p < 0 && in_base_initializer)
     453                 :             :         {
     454                 :             :           /* In a base member initializer, we cannot rely on the
     455                 :             :              vtable being set up.  We have to indirect via the
     456                 :             :              vtt_parm.  */
     457                 :           6 :           tree t;
     458                 :             : 
     459                 :           6 :           t = TREE_TYPE (TYPE_VFIELD (current_class_type));
     460                 :           6 :           t = build_pointer_type (t);
     461                 :           6 :           v_offset = fold_convert (t, current_vtt_parm);
     462                 :           6 :           v_offset = cp_build_fold_indirect_ref (v_offset);
     463                 :           6 :         }
     464                 :             :       else
     465                 :             :         {
     466                 :       86560 :           tree t = expr;
     467                 :       86560 :           if (sanitize_flags_p (SANITIZE_VPTR)
     468                 :       86560 :               && fixed_type_p == 0)
     469                 :             :             {
     470                 :          44 :               t = cp_ubsan_maybe_instrument_cast_to_vbase (input_location,
     471                 :             :                                                            probe, expr);
     472                 :          44 :               if (t == NULL_TREE)
     473                 :       86516 :                 t = expr;
     474                 :             :             }
     475                 :       86560 :           v_offset = build_vfield_ref (cp_build_fold_indirect_ref (t),
     476                 :       86560 :           TREE_TYPE (TREE_TYPE (expr)));
     477                 :             :         }
     478                 :             : 
     479                 :       86566 :       if (v_offset == error_mark_node)
     480                 :             :         return error_mark_node;
     481                 :             : 
     482                 :       86563 :       v_offset = fold_build_pointer_plus (v_offset, BINFO_VPTR_FIELD (v_binfo));
     483                 :       86563 :       v_offset = build1 (NOP_EXPR,
     484                 :             :                          build_pointer_type (ptrdiff_type_node),
     485                 :             :                          v_offset);
     486                 :       86563 :       v_offset = cp_build_fold_indirect_ref (v_offset);
     487                 :       86563 :       TREE_CONSTANT (v_offset) = 1;
     488                 :             : 
     489                 :      173126 :       offset = convert_to_integer (ptrdiff_type_node,
     490                 :             :                                    size_diffop_loc (input_location, offset,
     491                 :       86563 :                                                 BINFO_OFFSET (v_binfo)));
     492                 :             : 
     493                 :       86563 :       if (!integer_zerop (offset))
     494                 :         502 :         v_offset = build2 (code, ptrdiff_type_node, v_offset, offset);
     495                 :             : 
     496                 :       86563 :       if (fixed_type_p < 0)
     497                 :             :         /* Negative fixed_type_p means this is a constructor or destructor;
     498                 :             :            virtual base layout is fixed in in-charge [cd]tors, but not in
     499                 :             :            base [cd]tors.  */
     500                 :       48236 :         offset = build_if_in_charge
     501                 :       48236 :           (convert_to_integer (ptrdiff_type_node, BINFO_OFFSET (binfo)),
     502                 :             :            v_offset);
     503                 :             :       else
     504                 :             :         offset = v_offset;
     505                 :             :     }
     506                 :             : 
     507                 :     1842834 :   if (want_pointer)
     508                 :     1842834 :     target_type = ptr_target_type;
     509                 :             : 
     510                 :     1842834 :   if (!integer_zerop (offset))
     511                 :             :     {
     512                 :       87355 :       offset = fold_convert (sizetype, offset);
     513                 :       87355 :       if (code == MINUS_EXPR)
     514                 :         345 :         offset = fold_build1_loc (input_location, NEGATE_EXPR, sizetype, offset);
     515                 :       87355 :       expr = fold_build_pointer_plus (expr, offset);
     516                 :             :     }
     517                 :             :   else
     518                 :             :     null_test = NULL;
     519                 :             : 
     520                 :     1842834 :   expr = build1 (NOP_EXPR, ptr_target_type, expr);
     521                 :             : 
     522                 :     2494880 :  indout:
     523                 :     2494880 :   if (!want_pointer)
     524                 :             :     {
     525                 :     1105936 :       expr = cp_build_fold_indirect_ref (expr);
     526                 :     1105936 :       if (rvalue)
     527                 :      223876 :         expr = move (expr);
     528                 :             :     }
     529                 :             : 
     530                 :     1388944 :  out:
     531                 :     4983476 :   if (null_test)
     532                 :             :     /* Wrap EXPR in a null test.  */
     533                 :        1783 :     expr = build_if_nonnull (null_test, expr, complain);
     534                 :             : 
     535                 :             :   return expr;
     536                 :             : }
     537                 :             : 
     538                 :             : /* Subroutine of build_base_path; EXPR and BINFO are as in that function.
     539                 :             :    Perform a derived-to-base conversion by recursively building up a
     540                 :             :    sequence of COMPONENT_REFs to the appropriate base fields.  */
     541                 :             : 
     542                 :             : static tree
     543                 :    15429100 : build_simple_base_path (tree expr, tree binfo)
     544                 :             : {
     545                 :    15429100 :   tree type = BINFO_TYPE (binfo);
     546                 :    15429100 :   tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
     547                 :    15429100 :   tree field;
     548                 :             : 
     549                 :    15429100 :   if (d_binfo == NULL_TREE)
     550                 :             :     {
     551                 :     7558919 :       tree temp;
     552                 :             : 
     553                 :     7558919 :       gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type);
     554                 :             : 
     555                 :             :       /* Transform `(a, b).x' into `(*(a, &b)).x', `(a ? b : c).x'
     556                 :             :          into `(*(a ?  &b : &c)).x', and so on.  A COND_EXPR is only
     557                 :             :          an lvalue in the front end; only _DECLs and _REFs are lvalues
     558                 :             :          in the back end.  */
     559                 :     7558919 :       temp = unary_complex_lvalue (ADDR_EXPR, expr);
     560                 :     7558919 :       if (temp)
     561                 :           0 :         expr = cp_build_fold_indirect_ref (temp);
     562                 :             : 
     563                 :     7558919 :       return expr;
     564                 :             :     }
     565                 :             : 
     566                 :             :   /* Recurse.  */
     567                 :     7870181 :   expr = build_simple_base_path (expr, d_binfo);
     568                 :             : 
     569                 :     7870181 :   for (field = TYPE_FIELDS (BINFO_TYPE (d_binfo));
     570                 :    42754643 :        field; field = DECL_CHAIN (field))
     571                 :             :     /* Is this the base field created by build_base_field?  */
     572                 :    42754643 :     if (TREE_CODE (field) == FIELD_DECL
     573                 :     9056433 :         && DECL_FIELD_IS_BASE (field)
     574                 :     9011003 :         && TREE_TYPE (field) == type
     575                 :             :         /* If we're looking for a field in the most-derived class,
     576                 :             :            also check the field offset; we can have two base fields
     577                 :             :            of the same type if one is an indirect virtual base and one
     578                 :             :            is a direct non-virtual base.  */
     579                 :    50624947 :         && (BINFO_INHERITANCE_CHAIN (d_binfo)
     580                 :     7559042 :             || tree_int_cst_equal (byte_position (field),
     581                 :     7559042 :                                    BINFO_OFFSET (binfo))))
     582                 :             :       {
     583                 :             :         /* We don't use build_class_member_access_expr here, as that
     584                 :             :            has unnecessary checks, and more importantly results in
     585                 :             :            recursive calls to dfs_walk_once.  */
     586                 :     7870181 :         int type_quals = cp_type_quals (TREE_TYPE (expr));
     587                 :             : 
     588                 :     7870181 :         expr = build3 (COMPONENT_REF,
     589                 :             :                        cp_build_qualified_type (type, type_quals),
     590                 :             :                        expr, field, NULL_TREE);
     591                 :             :         /* Mark the expression const or volatile, as appropriate.
     592                 :             :            Even though we've dealt with the type above, we still have
     593                 :             :            to mark the expression itself.  */
     594                 :     7870181 :         if (type_quals & TYPE_QUAL_CONST)
     595                 :      806553 :           TREE_READONLY (expr) = 1;
     596                 :     7870181 :         if (type_quals & TYPE_QUAL_VOLATILE)
     597                 :       22441 :           TREE_THIS_VOLATILE (expr) = 1;
     598                 :             : 
     599                 :     7870181 :         return expr;
     600                 :             :       }
     601                 :             : 
     602                 :             :   /* Didn't find the base field?!?  */
     603                 :           0 :   gcc_unreachable ();
     604                 :             : }
     605                 :             : 
     606                 :             : /* Convert OBJECT to the base TYPE.  OBJECT is an expression whose
     607                 :             :    type is a class type or a pointer to a class type.  In the former
     608                 :             :    case, TYPE is also a class type; in the latter it is another
     609                 :             :    pointer type.  If CHECK_ACCESS is true, an error message is emitted
     610                 :             :    if TYPE is inaccessible.  If OBJECT has pointer type, the value is
     611                 :             :    assumed to be non-NULL.  */
     612                 :             : 
     613                 :             : tree
     614                 :     1366059 : convert_to_base (tree object, tree type, bool check_access, bool nonnull,
     615                 :             :                  tsubst_flags_t complain)
     616                 :             : {
     617                 :     1366059 :   tree binfo;
     618                 :     1366059 :   tree object_type;
     619                 :             : 
     620                 :     1366059 :   if (TYPE_PTR_P (TREE_TYPE (object)))
     621                 :             :     {
     622                 :      138207 :       object_type = TREE_TYPE (TREE_TYPE (object));
     623                 :      138207 :       type = TREE_TYPE (type);
     624                 :             :     }
     625                 :             :   else
     626                 :     1227852 :     object_type = TREE_TYPE (object);
     627                 :             : 
     628                 :     1368018 :   binfo = lookup_base (object_type, type, check_access ? ba_check : ba_unique,
     629                 :             :                        NULL, complain);
     630                 :     1366059 :   if (!binfo || binfo == error_mark_node)
     631                 :         105 :     return error_mark_node;
     632                 :             : 
     633                 :     1365954 :   return build_base_path (PLUS_EXPR, object, binfo, nonnull, complain);
     634                 :             : }
     635                 :             : 
     636                 :             : /* EXPR is an expression with unqualified class type.  BASE is a base
     637                 :             :    binfo of that class type.  Returns EXPR, converted to the BASE
     638                 :             :    type.  This function assumes that EXPR is the most derived class;
     639                 :             :    therefore virtual bases can be found at their static offsets.  */
     640                 :             : 
     641                 :             : tree
     642                 :     1639016 : convert_to_base_statically (tree expr, tree base)
     643                 :             : {
     644                 :     1639016 :   tree expr_type;
     645                 :             : 
     646                 :     1639016 :   expr_type = TREE_TYPE (expr);
     647                 :     1639016 :   if (!SAME_BINFO_TYPE_P (BINFO_TYPE (base), expr_type))
     648                 :             :     {
     649                 :             :       /* If this is a non-empty base, use a COMPONENT_REF.  */
     650                 :     1639016 :       if (!is_empty_class (BINFO_TYPE (base)))
     651                 :     1238295 :         return build_simple_base_path (expr, base);
     652                 :             : 
     653                 :             :       /* We use fold_build2 and fold_convert below to simplify the trees
     654                 :             :          provided to the optimizers.  It is not safe to call these functions
     655                 :             :          when processing a template because they do not handle C++-specific
     656                 :             :          trees.  */
     657                 :      400721 :       gcc_assert (!processing_template_decl);
     658                 :      400721 :       expr = cp_build_addr_expr (expr, tf_warning_or_error);
     659                 :      400721 :       if (!integer_zerop (BINFO_OFFSET (base)))
     660                 :         189 :         expr = fold_build_pointer_plus_loc (input_location,
     661                 :         189 :                                             expr, BINFO_OFFSET (base));
     662                 :      400721 :       expr = fold_convert (build_pointer_type (BINFO_TYPE (base)), expr);
     663                 :      400721 :       expr = build_fold_indirect_ref_loc (input_location, expr);
     664                 :             :     }
     665                 :             : 
     666                 :             :   return expr;
     667                 :             : }
     668                 :             : 
     669                 :             : /* True IFF EXPR is a reference to an empty base class "subobject", as built in
     670                 :             :    convert_to_base_statically.  We look for the result of the fold_convert
     671                 :             :    call, a NOP_EXPR from one pointer type to another, where the target is an
     672                 :             :    empty base of the original type.  */
     673                 :             : 
     674                 :             : bool
     675                 :    29224712 : is_empty_base_ref (tree expr)
     676                 :             : {
     677                 :    29224712 :   if (INDIRECT_REF_P (expr))
     678                 :    23805138 :     expr = TREE_OPERAND (expr, 0);
     679                 :    29224712 :   if (TREE_CODE (expr) != NOP_EXPR)
     680                 :             :     return false;
     681                 :      848313 :   tree type = TREE_TYPE (expr);
     682                 :      848313 :   if (!POINTER_TYPE_P (type))
     683                 :             :     return false;
     684                 :      848313 :   type = TREE_TYPE (type);
     685                 :      848313 :   if (!is_empty_class (type))
     686                 :             :     return false;
     687                 :      460684 :   STRIP_NOPS (expr);
     688                 :      460684 :   tree fromtype = TREE_TYPE (expr);
     689                 :      460684 :   if (!POINTER_TYPE_P (fromtype))
     690                 :             :     return false;
     691                 :      460684 :   fromtype = TREE_TYPE (fromtype);
     692                 :      453793 :   return (CLASS_TYPE_P (fromtype)
     693                 :      453793 :           && !same_type_ignoring_top_level_qualifiers_p (fromtype, type)
     694                 :      913894 :           && DERIVED_FROM_P (type, fromtype));
     695                 :             : }
     696                 :             : 
     697                 :             : tree
     698                 :     1602675 : build_vfield_ref (tree datum, tree type)
     699                 :             : {
     700                 :     1602675 :   tree vfield, vcontext;
     701                 :             : 
     702                 :     1602675 :   if (datum == error_mark_node
     703                 :             :       /* Can happen in case of duplicate base types (c++/59082).  */
     704                 :     1602675 :       || !TYPE_VFIELD (type))
     705                 :             :     return error_mark_node;
     706                 :             : 
     707                 :             :   /* First, convert to the requested type.  */
     708                 :     1602672 :   if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (datum), type))
     709                 :           0 :     datum = convert_to_base (datum, type, /*check_access=*/false,
     710                 :             :                              /*nonnull=*/true, tf_warning_or_error);
     711                 :             : 
     712                 :             :   /* Second, the requested type may not be the owner of its own vptr.
     713                 :             :      If not, convert to the base class that owns it.  We cannot use
     714                 :             :      convert_to_base here, because VCONTEXT may appear more than once
     715                 :             :      in the inheritance hierarchy of TYPE, and thus direct conversion
     716                 :             :      between the types may be ambiguous.  Following the path back up
     717                 :             :      one step at a time via primary bases avoids the problem.  */
     718                 :     1602672 :   vfield = TYPE_VFIELD (type);
     719                 :     1602672 :   vcontext = DECL_CONTEXT (vfield);
     720                 :     3348443 :   while (!same_type_ignoring_top_level_qualifiers_p (vcontext, type))
     721                 :             :     {
     722                 :     1745771 :       datum = build_simple_base_path (datum, CLASSTYPE_PRIMARY_BINFO (type));
     723                 :     1745771 :       type = TREE_TYPE (datum);
     724                 :             :     }
     725                 :             : 
     726                 :     1602672 :   return build3 (COMPONENT_REF, TREE_TYPE (vfield), datum, vfield, NULL_TREE);
     727                 :             : }
     728                 :             : 
     729                 :             : /* Given an object INSTANCE, return an expression which yields the
     730                 :             :    vtable element corresponding to INDEX.  There are many special
     731                 :             :    cases for INSTANCE which we take care of here, mainly to avoid
     732                 :             :    creating extra tree nodes when we don't have to.  */
     733                 :             : 
     734                 :             : tree
     735                 :      543955 : build_vtbl_ref (tree instance, tree idx)
     736                 :             : {
     737                 :      543955 :   tree aref;
     738                 :      543955 :   tree vtbl = NULL_TREE;
     739                 :             : 
     740                 :             :   /* Try to figure out what a reference refers to, and
     741                 :             :      access its virtual function table directly.  */
     742                 :             : 
     743                 :      543955 :   int cdtorp = 0;
     744                 :      543955 :   tree fixed_type = fixed_type_or_null (instance, NULL, &cdtorp);
     745                 :             : 
     746                 :      543955 :   tree basetype = non_reference (TREE_TYPE (instance));
     747                 :             : 
     748                 :      543955 :   if (fixed_type && !cdtorp)
     749                 :             :     {
     750                 :         116 :       tree binfo = lookup_base (fixed_type, basetype,
     751                 :             :                                 ba_unique, NULL, tf_none);
     752                 :         116 :       if (binfo && binfo != error_mark_node)
     753                 :         101 :         vtbl = unshare_expr (BINFO_VTABLE (binfo));
     754                 :             :     }
     755                 :             : 
     756                 :         101 :   if (!vtbl)
     757                 :      543924 :     vtbl = build_vfield_ref (instance, basetype);
     758                 :             : 
     759                 :      543955 :   aref = build_array_ref (input_location, vtbl, idx);
     760                 :     1087879 :   TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
     761                 :             : 
     762                 :      543955 :   return aref;
     763                 :             : }
     764                 :             : 
     765                 :             : /* Given a stable object pointer INSTANCE_PTR, return an expression which
     766                 :             :    yields a function pointer corresponding to vtable element INDEX.  */
     767                 :             : 
     768                 :             : tree
     769                 :      543043 : build_vfn_ref (tree instance_ptr, tree idx)
     770                 :             : {
     771                 :      543043 :   tree aref;
     772                 :             : 
     773                 :      543043 :   aref = build_vtbl_ref (cp_build_fold_indirect_ref (instance_ptr), idx);
     774                 :             : 
     775                 :             :   /* When using function descriptors, the address of the
     776                 :             :      vtable entry is treated as a function pointer.  */
     777                 :      543043 :   if (TARGET_VTABLE_USES_DESCRIPTORS)
     778                 :             :     aref = build1 (NOP_EXPR, TREE_TYPE (aref),
     779                 :             :                    cp_build_addr_expr (aref, tf_warning_or_error));
     780                 :             : 
     781                 :             :   /* Remember this as a method reference, for later devirtualization.  */
     782                 :      543043 :   aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr,
     783                 :      543043 :                  fold_convert (TREE_TYPE (instance_ptr), idx));
     784                 :             : 
     785                 :      543043 :   return aref;
     786                 :             : }
     787                 :             : 
     788                 :             : /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
     789                 :             :    for the given TYPE.  */
     790                 :             : 
     791                 :             : static tree
     792                 :     1697789 : get_vtable_name (tree type)
     793                 :             : {
     794                 :           0 :   return mangle_vtbl_for_type (type);
     795                 :             : }
     796                 :             : 
     797                 :             : /* DECL is an entity associated with TYPE, like a virtual table or an
     798                 :             :    implicitly generated constructor.  Determine whether or not DECL
     799                 :             :    should have external or internal linkage at the object file
     800                 :             :    level.  This routine does not deal with COMDAT linkage and other
     801                 :             :    similar complexities; it simply sets TREE_PUBLIC if it possible for
     802                 :             :    entities in other translation units to contain copies of DECL, in
     803                 :             :    the abstract.  */
     804                 :             : 
     805                 :             : void
     806                 :    27294197 : set_linkage_according_to_type (tree /*type*/, tree decl)
     807                 :             : {
     808                 :    27294197 :   TREE_PUBLIC (decl) = 1;
     809                 :    27294197 :   determine_visibility (decl);
     810                 :    27294197 : }
     811                 :             : 
     812                 :             : /* Create a VAR_DECL for a primary or secondary vtable for CLASS_TYPE.
     813                 :             :    (For a secondary vtable for B-in-D, CLASS_TYPE should be D, not B.)
     814                 :             :    Use NAME for the name of the vtable, and VTABLE_TYPE for its type.  */
     815                 :             : 
     816                 :             : static tree
     817                 :     2141926 : build_vtable (tree class_type, tree name, tree vtable_type)
     818                 :             : {
     819                 :     2141926 :   tree decl;
     820                 :             : 
     821                 :     2141926 :   decl = build_lang_decl (VAR_DECL, name, vtable_type);
     822                 :             :   /* vtable names are already mangled; give them their DECL_ASSEMBLER_NAME
     823                 :             :      now to avoid confusion in mangle_decl.  */
     824                 :     2141926 :   SET_DECL_ASSEMBLER_NAME (decl, name);
     825                 :     2141926 :   DECL_CONTEXT (decl) = class_type;
     826                 :     2141926 :   DECL_ARTIFICIAL (decl) = 1;
     827                 :     2141926 :   TREE_STATIC (decl) = 1;
     828                 :     2141926 :   TREE_READONLY (decl) = 1;
     829                 :     2141926 :   DECL_VIRTUAL_P (decl) = 1;
     830                 :     2152502 :   SET_DECL_ALIGN (decl, TARGET_VTABLE_ENTRY_ALIGN);
     831                 :     2141926 :   DECL_USER_ALIGN (decl) = true;
     832                 :     2141926 :   DECL_VTABLE_OR_VTT_P (decl) = 1;
     833                 :     2141926 :   set_linkage_according_to_type (class_type, decl);
     834                 :             :   /* The vtable has not been defined -- yet.  */
     835                 :     2141926 :   DECL_EXTERNAL (decl) = 1;
     836                 :     2141926 :   DECL_NOT_REALLY_EXTERN (decl) = 1;
     837                 :             : 
     838                 :             :   /* Mark the VAR_DECL node representing the vtable itself as a
     839                 :             :      "gratuitous" one, thereby forcing dwarfout.c to ignore it.  It
     840                 :             :      is rather important that such things be ignored because any
     841                 :             :      effort to actually generate DWARF for them will run into
     842                 :             :      trouble when/if we encounter code like:
     843                 :             : 
     844                 :             :      #pragma interface
     845                 :             :      struct S { virtual void member (); };
     846                 :             : 
     847                 :             :      because the artificial declaration of the vtable itself (as
     848                 :             :      manufactured by the g++ front end) will say that the vtable is
     849                 :             :      a static member of `S' but only *after* the debug output for
     850                 :             :      the definition of `S' has already been output.  This causes
     851                 :             :      grief because the DWARF entry for the definition of the vtable
     852                 :             :      will try to refer back to an earlier *declaration* of the
     853                 :             :      vtable as a static member of `S' and there won't be one.  We
     854                 :             :      might be able to arrange to have the "vtable static member"
     855                 :             :      attached to the member list for `S' before the debug info for
     856                 :             :      `S' get written (which would solve the problem) but that would
     857                 :             :      require more intrusive changes to the g++ front end.  */
     858                 :     2141926 :   DECL_IGNORED_P (decl) = 1;
     859                 :             : 
     860                 :     2141926 :   return decl;
     861                 :             : }
     862                 :             : 
     863                 :             : /* Get the VAR_DECL of the vtable for TYPE. TYPE need not be polymorphic,
     864                 :             :    or even complete.  If this does not exist, create it.  If COMPLETE is
     865                 :             :    nonzero, then complete the definition of it -- that will render it
     866                 :             :    impossible to actually build the vtable, but is useful to get at those
     867                 :             :    which are known to exist in the runtime.  */
     868                 :             : 
     869                 :             : tree
     870                 :     8081967 : get_vtable_decl (tree type, int complete)
     871                 :             : {
     872                 :     8081967 :   tree decl;
     873                 :             : 
     874                 :     8081967 :   if (CLASSTYPE_VTABLES (type))
     875                 :     6384178 :     return CLASSTYPE_VTABLES (type);
     876                 :             : 
     877                 :     1697789 :   decl = build_vtable (type, get_vtable_name (type), vtbl_type_node);
     878                 :     1697789 :   CLASSTYPE_VTABLES (type) = decl;
     879                 :             : 
     880                 :     1697789 :   if (complete)
     881                 :             :     {
     882                 :       40074 :       DECL_EXTERNAL (decl) = 1;
     883                 :       40074 :       cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
     884                 :             :     }
     885                 :             : 
     886                 :             :   return decl;
     887                 :             : }
     888                 :             : 
     889                 :             : /* Build the primary virtual function table for TYPE.  If BINFO is
     890                 :             :    non-NULL, build the vtable starting with the initial approximation
     891                 :             :    that it is the same as the one which is the head of the association
     892                 :             :    list.  Returns a nonzero value if a new vtable is actually
     893                 :             :    created.  */
     894                 :             : 
     895                 :             : static int
     896                 :     6373257 : build_primary_vtable (tree binfo, tree type)
     897                 :             : {
     898                 :     6373257 :   tree decl;
     899                 :     6373257 :   tree virtuals;
     900                 :             : 
     901                 :     6373257 :   decl = get_vtable_decl (type, /*complete=*/0);
     902                 :             : 
     903                 :     6373257 :   if (binfo)
     904                 :             :     {
     905                 :     6133412 :       if (BINFO_NEW_VTABLE_MARKED (binfo))
     906                 :             :         /* We have already created a vtable for this base, so there's
     907                 :             :            no need to do it again.  */
     908                 :             :         return 0;
     909                 :             : 
     910                 :     1417870 :       virtuals = copy_list (BINFO_VIRTUALS (binfo));
     911                 :     1417870 :       TREE_TYPE (decl) = TREE_TYPE (get_vtbl_decl_for_binfo (binfo));
     912                 :     1417870 :       DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (decl));
     913                 :     1417870 :       DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
     914                 :             :     }
     915                 :             :   else
     916                 :             :     {
     917                 :      239845 :       gcc_assert (TREE_TYPE (decl) == vtbl_type_node);
     918                 :             :       virtuals = NULL_TREE;
     919                 :             :     }
     920                 :             : 
     921                 :             :   /* Initialize the association list for this type, based
     922                 :             :      on our first approximation.  */
     923                 :     1657715 :   BINFO_VTABLE (TYPE_BINFO (type)) = decl;
     924                 :     1657715 :   BINFO_VIRTUALS (TYPE_BINFO (type)) = virtuals;
     925                 :     1657715 :   SET_BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (type));
     926                 :             :   return 1;
     927                 :             : }
     928                 :             : 
     929                 :             : /* Give BINFO a new virtual function table which is initialized
     930                 :             :    with a skeleton-copy of its original initialization.  The only
     931                 :             :    entry that changes is the `delta' entry, so we can really
     932                 :             :    share a lot of structure.
     933                 :             : 
     934                 :             :    FOR_TYPE is the most derived type which caused this table to
     935                 :             :    be needed.
     936                 :             : 
     937                 :             :    Returns nonzero if we haven't met BINFO before.
     938                 :             : 
     939                 :             :    The order in which vtables are built (by calling this function) for
     940                 :             :    an object must remain the same, otherwise a binary incompatibility
     941                 :             :    can result.  */
     942                 :             : 
     943                 :             : static int
     944                 :      752654 : build_secondary_vtable (tree binfo)
     945                 :             : {
     946                 :      752654 :   if (BINFO_NEW_VTABLE_MARKED (binfo))
     947                 :             :     /* We already created a vtable for this base.  There's no need to
     948                 :             :        do it again.  */
     949                 :             :     return 0;
     950                 :             : 
     951                 :             :   /* Remember that we've created a vtable for this BINFO, so that we
     952                 :             :      don't try to do so again.  */
     953                 :      260760 :   SET_BINFO_NEW_VTABLE_MARKED (binfo);
     954                 :             : 
     955                 :             :   /* Make fresh virtual list, so we can smash it later.  */
     956                 :      260760 :   BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
     957                 :             : 
     958                 :             :   /* Secondary vtables are laid out as part of the same structure as
     959                 :             :      the primary vtable.  */
     960                 :      260760 :   BINFO_VTABLE (binfo) = NULL_TREE;
     961                 :      260760 :   return 1;
     962                 :             : }
     963                 :             : 
     964                 :             : /* Create a new vtable for BINFO which is the hierarchy dominated by
     965                 :             :    T. Return nonzero if we actually created a new vtable.  */
     966                 :             : 
     967                 :             : static int
     968                 :     6886066 : make_new_vtable (tree t, tree binfo)
     969                 :             : {
     970                 :     6886066 :   if (binfo == TYPE_BINFO (t))
     971                 :             :     /* In this case, it is *type*'s vtable we are modifying.  We start
     972                 :             :        with the approximation that its vtable is that of the
     973                 :             :        immediate base class.  */
     974                 :     6133412 :     return build_primary_vtable (binfo, t);
     975                 :             :   else
     976                 :             :     /* This is our very own copy of `basetype' to play with.  Later,
     977                 :             :        we will fill in all the virtual functions that override the
     978                 :             :        virtual functions in these base classes which are not defined
     979                 :             :        by the current type.  */
     980                 :      752654 :     return build_secondary_vtable (binfo);
     981                 :             : }
     982                 :             : 
     983                 :             : /* Make *VIRTUALS, an entry on the BINFO_VIRTUALS list for BINFO
     984                 :             :    (which is in the hierarchy dominated by T) list FNDECL as its
     985                 :             :    BV_FN.  DELTA is the required constant adjustment from the `this'
     986                 :             :    pointer where the vtable entry appears to the `this' required when
     987                 :             :    the function is actually called.  */
     988                 :             : 
     989                 :             : static void
     990                 :     7141637 : modify_vtable_entry (tree t,
     991                 :             :                      tree binfo,
     992                 :             :                      tree fndecl,
     993                 :             :                      tree delta,
     994                 :             :                      tree *virtuals)
     995                 :             : {
     996                 :     7141637 :   tree v;
     997                 :             : 
     998                 :     7141637 :   v = *virtuals;
     999                 :             : 
    1000                 :     7141637 :   if (fndecl != BV_FN (v)
    1001                 :     7141637 :       || !tree_int_cst_equal (delta, BV_DELTA (v)))
    1002                 :             :     {
    1003                 :             :       /* We need a new vtable for BINFO.  */
    1004                 :     5207436 :       if (make_new_vtable (t, binfo))
    1005                 :             :         {
    1006                 :             :           /* If we really did make a new vtable, we also made a copy
    1007                 :             :              of the BINFO_VIRTUALS list.  Now, we have to find the
    1008                 :             :              corresponding entry in that list.  */
    1009                 :           0 :           *virtuals = BINFO_VIRTUALS (binfo);
    1010                 :           0 :           while (BV_FN (*virtuals) != BV_FN (v))
    1011                 :           0 :             *virtuals = TREE_CHAIN (*virtuals);
    1012                 :             :           v = *virtuals;
    1013                 :             :         }
    1014                 :             : 
    1015                 :     5207436 :       BV_DELTA (v) = delta;
    1016                 :     5207436 :       BV_VCALL_INDEX (v) = NULL_TREE;
    1017                 :     5207436 :       BV_FN (v) = fndecl;
    1018                 :             :     }
    1019                 :     7141637 : }
    1020                 :             : 
    1021                 :             : 
    1022                 :             : /* Check if the object parameter of an iobj member function corresponds to
    1023                 :             :    another parameter type.  CONTEXT is the class that the implicit object
    1024                 :             :    parameter is considered to refer to.  */
    1025                 :             : 
    1026                 :             : bool
    1027                 :       86731 : iobj_parm_corresponds_to (tree iobj_fn, tree xobj_param, tree context)
    1028                 :             : {
    1029                 :       86731 :   tree iobj_fn_type = TREE_TYPE (iobj_fn);
    1030                 :             : 
    1031                 :             :   /* If the iobj member function was introduced with a using declaration, the
    1032                 :             :      type of its object parameter is considered to be that of the class it was
    1033                 :             :      introduced into.
    1034                 :             : 
    1035                 :             :      [over.match.funcs.general.4]
    1036                 :             :      For non-conversion functions that are implicit object member
    1037                 :             :      functions nominated by a using-declaration in a derived class, the
    1038                 :             :      function is considered to be a member of the derived class for the purpose
    1039                 :             :      of defining the type of the implicit object parameter.
    1040                 :             : 
    1041                 :             :      Unfortunately, because of this rule, we can't just compare the xobj member
    1042                 :             :      function's DECL_CONTEXT to its object parameter.
    1043                 :             : 
    1044                 :             :      struct S;
    1045                 :             : 
    1046                 :             :      struct B {
    1047                 :             :        int f(this S&) { return 5; }
    1048                 :             :      };
    1049                 :             : 
    1050                 :             :      struct S : B {
    1051                 :             :        using B::f;
    1052                 :             :        int f() { return 10; }
    1053                 :             :      };
    1054                 :             : 
    1055                 :             :      The using declaration does not change the object parameter of B::f as it
    1056                 :             :      is an xobj member function.  However, its object parameter still
    1057                 :             :      corresponds to S::f as it was declared with an object parameter of type
    1058                 :             :      S const&.  The DECL_CONTEXT of B::f is B, so if we compare the type of the
    1059                 :             :      object parameter to that, it will not match.  If we naively assume a
    1060                 :             :      different type from the DECL_CONTEXT for an xobj parameter means that the
    1061                 :             :      object parameters do not correspond, then the object parameters in the
    1062                 :             :      above example will be considered non-corresponding.
    1063                 :             : 
    1064                 :             :      As a result of this, B::f would incorrectly not be discarded, causing an
    1065                 :             :      ambiguity when f is called on an object of type S.
    1066                 :             : 
    1067                 :             :      This also impacts member functions with constraints as in the following
    1068                 :             :      example.
    1069                 :             : 
    1070                 :             :      template<typename = void>
    1071                 :             :      struct S;
    1072                 :             : 
    1073                 :             :      template<typename = void>
    1074                 :             :      struct B {
    1075                 :             :        int f(this S<>&) requires true { return 5; }
    1076                 :             :      };
    1077                 :             : 
    1078                 :             :      template<typename>
    1079                 :             :      struct S : B<> {
    1080                 :             :        using B<>::f;
    1081                 :             :        int f() { return 10; }
    1082                 :             :      };
    1083                 :             : 
    1084                 :             :      Once again, if we compare the DECL_CONTEXT of B<>::f to it's xobj
    1085                 :             :      parameter, it would not match.  If the object parameters do not
    1086                 :             :      correspond, constraints are not taken into account, so in this example we
    1087                 :             :      would (probably) get an ambiguous lookup instead of correctly picking
    1088                 :             :      B<>::f.
    1089                 :             : 
    1090                 :             :      Because of this caveat, we must actually compare the type of the iobj
    1091                 :             :      parameter to the type of the xobj parameter, shortcuts will have these
    1092                 :             :      edge cases.
    1093                 :             : 
    1094                 :             :      Aside from the more complex reasons above, this logic also implicitly
    1095                 :             :      handles xobj parameters of pointer type, we don't have to explicitly
    1096                 :             :      check for that case.  */
    1097                 :             : 
    1098                 :       86731 :   if (!same_type_ignoring_top_level_qualifiers_p
    1099                 :       86731 :       (context, non_reference (xobj_param)))
    1100                 :             :     return false;
    1101                 :             : 
    1102                 :             :   /* We don't get to bail yet even if we have a by-value xobj parameter,
    1103                 :             :      a by-value xobj parameter can correspond to an iobj parameter provided the
    1104                 :             :      iobj member function is not declared with a reference qualifier.
    1105                 :             : 
    1106                 :             :      From this point on, we know we are dealing with an xobj parameter that has
    1107                 :             :      an object parameter of the same type as the class it was declared in.
    1108                 :             :      We still don't know if we have a reference or by-value parameter yet
    1109                 :             :      though.  */
    1110                 :             : 
    1111                 :       86728 :   cp_ref_qualifier const iobj_ref_qual = type_memfn_rqual (iobj_fn_type);
    1112                 :             :   /* We only care about cv qualifiers when determining correspondence.  */
    1113                 :       86728 :   static constexpr cp_cv_quals cv_bits = TYPE_QUAL_VOLATILE
    1114                 :             :                                        | TYPE_QUAL_CONST;
    1115                 :       86728 :   cp_cv_quals const iobj_cv_quals = type_memfn_quals (iobj_fn_type) & cv_bits;
    1116                 :             :   /* We need to ignore the ref qualifier of the xobj parameter if the iobj
    1117                 :             :      member function lacks a ref qualifier.
    1118                 :             : 
    1119                 :             :      [basic.scope.scope.3]
    1120                 :             :      Two non-static member functions have corresponding object parameters if:
    1121                 :             :      -- exactly one is an implicit object member function with no ref-qualifier
    1122                 :             :         and the types of their object parameters ([dcl.fct]), after removing
    1123                 :             :         top-level references, are the same, or
    1124                 :             :      -- their object parameters have the same type.
    1125                 :             : 
    1126                 :             :      The cv qualifiers of a by-value parameter are supposed to be discarded, so
    1127                 :             :      we ignore them.
    1128                 :             : 
    1129                 :             :      [dcl.fct.5]
    1130                 :             :      After producing the list of parameter types, any top-level cv-qualifiers
    1131                 :             :      modifying a parameter type are deleted when forming the function type.
    1132                 :             : 
    1133                 :             :      However, they still need to be taken into account when our xobj parameter
    1134                 :             :      is a reference that is being ignored (according to [basic.scope.scope.3]
    1135                 :             :      quoted above), but when we are actually dealing with a by-value xobj
    1136                 :             :      parameter we can proceed following this table.
    1137                 :             :      | iobj | xobj | equal |
    1138                 :             :      | none | none |   X   |
    1139                 :             :      | none |    c |   X   |
    1140                 :             :      | none |    v |   X   |
    1141                 :             :      | none |   cv |   X   |
    1142                 :             :      |    c | none |   O   |
    1143                 :             :      |    c |    c |   O   |
    1144                 :             :      |    c |    v |   O   |
    1145                 :             :      |    c |   cv |   O   |
    1146                 :             :      |    v | none |   O   |
    1147                 :             :      |    v |    c |   O   |
    1148                 :             :      |    v |    v |   O   |
    1149                 :             :      |    v |   cv |   O   |
    1150                 :             :      |   cv | none |   O   |
    1151                 :             :      |   cv |    c |   O   |
    1152                 :             :      |   cv |    v |   O   |
    1153                 :             :      |   cv |   cv |   O   |
    1154                 :             : 
    1155                 :             :      Additionally, if the iobj member function is ref qualified, we aren't
    1156                 :             :      ignoring the ref qualifier of the iobj parameter, so we can't be dealing
    1157                 :             :      with correspondence in that case either.
    1158                 :             : 
    1159                 :             :      So to recap, if we have a by-value xobj parameter, we know for sure that
    1160                 :             :      we aren't dealing with corresponding object parameters if the iobj member
    1161                 :             :      function has any cv-ref qualifiers.  The only case where we might still be
    1162                 :             :      dealing with corresponding object parameters is when the iobj member
    1163                 :             :      function lacks any cv-ref qualification.  */
    1164                 :       86728 :   if (!TYPE_REF_P (xobj_param))
    1165                 :             :     {
    1166                 :         997 :       if (iobj_ref_qual || iobj_cv_quals)
    1167                 :             :         return false;
    1168                 :             :     }
    1169                 :             :   else
    1170                 :             :     {
    1171                 :             :       /* We are dealing with an xobj parameter that is a reference now, but due
    1172                 :             :          to [basic.scope.scope.3] we need to ignore its ref qual.  */
    1173                 :      171462 :       cp_ref_qualifier const xobj_ref_qual = [&](){
    1174                 :       85731 :           if (!TYPE_REF_P (xobj_param) || !iobj_ref_qual)
    1175                 :             :             return REF_QUAL_NONE;
    1176                 :         816 :           return TYPE_REF_IS_RVALUE (xobj_param) ? REF_QUAL_RVALUE
    1177                 :             :                                                  : REF_QUAL_LVALUE;
    1178                 :       85731 :         }(); /* IILE.  */
    1179                 :             : 
    1180                 :             :       /* Even if we are ignoring the reference qualifier, the xobj parameter
    1181                 :             :          was still a reference so we still take the cv qualifiers into
    1182                 :             :          account.  */
    1183                 :       85731 :       cp_cv_quals const xobj_cv_quals
    1184                 :       85731 :         = cp_type_quals (TREE_TYPE (xobj_param)) & cv_bits;
    1185                 :             : 
    1186                 :             :       /* Finally, if the qualifications don't match exactly, the object
    1187                 :             :          parameters don't correspond.  */
    1188                 :       85731 :       if (iobj_ref_qual != xobj_ref_qual
    1189                 :       85347 :           || iobj_cv_quals != xobj_cv_quals)
    1190                 :             :         return false;
    1191                 :             :     }
    1192                 :             :   /* If we got past everything else, the object parameters of fn1 and fn2
    1193                 :             :      definitely correspond.  */
    1194                 :             :   return true;
    1195                 :             : }
    1196                 :             : 
    1197                 :             : /* True if FN and METHOD have corresponding object parms per
    1198                 :             :    [basic.scope.scope], or if one of them is a static member function (which
    1199                 :             :    are considered to have an object parm that corresponds to any other).
    1200                 :             :    CONTEXT is the class that an implicit object member function is considered
    1201                 :             :    to be a member of for the purpose of this comparison, per
    1202                 :             :    [over.match.funcs].  */
    1203                 :             : 
    1204                 :             : bool
    1205                 :   390591597 : object_parms_correspond (tree fn, tree method, tree context)
    1206                 :             : {
    1207                 :   390591597 :   tree fn_type = TREE_TYPE (fn);
    1208                 :   390591597 :   tree method_type = TREE_TYPE (method);
    1209                 :             : 
    1210                 :             :   /* Compare the quals on the 'this' parm.  Don't compare
    1211                 :             :      the whole types, as used functions are treated as
    1212                 :             :      coming from the using class in overload resolution.  */
    1213                 :   390591597 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    1214                 :   390591597 :       && DECL_IOBJ_MEMBER_FUNCTION_P (method))
    1215                 :             :     {
    1216                 :             :       /* Either both or neither need to be ref-qualified for
    1217                 :             :          differing quals to allow overloading.  */
    1218                 :   388494660 :       if ((FUNCTION_REF_QUALIFIED (fn_type)
    1219                 :   388494660 :            == FUNCTION_REF_QUALIFIED (method_type))
    1220                 :   388494660 :           && (type_memfn_quals (fn_type) != type_memfn_quals (method_type)
    1221                 :   371902574 :               || type_memfn_rqual (fn_type) != type_memfn_rqual (method_type)))
    1222                 :    16702102 :         return false;
    1223                 :   371792558 :       return true;
    1224                 :             :     }
    1225                 :             :   /* Treat a static member function as corresponding to any object parm.  */
    1226                 :     2096937 :   else if (DECL_STATIC_FUNCTION_P (fn) || DECL_STATIC_FUNCTION_P (method))
    1227                 :             :     return true;
    1228                 :             :   /* Handle special correspondence rules for xobj vs xobj and xobj vs iobj
    1229                 :             :      member function declarations.
    1230                 :             :      We don't worry about static member functions here.  */
    1231                 :        9237 :   else if (DECL_XOBJ_MEMBER_FUNCTION_P (fn)
    1232                 :       17740 :            && DECL_XOBJ_MEMBER_FUNCTION_P (method))
    1233                 :             :     {
    1234                 :       23361 :       auto get_object_param = [] (tree fn)
    1235                 :             :         {
    1236                 :       15574 :           return TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fn)));
    1237                 :             :         };
    1238                 :             :       /* We skip the object parameter below, check it here instead of
    1239                 :             :          making changes to that code.  */
    1240                 :        7787 :       tree fn_param = get_object_param (fn);
    1241                 :        7787 :       tree method_param = get_object_param (method);
    1242                 :        7787 :       if (!same_type_p (fn_param, method_param))
    1243                 :        2004 :         return false;
    1244                 :             :     }
    1245                 :             :   else
    1246                 :             :     {
    1247                 :        1450 :       tree xobj_fn = DECL_XOBJ_MEMBER_FUNCTION_P (fn) ? fn : method;
    1248                 :        1450 :       tree iobj_fn = xobj_fn != fn ? fn : method;
    1249                 :        1450 :       tree xobj_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (xobj_fn)));
    1250                 :             : 
    1251                 :        1450 :       return iobj_parm_corresponds_to (iobj_fn, xobj_param, context);
    1252                 :             :     }
    1253                 :             : 
    1254                 :        5783 :   return true;
    1255                 :             : }
    1256                 :             : 
    1257                 :             : /* Add method METHOD to class TYPE.  If VIA_USING indicates whether
    1258                 :             :    METHOD is being injected via a using_decl.  Returns true if the
    1259                 :             :    method could be added to the method vec.  */
    1260                 :             : 
    1261                 :             : bool
    1262                 :   285886218 : add_method (tree type, tree method, bool via_using)
    1263                 :             : {
    1264                 :   285886218 :   if (method == error_mark_node)
    1265                 :             :     return false;
    1266                 :             : 
    1267                 :   285886218 :   gcc_assert (!DECL_EXTERN_C_P (method));
    1268                 :             : 
    1269                 :   285886218 :   tree *slot = find_member_slot (type, DECL_NAME (method));
    1270                 :   285886218 :   tree current_fns = slot ? *slot : NULL_TREE;
    1271                 :             : 
    1272                 :             :   /* See below.  */
    1273                 :   285886218 :   int losem = -1;
    1274                 :             : 
    1275                 :             :   /* Check to see if we've already got this method.  */
    1276                 :  1226844103 :   for (ovl_iterator iter (current_fns); iter; ++iter)
    1277                 :             :     {
    1278                 :   524065329 :       tree fn = *iter;
    1279                 :             : 
    1280                 :   524065329 :       if (TREE_CODE (fn) != TREE_CODE (method))
    1281                 :   132186979 :         continue;
    1282                 :             : 
    1283                 :             :       /* Two using-declarations can coexist, we'll complain about ambiguity in
    1284                 :             :          overload resolution.  */
    1285                 :     3097268 :       if (via_using && iter.using_p ()
    1286                 :             :           /* Except handle inherited constructors specially.  */
    1287                 :   395204314 :           && ! DECL_CONSTRUCTOR_P (fn))
    1288                 :             :         {
    1289                 :     1301499 :           if (fn == method)
    1290                 :             :             /* Don't add the same one twice.  */
    1291                 :        6985 :             return false;
    1292                 :     1301490 :           continue;
    1293                 :             :         }
    1294                 :             : 
    1295                 :             :       /* [over.load] Member function declarations with the
    1296                 :             :          same name and the same parameter types cannot be
    1297                 :             :          overloaded if any of them is a static member
    1298                 :             :          function declaration.
    1299                 :             : 
    1300                 :             :          [over.load] Member function declarations with the same name and
    1301                 :             :          the same parameter-type-list as well as member function template
    1302                 :             :          declarations with the same name, the same parameter-type-list, and
    1303                 :             :          the same template parameter lists cannot be overloaded if any of
    1304                 :             :          them, but not all, have a ref-qualifier.
    1305                 :             : 
    1306                 :             :          [namespace.udecl] When a using-declaration brings names
    1307                 :             :          from a base class into a derived class scope, member
    1308                 :             :          functions in the derived class override and/or hide member
    1309                 :             :          functions with the same name and parameter types in a base
    1310                 :             :          class (rather than conflicting).  */
    1311                 :   390576851 :       if (!object_parms_correspond (fn, method, type))
    1312                 :    16705171 :         continue;
    1313                 :             : 
    1314                 :   373871680 :       tree fn_type = TREE_TYPE (fn);
    1315                 :   373871680 :       tree method_type = TREE_TYPE (method);
    1316                 :             : 
    1317                 :   373871680 :       tree real_fn = fn;
    1318                 :   373871680 :       tree real_method = method;
    1319                 :             : 
    1320                 :             :       /* Templates and conversion ops must match return types.  */
    1321                 :   747640653 :       if ((DECL_CONV_FN_P (fn) || TREE_CODE (fn) == TEMPLATE_DECL)
    1322                 :   540091731 :           && !same_type_p (TREE_TYPE (fn_type), TREE_TYPE (method_type)))
    1323                 :     3829085 :         continue;
    1324                 :             : 
    1325                 :             :       /* For templates, the template parameters must be identical.  */
    1326                 :   370042595 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    1327                 :             :         {
    1328                 :   324987310 :           if (!comp_template_parms (DECL_TEMPLATE_PARMS (fn),
    1329                 :   162493655 :                                     DECL_TEMPLATE_PARMS (method)))
    1330                 :   127550259 :             continue;
    1331                 :             : 
    1332                 :    34943396 :           real_fn = DECL_TEMPLATE_RESULT (fn);
    1333                 :    34943396 :           real_method = DECL_TEMPLATE_RESULT (method);
    1334                 :             :         }
    1335                 :             : 
    1336                 :   242492336 :       tree parms1 = TYPE_ARG_TYPES (fn_type);
    1337                 :   242492336 :       tree parms2 = TYPE_ARG_TYPES (method_type);
    1338                 :   242492336 :       if (! DECL_STATIC_FUNCTION_P (real_fn))
    1339                 :   241237784 :         parms1 = TREE_CHAIN (parms1);
    1340                 :   242492336 :       if (! DECL_STATIC_FUNCTION_P (real_method))
    1341                 :   241229642 :         parms2 = TREE_CHAIN (parms2);
    1342                 :             : 
    1343                 :             :       /* Bring back parameters omitted from an inherited ctor.  The
    1344                 :             :          method and the function can have different omittedness.  */
    1345                 :   242492336 :       if (ctor_omit_inherited_parms (real_fn))
    1346                 :         729 :         parms1 = FUNCTION_FIRST_USER_PARMTYPE (DECL_CLONED_FUNCTION (real_fn));
    1347                 :   242492336 :       if (ctor_omit_inherited_parms (real_method))
    1348                 :         330 :         parms2 = (FUNCTION_FIRST_USER_PARMTYPE
    1349                 :             :                   (DECL_CLONED_FUNCTION (real_method)));
    1350                 :             : 
    1351                 :   242492336 :       if (!compparms (parms1, parms2))
    1352                 :   241047875 :         continue;
    1353                 :             : 
    1354                 :     1444461 :       if (!equivalently_constrained (fn, method))
    1355                 :             :         {
    1356                 :     1291487 :           if (processing_template_decl)
    1357                 :             :             /* We can't check satisfaction in dependent context, wait until
    1358                 :             :                the class is instantiated.  */
    1359                 :      163503 :             continue;
    1360                 :             : 
    1361                 :     1127984 :           special_function_kind sfk = special_memfn_p (method);
    1362                 :             : 
    1363                 :     2216369 :           if (sfk == sfk_none
    1364                 :      171818 :               || DECL_INHERITED_CTOR (fn)
    1365                 :     1213828 :               || TREE_CODE (fn) == TEMPLATE_DECL)
    1366                 :             :             /* Member function templates and non-special member functions
    1367                 :             :                coexist if they are not equivalently constrained.  A member
    1368                 :             :                function is not hidden by an inherited constructor.  */
    1369                 :     1088385 :             continue;
    1370                 :             : 
    1371                 :             :           /* P0848: For special member functions, deleted, unsatisfied, or
    1372                 :             :              less constrained overloads are ineligible.  We implement this
    1373                 :             :              by removing them from CLASSTYPE_MEMBER_VEC.  Destructors don't
    1374                 :             :              use the notion of eligibility, and the selected destructor can
    1375                 :             :              be deleted, but removing unsatisfied or less constrained
    1376                 :             :              overloads has the same effect as overload resolution.  */
    1377                 :       39599 :           bool dtor = (sfk == sfk_destructor);
    1378                 :       39599 :           if (losem == -1)
    1379                 :       78090 :             losem = ((!dtor && DECL_DELETED_FN (method))
    1380                 :       78048 :                      || !constraints_satisfied_p (method));
    1381                 :       38543 :           bool losef = ((!dtor && DECL_DELETED_FN (fn))
    1382                 :       45015 :                         || !constraints_satisfied_p (fn));
    1383                 :       39599 :           int win;
    1384                 :       39599 :           if (losem || losef)
    1385                 :       38743 :             win = losem - losef;
    1386                 :             :           else
    1387                 :         856 :             win = more_constrained (fn, method);
    1388                 :       39599 :           if (win > 0)
    1389                 :             :             /* Leave FN in the method vec, discard METHOD.  */
    1390                 :             :             return false;
    1391                 :       34091 :           else if (win < 0)
    1392                 :             :             {
    1393                 :             :               /* Remove FN, add METHOD.  */
    1394                 :       30657 :               current_fns = iter.remove_node (current_fns);
    1395                 :       30657 :               continue;
    1396                 :             :             }
    1397                 :             :           else
    1398                 :             :             /* Let them coexist for now.  */
    1399                 :        3434 :             continue;
    1400                 :             :         }
    1401                 :             : 
    1402                 :             :       /* If these are versions of the same function, process and
    1403                 :             :          move on.  */
    1404                 :      153001 :       if (TREE_CODE (fn) == FUNCTION_DECL
    1405                 :      152974 :           && maybe_version_functions (method, fn, true))
    1406                 :          27 :         continue;
    1407                 :             : 
    1408                 :      305894 :       if (DECL_INHERITED_CTOR (method))
    1409                 :             :         {
    1410                 :        2412 :           if (!DECL_INHERITED_CTOR (fn))
    1411                 :             :             /* Defer to the other function.  */
    1412                 :        1134 :             return false;
    1413                 :             : 
    1414                 :         105 :           tree basem = DECL_INHERITED_CTOR_BASE (method);
    1415                 :         210 :           tree basef = DECL_INHERITED_CTOR_BASE (fn);
    1416                 :         105 :           if (flag_new_inheriting_ctors)
    1417                 :             :             {
    1418                 :         102 :               if (basem == basef)
    1419                 :             :                 {
    1420                 :             :                   /* Inheriting the same constructor along different
    1421                 :             :                      paths, combine them.  */
    1422                 :          90 :                   SET_DECL_INHERITED_CTOR
    1423                 :             :                     (fn, ovl_make (DECL_INHERITED_CTOR (method),
    1424                 :             :                                    DECL_INHERITED_CTOR (fn)));
    1425                 :             :                   /* And discard the new one.  */
    1426                 :          30 :                   return false;
    1427                 :             :                 }
    1428                 :             :               else
    1429                 :             :                 /* Inherited ctors can coexist until overload
    1430                 :             :                    resolution.  */
    1431                 :          72 :                 continue;
    1432                 :             :             }
    1433                 :             : 
    1434                 :           3 :           auto_diagnostic_group d;
    1435                 :           3 :           error_at (DECL_SOURCE_LOCATION (method),
    1436                 :             :                     "%q#D conflicts with version inherited from %qT",
    1437                 :             :                     method, basef);
    1438                 :           3 :           inform (DECL_SOURCE_LOCATION (fn),
    1439                 :             :                   "version inherited from %qT declared here",
    1440                 :             :                   basef);
    1441                 :           3 :           return false;
    1442                 :           3 :         }
    1443                 :             : 
    1444                 :      151741 :       if (via_using)
    1445                 :             :         /* Defer to the local function.  */
    1446                 :             :         return false;
    1447                 :      151729 :       else if (iter.using_p ()
    1448                 :      151729 :                ||  (flag_new_inheriting_ctors
    1449                 :      188316 :                     && DECL_INHERITED_CTOR (fn)))
    1450                 :             :         {
    1451                 :             :           /* Remove the inherited function.  */
    1452                 :      151407 :           current_fns = iter.remove_node (current_fns);
    1453                 :      151407 :           continue;
    1454                 :             :         }
    1455                 :             :       else
    1456                 :             :         {
    1457                 :         322 :           auto_diagnostic_group d;
    1458                 :         322 :           error_at (DECL_SOURCE_LOCATION (method),
    1459                 :             :                     "%q#D cannot be overloaded with %q#D", method, fn);
    1460                 :         322 :           inform (DECL_SOURCE_LOCATION (fn),
    1461                 :             :                   "previous declaration %q#D", fn);
    1462                 :         322 :           return false;
    1463                 :         322 :         }
    1464                 :             :     }
    1465                 :             : 
    1466                 :   285879233 :   current_fns = ovl_insert (method, current_fns, via_using);
    1467                 :             : 
    1468                 :   526842671 :   if (!COMPLETE_TYPE_P (type) && !DECL_CONV_FN_P (method)
    1469                 :   524931226 :       && !push_class_level_binding (DECL_NAME (method), current_fns))
    1470                 :             :     return false;
    1471                 :             : 
    1472                 :   285879215 :   if (!slot)
    1473                 :   129657602 :     slot = add_member_slot (type, DECL_NAME (method));
    1474                 :             : 
    1475                 :             :   /* Maintain TYPE_HAS_USER_CONSTRUCTOR, etc.  */
    1476                 :   285879215 :   grok_special_member_properties (method);
    1477                 :             : 
    1478                 :   285879215 :   *slot = current_fns;
    1479                 :             : 
    1480                 :   285879215 :   return true;
    1481                 :             : }
    1482                 :             : 
    1483                 :             : /* Subroutines of finish_struct.  */
    1484                 :             : 
    1485                 :             : /* Change the access of FDECL to ACCESS in T.  Return 1 if change was
    1486                 :             :    legit, otherwise return 0.  */
    1487                 :             : 
    1488                 :             : static int
    1489                 :     2459531 : alter_access (tree t, tree fdecl, tree access)
    1490                 :             : {
    1491                 :     2459531 :   tree elem;
    1492                 :             : 
    1493                 :     2459531 :   retrofit_lang_decl (fdecl);
    1494                 :             : 
    1495                 :     2459531 :   gcc_assert (!DECL_DISCRIMINATOR_P (fdecl));
    1496                 :             : 
    1497                 :     2459531 :   elem = purpose_member (t, DECL_ACCESS (fdecl));
    1498                 :     2459531 :   if (elem)
    1499                 :             :     {
    1500                 :           0 :       if (TREE_VALUE (elem) != access)
    1501                 :             :         {
    1502                 :           0 :           if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
    1503                 :           0 :             error ("conflicting access specifications for method"
    1504                 :           0 :                    " %q+D, ignored", TREE_TYPE (fdecl));
    1505                 :             :           else
    1506                 :           0 :             error ("conflicting access specifications for field %qE, ignored",
    1507                 :           0 :                    DECL_NAME (fdecl));
    1508                 :             :         }
    1509                 :             :       else
    1510                 :             :         {
    1511                 :             :           /* They're changing the access to the same thing they changed
    1512                 :             :              it to before.  That's OK.  */
    1513                 :             :           ;
    1514                 :             :         }
    1515                 :             :     }
    1516                 :             :   else
    1517                 :             :     {
    1518                 :     2459531 :       perform_or_defer_access_check (TYPE_BINFO (t), fdecl, fdecl,
    1519                 :             :                                      tf_warning_or_error);
    1520                 :     2459531 :       DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
    1521                 :     2459531 :       return 1;
    1522                 :             :     }
    1523                 :             :   return 0;
    1524                 :             : }
    1525                 :             : 
    1526                 :             : /* Return the access node for DECL's access in its enclosing class.  */
    1527                 :             : 
    1528                 :             : tree
    1529                 :      537648 : declared_access (tree decl)
    1530                 :             : {
    1531                 :      537648 :   return (TREE_PRIVATE (decl) ? access_private_node
    1532                 :      527312 :           : TREE_PROTECTED (decl) ? access_protected_node
    1533                 :      537648 :           : access_public_node);
    1534                 :             : }
    1535                 :             : 
    1536                 :             : /* If DECL is a non-dependent using of non-ctor function members, push them
    1537                 :             :    and return true, otherwise return false.  Called from
    1538                 :             :    finish_member_declaration.  */
    1539                 :             : 
    1540                 :             : bool
    1541                 :   156509195 : maybe_push_used_methods (tree decl)
    1542                 :             : {
    1543                 :   156509195 :   if (TREE_CODE (decl) != USING_DECL)
    1544                 :             :     return false;
    1545                 :     2867829 :   tree used = strip_using_decl (decl);
    1546                 :     2867829 :   if (!used || !is_overloaded_fn (used))
    1547                 :             :     return false;
    1548                 :             : 
    1549                 :             :   /* Add the functions to CLASSTYPE_MEMBER_VEC so that overload resolution
    1550                 :             :      works within the class body.  */
    1551                 :     4983399 :   for (tree f : ovl_range (used))
    1552                 :             :     {
    1553                 :     4693724 :       if (DECL_CONSTRUCTOR_P (f))
    1554                 :             :         /* Inheriting constructors are handled separately.  */
    1555                 :       55400 :         return false;
    1556                 :             : 
    1557                 :     2291462 :       bool added = add_method (current_class_type, f, true);
    1558                 :             : 
    1559                 :     2291462 :       if (added)
    1560                 :     2291441 :         alter_access (current_class_type, f, current_access_specifier);
    1561                 :             : 
    1562                 :             :       /* If add_method returns false because f was already declared, look
    1563                 :             :          for a duplicate using-declaration.  */
    1564                 :             :       else
    1565                 :          72 :         for (tree d = TYPE_FIELDS (current_class_type); d; d = DECL_CHAIN (d))
    1566                 :          57 :           if (TREE_CODE (d) == USING_DECL
    1567                 :          24 :               && DECL_NAME (d) == DECL_NAME (decl)
    1568                 :          66 :               && same_type_p (USING_DECL_SCOPE (d), USING_DECL_SCOPE (decl)))
    1569                 :             :             {
    1570                 :           6 :               diagnose_name_conflict (decl, d);
    1571                 :           6 :               break;
    1572                 :             :             }
    1573                 :             :     }
    1574                 :     1451852 :   return true;
    1575                 :             : }
    1576                 :             : 
    1577                 :             : /* Process the USING_DECL, which is a member of T.  */
    1578                 :             : 
    1579                 :             : static void
    1580                 :     1978734 : handle_using_decl (tree using_decl, tree t)
    1581                 :             : {
    1582                 :     1978734 :   tree decl = USING_DECL_DECLS (using_decl);
    1583                 :             : 
    1584                 :     1978734 :   gcc_assert (!processing_template_decl && decl);
    1585                 :             : 
    1586                 :     1978734 :   cp_emit_debug_info_for_using (decl, t);
    1587                 :             : 
    1588                 :     1978734 :   if (is_overloaded_fn (decl))
    1589                 :             :     /* Handled in maybe_push_used_methods.  */
    1590                 :     1978734 :     return;
    1591                 :             : 
    1592                 :      527045 :   tree name = DECL_NAME (using_decl);
    1593                 :      527045 :   tree old_value = lookup_member (t, name, /*protect=*/0, /*want_type=*/false,
    1594                 :             :                                   tf_warning_or_error);
    1595                 :      527045 :   if (old_value)
    1596                 :             :     {
    1597                 :      527045 :       old_value = OVL_FIRST (old_value);
    1598                 :             : 
    1599                 :      527045 :       if (DECL_P (old_value) && DECL_CONTEXT (old_value) == t)
    1600                 :             :         /* OK */;
    1601                 :             :       else
    1602                 :             :         old_value = NULL_TREE;
    1603                 :             :     }
    1604                 :             : 
    1605                 :           0 :   if (! old_value)
    1606                 :             :     ;
    1607                 :           0 :   else if (is_overloaded_fn (old_value))
    1608                 :             :     {
    1609                 :           0 :       auto_diagnostic_group d;
    1610                 :           0 :       error_at (DECL_SOURCE_LOCATION (using_decl), "%qD invalid in %q#T "
    1611                 :             :                 "because of local method %q#D with same name",
    1612                 :             :                 using_decl, t, old_value);
    1613                 :           0 :       inform (DECL_SOURCE_LOCATION (old_value),
    1614                 :             :               "local method %q#D declared here", old_value);
    1615                 :           0 :       return;
    1616                 :           0 :     }
    1617                 :           0 :   else if (!DECL_ARTIFICIAL (old_value))
    1618                 :             :     {
    1619                 :           0 :       auto_diagnostic_group d;
    1620                 :           0 :       error_at (DECL_SOURCE_LOCATION (using_decl), "%qD invalid in %q#T "
    1621                 :             :                 "because of local member %q#D with same name",
    1622                 :             :                 using_decl, t, old_value);
    1623                 :           0 :       inform (DECL_SOURCE_LOCATION (old_value),
    1624                 :             :               "local member %q#D declared here", old_value);
    1625                 :           0 :       return;
    1626                 :           0 :     }
    1627                 :             : 
    1628                 :      527045 :   iloc_sentinel ils (DECL_SOURCE_LOCATION (using_decl));
    1629                 :      527045 :   tree access = declared_access (using_decl);
    1630                 :             : 
    1631                 :             :   /* Make type T see field decl FDECL with access ACCESS.  */
    1632                 :      527045 :   if (USING_DECL_UNRELATED_P (using_decl))
    1633                 :             :     {
    1634                 :             :       /* C++20 using enum can import non-inherited enumerators into class
    1635                 :             :          scope.  We implement that by making a copy of the CONST_DECL for which
    1636                 :             :          CONST_DECL_USING_P is true.  */
    1637                 :      358955 :       gcc_assert (TREE_CODE (decl) == CONST_DECL);
    1638                 :             : 
    1639                 :      358955 :       auto cas = make_temp_override (current_access_specifier, access);
    1640                 :      358955 :       tree copy = copy_decl (decl);
    1641                 :      358955 :       DECL_CONTEXT (copy) = t;
    1642                 :      358955 :       DECL_ARTIFICIAL (copy) = true;
    1643                 :             :       /* We emitted debug info for the USING_DECL above; make sure we don't
    1644                 :             :          also emit anything for this clone.  */
    1645                 :      358955 :       DECL_IGNORED_P (copy) = true;
    1646                 :      358955 :       DECL_SOURCE_LOCATION (copy) = DECL_SOURCE_LOCATION (using_decl);
    1647                 :      358955 :       finish_member_declaration (copy);
    1648                 :      358955 :       DECL_ABSTRACT_ORIGIN (copy) = decl;
    1649                 :      358955 :     }
    1650                 :             :   else
    1651                 :      168090 :     alter_access (t, decl, access);
    1652                 :      527045 : }
    1653                 :             : 
    1654                 :             : /* Data structure for find_abi_tags_r, below.  */
    1655                 :             : 
    1656                 :             : struct abi_tag_data
    1657                 :             : {
    1658                 :             :   tree t;               // The type that we're checking for missing tags.
    1659                 :             :   tree subob;           // The subobject of T that we're getting tags from.
    1660                 :             :   tree tags; // error_mark_node for diagnostics, or a list of missing tags.
    1661                 :             : };
    1662                 :             : 
    1663                 :             : /* Subroutine of find_abi_tags_r. Handle a single TAG found on the class TP
    1664                 :             :    in the context of P.  TAG can be either an identifier (the DECL_NAME of
    1665                 :             :    a tag NAMESPACE_DECL) or a STRING_CST (a tag attribute).  */
    1666                 :             : 
    1667                 :             : static void
    1668                 :    15190456 : check_tag (tree tag, tree id, tree *tp, abi_tag_data *p)
    1669                 :             : {
    1670                 :    15190456 :   if (!IDENTIFIER_MARKED (id))
    1671                 :             :     {
    1672                 :     4998999 :       if (p->tags != error_mark_node)
    1673                 :             :         {
    1674                 :             :           /* We're collecting tags from template arguments or from
    1675                 :             :              the type of a variable or function return type.  */
    1676                 :     4998981 :           p->tags = tree_cons (NULL_TREE, tag, p->tags);
    1677                 :             : 
    1678                 :             :           /* Don't inherit this tag multiple times.  */
    1679                 :     4998981 :           IDENTIFIER_MARKED (id) = true;
    1680                 :             : 
    1681                 :     4998981 :           if (TYPE_P (p->t))
    1682                 :             :             {
    1683                 :             :               /* Tags inherited from type template arguments are only used
    1684                 :             :                  to avoid warnings.  */
    1685                 :     4977704 :               ABI_TAG_IMPLICIT (p->tags) = true;
    1686                 :     4977704 :               return;
    1687                 :             :             }
    1688                 :             :           /* For functions and variables we want to warn, too.  */
    1689                 :             :         }
    1690                 :             : 
    1691                 :             :       /* Otherwise we're diagnosing missing tags.  */
    1692                 :       21295 :       if (TREE_CODE (p->t) == FUNCTION_DECL)
    1693                 :             :         {
    1694                 :       20881 :           auto_diagnostic_group d;
    1695                 :       20881 :           if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag "
    1696                 :             :                        "that %qT (used in its return type) has",
    1697                 :             :                        p->t, tag, *tp))
    1698                 :           3 :             inform (location_of (*tp), "%qT declared here", *tp);
    1699                 :       20881 :         }
    1700                 :         414 :       else if (VAR_P (p->t))
    1701                 :             :         {
    1702                 :         396 :           auto_diagnostic_group d;
    1703                 :         396 :           if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag "
    1704                 :             :                        "that %qT (used in its type) has", p->t, tag, *tp))
    1705                 :           3 :             inform (location_of (*tp), "%qT declared here", *tp);
    1706                 :         396 :         }
    1707                 :          18 :       else if (TYPE_P (p->subob))
    1708                 :             :         {
    1709                 :           6 :           auto_diagnostic_group d;
    1710                 :           6 :           if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag "
    1711                 :             :                        "that base %qT has", p->t, tag, p->subob))
    1712                 :           6 :             inform (location_of (p->subob), "%qT declared here",
    1713                 :             :                     p->subob);
    1714                 :           6 :         }
    1715                 :             :       else
    1716                 :             :         {
    1717                 :          12 :           auto_diagnostic_group d;
    1718                 :          12 :           if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag "
    1719                 :             :                        "that %qT (used in the type of %qD) has",
    1720                 :             :                        p->t, tag, *tp, p->subob))
    1721                 :             :             {
    1722                 :          12 :               inform (location_of (p->subob), "%qD declared here",
    1723                 :             :                       p->subob);
    1724                 :          12 :               inform (location_of (*tp), "%qT declared here", *tp);
    1725                 :             :             }
    1726                 :          12 :         }
    1727                 :             :     }
    1728                 :             : }
    1729                 :             : 
    1730                 :             : /* Find all the ABI tags in the attribute list ATTR and either call
    1731                 :             :    check_tag (if TP is non-null) or set IDENTIFIER_MARKED to val.  */
    1732                 :             : 
    1733                 :             : static void
    1734                 :  2059929950 : mark_or_check_attr_tags (tree attr, tree *tp, abi_tag_data *p, bool val)
    1735                 :             : {
    1736                 :  2059929950 :   if (!attr)
    1737                 :             :     return;
    1738                 :   251640489 :   for (; (attr = lookup_attribute ("abi_tag", attr));
    1739                 :    90669657 :        attr = TREE_CHAIN (attr))
    1740                 :   181339344 :     for (tree list = TREE_VALUE (attr); list;
    1741                 :    90669687 :          list = TREE_CHAIN (list))
    1742                 :             :       {
    1743                 :    90669687 :         tree tag = TREE_VALUE (list);
    1744                 :    90669687 :         tree id = get_identifier (TREE_STRING_POINTER (tag));
    1745                 :    90669687 :         if (tp)
    1746                 :    15190456 :           check_tag (tag, id, tp, p);
    1747                 :             :         else
    1748                 :    75479231 :           IDENTIFIER_MARKED (id) = val;
    1749                 :             :       }
    1750                 :             : }
    1751                 :             : 
    1752                 :             : /* Find all the ABI tags on T and its enclosing scopes and either call
    1753                 :             :    check_tag (if TP is non-null) or set IDENTIFIER_MARKED to val.  */
    1754                 :             : 
    1755                 :             : static void
    1756                 :   771786071 : mark_or_check_tags (tree t, tree *tp, abi_tag_data *p, bool val)
    1757                 :             : {
    1758                 :  2831716021 :   while (t != global_namespace)
    1759                 :             :     {
    1760                 :  2059929950 :       tree attr;
    1761                 :  2059929950 :       if (TYPE_P (t))
    1762                 :             :         {
    1763                 :   783098561 :           attr = TYPE_ATTRIBUTES (t);
    1764                 :   783098561 :           t = CP_TYPE_CONTEXT (t);
    1765                 :             :         }
    1766                 :             :       else
    1767                 :             :         {
    1768                 :  1276831389 :           attr = DECL_ATTRIBUTES (t);
    1769                 :  1276831389 :           t = CP_DECL_CONTEXT (t);
    1770                 :             :         }
    1771                 :  2059929950 :       mark_or_check_attr_tags (attr, tp, p, val);
    1772                 :             :     }
    1773                 :   771786071 : }
    1774                 :             : 
    1775                 :             : /* walk_tree callback for check_abi_tags: if the type at *TP involves any
    1776                 :             :    types with ABI tags, add the corresponding identifiers to the VEC in
    1777                 :             :    *DATA and set IDENTIFIER_MARKED.  */
    1778                 :             : 
    1779                 :             : static tree
    1780                 :   652671388 : find_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1781                 :             : {
    1782                 :   652671388 :   if (TYPE_P (*tp) && *walk_subtrees == 1 && flag_abi_version != 14)
    1783                 :             :     /* Tell cp_walk_subtrees to look though typedefs. [PR98481] */
    1784                 :   424008365 :     *walk_subtrees = 2;
    1785                 :             : 
    1786                 :   652671388 :   if (!OVERLOAD_TYPE_P (*tp))
    1787                 :             :     return NULL_TREE;
    1788                 :             : 
    1789                 :             :   /* walk_tree shouldn't be walking into any subtrees of a RECORD_TYPE
    1790                 :             :      anyway, but let's make sure of it.  */
    1791                 :   124006441 :   *walk_subtrees = false;
    1792                 :             : 
    1793                 :   124006441 :   abi_tag_data *p = static_cast<struct abi_tag_data*>(data);
    1794                 :             : 
    1795                 :   124006441 :   mark_or_check_tags (*tp, tp, p, false);
    1796                 :             : 
    1797                 :   124006441 :   return NULL_TREE;
    1798                 :             : }
    1799                 :             : 
    1800                 :             : /* walk_tree callback for mark_abi_tags: if *TP is a class, set
    1801                 :             :    IDENTIFIER_MARKED on its ABI tags.  */
    1802                 :             : 
    1803                 :             : static tree
    1804                 :  1051017892 : mark_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1805                 :             : {
    1806                 :  1051017892 :   if (TYPE_P (*tp) && *walk_subtrees == 1 && flag_abi_version != 14)
    1807                 :             :     /* Tell cp_walk_subtrees to look though typedefs.  */
    1808                 :   753233078 :     *walk_subtrees = 2;
    1809                 :             : 
    1810                 :  1051017892 :   if (!OVERLOAD_TYPE_P (*tp))
    1811                 :             :     return NULL_TREE;
    1812                 :             : 
    1813                 :             :   /* walk_tree shouldn't be walking into any subtrees of a RECORD_TYPE
    1814                 :             :      anyway, but let's make sure of it.  */
    1815                 :   143587130 :   *walk_subtrees = false;
    1816                 :             : 
    1817                 :   143587130 :   bool *valp = static_cast<bool*>(data);
    1818                 :             : 
    1819                 :   143587130 :   mark_or_check_tags (*tp, NULL, NULL, *valp);
    1820                 :             : 
    1821                 :   143587130 :   return NULL_TREE;
    1822                 :             : }
    1823                 :             : 
    1824                 :             : /* Set IDENTIFIER_MARKED on all the ABI tags on T and its enclosing
    1825                 :             :    scopes.  */
    1826                 :             : 
    1827                 :             : static void
    1828                 :   504192500 : mark_abi_tags (tree t, bool val)
    1829                 :             : {
    1830                 :   504192500 :   mark_or_check_tags (t, NULL, NULL, val);
    1831                 :   504192500 :   if (DECL_P (t))
    1832                 :             :     {
    1833                 :   638014894 :       if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t)
    1834                 :   547899332 :           && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))
    1835                 :             :         {
    1836                 :             :           /* Template arguments are part of the signature.  */
    1837                 :    13753382 :           tree level = INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t));
    1838                 :    35090440 :           for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1839                 :             :             {
    1840                 :    21337058 :               tree arg = TREE_VEC_ELT (level, j);
    1841                 :    21337058 :               cp_walk_tree_without_duplicates (&arg, mark_abi_tags_r, &val);
    1842                 :             :             }
    1843                 :             :         }
    1844                 :   320236958 :       if (TREE_CODE (t) == FUNCTION_DECL)
    1845                 :             :         /* A function's parameter types are part of the signature, so
    1846                 :             :            we don't need to inherit any tags that are also in them.  */
    1847                 :   865525080 :         for (tree arg = FUNCTION_FIRST_USER_PARMTYPE (t); arg;
    1848                 :   581055388 :              arg = TREE_CHAIN (arg))
    1849                 :   581055388 :           cp_walk_tree_without_duplicates (&TREE_VALUE (arg),
    1850                 :             :                                            mark_abi_tags_r, &val);
    1851                 :             :     }
    1852                 :   504192500 : }
    1853                 :             : 
    1854                 :             : /* Check that T has all the ABI tags that subobject SUBOB has, or
    1855                 :             :    warn if not.  If T is a (variable or function) declaration, also
    1856                 :             :    return any missing tags, and add them to T if JUST_CHECKING is false.  */
    1857                 :             : 
    1858                 :             : static tree
    1859                 :   195590615 : check_abi_tags (tree t, tree subob, bool just_checking = false)
    1860                 :             : {
    1861                 :   195590615 :   bool inherit = DECL_P (t);
    1862                 :             : 
    1863                 :   195590615 :   if (!inherit && !warn_abi_tag)
    1864                 :             :     return NULL_TREE;
    1865                 :             : 
    1866                 :   160297694 :   tree decl = TYPE_P (t) ? TYPE_NAME (t) : t;
    1867                 :   160297694 :   if (!TREE_PUBLIC (decl))
    1868                 :             :     /* No need to worry about things local to this TU.  */
    1869                 :             :     return NULL_TREE;
    1870                 :             : 
    1871                 :   160118500 :   mark_abi_tags (t, true);
    1872                 :             : 
    1873                 :   160118500 :   tree subtype = TYPE_P (subob) ? subob : TREE_TYPE (subob);
    1874                 :   160118500 :   struct abi_tag_data data = { t, subob, error_mark_node };
    1875                 :   160118500 :   if (inherit)
    1876                 :   160118479 :     data.tags = NULL_TREE;
    1877                 :             : 
    1878                 :   160118500 :   cp_walk_tree_without_duplicates (&subtype, find_abi_tags_r, &data);
    1879                 :             : 
    1880                 :   160118500 :   if (!(inherit && data.tags))
    1881                 :             :     /* We don't need to do anything with data.tags.  */;
    1882                 :       21262 :   else if (just_checking)
    1883                 :          75 :     for (tree t = data.tags; t; t = TREE_CHAIN (t))
    1884                 :             :       {
    1885                 :          42 :         tree id = get_identifier (TREE_STRING_POINTER (TREE_VALUE (t)));
    1886                 :          42 :         IDENTIFIER_MARKED (id) = false;
    1887                 :             :       }
    1888                 :             :   else
    1889                 :             :     {
    1890                 :       21229 :       tree attr = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (t));
    1891                 :       21229 :       if (attr)
    1892                 :           0 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1893                 :             :       else
    1894                 :       21229 :         DECL_ATTRIBUTES (t)
    1895                 :       42458 :           = tree_cons (abi_tag_identifier, data.tags, DECL_ATTRIBUTES (t));
    1896                 :             :     }
    1897                 :             : 
    1898                 :   160118500 :   mark_abi_tags (t, false);
    1899                 :             : 
    1900                 :   160118500 :   return data.tags;
    1901                 :             : }
    1902                 :             : 
    1903                 :             : /* Check that DECL has all the ABI tags that are used in parts of its type
    1904                 :             :    that are not reflected in its mangled name.  */
    1905                 :             : 
    1906                 :             : void
    1907                 :   170358912 : check_abi_tags (tree decl)
    1908                 :             : {
    1909                 :   170358912 :   if (VAR_P (decl))
    1910                 :    17986113 :     check_abi_tags (decl, TREE_TYPE (decl));
    1911                 :   152372799 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1912                 :   152369636 :            && !DECL_CONV_FN_P (decl)
    1913                 :   302936673 :            && !mangle_return_type_p (decl))
    1914                 :   142228006 :     check_abi_tags (decl, TREE_TYPE (TREE_TYPE (decl)));
    1915                 :   170358912 : }
    1916                 :             : 
    1917                 :             : /* Return any ABI tags that are used in parts of the type of DECL
    1918                 :             :    that are not reflected in its mangled name.  This function is only
    1919                 :             :    used in backward-compatible mangling for ABI <11.  */
    1920                 :             : 
    1921                 :             : tree
    1922                 :       84279 : missing_abi_tags (tree decl)
    1923                 :             : {
    1924                 :       84279 :   if (VAR_P (decl))
    1925                 :        1112 :     return check_abi_tags (decl, TREE_TYPE (decl), true);
    1926                 :       83167 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1927                 :             :            /* Don't check DECL_CONV_FN_P here like we do in check_abi_tags, so
    1928                 :             :               that we can use this function for setting need_abi_warning
    1929                 :             :               regardless of the current flag_abi_version.  */
    1930                 :       83167 :            && !mangle_return_type_p (decl))
    1931                 :       82439 :     return check_abi_tags (decl, TREE_TYPE (TREE_TYPE (decl)), true);
    1932                 :             :   else
    1933                 :         728 :     return NULL_TREE;
    1934                 :             : }
    1935                 :             : 
    1936                 :             : void
    1937                 :    92318091 : inherit_targ_abi_tags (tree t)
    1938                 :             : {
    1939                 :    91977750 :   if (!CLASS_TYPE_P (t)
    1940                 :   184295841 :       || CLASSTYPE_TEMPLATE_INFO (t) == NULL_TREE)
    1941                 :      340341 :     return;
    1942                 :             : 
    1943                 :    91977750 :   mark_abi_tags (t, true);
    1944                 :             : 
    1945                 :    91977750 :   tree args = CLASSTYPE_TI_ARGS (t);
    1946                 :    91977750 :   struct abi_tag_data data = { t, NULL_TREE, NULL_TREE };
    1947                 :   551866682 :   for (int i = 0; i < TMPL_ARGS_DEPTH (args); ++i)
    1948                 :             :     {
    1949                 :   188732598 :       tree level = TMPL_ARGS_LEVEL (args, i+1);
    1950                 :   263031133 :       for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1951                 :             :         {
    1952                 :   168664834 :           tree arg = TREE_VEC_ELT (level, j);
    1953                 :   168664834 :           data.subob = arg;
    1954                 :   168664834 :           cp_walk_tree_without_duplicates (&arg, find_abi_tags_r, &data);
    1955                 :             :         }
    1956                 :             :     }
    1957                 :             : 
    1958                 :             :   // If we found some tags on our template arguments, add them to our
    1959                 :             :   // abi_tag attribute.
    1960                 :    91977750 :   if (data.tags)
    1961                 :             :     {
    1962                 :     4977704 :       tree attr = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (t));
    1963                 :     4977704 :       if (attr)
    1964                 :           3 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1965                 :             :       else
    1966                 :     4977701 :         TYPE_ATTRIBUTES (t)
    1967                 :     9955402 :           = tree_cons (abi_tag_identifier, data.tags, TYPE_ATTRIBUTES (t));
    1968                 :             :     }
    1969                 :             : 
    1970                 :    91977750 :   mark_abi_tags (t, false);
    1971                 :             : }
    1972                 :             : 
    1973                 :             : /* Return true, iff class T has a non-virtual destructor that is
    1974                 :             :    accessible from outside the class heirarchy (i.e. is public, or
    1975                 :             :    there's a suitable friend.  */
    1976                 :             : 
    1977                 :             : static bool
    1978                 :          99 : accessible_nvdtor_p (tree t)
    1979                 :             : {
    1980                 :          99 :   tree dtor = CLASSTYPE_DESTRUCTOR (t);
    1981                 :             : 
    1982                 :             :   /* An implicitly declared destructor is always public.  And,
    1983                 :             :      if it were virtual, we would have created it by now.  */
    1984                 :          99 :   if (!dtor)
    1985                 :             :     return true;
    1986                 :             : 
    1987                 :          78 :   if (DECL_VINDEX (dtor))
    1988                 :             :     return false; /* Virtual */
    1989                 :             : 
    1990                 :          42 :   if (!TREE_PRIVATE (dtor) && !TREE_PROTECTED (dtor))
    1991                 :             :     return true;  /* Public */
    1992                 :             : 
    1993                 :          30 :   if (CLASSTYPE_FRIEND_CLASSES (t)
    1994                 :          30 :       || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
    1995                 :          12 :     return true;   /* Has friends */
    1996                 :             : 
    1997                 :             :   return false;
    1998                 :             : }
    1999                 :             : 
    2000                 :             : /* Run through the base classes of T, updating CANT_HAVE_CONST_CTOR_P,
    2001                 :             :    and NO_CONST_ASN_REF_P.  Also set flag bits in T based on
    2002                 :             :    properties of the bases.  */
    2003                 :             : 
    2004                 :             : static void
    2005                 :    37061824 : check_bases (tree t,
    2006                 :             :              int* cant_have_const_ctor_p,
    2007                 :             :              int* no_const_asn_ref_p)
    2008                 :             : {
    2009                 :    37061824 :   int i;
    2010                 :    37061824 :   bool seen_non_virtual_nearly_empty_base_p = 0;
    2011                 :    37061824 :   int seen_tm_mask = 0;
    2012                 :    37061824 :   tree base_binfo;
    2013                 :    37061824 :   tree binfo;
    2014                 :    37061824 :   tree field = NULL_TREE;
    2015                 :             : 
    2016                 :    37061824 :   if (!CLASSTYPE_NON_STD_LAYOUT (t))
    2017                 :   174554798 :     for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    2018                 :   143422730 :       if (TREE_CODE (field) == FIELD_DECL)
    2019                 :             :         break;
    2020                 :             : 
    2021                 :    56447374 :   for (binfo = TYPE_BINFO (t), i = 0;
    2022                 :    56447374 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    2023                 :             :     {
    2024                 :    19385550 :       tree basetype = TREE_TYPE (base_binfo);
    2025                 :             : 
    2026                 :    19385550 :       gcc_assert (COMPLETE_TYPE_P (basetype));
    2027                 :             : 
    2028                 :    19385550 :       if (CLASSTYPE_FINAL (basetype))
    2029                 :          14 :         error ("cannot derive from %<final%> base %qT in derived type %qT",
    2030                 :             :                basetype, t);
    2031                 :             : 
    2032                 :             :       /* If any base class is non-literal, so is the derived class.  */
    2033                 :    19385550 :       if (!CLASSTYPE_LITERAL_P (basetype))
    2034                 :     2002359 :         CLASSTYPE_LITERAL_P (t) = false;
    2035                 :             : 
    2036                 :             :       /* If the base class doesn't have copy constructors or
    2037                 :             :          assignment operators that take const references, then the
    2038                 :             :          derived class cannot have such a member automatically
    2039                 :             :          generated.  */
    2040                 :    19385550 :       if (TYPE_HAS_COPY_CTOR (basetype)
    2041                 :    19385550 :           && ! TYPE_HAS_CONST_COPY_CTOR (basetype))
    2042                 :          60 :         *cant_have_const_ctor_p = 1;
    2043                 :    19385550 :       if (TYPE_HAS_COPY_ASSIGN (basetype)
    2044                 :    19385550 :           && !TYPE_HAS_CONST_COPY_ASSIGN (basetype))
    2045                 :          18 :         *no_const_asn_ref_p = 1;
    2046                 :             : 
    2047                 :    19385550 :       if (BINFO_VIRTUAL_P (base_binfo))
    2048                 :             :         /* A virtual base does not effect nearly emptiness.  */
    2049                 :             :         ;
    2050                 :    19338150 :       else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
    2051                 :             :         {
    2052                 :      273252 :           if (seen_non_virtual_nearly_empty_base_p)
    2053                 :             :             /* And if there is more than one nearly empty base, then the
    2054                 :             :                derived class is not nearly empty either.  */
    2055                 :        1080 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    2056                 :             :           else
    2057                 :             :             /* Remember we've seen one.  */
    2058                 :             :             seen_non_virtual_nearly_empty_base_p = 1;
    2059                 :             :         }
    2060                 :    19064898 :       else if (!is_empty_class (basetype))
    2061                 :             :         /* If the base class is not empty or nearly empty, then this
    2062                 :             :            class cannot be nearly empty.  */
    2063                 :     1891620 :         CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    2064                 :             : 
    2065                 :             :       /* A lot of properties from the bases also apply to the derived
    2066                 :             :          class.  */
    2067                 :    19385550 :       TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
    2068                 :    58156650 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    2069                 :    19385550 :         |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
    2070                 :    19385550 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    2071                 :    19385550 :         |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (basetype)
    2072                 :    19385550 :             || !TYPE_HAS_COPY_ASSIGN (basetype));
    2073                 :    38771100 :       TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (basetype)
    2074                 :    19385550 :                                          || !TYPE_HAS_COPY_CTOR (basetype));
    2075                 :    58156650 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
    2076                 :    19385550 :         |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (basetype);
    2077                 :    19385550 :       TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (basetype);
    2078                 :    19385550 :       TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
    2079                 :    58156650 :       CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
    2080                 :    19385550 :         |= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
    2081                 :    38771100 :       TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
    2082                 :    19385550 :                                     || TYPE_HAS_COMPLEX_DFLT (basetype));
    2083                 :    19385550 :       SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT
    2084                 :             :         (t, CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
    2085                 :             :          | CLASSTYPE_READONLY_FIELDS_NEED_INIT (basetype));
    2086                 :    19385550 :       SET_CLASSTYPE_REF_FIELDS_NEED_INIT
    2087                 :             :         (t, CLASSTYPE_REF_FIELDS_NEED_INIT (t)
    2088                 :             :          | CLASSTYPE_REF_FIELDS_NEED_INIT (basetype));
    2089                 :    19385550 :       if (TYPE_HAS_MUTABLE_P (basetype))
    2090                 :      956836 :         CLASSTYPE_HAS_MUTABLE (t) = 1;
    2091                 :             : 
    2092                 :             :       /*  A standard-layout class is a class that:
    2093                 :             :           ...
    2094                 :             :           * has no non-standard-layout base classes,  */
    2095                 :    19385550 :       CLASSTYPE_NON_STD_LAYOUT (t) |= CLASSTYPE_NON_STD_LAYOUT (basetype);
    2096                 :    19385550 :       if (!CLASSTYPE_NON_STD_LAYOUT (t))
    2097                 :             :         {
    2098                 :    17523685 :           tree basefield;
    2099                 :             :           /* ...has no base classes of the same type as the first non-static
    2100                 :             :              data member...  */
    2101                 :      505228 :           if (field && DECL_CONTEXT (field) == t
    2102                 :    17974102 :               && (same_type_ignoring_top_level_qualifiers_p
    2103                 :      450417 :                   (TREE_TYPE (field), basetype)))
    2104                 :         129 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    2105                 :             :           /* DR 1813:
    2106                 :             :              ...has at most one base class subobject of any given type...  */
    2107                 :    17523556 :           else if (CLASSTYPE_REPEATED_BASE_P (t))
    2108                 :         370 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    2109                 :             :           else
    2110                 :             :             /* ...has all non-static data members and bit-fields in the class
    2111                 :             :                and its base classes first declared in the same class.  */
    2112                 :   239450402 :             for (basefield = TYPE_FIELDS (basetype); basefield;
    2113                 :   221927216 :                  basefield = DECL_CHAIN (basefield))
    2114                 :   222704566 :               if (TREE_CODE (basefield) == FIELD_DECL
    2115                 :   223612292 :                   && !(DECL_FIELD_IS_BASE (basefield)
    2116                 :      907726 :                        && is_empty_field (basefield)))
    2117                 :             :                 {
    2118                 :      777350 :                   if (field)
    2119                 :      138417 :                     CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    2120                 :             :                   else
    2121                 :             :                     field = basefield;
    2122                 :             :                   break;
    2123                 :             :                 }
    2124                 :             :         }
    2125                 :             : 
    2126                 :             :       /* Don't bother collecting tm attributes if transactional memory
    2127                 :             :          support is not enabled.  */
    2128                 :    19385550 :       if (flag_tm)
    2129                 :             :         {
    2130                 :        1246 :           tree tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (basetype));
    2131                 :        1246 :           if (tm_attr)
    2132                 :          15 :             seen_tm_mask |= tm_attr_to_mask (tm_attr);
    2133                 :             :         }
    2134                 :             : 
    2135                 :    19385550 :       check_abi_tags (t, basetype);
    2136                 :             :     }
    2137                 :             : 
    2138                 :             :   /* If one of the base classes had TM attributes, and the current class
    2139                 :             :      doesn't define its own, then the current class inherits one.  */
    2140                 :    37061824 :   if (seen_tm_mask && !find_tm_attribute (TYPE_ATTRIBUTES (t)))
    2141                 :             :     {
    2142                 :          12 :       tree tm_attr = tm_mask_to_attr (least_bit_hwi (seen_tm_mask));
    2143                 :          12 :       TYPE_ATTRIBUTES (t) = tree_cons (tm_attr, NULL, TYPE_ATTRIBUTES (t));
    2144                 :             :     }
    2145                 :    37061824 : }
    2146                 :             : 
    2147                 :             : /* Determine all the primary bases within T.  Sets BINFO_PRIMARY_BASE_P for
    2148                 :             :    those that are primaries.  Sets BINFO_LOST_PRIMARY_P for those
    2149                 :             :    that have had a nearly-empty virtual primary base stolen by some
    2150                 :             :    other base in the hierarchy.  Determines CLASSTYPE_PRIMARY_BASE for
    2151                 :             :    T.  */
    2152                 :             : 
    2153                 :             : static void
    2154                 :    37061824 : determine_primary_bases (tree t)
    2155                 :             : {
    2156                 :    37061824 :   unsigned i;
    2157                 :    37061824 :   tree primary = NULL_TREE;
    2158                 :    37061824 :   tree type_binfo = TYPE_BINFO (t);
    2159                 :    37061824 :   tree base_binfo;
    2160                 :             : 
    2161                 :             :   /* Determine the primary bases of our bases.  */
    2162                 :    59570248 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    2163                 :    22508424 :        base_binfo = TREE_CHAIN (base_binfo))
    2164                 :             :     {
    2165                 :    22508424 :       tree primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (base_binfo));
    2166                 :             : 
    2167                 :             :       /* See if we're the non-virtual primary of our inheritance
    2168                 :             :          chain.  */
    2169                 :    22508424 :       if (!BINFO_VIRTUAL_P (base_binfo))
    2170                 :             :         {
    2171                 :    22307867 :           tree parent = BINFO_INHERITANCE_CHAIN (base_binfo);
    2172                 :    22307867 :           tree parent_primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (parent));
    2173                 :             : 
    2174                 :    22307867 :           if (parent_primary
    2175                 :    22307867 :               && SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
    2176                 :             :                                     BINFO_TYPE (parent_primary)))
    2177                 :             :             /* We are the primary binfo.  */
    2178                 :     1046587 :             BINFO_PRIMARY_P (base_binfo) = 1;
    2179                 :             :         }
    2180                 :             :       /* Determine if we have a virtual primary base, and mark it so.
    2181                 :             :        */
    2182                 :    23562113 :       if (primary && BINFO_VIRTUAL_P (primary))
    2183                 :             :         {
    2184                 :        7102 :           tree this_primary = copied_binfo (primary, base_binfo);
    2185                 :             : 
    2186                 :        7102 :           if (BINFO_PRIMARY_P (this_primary))
    2187                 :             :             /* Someone already claimed this base.  */
    2188                 :         634 :             BINFO_LOST_PRIMARY_P (base_binfo) = 1;
    2189                 :             :           else
    2190                 :             :             {
    2191                 :        6468 :               tree delta;
    2192                 :             : 
    2193                 :        6468 :               BINFO_PRIMARY_P (this_primary) = 1;
    2194                 :        6468 :               BINFO_INHERITANCE_CHAIN (this_primary) = base_binfo;
    2195                 :             : 
    2196                 :             :               /* A virtual binfo might have been copied from within
    2197                 :             :                  another hierarchy. As we're about to use it as a
    2198                 :             :                  primary base, make sure the offsets match.  */
    2199                 :        6468 :               delta = size_diffop_loc (input_location,
    2200                 :        6468 :                                    fold_convert (ssizetype,
    2201                 :             :                                             BINFO_OFFSET (base_binfo)),
    2202                 :        6468 :                                    fold_convert (ssizetype,
    2203                 :             :                                             BINFO_OFFSET (this_primary)));
    2204                 :             : 
    2205                 :        6468 :               propagate_binfo_offsets (this_primary, delta);
    2206                 :             :             }
    2207                 :             :         }
    2208                 :             :     }
    2209                 :             : 
    2210                 :             :   /* First look for a dynamic direct non-virtual base.  */
    2211                 :    54855193 :   for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, base_binfo); i++)
    2212                 :             :     {
    2213                 :    19209606 :       tree basetype = BINFO_TYPE (base_binfo);
    2214                 :             : 
    2215                 :    19209606 :       if (TYPE_CONTAINS_VPTR_P (basetype) && !BINFO_VIRTUAL_P (base_binfo))
    2216                 :             :         {
    2217                 :     1416237 :           primary = base_binfo;
    2218                 :     1416237 :           goto found;
    2219                 :             :         }
    2220                 :             :     }
    2221                 :             : 
    2222                 :             :   /* A "nearly-empty" virtual base class can be the primary base
    2223                 :             :      class, if no non-virtual polymorphic base can be found.  Look for
    2224                 :             :      a nearly-empty virtual dynamic base that is not already a primary
    2225                 :             :      base of something in the hierarchy.  If there is no such base,
    2226                 :             :      just pick the first nearly-empty virtual base.  */
    2227                 :             : 
    2228                 :    54964149 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    2229                 :    19318562 :        base_binfo = TREE_CHAIN (base_binfo))
    2230                 :    19320114 :     if (BINFO_VIRTUAL_P (base_binfo)
    2231                 :    19320114 :         && CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (base_binfo)))
    2232                 :             :       {
    2233                 :        1681 :         if (!BINFO_PRIMARY_P (base_binfo))
    2234                 :             :           {
    2235                 :             :             /* Found one that is not primary.  */
    2236                 :        1552 :             primary = base_binfo;
    2237                 :        1552 :             goto found;
    2238                 :             :           }
    2239                 :         129 :         else if (!primary)
    2240                 :             :           /* Remember the first candidate.  */
    2241                 :    19318562 :           primary = base_binfo;
    2242                 :             :       }
    2243                 :             : 
    2244                 :    35644035 :  found:
    2245                 :             :   /* If we've got a primary base, use it.  */
    2246                 :    37061824 :   if (primary)
    2247                 :             :     {
    2248                 :     1417870 :       tree basetype = BINFO_TYPE (primary);
    2249                 :             : 
    2250                 :     1417870 :       CLASSTYPE_PRIMARY_BINFO (t) = primary;
    2251                 :     1417870 :       if (BINFO_PRIMARY_P (primary))
    2252                 :             :         /* We are stealing a primary base.  */
    2253                 :          81 :         BINFO_LOST_PRIMARY_P (BINFO_INHERITANCE_CHAIN (primary)) = 1;
    2254                 :     1417870 :       BINFO_PRIMARY_P (primary) = 1;
    2255                 :     1417870 :       if (BINFO_VIRTUAL_P (primary))
    2256                 :             :         {
    2257                 :        1633 :           tree delta;
    2258                 :             : 
    2259                 :        1633 :           BINFO_INHERITANCE_CHAIN (primary) = type_binfo;
    2260                 :             :           /* A virtual binfo might have been copied from within
    2261                 :             :              another hierarchy. As we're about to use it as a primary
    2262                 :             :              base, make sure the offsets match.  */
    2263                 :        1633 :           delta = size_diffop_loc (input_location, ssize_int (0),
    2264                 :        1633 :                                fold_convert (ssizetype, BINFO_OFFSET (primary)));
    2265                 :             : 
    2266                 :        1633 :           propagate_binfo_offsets (primary, delta);
    2267                 :             :         }
    2268                 :             : 
    2269                 :     1417870 :       primary = TYPE_BINFO (basetype);
    2270                 :             : 
    2271                 :     1417870 :       TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
    2272                 :     1417870 :       BINFO_VTABLE (type_binfo) = BINFO_VTABLE (primary);
    2273                 :     1417870 :       BINFO_VIRTUALS (type_binfo) = BINFO_VIRTUALS (primary);
    2274                 :             :     }
    2275                 :    37061824 : }
    2276                 :             : 
    2277                 :             : /* Update the variant types of T.  */
    2278                 :             : 
    2279                 :             : void
    2280                 :   124037447 : fixup_type_variants (tree type)
    2281                 :             : {
    2282                 :   124037447 :   if (!type)
    2283                 :             :     return;
    2284                 :             : 
    2285                 :   124037447 :   for (tree variant = TYPE_NEXT_VARIANT (type);
    2286                 :   248695794 :        variant;
    2287                 :   124658347 :        variant = TYPE_NEXT_VARIANT (variant))
    2288                 :             :     {
    2289                 :             :       /* These fields are in the _TYPE part of the node, not in
    2290                 :             :          the TYPE_LANG_SPECIFIC component, so they are not shared.  */
    2291                 :   124658347 :       TYPE_HAS_USER_CONSTRUCTOR (variant) = TYPE_HAS_USER_CONSTRUCTOR (type);
    2292                 :   124658347 :       TYPE_NEEDS_CONSTRUCTING (variant) = TYPE_NEEDS_CONSTRUCTING (type);
    2293                 :   249316694 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variant)
    2294                 :   124658347 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    2295                 :             : 
    2296                 :   124658347 :       TYPE_POLYMORPHIC_P (variant) = TYPE_POLYMORPHIC_P (type);
    2297                 :   124658347 :       CLASSTYPE_FINAL (variant) = CLASSTYPE_FINAL (type);
    2298                 :             : 
    2299                 :   124658347 :       TYPE_BINFO (variant) = TYPE_BINFO (type);
    2300                 :             : 
    2301                 :             :       /* Copy whatever these are holding today.  */
    2302                 :   124658347 :       TYPE_VFIELD (variant) = TYPE_VFIELD (type);
    2303                 :   124658347 :       TYPE_FIELDS (variant) = TYPE_FIELDS (type);
    2304                 :             : 
    2305                 :   124658347 :       TYPE_SIZE (variant) = TYPE_SIZE (type);
    2306                 :   124658347 :       TYPE_SIZE_UNIT (variant) = TYPE_SIZE_UNIT (type);
    2307                 :             : 
    2308                 :   124658347 :       if (!TYPE_USER_ALIGN (variant)
    2309                 :     2377119 :           || TYPE_NAME (variant) == TYPE_NAME (type)
    2310                 :   125825763 :           || TYPE_ALIGN_RAW (variant) < TYPE_ALIGN_RAW (type))
    2311                 :             :         {
    2312                 :   123490931 :           TYPE_ALIGN_RAW (variant) =  TYPE_ALIGN_RAW (type);
    2313                 :   123490931 :           TYPE_USER_ALIGN (variant) = TYPE_USER_ALIGN (type);
    2314                 :             :         }
    2315                 :             : 
    2316                 :   124658347 :       TYPE_PRECISION (variant) = TYPE_PRECISION (type);
    2317                 :   124658347 :       TYPE_MODE_RAW (variant) = TYPE_MODE_RAW (type);
    2318                 :   124658347 :       TYPE_EMPTY_P (variant) = TYPE_EMPTY_P (type);
    2319                 :   124658347 :       TREE_ADDRESSABLE (variant) = TREE_ADDRESSABLE (type);
    2320                 :             :     }
    2321                 :             : }
    2322                 :             : 
    2323                 :             : /* KLASS is a class that we're applying may_alias to after the body is
    2324                 :             :    parsed.  Fixup any POINTER_TO and REFERENCE_TO types.  The
    2325                 :             :    canonical type(s) will be implicitly updated.  */
    2326                 :             : 
    2327                 :             : static void
    2328                 :       39583 : fixup_may_alias (tree klass)
    2329                 :             : {
    2330                 :       39583 :   tree t, v;
    2331                 :             : 
    2332                 :       59004 :   for (t = TYPE_POINTER_TO (klass); t; t = TYPE_NEXT_PTR_TO (t))
    2333                 :       58248 :     for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    2334                 :       38827 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    2335                 :       39604 :   for (t = TYPE_REFERENCE_TO (klass); t; t = TYPE_NEXT_REF_TO (t))
    2336                 :          42 :     for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    2337                 :          21 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    2338                 :       39583 : }
    2339                 :             : 
    2340                 :             : /* Early variant fixups: we apply attributes at the beginning of the class
    2341                 :             :    definition, and we need to fix up any variants that have already been
    2342                 :             :    made via elaborated-type-specifier so that check_qualified_type works.  */
    2343                 :             : 
    2344                 :             : void
    2345                 :    78130920 : fixup_attribute_variants (tree t)
    2346                 :             : {
    2347                 :    78130920 :   tree variants;
    2348                 :             : 
    2349                 :    78130920 :   if (!t)
    2350                 :             :     return;
    2351                 :             : 
    2352                 :    78130920 :   tree attrs = TYPE_ATTRIBUTES (t);
    2353                 :    78130920 :   unsigned align = TYPE_ALIGN (t);
    2354                 :    78130920 :   bool user_align = TYPE_USER_ALIGN (t);
    2355                 :    78130920 :   bool may_alias = lookup_attribute ("may_alias", attrs);
    2356                 :    78130920 :   bool packed = TYPE_PACKED (t);
    2357                 :             : 
    2358                 :    78130920 :   if (may_alias)
    2359                 :       19905 :     fixup_may_alias (t);
    2360                 :             : 
    2361                 :    78130920 :   for (variants = TYPE_NEXT_VARIANT (t);
    2362                 :   117951587 :        variants;
    2363                 :    39820667 :        variants = TYPE_NEXT_VARIANT (variants))
    2364                 :             :     {
    2365                 :             :       /* These are the two fields that check_qualified_type looks at and
    2366                 :             :          are affected by attributes.  */
    2367                 :    39820667 :       TYPE_ATTRIBUTES (variants) = attrs;
    2368                 :    39820667 :       unsigned valign = align;
    2369                 :    39820667 :       if (TYPE_USER_ALIGN (variants))
    2370                 :       17751 :         valign = MAX (valign, TYPE_ALIGN (variants));
    2371                 :             :       else
    2372                 :    39802916 :         TYPE_USER_ALIGN (variants) = user_align;
    2373                 :    39820667 :       SET_TYPE_ALIGN (variants, valign);
    2374                 :    39820667 :       TYPE_PACKED (variants) = packed;
    2375                 :    39820667 :       if (may_alias)
    2376                 :       19678 :         fixup_may_alias (variants);
    2377                 :             :     }
    2378                 :             : }
    2379                 :             : 
    2380                 :             : /* Set memoizing fields and bits of T (and its variants) for later
    2381                 :             :    use.  */
    2382                 :             : 
    2383                 :             : static void
    2384                 :    37061824 : finish_struct_bits (tree t)
    2385                 :             : {
    2386                 :             :   /* If this type has a copy constructor or a destructor, force its
    2387                 :             :      mode to be BLKmode, and force its TREE_ADDRESSABLE bit to be
    2388                 :             :      nonzero.  This will cause it to be passed by invisible reference
    2389                 :             :      and prevent it from being returned in a register.  */
    2390                 :    37061824 :   if (type_has_nontrivial_copy_init (t)
    2391                 :    37061824 :       || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    2392                 :             :     {
    2393                 :     4559542 :       SET_DECL_MODE (TYPE_MAIN_DECL (t), BLKmode);
    2394                 :     4559542 :       SET_TYPE_MODE (t, BLKmode);
    2395                 :     4559542 :       TREE_ADDRESSABLE (t) = 1;
    2396                 :             :     }
    2397                 :             : 
    2398                 :    37061824 :   if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) && TYPE_POLYMORPHIC_P (t))
    2399                 :             :     /* For a class w/o baseclasses, 'finish_struct' has set
    2400                 :             :        CLASSTYPE_PURE_VIRTUALS correctly (by definition).
    2401                 :             :        Similarly for a class whose base classes do not have vtables.
    2402                 :             :        When neither of these is true, we might have removed abstract
    2403                 :             :        virtuals (by providing a definition), added some (by declaring
    2404                 :             :        new ones), or redeclared ones from a base class.  We need to
    2405                 :             :        recalculate what's really an abstract virtual at this point (by
    2406                 :             :        looking in the vtables).  */
    2407                 :     1489775 :     get_pure_virtuals (t);
    2408                 :             : 
    2409                 :             :   /* Fix up variants (if any).  */
    2410                 :    37061824 :   fixup_type_variants (t);
    2411                 :    37061824 : }
    2412                 :             : 
    2413                 :             : /* Issue warnings about T having private constructors, but no friends,
    2414                 :             :    and so forth.
    2415                 :             : 
    2416                 :             :    HAS_NONPRIVATE_METHOD is nonzero if T has any non-private methods or
    2417                 :             :    static members.  HAS_NONPRIVATE_STATIC_FN is nonzero if T has any
    2418                 :             :    non-private static member functions.  */
    2419                 :             : 
    2420                 :             : static void
    2421                 :    25333445 : maybe_warn_about_overly_private_class (tree t)
    2422                 :             : {
    2423                 :    25333445 :   int has_member_fn = 0;
    2424                 :    25333445 :   int has_nonprivate_method = 0;
    2425                 :    25333445 :   bool nonprivate_ctor = false;
    2426                 :             : 
    2427                 :    25333445 :   if (!warn_ctor_dtor_privacy
    2428                 :             :       /* If the class has friends, those entities might create and
    2429                 :             :          access instances, so we should not warn.  */
    2430                 :          48 :       || (CLASSTYPE_FRIEND_CLASSES (t)
    2431                 :          48 :           || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
    2432                 :             :       /* We will have warned when the template was declared; there's
    2433                 :             :          no need to warn on every instantiation.  */
    2434                 :    25333493 :       || CLASSTYPE_TEMPLATE_INSTANTIATION (t))
    2435                 :             :     /* There's no reason to even consider warning about this
    2436                 :             :        class.  */
    2437                 :             :     return;
    2438                 :             : 
    2439                 :             :   /* We only issue one warning, if more than one applies, because
    2440                 :             :      otherwise, on code like:
    2441                 :             : 
    2442                 :             :      class A {
    2443                 :             :        // Oops - forgot `public:'
    2444                 :             :        A();
    2445                 :             :        A(const A&);
    2446                 :             :        ~A();
    2447                 :             :      };
    2448                 :             : 
    2449                 :             :      we warn several times about essentially the same problem.  */
    2450                 :             : 
    2451                 :             :   /* Check to see if all (non-constructor, non-destructor) member
    2452                 :             :      functions are private.  (Since there are no friends or
    2453                 :             :      non-private statics, we can't ever call any of the private member
    2454                 :             :      functions.)  */
    2455                 :         216 :   for (tree fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    2456                 :         168 :     if (TREE_CODE (fn) == USING_DECL
    2457                 :          18 :         && DECL_NAME (fn) == ctor_identifier
    2458                 :         171 :         && !TREE_PRIVATE (fn))
    2459                 :             :       nonprivate_ctor = true;
    2460                 :         165 :     else if (!DECL_DECLARES_FUNCTION_P (fn))
    2461                 :             :       /* Not a function.  */;
    2462                 :          96 :     else if (DECL_ARTIFICIAL (fn))
    2463                 :             :       /* We're not interested in compiler-generated methods; they don't
    2464                 :             :          provide any way to call private members.  */;
    2465                 :          96 :     else if (!TREE_PRIVATE (fn))
    2466                 :             :       {
    2467                 :          48 :         if (DECL_STATIC_FUNCTION_P (fn))
    2468                 :             :           /* A non-private static member function is just like a
    2469                 :             :              friend; it can create and invoke private member
    2470                 :             :              functions, and be accessed without a class
    2471                 :             :              instance.  */
    2472                 :             :           return;
    2473                 :             : 
    2474                 :             :         has_nonprivate_method = 1;
    2475                 :             :         /* Keep searching for a static member function.  */
    2476                 :             :       }
    2477                 :          96 :     else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
    2478                 :             :       has_member_fn = 1;
    2479                 :             : 
    2480                 :          48 :   if (!has_nonprivate_method && has_member_fn)
    2481                 :             :     {
    2482                 :             :       /* There are no non-private methods, and there's at least one
    2483                 :             :          private member function that isn't a constructor or
    2484                 :             :          destructor.  (If all the private members are
    2485                 :             :          constructors/destructors we want to use the code below that
    2486                 :             :          issues error messages specifically referring to
    2487                 :             :          constructors/destructors.)  */
    2488                 :          12 :       unsigned i;
    2489                 :          12 :       tree binfo = TYPE_BINFO (t);
    2490                 :             : 
    2491                 :          12 :       for (i = 0; i != BINFO_N_BASE_BINFOS (binfo); i++)
    2492                 :           0 :         if (BINFO_BASE_ACCESS (binfo, i) != access_private_node)
    2493                 :             :           {
    2494                 :             :             has_nonprivate_method = 1;
    2495                 :             :             break;
    2496                 :             :           }
    2497                 :          12 :       if (!has_nonprivate_method)
    2498                 :             :         {
    2499                 :          12 :           warning (OPT_Wctor_dtor_privacy,
    2500                 :             :                    "all member functions in class %qT are private", t);
    2501                 :          12 :           return;
    2502                 :             :         }
    2503                 :             :     }
    2504                 :             : 
    2505                 :             :   /* Even if some of the member functions are non-private, the class
    2506                 :             :      won't be useful for much if all the constructors or destructors
    2507                 :             :      are private: such an object can never be created or destroyed.  */
    2508                 :          36 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    2509                 :           6 :     if (TREE_PRIVATE (dtor))
    2510                 :             :       {
    2511                 :           6 :         warning (OPT_Wctor_dtor_privacy,
    2512                 :             :                  "%q#T only defines a private destructor and has no friends",
    2513                 :             :                  t);
    2514                 :           6 :         return;
    2515                 :             :       }
    2516                 :             : 
    2517                 :             :   /* Warn about classes that have private constructors and no friends.  */
    2518                 :          30 :   if (TYPE_HAS_USER_CONSTRUCTOR (t)
    2519                 :             :       /* Implicitly generated constructors are always public.  */
    2520                 :          30 :       && !CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    2521                 :             :     {
    2522                 :          21 :       tree copy_or_move = NULL_TREE;
    2523                 :             : 
    2524                 :             :       /* If a non-template class does not define a copy
    2525                 :             :          constructor, one is defined for it, enabling it to avoid
    2526                 :             :          this warning.  For a template class, this does not
    2527                 :             :          happen, and so we would normally get a warning on:
    2528                 :             : 
    2529                 :             :            template <class T> class C { private: C(); };
    2530                 :             : 
    2531                 :             :          To avoid this asymmetry, we check TYPE_HAS_COPY_CTOR.  All
    2532                 :             :          complete non-template or fully instantiated classes have this
    2533                 :             :          flag set.  */
    2534                 :          21 :       if (!TYPE_HAS_COPY_CTOR (t))
    2535                 :             :         nonprivate_ctor = true;
    2536                 :             :       else
    2537                 :          51 :         for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    2538                 :          27 :           if (TREE_PRIVATE (fn))
    2539                 :          12 :             continue;
    2540                 :          15 :           else if (copy_fn_p (fn) || move_fn_p (fn))
    2541                 :             :             /* Ideally, we wouldn't count any constructor that takes
    2542                 :             :                an argument of the class type as a parameter, because
    2543                 :             :                such things cannot be used to construct an instance of
    2544                 :             :                the class unless you already have one.  */
    2545                 :             :             copy_or_move = fn;
    2546                 :             :           else
    2547                 :             :             {
    2548                 :             :               nonprivate_ctor = true;
    2549                 :             :               break;
    2550                 :             :             }
    2551                 :             : 
    2552                 :          21 :       if (!nonprivate_ctor)
    2553                 :             :         {
    2554                 :          15 :           auto_diagnostic_group d;
    2555                 :          15 :           bool w = warning (OPT_Wctor_dtor_privacy,
    2556                 :             :                             "%q#T only defines private constructors and has "
    2557                 :             :                             "no friends", t);
    2558                 :          15 :           if (w && copy_or_move)
    2559                 :           6 :             inform (DECL_SOURCE_LOCATION (copy_or_move),
    2560                 :             :                     "%q#D is public, but requires an existing %q#T object",
    2561                 :             :                     copy_or_move, t);
    2562                 :          15 :           return;
    2563                 :          15 :         }
    2564                 :             :     }
    2565                 :             : }
    2566                 :             : 
    2567                 :             : /* Make BINFO's vtable have N entries, including RTTI entries,
    2568                 :             :    vbase and vcall offsets, etc.  Set its type and call the back end
    2569                 :             :    to lay it out.  */
    2570                 :             : 
    2571                 :             : static void
    2572                 :     1657715 : layout_vtable_decl (tree binfo, int n)
    2573                 :             : {
    2574                 :     1657715 :   tree atype;
    2575                 :     1657715 :   tree vtable;
    2576                 :             : 
    2577                 :     1657715 :   atype = build_array_of_n_type (vtable_entry_type, n);
    2578                 :     1657715 :   layout_type (atype);
    2579                 :             : 
    2580                 :             :   /* We may have to grow the vtable.  */
    2581                 :     1657715 :   vtable = get_vtbl_decl_for_binfo (binfo);
    2582                 :     1657715 :   if (!same_type_p (TREE_TYPE (vtable), atype))
    2583                 :             :     {
    2584                 :      569233 :       TREE_TYPE (vtable) = atype;
    2585                 :      569233 :       DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE;
    2586                 :      569233 :       layout_decl (vtable, 0);
    2587                 :             :     }
    2588                 :     1657715 : }
    2589                 :             : 
    2590                 :             : /* True iff FNDECL and BASE_FNDECL (both non-static member functions)
    2591                 :             :    have the same signature.  */
    2592                 :             : 
    2593                 :             : int
    2594                 :    76500375 : same_signature_p (const_tree fndecl, const_tree base_fndecl)
    2595                 :             : {
    2596                 :             :   /* One destructor overrides another if they are the same kind of
    2597                 :             :      destructor.  */
    2598                 :   118039043 :   if (DECL_DESTRUCTOR_P (base_fndecl) && DECL_DESTRUCTOR_P (fndecl)
    2599                 :    97162066 :       && special_function_p (base_fndecl) == special_function_p (fndecl))
    2600                 :             :     return 1;
    2601                 :             :   /* But a non-destructor never overrides a destructor, nor vice
    2602                 :             :      versa, nor do different kinds of destructors override
    2603                 :             :      one-another.  For example, a complete object destructor does not
    2604                 :             :      override a deleting destructor.  */
    2605                 :   186248513 :   if (DECL_DESTRUCTOR_P (base_fndecl) || DECL_DESTRUCTOR_P (fndecl))
    2606                 :             :     return 0;
    2607                 :             : 
    2608                 :    46069438 :   if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl)
    2609                 :    46069438 :       || (DECL_CONV_FN_P (fndecl)
    2610                 :         111 :           && DECL_CONV_FN_P (base_fndecl)
    2611                 :          90 :           && same_type_p (DECL_CONV_FN_TYPE (fndecl),
    2612                 :             :                           DECL_CONV_FN_TYPE (base_fndecl))))
    2613                 :             :     {
    2614                 :    16136614 :       tree fntype = TREE_TYPE (fndecl);
    2615                 :    16136614 :       tree base_fntype = TREE_TYPE (base_fndecl);
    2616                 :    16136614 :       if (type_memfn_quals (fntype) == type_memfn_quals (base_fntype)
    2617                 :    16136234 :           && type_memfn_rqual (fntype) == type_memfn_rqual (base_fntype)
    2618                 :    32272845 :           && compparms (FUNCTION_FIRST_USER_PARMTYPE (fndecl),
    2619                 :    16136231 :                         FUNCTION_FIRST_USER_PARMTYPE (base_fndecl)))
    2620                 :             :         return 1;
    2621                 :             :     }
    2622                 :             :   return 0;
    2623                 :             : }
    2624                 :             : 
    2625                 :             : /* Returns TRUE if DERIVED is a binfo containing the binfo BASE as a
    2626                 :             :    subobject.  */
    2627                 :             : 
    2628                 :             : static bool
    2629                 :      238455 : base_derived_from (tree derived, tree base)
    2630                 :             : {
    2631                 :      238455 :   tree probe;
    2632                 :             : 
    2633                 :      238731 :   for (probe = base; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
    2634                 :             :     {
    2635                 :      238626 :       if (probe == derived)
    2636                 :             :         return true;
    2637                 :        1551 :       else if (BINFO_VIRTUAL_P (probe))
    2638                 :             :         /* If we meet a virtual base, we can't follow the inheritance
    2639                 :             :            any more.  See if the complete type of DERIVED contains
    2640                 :             :            such a virtual base.  */
    2641                 :        1275 :         return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (derived))
    2642                 :        1275 :                 != NULL_TREE);
    2643                 :             :     }
    2644                 :             :   return false;
    2645                 :             : }
    2646                 :             : 
    2647                 :     7580162 : struct find_final_overrider_data {
    2648                 :             :   /* The function for which we are trying to find a final overrider.  */
    2649                 :             :   tree fn;
    2650                 :             :   /* The base class in which the function was declared.  */
    2651                 :             :   tree declaring_base;
    2652                 :             :   /* The candidate overriders.  */
    2653                 :             :   tree candidates;
    2654                 :             :   /* Path to most derived.  */
    2655                 :             :   auto_vec<tree> path;
    2656                 :             : };
    2657                 :             : 
    2658                 :             : /* Add the overrider along the current path to FFOD->CANDIDATES.
    2659                 :             :    Returns true if an overrider was found; false otherwise.  */
    2660                 :             : 
    2661                 :             : static bool
    2662                 :    12594395 : dfs_find_final_overrider_1 (tree binfo,
    2663                 :             :                             find_final_overrider_data *ffod,
    2664                 :             :                             unsigned depth)
    2665                 :             : {
    2666                 :    12594395 :   tree method;
    2667                 :             : 
    2668                 :             :   /* If BINFO is not the most derived type, try a more derived class.
    2669                 :             :      A definition there will overrider a definition here.  */
    2670                 :    12594395 :   if (depth)
    2671                 :             :     {
    2672                 :     4776318 :       depth--;
    2673                 :     4776318 :       if (dfs_find_final_overrider_1
    2674                 :     4776318 :           (ffod->path[depth], ffod, depth))
    2675                 :             :         return true;
    2676                 :             :     }
    2677                 :             : 
    2678                 :     9897005 :   method = look_for_overrides_here (BINFO_TYPE (binfo), ffod->fn);
    2679                 :     9897005 :   if (method)
    2680                 :             :     {
    2681                 :     7818077 :       tree *candidate = &ffod->candidates;
    2682                 :             : 
    2683                 :             :       /* Remove any candidates overridden by this new function.  */
    2684                 :     7818599 :       while (*candidate)
    2685                 :             :         {
    2686                 :             :           /* If *CANDIDATE overrides METHOD, then METHOD
    2687                 :             :              cannot override anything else on the list.  */
    2688                 :      237933 :           if (base_derived_from (TREE_VALUE (*candidate), binfo))
    2689                 :             :             return true;
    2690                 :             :           /* If METHOD overrides *CANDIDATE, remove *CANDIDATE.  */
    2691                 :         522 :           if (base_derived_from (binfo, TREE_VALUE (*candidate)))
    2692                 :         468 :             *candidate = TREE_CHAIN (*candidate);
    2693                 :             :           else
    2694                 :          54 :             candidate = &TREE_CHAIN (*candidate);
    2695                 :             :         }
    2696                 :             : 
    2697                 :             :       /* Add the new function.  */
    2698                 :     7580666 :       ffod->candidates = tree_cons (method, binfo, ffod->candidates);
    2699                 :     7580666 :       return true;
    2700                 :             :     }
    2701                 :             : 
    2702                 :             :   return false;
    2703                 :             : }
    2704                 :             : 
    2705                 :             : /* Called from find_final_overrider via dfs_walk.  */
    2706                 :             : 
    2707                 :             : static tree
    2708                 :    28843213 : dfs_find_final_overrider_pre (tree binfo, void *data)
    2709                 :             : {
    2710                 :    28843213 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2711                 :             : 
    2712                 :    28843213 :   if (binfo == ffod->declaring_base)
    2713                 :    15636154 :     dfs_find_final_overrider_1 (binfo, ffod, ffod->path.length ());
    2714                 :    28843213 :   ffod->path.safe_push (binfo);
    2715                 :             : 
    2716                 :    28843213 :   return NULL_TREE;
    2717                 :             : }
    2718                 :             : 
    2719                 :             : static tree
    2720                 :    28843213 : dfs_find_final_overrider_post (tree /*binfo*/, void *data)
    2721                 :             : {
    2722                 :    28843213 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2723                 :    28843213 :   ffod->path.pop ();
    2724                 :             : 
    2725                 :    28843213 :   return NULL_TREE;
    2726                 :             : }
    2727                 :             : 
    2728                 :             : /* Returns a TREE_LIST whose TREE_PURPOSE is the final overrider for
    2729                 :             :    FN and whose TREE_VALUE is the binfo for the base where the
    2730                 :             :    overriding occurs.  BINFO (in the hierarchy dominated by the binfo
    2731                 :             :    DERIVED) is the base object in which FN is declared.  */
    2732                 :             : 
    2733                 :             : static tree
    2734                 :     7580162 : find_final_overrider (tree derived, tree binfo, tree fn)
    2735                 :             : {
    2736                 :     7580162 :   find_final_overrider_data ffod;
    2737                 :             : 
    2738                 :             :   /* Getting this right is a little tricky.  This is valid:
    2739                 :             : 
    2740                 :             :        struct S { virtual void f (); };
    2741                 :             :        struct T { virtual void f (); };
    2742                 :             :        struct U : public S, public T { };
    2743                 :             : 
    2744                 :             :      even though calling `f' in `U' is ambiguous.  But,
    2745                 :             : 
    2746                 :             :        struct R { virtual void f(); };
    2747                 :             :        struct S : virtual public R { virtual void f (); };
    2748                 :             :        struct T : virtual public R { virtual void f (); };
    2749                 :             :        struct U : public S, public T { };
    2750                 :             : 
    2751                 :             :      is not -- there's no way to decide whether to put `S::f' or
    2752                 :             :      `T::f' in the vtable for `R'.
    2753                 :             : 
    2754                 :             :      The solution is to look at all paths to BINFO.  If we find
    2755                 :             :      different overriders along any two, then there is a problem.  */
    2756                 :     7580162 :   if (DECL_THUNK_P (fn))
    2757                 :           0 :     fn = THUNK_TARGET (fn);
    2758                 :             : 
    2759                 :             :   /* Determine the depth of the hierarchy.  */
    2760                 :     7580162 :   ffod.fn = fn;
    2761                 :     7580162 :   ffod.declaring_base = binfo;
    2762                 :     7580162 :   ffod.candidates = NULL_TREE;
    2763                 :     7580162 :   ffod.path.create (30);
    2764                 :             : 
    2765                 :     7580162 :   dfs_walk_all (derived, dfs_find_final_overrider_pre,
    2766                 :             :                 dfs_find_final_overrider_post, &ffod);
    2767                 :             : 
    2768                 :             :   /* If there was no winner, issue an error message.  */
    2769                 :     7580162 :   if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
    2770                 :          36 :     return error_mark_node;
    2771                 :             : 
    2772                 :             :   return ffod.candidates;
    2773                 :     7580162 : }
    2774                 :             : 
    2775                 :             : /* Return the index of the vcall offset for FN when TYPE is used as a
    2776                 :             :    virtual base.  */
    2777                 :             : 
    2778                 :             : static tree
    2779                 :      369355 : get_vcall_index (tree fn, tree type)
    2780                 :             : {
    2781                 :      369355 :   vec<tree_pair_s, va_gc> *indices = CLASSTYPE_VCALL_INDICES (type);
    2782                 :      369355 :   tree_pair_p p;
    2783                 :      369355 :   unsigned ix;
    2784                 :             : 
    2785                 :      375302 :   FOR_EACH_VEC_SAFE_ELT (indices, ix, p)
    2786                 :     1122510 :     if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (p->purpose))
    2787                 :      380944 :         || same_signature_p (fn, p->purpose))
    2788                 :      369355 :       return p->value;
    2789                 :             : 
    2790                 :             :   /* There should always be an appropriate index.  */
    2791                 :           0 :   gcc_unreachable ();
    2792                 :             : }
    2793                 :             : 
    2794                 :             : /* Given a DECL_VINDEX of a virtual function found in BINFO, return the final
    2795                 :             :    overrider at that index in the vtable.  This should only be used when we
    2796                 :             :    know that BINFO is correct for the dynamic type of the object.  */
    2797                 :             : 
    2798                 :             : tree
    2799                 :         816 : lookup_vfn_in_binfo (tree idx, tree binfo)
    2800                 :             : {
    2801                 :         816 :   int ix = tree_to_shwi (idx);
    2802                 :         816 :   if (TARGET_VTABLE_USES_DESCRIPTORS)
    2803                 :             :     ix /= MAX (TARGET_VTABLE_USES_DESCRIPTORS, 1);
    2804                 :         996 :   while (BINFO_PRIMARY_P (binfo))
    2805                 :             :     /* BINFO_VIRTUALS in a primary base isn't accurate, find the derived
    2806                 :             :        class that actually owns the vtable.  */
    2807                 :         180 :     binfo = BINFO_INHERITANCE_CHAIN (binfo);
    2808                 :         816 :   tree virtuals = BINFO_VIRTUALS (binfo);
    2809                 :         816 :   return TREE_VALUE (chain_index (ix, virtuals));
    2810                 :             : }
    2811                 :             : 
    2812                 :             : /* Update an entry in the vtable for BINFO, which is in the hierarchy
    2813                 :             :    dominated by T.  FN is the old function; VIRTUALS points to the
    2814                 :             :    corresponding position in the new BINFO_VIRTUALS list.  IX is the index
    2815                 :             :    of that entry in the list.  */
    2816                 :             : 
    2817                 :             : static void
    2818                 :     7141646 : update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
    2819                 :             :                             unsigned ix)
    2820                 :             : {
    2821                 :     7141646 :   tree b;
    2822                 :     7141646 :   tree overrider;
    2823                 :     7141646 :   tree delta;
    2824                 :     7141646 :   tree virtual_base;
    2825                 :     7141646 :   tree first_defn;
    2826                 :     7141646 :   tree overrider_fn, overrider_target;
    2827                 :     7141646 :   tree target_fn = DECL_THUNK_P (fn) ? THUNK_TARGET (fn) : fn;
    2828                 :     7141646 :   tree over_return, base_return;
    2829                 :     7141646 :   bool lost = false;
    2830                 :             : 
    2831                 :             :   /* Find the nearest primary base (possibly binfo itself) which defines
    2832                 :             :      this function; this is the class the caller will convert to when
    2833                 :             :      calling FN through BINFO.  */
    2834                 :     9163157 :   for (b = binfo; ; b = get_primary_binfo (b))
    2835                 :             :     {
    2836                 :     9163157 :       gcc_assert (b);
    2837                 :     9163157 :       if (look_for_overrides_here (BINFO_TYPE (b), target_fn))
    2838                 :             :         break;
    2839                 :             : 
    2840                 :             :       /* The nearest definition is from a lost primary.  */
    2841                 :     2021511 :       if (BINFO_LOST_PRIMARY_P (b))
    2842                 :         412 :         lost = true;
    2843                 :             :     }
    2844                 :     7141646 :   first_defn = b;
    2845                 :             : 
    2846                 :             :   /* Find the final overrider.  */
    2847                 :     7141646 :   overrider = find_final_overrider (TYPE_BINFO (t), b, target_fn);
    2848                 :     7141646 :   if (overrider == error_mark_node)
    2849                 :             :     {
    2850                 :           9 :       error ("no unique final overrider for %qD in %qT", target_fn, t);
    2851                 :           9 :       return;
    2852                 :             :     }
    2853                 :     7141637 :   overrider_target = overrider_fn = TREE_PURPOSE (overrider);
    2854                 :             : 
    2855                 :             :   /* Check for adjusting covariant return types.  */
    2856                 :     7141637 :   over_return = TREE_TYPE (TREE_TYPE (overrider_target));
    2857                 :     7141637 :   base_return = TREE_TYPE (TREE_TYPE (target_fn));
    2858                 :             : 
    2859                 :     7141637 :   if (INDIRECT_TYPE_P (over_return)
    2860                 :      635455 :       && TREE_CODE (over_return) == TREE_CODE (base_return)
    2861                 :      635446 :       && CLASS_TYPE_P (TREE_TYPE (over_return))
    2862                 :       42865 :       && CLASS_TYPE_P (TREE_TYPE (base_return))
    2863                 :             :       /* If the overrider is invalid, don't even try.  */
    2864                 :     7184496 :       && !DECL_INVALID_OVERRIDER_P (overrider_target))
    2865                 :             :     {
    2866                 :             :       /* If FN is a covariant thunk, we must figure out the adjustment
    2867                 :             :          to the final base FN was converting to. As OVERRIDER_TARGET might
    2868                 :             :          also be converting to the return type of FN, we have to
    2869                 :             :          combine the two conversions here.  */
    2870                 :       42826 :       tree fixed_offset, virtual_offset;
    2871                 :             : 
    2872                 :       42826 :       over_return = TREE_TYPE (over_return);
    2873                 :       42826 :       base_return = TREE_TYPE (base_return);
    2874                 :             : 
    2875                 :       42826 :       if (DECL_THUNK_P (fn))
    2876                 :             :         {
    2877                 :          60 :           gcc_assert (DECL_RESULT_THUNK_P (fn));
    2878                 :          60 :           fixed_offset = ssize_int (THUNK_FIXED_OFFSET (fn));
    2879                 :          60 :           virtual_offset = THUNK_VIRTUAL_OFFSET (fn);
    2880                 :             :         }
    2881                 :             :       else
    2882                 :             :         fixed_offset = virtual_offset = NULL_TREE;
    2883                 :             : 
    2884                 :          60 :       if (virtual_offset)
    2885                 :             :         /* Find the equivalent binfo within the return type of the
    2886                 :             :            overriding function. We will want the vbase offset from
    2887                 :             :            there.  */
    2888                 :          54 :         virtual_offset = binfo_for_vbase (BINFO_TYPE (virtual_offset),
    2889                 :             :                                           over_return);
    2890                 :       42772 :       else if (!same_type_ignoring_top_level_qualifiers_p
    2891                 :       42772 :                (over_return, base_return))
    2892                 :             :         {
    2893                 :             :           /* There was no existing virtual thunk (which takes
    2894                 :             :              precedence).  So find the binfo of the base function's
    2895                 :             :              return type within the overriding function's return type.
    2896                 :             :              Fortunately we know the covariancy is valid (it
    2897                 :             :              has already been checked), so we can just iterate along
    2898                 :             :              the binfos, which have been chained in inheritance graph
    2899                 :             :              order.  Of course it is lame that we have to repeat the
    2900                 :             :              search here anyway -- we should really be caching pieces
    2901                 :             :              of the vtable and avoiding this repeated work.  */
    2902                 :         379 :           tree thunk_binfo = NULL_TREE;
    2903                 :         379 :           tree base_binfo = TYPE_BINFO (base_return);
    2904                 :             : 
    2905                 :             :           /* Find the base binfo within the overriding function's
    2906                 :             :              return type.  We will always find a thunk_binfo, except
    2907                 :             :              when the covariancy is invalid (which we will have
    2908                 :             :              already diagnosed).  */
    2909                 :         379 :           if (base_binfo)
    2910                 :         984 :             for (thunk_binfo = TYPE_BINFO (over_return); thunk_binfo;
    2911                 :         608 :                  thunk_binfo = TREE_CHAIN (thunk_binfo))
    2912                 :         984 :               if (SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo),
    2913                 :             :                                      BINFO_TYPE (base_binfo)))
    2914                 :             :                 break;
    2915                 :         379 :           gcc_assert (thunk_binfo || errorcount);
    2916                 :             : 
    2917                 :             :           /* See if virtual inheritance is involved.  */
    2918                 :         379 :           for (virtual_offset = thunk_binfo;
    2919                 :         671 :                virtual_offset;
    2920                 :         292 :                virtual_offset = BINFO_INHERITANCE_CHAIN (virtual_offset))
    2921                 :         537 :             if (BINFO_VIRTUAL_P (virtual_offset))
    2922                 :             :               break;
    2923                 :             : 
    2924                 :         379 :           if (virtual_offset
    2925                 :         510 :               || (thunk_binfo && !BINFO_OFFSET_ZEROP (thunk_binfo)))
    2926                 :             :             {
    2927                 :         320 :               tree offset = fold_convert (ssizetype, BINFO_OFFSET (thunk_binfo));
    2928                 :             : 
    2929                 :         320 :               if (virtual_offset)
    2930                 :             :                 {
    2931                 :             :                   /* We convert via virtual base.  Adjust the fixed
    2932                 :             :                      offset to be from there.  */
    2933                 :         245 :                   offset =
    2934                 :         245 :                     size_diffop (offset,
    2935                 :             :                                  fold_convert (ssizetype,
    2936                 :             :                                           BINFO_OFFSET (virtual_offset)));
    2937                 :             :                 }
    2938                 :         320 :               if (fixed_offset)
    2939                 :             :                 /* There was an existing fixed offset, this must be
    2940                 :             :                    from the base just converted to, and the base the
    2941                 :             :                    FN was thunking to.  */
    2942                 :           6 :                 fixed_offset = size_binop (PLUS_EXPR, fixed_offset, offset);
    2943                 :             :               else
    2944                 :             :                 fixed_offset = offset;
    2945                 :             :             }
    2946                 :             :         }
    2947                 :             : 
    2948                 :       42826 :       if (fixed_offset || virtual_offset)
    2949                 :             :         /* Replace the overriding function with a covariant thunk.  We
    2950                 :             :            will emit the overriding function in its own slot as
    2951                 :             :            well.  */
    2952                 :         374 :         overrider_fn = make_thunk (overrider_target, /*this_adjusting=*/0,
    2953                 :             :                                    fixed_offset, virtual_offset);
    2954                 :             :     }
    2955                 :             :   else
    2956                 :     7098811 :     gcc_assert (DECL_INVALID_OVERRIDER_P (overrider_target) ||
    2957                 :             :                 !DECL_THUNK_P (fn));
    2958                 :             : 
    2959                 :             :   /* If we need a covariant thunk, then we may need to adjust first_defn.
    2960                 :             :      The ABI specifies that the thunks emitted with a function are
    2961                 :             :      determined by which bases the function overrides, so we need to be
    2962                 :             :      sure that we're using a thunk for some overridden base; even if we
    2963                 :             :      know that the necessary this adjustment is zero, there may not be an
    2964                 :             :      appropriate zero-this-adjustment thunk for us to use since thunks for
    2965                 :             :      overriding virtual bases always use the vcall offset.
    2966                 :             : 
    2967                 :             :      Furthermore, just choosing any base that overrides this function isn't
    2968                 :             :      quite right, as this slot won't be used for calls through a type that
    2969                 :             :      puts a covariant thunk here.  Calling the function through such a type
    2970                 :             :      will use a different slot, and that slot is the one that determines
    2971                 :             :      the thunk emitted for that base.
    2972                 :             : 
    2973                 :             :      So, keep looking until we find the base that we're really overriding
    2974                 :             :      in this slot: the nearest primary base that doesn't use a covariant
    2975                 :             :      thunk in this slot.  */
    2976                 :     7141637 :   if (overrider_target != overrider_fn)
    2977                 :             :     {
    2978                 :         374 :       if (BINFO_TYPE (b) == DECL_CONTEXT (overrider_target))
    2979                 :             :         /* We already know that the overrider needs a covariant thunk.  */
    2980                 :         132 :         b = get_primary_binfo (b);
    2981                 :          30 :       for (; ; b = get_primary_binfo (b))
    2982                 :             :         {
    2983                 :         404 :           tree main_binfo = TYPE_BINFO (BINFO_TYPE (b));
    2984                 :         404 :           tree bv = chain_index (ix, BINFO_VIRTUALS (main_binfo));
    2985                 :         404 :           if (!DECL_THUNK_P (TREE_VALUE (bv)))
    2986                 :             :             break;
    2987                 :          30 :           if (BINFO_LOST_PRIMARY_P (b))
    2988                 :           6 :             lost = true;
    2989                 :          30 :         }
    2990                 :             :       first_defn = b;
    2991                 :             :     }
    2992                 :             : 
    2993                 :             :   /* Assume that we will produce a thunk that convert all the way to
    2994                 :             :      the final overrider, and not to an intermediate virtual base.  */
    2995                 :     7141637 :   virtual_base = NULL_TREE;
    2996                 :             : 
    2997                 :             :   /* See if we can convert to an intermediate virtual base first, and then
    2998                 :             :      use the vcall offset located there to finish the conversion.  */
    2999                 :     7344548 :   for (; b; b = BINFO_INHERITANCE_CHAIN (b))
    3000                 :             :     {
    3001                 :             :       /* If we find the final overrider, then we can stop
    3002                 :             :          walking.  */
    3003                 :     7344548 :       if (SAME_BINFO_TYPE_P (BINFO_TYPE (b),
    3004                 :             :                              BINFO_TYPE (TREE_VALUE (overrider))))
    3005                 :             :         break;
    3006                 :             : 
    3007                 :             :       /* If we find a virtual base, and we haven't yet found the
    3008                 :             :          overrider, then there is a virtual base between the
    3009                 :             :          declaring base (first_defn) and the final overrider.  */
    3010                 :      572266 :       if (BINFO_VIRTUAL_P (b))
    3011                 :             :         {
    3012                 :             :           virtual_base = b;
    3013                 :             :           break;
    3014                 :             :         }
    3015                 :             :     }
    3016                 :             : 
    3017                 :             :   /* Compute the constant adjustment to the `this' pointer.  The
    3018                 :             :      `this' pointer, when this function is called, will point at BINFO
    3019                 :             :      (or one of its primary bases, which are at the same offset).  */
    3020                 :     7141637 :   if (virtual_base)
    3021                 :             :     /* The `this' pointer needs to be adjusted from the declaration to
    3022                 :             :        the nearest virtual base.  */
    3023                 :     1108065 :     delta = size_diffop_loc (input_location,
    3024                 :      369355 :                          fold_convert (ssizetype, BINFO_OFFSET (virtual_base)),
    3025                 :      369355 :                          fold_convert (ssizetype, BINFO_OFFSET (first_defn)));
    3026                 :     6772282 :   else if (lost)
    3027                 :             :     /* If the nearest definition is in a lost primary, we don't need an
    3028                 :             :        entry in our vtable.  Except possibly in a constructor vtable,
    3029                 :             :        if we happen to get our primary back.  In that case, the offset
    3030                 :             :        will be zero, as it will be a primary base.  */
    3031                 :         367 :     delta = size_zero_node;
    3032                 :             :   else
    3033                 :             :     /* The `this' pointer needs to be adjusted from pointing to
    3034                 :             :        BINFO to pointing at the base where the final overrider
    3035                 :             :        appears.  */
    3036                 :    20315745 :     delta = size_diffop_loc (input_location,
    3037                 :     6771915 :                          fold_convert (ssizetype,
    3038                 :             :                                   BINFO_OFFSET (TREE_VALUE (overrider))),
    3039                 :     6771915 :                          fold_convert (ssizetype, BINFO_OFFSET (binfo)));
    3040                 :             : 
    3041                 :     7141637 :   modify_vtable_entry (t, binfo, overrider_fn, delta, virtuals);
    3042                 :             : 
    3043                 :     7141637 :   if (virtual_base)
    3044                 :      738710 :     BV_VCALL_INDEX (*virtuals)
    3045                 :      738710 :       = get_vcall_index (overrider_target, BINFO_TYPE (virtual_base));
    3046                 :             :   else
    3047                 :     6772282 :     BV_VCALL_INDEX (*virtuals) = NULL_TREE;
    3048                 :             : 
    3049                 :     7141637 :   BV_LOST_PRIMARY (*virtuals) = lost;
    3050                 :             : }
    3051                 :             : 
    3052                 :             : /* Called from modify_all_vtables via dfs_walk.  */
    3053                 :             : 
    3054                 :             : static tree
    3055                 :    40358319 : dfs_modify_vtables (tree binfo, void* data)
    3056                 :             : {
    3057                 :    40358319 :   tree t = (tree) data;
    3058                 :    40358319 :   tree virtuals;
    3059                 :    40358319 :   tree old_virtuals;
    3060                 :    40358319 :   unsigned ix;
    3061                 :             : 
    3062                 :    40358319 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
    3063                 :             :     /* A base without a vtable needs no modification, and its bases
    3064                 :             :        are uninteresting.  */
    3065                 :             :     return dfs_skip_bases;
    3066                 :             : 
    3067                 :     4381299 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t)
    3068                 :     4381299 :       && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    3069                 :             :     /* Don't do the primary vtable, if it's new.  */
    3070                 :             :     return NULL_TREE;
    3071                 :             : 
    3072                 :     4141454 :   if (BINFO_PRIMARY_P (binfo) && !BINFO_VIRTUAL_P (binfo))
    3073                 :             :     /* There's no need to modify the vtable for a non-virtual primary
    3074                 :             :        base; we're not going to use that vtable anyhow.  We do still
    3075                 :             :        need to do this for virtual primary bases, as they could become
    3076                 :             :        non-primary in a construction vtable.  */
    3077                 :             :     return NULL_TREE;
    3078                 :             : 
    3079                 :     1678630 :   make_new_vtable (t, binfo);
    3080                 :             : 
    3081                 :             :   /* Now, go through each of the virtual functions in the virtual
    3082                 :             :      function table for BINFO.  Find the final overrider, and update
    3083                 :             :      the BINFO_VIRTUALS list appropriately.  */
    3084                 :     1678630 :   for (ix = 0, virtuals = BINFO_VIRTUALS (binfo),
    3085                 :     1678630 :          old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
    3086                 :     8820276 :        virtuals;
    3087                 :     7141646 :        ix++, virtuals = TREE_CHAIN (virtuals),
    3088                 :     7141646 :          old_virtuals = TREE_CHAIN (old_virtuals))
    3089                 :     7141646 :     update_vtable_entry_for_fn (t,
    3090                 :             :                                 binfo,
    3091                 :     7141646 :                                 BV_FN (old_virtuals),
    3092                 :             :                                 &virtuals, ix);
    3093                 :             : 
    3094                 :             :   return NULL_TREE;
    3095                 :             : }
    3096                 :             : 
    3097                 :             : /* Update all of the primary and secondary vtables for T.  Create new
    3098                 :             :    vtables as required, and initialize their RTTI information.  Each
    3099                 :             :    of the functions in VIRTUALS is declared in T and may override a
    3100                 :             :    virtual function from a base class; find and modify the appropriate
    3101                 :             :    entries to point to the overriding functions.  Returns a list, in
    3102                 :             :    declaration order, of the virtual functions that are declared in T,
    3103                 :             :    but do not appear in the primary base class vtable, and which
    3104                 :             :    should therefore be appended to the end of the vtable for T.  */
    3105                 :             : 
    3106                 :             : static tree
    3107                 :    37061824 : modify_all_vtables (tree t, tree virtuals)
    3108                 :             : {
    3109                 :    37061824 :   tree binfo = TYPE_BINFO (t);
    3110                 :    37061824 :   tree *fnsp;
    3111                 :             : 
    3112                 :             :   /* Mangle the vtable name before entering dfs_walk (c++/51884).  */
    3113                 :    37061824 :   if (TYPE_CONTAINS_VPTR_P (t))
    3114                 :     1657715 :     get_vtable_decl (t, false);
    3115                 :             : 
    3116                 :             :   /* Update all of the vtables.  */
    3117                 :    37061824 :   dfs_walk_once (binfo, dfs_modify_vtables, NULL, t);
    3118                 :             : 
    3119                 :             :   /* Add virtual functions not already in our primary vtable. These
    3120                 :             :      will be both those introduced by this class, and those overridden
    3121                 :             :      from secondary bases.  It does not include virtuals merely
    3122                 :             :      inherited from secondary bases.  */
    3123                 :    44684502 :   for (fnsp = &virtuals; *fnsp; )
    3124                 :             :     {
    3125                 :     7622678 :       tree fn = TREE_VALUE (*fnsp);
    3126                 :             : 
    3127                 :     7622678 :       if (!value_member (fn, BINFO_VIRTUALS (binfo))
    3128                 :    12338045 :           || DECL_VINDEX (fn) == error_mark_node)
    3129                 :             :         {
    3130                 :             :           /* We don't need to adjust the `this' pointer when
    3131                 :             :              calling this function.  */
    3132                 :     2907311 :           BV_DELTA (*fnsp) = integer_zero_node;
    3133                 :     2907311 :           BV_VCALL_INDEX (*fnsp) = NULL_TREE;
    3134                 :             : 
    3135                 :             :           /* This is a function not already in our vtable.  Keep it.  */
    3136                 :     2907311 :           fnsp = &TREE_CHAIN (*fnsp);
    3137                 :             :         }
    3138                 :             :       else
    3139                 :             :         /* We've already got an entry for this function.  Skip it.  */
    3140                 :     4715367 :         *fnsp = TREE_CHAIN (*fnsp);
    3141                 :             :     }
    3142                 :             : 
    3143                 :    37061824 :   return virtuals;
    3144                 :             : }
    3145                 :             : 
    3146                 :             : /* Get the base virtual function declarations in T that have the
    3147                 :             :    indicated NAME.  */
    3148                 :             : 
    3149                 :             : static void
    3150                 :      218403 : get_basefndecls (tree name, tree t, vec<tree> *base_fndecls)
    3151                 :             : {
    3152                 :      218403 :   bool found_decls = false;
    3153                 :             : 
    3154                 :             :   /* Find virtual functions in T with the indicated NAME.  */
    3155                 :      315137 :   for (tree method : ovl_range (get_class_binding (t, name)))
    3156                 :             :     {
    3157                 :       73870 :       if (TREE_CODE (method) == FUNCTION_DECL && DECL_VINDEX (method))
    3158                 :             :         {
    3159                 :       19677 :           base_fndecls->safe_push (method);
    3160                 :       19677 :           found_decls = true;
    3161                 :             :         }
    3162                 :             :     }
    3163                 :             : 
    3164                 :      218403 :   if (found_decls)
    3165                 :             :     return;
    3166                 :             : 
    3167                 :      199918 :   int n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t));
    3168                 :      227431 :   for (int i = 0; i < n_baseclasses; i++)
    3169                 :             :     {
    3170                 :       27513 :       tree basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t), i));
    3171                 :       27513 :       get_basefndecls (name, basetype, base_fndecls);
    3172                 :             :     }
    3173                 :             : }
    3174                 :             : 
    3175                 :             : /* If this method overrides a virtual method from a base, then mark
    3176                 :             :    this member function as being virtual as well.  Do 'final' and
    3177                 :             :    'override' checks too.  */
    3178                 :             : 
    3179                 :             : void
    3180                 :   121979855 : check_for_override (tree decl, tree ctype)
    3181                 :             : {
    3182                 :   121979855 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    3183                 :             :     /* In [temp.mem] we have:
    3184                 :             : 
    3185                 :             :          A specialization of a member function template does not
    3186                 :             :          override a virtual function from a base class.  */
    3187                 :             :     return;
    3188                 :             : 
    3189                 :             :   /* IDENTIFIER_VIRTUAL_P indicates whether the name has ever been
    3190                 :             :      used for a vfunc.  That avoids the expensive look_for_overrides
    3191                 :             :      call that when we know there's nothing to find.  As conversion
    3192                 :             :      operators for the same type can have distinct identifiers, we
    3193                 :             :      cannot optimize those in that way.  */
    3194                 :   100484180 :   if ((IDENTIFIER_VIRTUAL_P (DECL_NAME (decl))
    3195                 :    88317565 :        || DECL_CONV_FN_P (decl))
    3196                 :    13245915 :       && look_for_overrides (ctype, decl)
    3197                 :             :       /* Check staticness after we've checked if we 'override'.  */
    3198                 :   103872870 :       && !DECL_STATIC_FUNCTION_P (decl))
    3199                 :             :     {
    3200                 :             :       /* Set DECL_VINDEX to a value that is neither an INTEGER_CST nor
    3201                 :             :          the error_mark_node so that we know it is an overriding
    3202                 :             :          function.  */
    3203                 :     3388684 :       DECL_VINDEX (decl) = decl;
    3204                 :             : 
    3205                 :     3388684 :       if (warn_override
    3206                 :           6 :           && !DECL_OVERRIDE_P (decl)
    3207                 :           5 :           && !DECL_FINAL_P (decl)
    3208                 :     3388688 :           && !DECL_DESTRUCTOR_P (decl))
    3209                 :           3 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
    3210                 :             :                     "%qD can be marked override", decl);
    3211                 :             :     }
    3212                 :    97095496 :   else if (DECL_OVERRIDE_P (decl))
    3213                 :          20 :     error ("%q+#D marked %<override%>, but does not override", decl);
    3214                 :             : 
    3215                 :   100484180 :   if (DECL_VIRTUAL_P (decl))
    3216                 :             :     {
    3217                 :             :       /* Remember this identifier is virtual name.  */
    3218                 :     6030795 :       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = true;
    3219                 :             : 
    3220                 :     6030795 :       if (!DECL_VINDEX (decl))
    3221                 :             :         /* It's a new vfunc.  */
    3222                 :     2642127 :         DECL_VINDEX (decl) = error_mark_node;
    3223                 :             : 
    3224                 :     6030795 :       if (DECL_DESTRUCTOR_P (decl))
    3225                 :     1591855 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
    3226                 :             :     }
    3227                 :    94453385 :   else if (DECL_FINAL_P (decl))
    3228                 :          19 :     error ("%q+#D marked %<final%>, but is not virtual", decl);
    3229                 :             : }
    3230                 :             : 
    3231                 :             : /* Warn about hidden virtual functions that are not overridden in t.
    3232                 :             :    We know that constructors and destructors don't apply.  */
    3233                 :             : 
    3234                 :             : static void
    3235                 :      353333 : warn_hidden (tree t)
    3236                 :             : {
    3237                 :      353333 :   if (vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (t))
    3238                 :     1904473 :     for (unsigned ix = member_vec->length (); ix--;)
    3239                 :             :       {
    3240                 :     1774968 :         tree fns = (*member_vec)[ix];
    3241                 :             : 
    3242                 :     1774968 :         if (!OVL_P (fns))
    3243                 :     1774812 :           continue;
    3244                 :             : 
    3245                 :      988647 :         tree name = OVL_NAME (fns);
    3246                 :      988647 :         size_t num_fns = 0; /* The number of fndecls in fns.  */
    3247                 :      988647 :         auto_vec<tree, 20> base_fndecls;
    3248                 :      988647 :         tree base_binfo;
    3249                 :      988647 :         tree binfo;
    3250                 :      988647 :         unsigned j;
    3251                 :      988647 :         size_t num_overriders = 0;
    3252                 :      988647 :         hash_set<tree> overriden_base_fndecls;
    3253                 :             :         /* base_fndecls that are hidden but not overriden. The "value"
    3254                 :             :            contains the last fndecl we saw that hides the "key".  */
    3255                 :      988647 :         hash_map<tree, tree> hidden_base_fndecls;
    3256                 :             : 
    3257                 :      988647 :         if (IDENTIFIER_CDTOR_P (name))
    3258                 :      337623 :           continue;
    3259                 :             : 
    3260                 :             :         /* Iterate through all of the base classes looking for possibly
    3261                 :             :            hidden functions.  */
    3262                 :      841914 :         for (binfo = TYPE_BINFO (t), j = 0;
    3263                 :      841914 :              BINFO_BASE_ITERATE (binfo, j, base_binfo); j++)
    3264                 :             :           {
    3265                 :      190890 :             tree basetype = BINFO_TYPE (base_binfo);
    3266                 :      190890 :             get_basefndecls (name, basetype, &base_fndecls);
    3267                 :             :           }
    3268                 :             : 
    3269                 :             :         /* If there are no functions to hide, continue.  */
    3270                 :      651024 :         if (base_fndecls.is_empty ())
    3271                 :      632545 :           continue;
    3272                 :             : 
    3273                 :             :         /* Find all the base_fndecls that are overridden, as well as those
    3274                 :             :            that are hidden, in T.  */
    3275                 :       39194 :         for (tree fndecl : ovl_range (fns))
    3276                 :             :           {
    3277                 :       19590 :             bool template_p = TREE_CODE (fndecl) == TEMPLATE_DECL;
    3278                 :       19590 :             bool fndecl_overrides_p = false;
    3279                 :       19590 :             fndecl = STRIP_TEMPLATE (fndecl);
    3280                 :       19590 :             if (TREE_CODE (fndecl) != FUNCTION_DECL
    3281                 :       19590 :                 || fndecl == conv_op_marker)
    3282                 :          15 :               continue;
    3283                 :       19575 :             num_fns++;
    3284                 :       41369 :             for (size_t k = 0; k < base_fndecls.length (); k++)
    3285                 :             :               {
    3286                 :       21794 :                 if (!base_fndecls[k] || !DECL_VINDEX (base_fndecls[k]))
    3287                 :           0 :                   continue;
    3288                 :       21794 :                 if (IDENTIFIER_CONV_OP_P (name)
    3289                 :       21794 :                     && !same_type_p (DECL_CONV_FN_TYPE (fndecl),
    3290                 :             :                                      DECL_CONV_FN_TYPE (base_fndecls[k])))
    3291                 :             :                   /* If base_fndecl[k] and fndecl are conversion operators
    3292                 :             :                      to different types, they're unrelated.  */
    3293                 :             :                   ;
    3294                 :       21761 :                 else if (!template_p /* Template methods don't override.  */
    3295                 :       21761 :                          && same_signature_p (fndecl, base_fndecls[k]))
    3296                 :             :                   {
    3297                 :       19464 :                     overriden_base_fndecls.add (base_fndecls[k]);
    3298                 :       19464 :                     fndecl_overrides_p = true;
    3299                 :             :                   }
    3300                 :             :                 else
    3301                 :             :                   {
    3302                 :             :                     /* fndecl hides base_fndecls[k].  */
    3303                 :        2297 :                     hidden_base_fndecls.put (base_fndecls[k], fndecl);
    3304                 :             :                   }
    3305                 :             :               }
    3306                 :       19575 :             if (fndecl_overrides_p)
    3307                 :       19458 :               ++num_overriders;
    3308                 :             :           }
    3309                 :             : 
    3310                 :       18479 :         if (warn_overloaded_virtual == 1 && num_overriders == num_fns)
    3311                 :             :           /* All the fns override a base virtual.  */
    3312                 :       18323 :           continue;
    3313                 :             : 
    3314                 :             :         /* Now give a warning for all hidden methods. Note that a method that
    3315                 :             :            is both in hidden_base_fndecls and overriden_base_fndecls is not
    3316                 :             :            hidden.  */
    3317                 :         612 :         for (auto hidden_base_fndecl : hidden_base_fndecls)
    3318                 :             :           {
    3319                 :         150 :             tree hidden_fndecl = hidden_base_fndecl.first;
    3320                 :         261 :             if (!hidden_fndecl
    3321                 :         150 :                 || overriden_base_fndecls.contains (hidden_fndecl))
    3322                 :         111 :               continue;
    3323                 :          39 :             auto_diagnostic_group d;
    3324                 :          39 :             if (warning_at (location_of (hidden_fndecl),
    3325                 :          39 :                             OPT_Woverloaded_virtual_,
    3326                 :             :                             "%qD was hidden", hidden_fndecl))
    3327                 :             :               {
    3328                 :          36 :                 tree hider = hidden_base_fndecl.second;
    3329                 :          36 :                 inform (location_of (hider), "  by %qD", hider);
    3330                 :             :               }
    3331                 :          39 :           }
    3332                 :      988647 :       }
    3333                 :      353333 : }
    3334                 :             : 
    3335                 :             : /* Recursive helper for finish_struct_anon.  */
    3336                 :             : 
    3337                 :             : static void
    3338                 :      149770 : finish_struct_anon_r (tree field)
    3339                 :             : {
    3340                 :      751935 :   for (tree elt = TYPE_FIELDS (TREE_TYPE (field)); elt; elt = DECL_CHAIN (elt))
    3341                 :             :     {
    3342                 :             :       /* We're generally only interested in entities the user
    3343                 :             :          declared, but we also find nested classes by noticing
    3344                 :             :          the TYPE_DECL that we create implicitly.  You're
    3345                 :             :          allowed to put one anonymous union inside another,
    3346                 :             :          though, so we explicitly tolerate that.  We use
    3347                 :             :          TYPE_UNNAMED_P rather than ANON_AGGR_TYPE_P so that
    3348                 :             :          we also allow unnamed types used for defining fields.  */
    3349                 :      602165 :       if (DECL_ARTIFICIAL (elt)
    3350                 :      602165 :           && (!DECL_IMPLICIT_TYPEDEF_P (elt)
    3351                 :       60162 :               || TYPE_UNNAMED_P (TREE_TYPE (elt))))
    3352                 :      169823 :         continue;
    3353                 :             : 
    3354                 :      432342 :       TREE_PRIVATE (elt) = TREE_PRIVATE (field);
    3355                 :      432342 :       TREE_PROTECTED (elt) = TREE_PROTECTED (field);
    3356                 :             : 
    3357                 :             :       /* Recurse into the anonymous aggregates to correctly handle
    3358                 :             :          access control (c++/24926):
    3359                 :             : 
    3360                 :             :          class A {
    3361                 :             :            union {
    3362                 :             :              union {
    3363                 :             :                int i;
    3364                 :             :              };
    3365                 :             :            };
    3366                 :             :          };
    3367                 :             : 
    3368                 :             :          int j=A().i;  */
    3369                 :      432342 :       if (DECL_NAME (elt) == NULL_TREE
    3370                 :      432342 :           && ANON_AGGR_TYPE_P (TREE_TYPE (elt)))
    3371                 :       19333 :         finish_struct_anon_r (elt);
    3372                 :             :     }
    3373                 :      149770 : }
    3374                 :             : 
    3375                 :             : /* Fix up any anonymous union/struct members of T.  */
    3376                 :             : 
    3377                 :             : static void
    3378                 :    37061824 : finish_struct_anon (tree t)
    3379                 :             : {
    3380                 :   260575625 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3381                 :             :     {
    3382                 :   223513801 :       if (TREE_STATIC (field))
    3383                 :    10217299 :         continue;
    3384                 :   213296502 :       if (TREE_CODE (field) != FIELD_DECL)
    3385                 :   197819588 :         continue;
    3386                 :             : 
    3387                 :    15476914 :       if (DECL_NAME (field) == NULL_TREE
    3388                 :    15476914 :           && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    3389                 :      130437 :         finish_struct_anon_r (field);
    3390                 :             :     }
    3391                 :    37061824 : }
    3392                 :             : 
    3393                 :             : /* Add T to CLASSTYPE_DECL_LIST of current_class_type which
    3394                 :             :    will be used later during class template instantiation.
    3395                 :             :    When FRIEND_P is zero, T can be a static member data (VAR_DECL),
    3396                 :             :    a non-static member data (FIELD_DECL), a member function
    3397                 :             :    (FUNCTION_DECL), a nested type (RECORD_TYPE, ENUM_TYPE),
    3398                 :             :    a typedef (TYPE_DECL) or a member class template (TEMPLATE_DECL)
    3399                 :             :    When FRIEND_P is nonzero, T is either a friend class
    3400                 :             :    (RECORD_TYPE, TEMPLATE_DECL) or a friend function
    3401                 :             :    (FUNCTION_DECL, TEMPLATE_DECL).  */
    3402                 :             : 
    3403                 :             : void
    3404                 :   369609420 : maybe_add_class_template_decl_list (tree type, tree t, int friend_p)
    3405                 :             : {
    3406                 :   369609420 :   if (CLASSTYPE_TEMPLATE_INFO (type)
    3407                 :   369609420 :       && TREE_CODE (t) != CONST_DECL)
    3408                 :             :     {
    3409                 :   325893398 :       tree purpose = friend_p ? NULL_TREE : type;
    3410                 :             : 
    3411                 :   325893398 :       CLASSTYPE_DECL_LIST (type)
    3412                 :   651786796 :         = tree_cons (purpose, t, CLASSTYPE_DECL_LIST (type));
    3413                 :             :     }
    3414                 :   369609420 : }
    3415                 :             : 
    3416                 :             : /* This function is called from declare_virt_assop_and_dtor via
    3417                 :             :    dfs_walk_all.
    3418                 :             : 
    3419                 :             :    DATA is a type that direcly or indirectly inherits the base
    3420                 :             :    represented by BINFO.  If BINFO contains a virtual assignment [copy
    3421                 :             :    assignment or move assigment] operator or a virtual constructor,
    3422                 :             :    declare that function in DATA if it hasn't been already declared.  */
    3423                 :             : 
    3424                 :             : static tree
    3425                 :     3403817 : dfs_declare_virt_assop_and_dtor (tree binfo, void *data)
    3426                 :             : {
    3427                 :     3403817 :   tree bv, fn, t = (tree)data;
    3428                 :     3403817 :   tree opname = assign_op_identifier;
    3429                 :             : 
    3430                 :     3403817 :   gcc_assert (t && CLASS_TYPE_P (t));
    3431                 :     3403817 :   gcc_assert (binfo && TREE_CODE (binfo) == TREE_BINFO);
    3432                 :             : 
    3433                 :     3403817 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
    3434                 :             :     /* A base without a vtable needs no modification, and its bases
    3435                 :             :        are uninteresting.  */
    3436                 :             :     return dfs_skip_bases;
    3437                 :             : 
    3438                 :     2864639 :   if (BINFO_PRIMARY_P (binfo))
    3439                 :             :     /* If this is a primary base, then we have already looked at the
    3440                 :             :        virtual functions of its vtable.  */
    3441                 :             :     return NULL_TREE;
    3442                 :             : 
    3443                 :    11429052 :   for (bv = BINFO_VIRTUALS (binfo); bv; bv = TREE_CHAIN (bv))
    3444                 :             :     {
    3445                 :     8564413 :       fn = BV_FN (bv);
    3446                 :             : 
    3447                 :     8564413 :       if (DECL_NAME (fn) == opname)
    3448                 :             :         {
    3449                 :          21 :           if (CLASSTYPE_LAZY_COPY_ASSIGN (t))
    3450                 :          21 :             lazily_declare_fn (sfk_copy_assignment, t);
    3451                 :          21 :           if (CLASSTYPE_LAZY_MOVE_ASSIGN (t))
    3452                 :          14 :             lazily_declare_fn (sfk_move_assignment, t);
    3453                 :             :         }
    3454                 :     8564392 :       else if (DECL_DESTRUCTOR_P (fn)
    3455                 :     8564392 :                && CLASSTYPE_LAZY_DESTRUCTOR (t))
    3456                 :      169658 :         lazily_declare_fn (sfk_destructor, t);
    3457                 :             :     }
    3458                 :             : 
    3459                 :             :   return NULL_TREE;
    3460                 :             : }
    3461                 :             : 
    3462                 :             : /* If the class type T has a direct or indirect base that contains a
    3463                 :             :    virtual assignment operator or a virtual destructor, declare that
    3464                 :             :    function in T if it hasn't been already declared.  */
    3465                 :             : 
    3466                 :             : static void
    3467                 :    37061824 : declare_virt_assop_and_dtor (tree t)
    3468                 :             : {
    3469                 :    37061824 :   if (!(TYPE_POLYMORPHIC_P (t)
    3470                 :     1655283 :         && (CLASSTYPE_LAZY_COPY_ASSIGN (t)
    3471                 :      619726 :             || CLASSTYPE_LAZY_MOVE_ASSIGN (t)
    3472                 :      619726 :             || CLASSTYPE_LAZY_DESTRUCTOR (t))))
    3473                 :             :     return;
    3474                 :             : 
    3475                 :     1090503 :   dfs_walk_all (TYPE_BINFO (t),
    3476                 :             :                 dfs_declare_virt_assop_and_dtor,
    3477                 :             :                 NULL, t);
    3478                 :             : }
    3479                 :             : 
    3480                 :             : /* Declare the inheriting constructor for class T inherited from base
    3481                 :             :    constructor CTOR with the parameter array PARMS of size NPARMS.  */
    3482                 :             : 
    3483                 :             : static void
    3484                 :          90 : one_inheriting_sig (tree t, tree ctor, tree *parms, int nparms)
    3485                 :             : {
    3486                 :          90 :   gcc_assert (TYPE_MAIN_VARIANT (t) == t);
    3487                 :             : 
    3488                 :             :   /* We don't declare an inheriting ctor that would be a default,
    3489                 :             :      copy or move ctor for derived or base.  */
    3490                 :          90 :   if (nparms == 0)
    3491                 :             :     return;
    3492                 :          90 :   if (nparms == 1
    3493                 :          87 :       && TYPE_REF_P (parms[0]))
    3494                 :             :     {
    3495                 :          54 :       tree parm = TYPE_MAIN_VARIANT (TREE_TYPE (parms[0]));
    3496                 :          54 :       if (parm == t || parm == DECL_CONTEXT (ctor))
    3497                 :             :         return;
    3498                 :             :     }
    3499                 :             : 
    3500                 :          36 :   tree parmlist = void_list_node;
    3501                 :          75 :   for (int i = nparms - 1; i >= 0; i--)
    3502                 :          39 :     parmlist = tree_cons (NULL_TREE, parms[i], parmlist);
    3503                 :          36 :   tree fn = implicitly_declare_fn (sfk_inheriting_constructor,
    3504                 :             :                                    t, false, ctor, parmlist);
    3505                 :             : 
    3506                 :          36 :   if (add_method (t, fn, false))
    3507                 :             :     {
    3508                 :          27 :       DECL_CHAIN (fn) = TYPE_FIELDS (t);
    3509                 :          27 :       TYPE_FIELDS (t) = fn;
    3510                 :             :     }
    3511                 :             : }
    3512                 :             : 
    3513                 :             : /* Declare all the inheriting constructors for class T inherited from base
    3514                 :             :    constructor CTOR.  */
    3515                 :             : 
    3516                 :             : static void
    3517                 :      264814 : one_inherited_ctor (tree ctor, tree t, tree using_decl)
    3518                 :             : {
    3519                 :      264814 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (ctor);
    3520                 :             : 
    3521                 :      264814 :   if (flag_new_inheriting_ctors)
    3522                 :             :     {
    3523                 :      264724 :       ctor = implicitly_declare_fn (sfk_inheriting_constructor,
    3524                 :             :                                     t, /*const*/false, ctor, parms);
    3525                 :      264724 :       add_method (t, ctor, using_decl != NULL_TREE);
    3526                 :      264724 :       return;
    3527                 :             :     }
    3528                 :             : 
    3529                 :          90 :   tree *new_parms = XALLOCAVEC (tree, list_length (parms));
    3530                 :          90 :   int i = 0;
    3531                 :         183 :   for (; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
    3532                 :             :     {
    3533                 :          93 :       if (TREE_PURPOSE (parms))
    3534                 :           0 :         one_inheriting_sig (t, ctor, new_parms, i);
    3535                 :          93 :       new_parms[i++] = TREE_VALUE (parms);
    3536                 :             :     }
    3537                 :          90 :   one_inheriting_sig (t, ctor, new_parms, i);
    3538                 :          90 :   if (parms == NULL_TREE)
    3539                 :             :     {
    3540                 :           3 :       auto_diagnostic_group d;
    3541                 :           3 :       if (warning (OPT_Winherited_variadic_ctor,
    3542                 :             :                    "the ellipsis in %qD is not inherited", ctor))
    3543                 :           3 :         inform (DECL_SOURCE_LOCATION (ctor), "%qD declared here", ctor);
    3544                 :           3 :     }
    3545                 :             : }
    3546                 :             : 
    3547                 :             : /* Implicitly declare T().  */
    3548                 :             : 
    3549                 :             : static void
    3550                 :    31154710 : add_implicit_default_ctor (tree t)
    3551                 :             : {
    3552                 :    31154710 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 1;
    3553                 :    31154710 :   CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1;
    3554                 :    31154710 :   if (cxx_dialect >= cxx11)
    3555                 :    31073485 :     TYPE_HAS_CONSTEXPR_CTOR (t)
    3556                 :             :       /* Don't force the declaration to get a hard answer; if the
    3557                 :             :          definition would have made the class non-literal, it will still be
    3558                 :             :          non-literal because of the base or member in question, and that
    3559                 :             :          gives a better diagnostic.  */
    3560                 :    62146970 :       = type_maybe_constexpr_default_constructor (t);
    3561                 :    31154710 : }
    3562                 :             : 
    3563                 :             : /* Create default constructors, assignment operators, and so forth for
    3564                 :             :    the type indicated by T, if they are needed.  CANT_HAVE_CONST_CTOR,
    3565                 :             :    and CANT_HAVE_CONST_ASSIGNMENT are nonzero if, for whatever reason,
    3566                 :             :    the class cannot have a default constructor, copy constructor
    3567                 :             :    taking a const reference argument, or an assignment operator taking
    3568                 :             :    a const reference, respectively.  */
    3569                 :             : 
    3570                 :             : static void
    3571                 :    37061824 : add_implicitly_declared_members (tree t, tree* access_decls,
    3572                 :             :                                  int cant_have_const_cctor,
    3573                 :             :                                  int cant_have_const_assignment)
    3574                 :             : {
    3575                 :             :   /* Destructor.  */
    3576                 :    37061824 :   if (!CLASSTYPE_DESTRUCTOR (t))
    3577                 :             :     /* In general, we create destructors lazily.  */
    3578                 :    33492961 :     CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
    3579                 :             : 
    3580                 :    37061824 :   bool move_ok = false;
    3581                 :    36953834 :   if (cxx_dialect >= cxx11 && CLASSTYPE_LAZY_DESTRUCTOR (t)
    3582                 :    33404505 :       && !TYPE_HAS_COPY_CTOR (t) && !TYPE_HAS_COPY_ASSIGN (t)
    3583                 :    69518692 :       && !classtype_has_move_assign_or_move_ctor_p (t, false))
    3584                 :             :     move_ok = true;
    3585                 :             : 
    3586                 :             :   /* [class.ctor]
    3587                 :             : 
    3588                 :             :      If there is no user-declared constructor for a class, a default
    3589                 :             :      constructor is implicitly declared.  */
    3590                 :    37061824 :   if (! TYPE_HAS_USER_CONSTRUCTOR (t))
    3591                 :    31109630 :     add_implicit_default_ctor (t);
    3592                 :             : 
    3593                 :             :   /* [class.ctor]
    3594                 :             : 
    3595                 :             :      If a class definition does not explicitly declare a copy
    3596                 :             :      constructor, one is declared implicitly.  */
    3597                 :    37061824 :   if (! TYPE_HAS_COPY_CTOR (t))
    3598                 :             :     {
    3599                 :    34003773 :       TYPE_HAS_COPY_CTOR (t) = 1;
    3600                 :    34003773 :       TYPE_HAS_CONST_COPY_CTOR (t) = !cant_have_const_cctor;
    3601                 :    34003773 :       CLASSTYPE_LAZY_COPY_CTOR (t) = 1;
    3602                 :    34003773 :       if (move_ok)
    3603                 :    32217638 :         CLASSTYPE_LAZY_MOVE_CTOR (t) = 1;
    3604                 :             :     }
    3605                 :             : 
    3606                 :             :   /* If there is no assignment operator, one will be created if and
    3607                 :             :      when it is needed.  For now, just record whether or not the type
    3608                 :             :      of the parameter to the assignment operator will be a const or
    3609                 :             :      non-const reference.  */
    3610                 :    37061824 :   if (!TYPE_HAS_COPY_ASSIGN (t))
    3611                 :             :     {
    3612                 :    34133254 :       TYPE_HAS_COPY_ASSIGN (t) = 1;
    3613                 :    34133254 :       TYPE_HAS_CONST_COPY_ASSIGN (t) = !cant_have_const_assignment;
    3614                 :    34133254 :       CLASSTYPE_LAZY_COPY_ASSIGN (t) = 1;
    3615                 :    65983923 :       if (move_ok && !LAMBDA_TYPE_P (t))
    3616                 :    31926818 :         CLASSTYPE_LAZY_MOVE_ASSIGN (t) = 1;
    3617                 :             :     }
    3618                 :             : 
    3619                 :             :   /* We can't be lazy about declaring functions that might override
    3620                 :             :      a virtual function from a base class.  */
    3621                 :    37061824 :   declare_virt_assop_and_dtor (t);
    3622                 :             : 
    3623                 :             :   /* If the class definition does not explicitly declare an == operator
    3624                 :             :      function, but declares a defaulted three-way comparison operator function,
    3625                 :             :      an == operator function is declared implicitly.  */
    3626                 :    37061824 :   if (!classtype_has_op (t, EQ_EXPR))
    3627                 :    36197354 :     if (tree space = classtype_has_defaulted_op (t, SPACESHIP_EXPR))
    3628                 :             :       {
    3629                 :         226 :         tree eq = implicitly_declare_fn (sfk_comparison, t, false, space,
    3630                 :             :                                          NULL_TREE);
    3631                 :         226 :         bool is_friend = DECL_CONTEXT (space) != t;
    3632                 :         226 :         if (is_friend)
    3633                 :          35 :           do_friend (NULL_TREE, DECL_NAME (eq), eq,
    3634                 :             :                      NO_SPECIAL, true);
    3635                 :             :         else
    3636                 :             :           {
    3637                 :         191 :             add_method (t, eq, false);
    3638                 :         191 :             DECL_CHAIN (eq) = TYPE_FIELDS (t);
    3639                 :         191 :             TYPE_FIELDS (t) = eq;
    3640                 :             :           }
    3641                 :         226 :         maybe_add_class_template_decl_list (t, eq, is_friend);
    3642                 :             :       }
    3643                 :             : 
    3644                 :    39094738 :   while (*access_decls)
    3645                 :             :     {
    3646                 :     2032914 :       tree using_decl = TREE_VALUE (*access_decls);
    3647                 :     2032914 :       tree decl = USING_DECL_DECLS (using_decl);
    3648                 :     2032914 :       if (DECL_NAME (using_decl) == ctor_identifier)
    3649                 :             :         {
    3650                 :             :           /* declare, then remove the decl */
    3651                 :       54180 :           tree ctor_list = decl;
    3652                 :       54180 :           location_t loc = input_location;
    3653                 :       54180 :           input_location = DECL_SOURCE_LOCATION (using_decl);
    3654                 :      530744 :           for (tree fn : ovl_range (ctor_list))
    3655                 :             :             {
    3656                 :      264814 :               if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t) && default_ctor_p (fn))
    3657                 :             :                 /* CWG2799: Inheriting a default constructor gives us a default
    3658                 :             :                    constructor, not just an inherited constructor.  */
    3659                 :       45080 :                 add_implicit_default_ctor (t);
    3660                 :      264814 :               one_inherited_ctor (fn, t, using_decl);
    3661                 :             :             }
    3662                 :       54180 :           *access_decls = TREE_CHAIN (*access_decls);
    3663                 :       54180 :           input_location = loc;
    3664                 :             :         }
    3665                 :             :       else
    3666                 :     1978734 :         access_decls = &TREE_CHAIN (*access_decls);
    3667                 :             :     }
    3668                 :    37061824 : }
    3669                 :             : 
    3670                 :             : /* Cache of enum_min_precision values.  */
    3671                 :             : static GTY((deletable)) hash_map<tree, int> *enum_to_min_precision;
    3672                 :             : 
    3673                 :             : /* Return the minimum precision of a bit-field needed to store all
    3674                 :             :    enumerators of ENUMERAL_TYPE TYPE.  */
    3675                 :             : 
    3676                 :             : static int
    3677                 :       33765 : enum_min_precision (tree type)
    3678                 :             : {
    3679                 :       33765 :   type = TYPE_MAIN_VARIANT (type);
    3680                 :             :   /* For unscoped enums without fixed underlying type and without mode
    3681                 :             :      attribute we can just use precision of the underlying type.  */
    3682                 :       33765 :   if (UNSCOPED_ENUM_P (type)
    3683                 :       18663 :       && !ENUM_FIXED_UNDERLYING_TYPE_P (type)
    3684                 :       42557 :       && !lookup_attribute ("mode", TYPE_ATTRIBUTES (type)))
    3685                 :        8780 :     return TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type));
    3686                 :             : 
    3687                 :       24985 :   if (enum_to_min_precision == NULL)
    3688                 :        2542 :     enum_to_min_precision = hash_map<tree, int>::create_ggc (37);
    3689                 :             : 
    3690                 :       24985 :   bool existed;
    3691                 :       24985 :   int &prec = enum_to_min_precision->get_or_insert (type, &existed);
    3692                 :       24985 :   if (existed)
    3693                 :       15045 :     return prec;
    3694                 :             : 
    3695                 :        9940 :   tree minnode, maxnode;
    3696                 :        9940 :   if (TYPE_VALUES (type))
    3697                 :             :     {
    3698                 :             :       minnode = maxnode = NULL_TREE;
    3699                 :       76674 :       for (tree values = TYPE_VALUES (type);
    3700                 :       86611 :            values; values = TREE_CHAIN (values))
    3701                 :             :         {
    3702                 :       76674 :           tree decl = TREE_VALUE (values);
    3703                 :       76674 :           tree value = DECL_INITIAL (decl);
    3704                 :       76674 :           if (value == error_mark_node)
    3705                 :           0 :             value = integer_zero_node;
    3706                 :       76674 :           if (!minnode)
    3707                 :             :             minnode = maxnode = value;
    3708                 :       66737 :           else if (tree_int_cst_lt (maxnode, value))
    3709                 :             :             maxnode = value;
    3710                 :       24610 :           else if (tree_int_cst_lt (value, minnode))
    3711                 :           0 :             minnode = value;
    3712                 :             :         }
    3713                 :             :     }
    3714                 :             :   else
    3715                 :           3 :     minnode = maxnode = integer_zero_node;
    3716                 :             : 
    3717                 :        9940 :   signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
    3718                 :        9940 :   int lowprec = tree_int_cst_min_precision (minnode, sgn);
    3719                 :        9940 :   int highprec = tree_int_cst_min_precision (maxnode, sgn);
    3720                 :        9940 :   prec = MAX (lowprec, highprec);
    3721                 :        9940 :   return prec;
    3722                 :             : }
    3723                 :             : 
    3724                 :             : /* FIELD is a bit-field.  We are finishing the processing for its
    3725                 :             :    enclosing type.  Issue any appropriate messages and set appropriate
    3726                 :             :    flags.  Returns false if an error has been diagnosed.  */
    3727                 :             : 
    3728                 :             : static bool
    3729                 :      417323 : check_bitfield_decl (tree field)
    3730                 :             : {
    3731                 :      417323 :   tree type = TREE_TYPE (field);
    3732                 :      417323 :   tree w;
    3733                 :             : 
    3734                 :             :   /* Extract the declared width of the bitfield, which has been
    3735                 :             :      temporarily stashed in DECL_BIT_FIELD_REPRESENTATIVE by grokbitfield.  */
    3736                 :      417323 :   w = DECL_BIT_FIELD_REPRESENTATIVE (field);
    3737                 :      417323 :   gcc_assert (w != NULL_TREE);
    3738                 :             :   /* Remove the bit-field width indicator so that the rest of the
    3739                 :             :      compiler does not treat that value as a qualifier.  */
    3740                 :      417323 :   DECL_BIT_FIELD_REPRESENTATIVE (field) = NULL_TREE;
    3741                 :             : 
    3742                 :             :   /* Detect invalid bit-field type.  */
    3743                 :      417323 :   if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    3744                 :             :     {
    3745                 :           3 :       error_at (DECL_SOURCE_LOCATION (field),
    3746                 :             :                 "bit-field %q#D with non-integral type %qT", field, type);
    3747                 :           3 :       w = error_mark_node;
    3748                 :             :     }
    3749                 :             :   else
    3750                 :             :     {
    3751                 :      417320 :       location_t loc = input_location;
    3752                 :             :       /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs.  */
    3753                 :      417320 :       STRIP_NOPS (w);
    3754                 :             : 
    3755                 :             :       /* detect invalid field size.  */
    3756                 :      417320 :       input_location = DECL_SOURCE_LOCATION (field);
    3757                 :      417320 :       w = cxx_constant_value (w);
    3758                 :      417320 :       input_location = loc;
    3759                 :             : 
    3760                 :      417320 :       if (TREE_CODE (w) != INTEGER_CST)
    3761                 :             :         {
    3762                 :          15 :           error ("bit-field %q+D width not an integer constant", field);
    3763                 :          15 :           w = error_mark_node;
    3764                 :             :         }
    3765                 :      417305 :       else if (tree_int_cst_sgn (w) < 0)
    3766                 :             :         {
    3767                 :           0 :           error ("negative width in bit-field %q+D", field);
    3768                 :           0 :           w = error_mark_node;
    3769                 :             :         }
    3770                 :      417305 :       else if (integer_zerop (w) && DECL_NAME (field) != 0)
    3771                 :             :         {
    3772                 :          15 :           error ("zero width for bit-field %q+D", field);
    3773                 :          15 :           w = error_mark_node;
    3774                 :             :         }
    3775                 :      417290 :       else if ((TREE_CODE (type) != ENUMERAL_TYPE
    3776                 :      417290 :                 && TREE_CODE (type) != BOOLEAN_TYPE
    3777                 :      382072 :                 && compare_tree_int (w, TYPE_PRECISION (type)) > 0)
    3778                 :      417290 :                || ((TREE_CODE (type) == ENUMERAL_TYPE
    3779                 :      416856 :                     || TREE_CODE (type) == BOOLEAN_TYPE)
    3780                 :       35218 :                    && tree_int_cst_lt (TYPE_SIZE (type), w)))
    3781                 :         774 :         warning_at (DECL_SOURCE_LOCATION (field), 0,
    3782                 :             :                     "width of %qD exceeds its type", field);
    3783                 :      416516 :       else if (TREE_CODE (type) == ENUMERAL_TYPE)
    3784                 :             :         {
    3785                 :       33765 :           int prec = enum_min_precision (type);
    3786                 :       33765 :           if (compare_tree_int (w, prec) < 0)
    3787                 :          48 :             warning_at (DECL_SOURCE_LOCATION (field), 0,
    3788                 :             :                         "%qD is too small to hold all values of %q#T",
    3789                 :             :                         field, type);
    3790                 :             :         }
    3791                 :             :     }
    3792                 :             : 
    3793                 :      417323 :   if (w != error_mark_node)
    3794                 :             :     {
    3795                 :      417290 :       DECL_SIZE (field) = fold_convert (bitsizetype, w);
    3796                 :      417290 :       DECL_BIT_FIELD (field) = 1;
    3797                 :      417290 :       return true;
    3798                 :             :     }
    3799                 :             :   else
    3800                 :             :     {
    3801                 :             :       /* Non-bit-fields are aligned for their type.  */
    3802                 :          33 :       DECL_BIT_FIELD (field) = 0;
    3803                 :          33 :       CLEAR_DECL_C_BIT_FIELD (field);
    3804                 :          33 :       return false;
    3805                 :             :     }
    3806                 :             : }
    3807                 :             : 
    3808                 :             : /* FIELD is a non bit-field.  We are finishing the processing for its
    3809                 :             :    enclosing type T.  Issue any appropriate messages and set appropriate
    3810                 :             :    flags.  */
    3811                 :             : 
    3812                 :             : static bool
    3813                 :    15907392 : check_field_decl (tree field,
    3814                 :             :                   tree t,
    3815                 :             :                   int* cant_have_const_ctor,
    3816                 :             :                   int* no_const_asn_ref)
    3817                 :             : {
    3818                 :    15907392 :   tree type = strip_array_types (TREE_TYPE (field));
    3819                 :    15907392 :   bool any_default_members = false;
    3820                 :             : 
    3821                 :             :   /* In C++98 an anonymous union cannot contain any fields which would change
    3822                 :             :      the settings of CANT_HAVE_CONST_CTOR and friends.  */
    3823                 :    15907392 :   if (ANON_UNION_TYPE_P (type) && cxx_dialect < cxx11)
    3824                 :             :     ;
    3825                 :             :   /* And, we don't set TYPE_HAS_CONST_COPY_CTOR, etc., for anonymous
    3826                 :             :      structs.  So, we recurse through their fields here.  */
    3827                 :    15906556 :   else if (ANON_AGGR_TYPE_P (type))
    3828                 :             :     {
    3829                 :      748494 :       for (tree fields = TYPE_FIELDS (type); fields;
    3830                 :      599577 :            fields = DECL_CHAIN (fields))
    3831                 :      599577 :         if (TREE_CODE (fields) == FIELD_DECL)
    3832                 :      430636 :           any_default_members |= check_field_decl (fields, t,
    3833                 :             :                                                    cant_have_const_ctor,
    3834                 :             :                                                    no_const_asn_ref);
    3835                 :             :     }
    3836                 :             :   /* Check members with class type for constructors, destructors,
    3837                 :             :      etc.  */
    3838                 :    15757639 :   else if (CLASS_TYPE_P (type))
    3839                 :             :     {
    3840                 :             :       /* Never let anything with uninheritable virtuals
    3841                 :             :          make it through without complaint.  */
    3842                 :     2803977 :       abstract_virtuals_error (field, type);
    3843                 :             : 
    3844                 :     2803977 :       if (TREE_CODE (t) == UNION_TYPE && cxx_dialect < cxx11)
    3845                 :             :         {
    3846                 :        2932 :           static bool warned;
    3847                 :        2932 :           auto_diagnostic_group d;
    3848                 :        2932 :           int oldcount = errorcount;
    3849                 :        2932 :           if (TYPE_NEEDS_CONSTRUCTING (type))
    3850                 :           2 :             error ("member %q+#D with constructor not allowed in union",
    3851                 :             :                    field);
    3852                 :        2932 :           if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    3853                 :           0 :             error ("member %q+#D with destructor not allowed in union", field);
    3854                 :        2932 :           if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    3855                 :           3 :             error ("member %q+#D with copy assignment operator not allowed in union",
    3856                 :             :                    field);
    3857                 :        2932 :           if (!warned && errorcount > oldcount)
    3858                 :             :             {
    3859                 :           4 :               inform (DECL_SOURCE_LOCATION (field), "unrestricted unions "
    3860                 :             :                       "only available with %<-std=c++11%> or %<-std=gnu++11%>");
    3861                 :           4 :               warned = true;
    3862                 :             :             }
    3863                 :        2932 :         }
    3864                 :             :       else
    3865                 :             :         {
    3866                 :     2801045 :           TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
    3867                 :     8403135 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    3868                 :     2801045 :             |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    3869                 :     2801045 :           TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    3870                 :     2801045 :             |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (type)
    3871                 :     2801045 :                 || !TYPE_HAS_COPY_ASSIGN (type));
    3872                 :     5602090 :           TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (type)
    3873                 :     2801045 :                                              || !TYPE_HAS_COPY_CTOR (type));
    3874                 :     2801045 :           TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (type);
    3875                 :     2801045 :           TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (type);
    3876                 :     5602090 :           TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type)
    3877                 :     2801045 :                                         || TYPE_HAS_COMPLEX_DFLT (type));
    3878                 :             :         }
    3879                 :             : 
    3880                 :     2803977 :       if (TYPE_HAS_COPY_CTOR (type)
    3881                 :     2803977 :           && !TYPE_HAS_CONST_COPY_CTOR (type))
    3882                 :        2458 :         *cant_have_const_ctor = 1;
    3883                 :             : 
    3884                 :     2803977 :       if (TYPE_HAS_COPY_ASSIGN (type)
    3885                 :     2803977 :           && !TYPE_HAS_CONST_COPY_ASSIGN (type))
    3886                 :          55 :         *no_const_asn_ref = 1;
    3887                 :             :     }
    3888                 :             : 
    3889                 :    15907392 :   check_abi_tags (t, field);
    3890                 :             : 
    3891                 :    15907392 :   if (DECL_INITIAL (field) != NULL_TREE)
    3892                 :             :     /* `build_class_init_list' does not recognize
    3893                 :             :        non-FIELD_DECLs.  */
    3894                 :      866439 :     any_default_members = true;
    3895                 :             : 
    3896                 :    15907392 :   return any_default_members;
    3897                 :             : }
    3898                 :             : 
    3899                 :             : /* Check the data members (both static and non-static), class-scoped
    3900                 :             :    typedefs, etc., appearing in the declaration of T.  Issue
    3901                 :             :    appropriate diagnostics.  Sets ACCESS_DECLS to a list (in
    3902                 :             :    declaration order) of access declarations; each TREE_VALUE in this
    3903                 :             :    list is a USING_DECL.
    3904                 :             : 
    3905                 :             :    In addition, set the following flags:
    3906                 :             : 
    3907                 :             :      EMPTY_P
    3908                 :             :        The class is empty, i.e., contains no non-static data members.
    3909                 :             : 
    3910                 :             :      CANT_HAVE_CONST_CTOR_P
    3911                 :             :        This class cannot have an implicitly generated copy constructor
    3912                 :             :        taking a const reference.
    3913                 :             : 
    3914                 :             :      CANT_HAVE_CONST_ASN_REF
    3915                 :             :        This class cannot have an implicitly generated assignment
    3916                 :             :        operator taking a const reference.
    3917                 :             : 
    3918                 :             :    All of these flags should be initialized before calling this
    3919                 :             :    function.   */
    3920                 :             : 
    3921                 :             : static void
    3922                 :    37061824 : check_field_decls (tree t, tree *access_decls,
    3923                 :             :                    int *cant_have_const_ctor_p,
    3924                 :             :                    int *no_const_asn_ref_p)
    3925                 :             : {
    3926                 :    37061824 :   int cant_pack = 0;
    3927                 :             : 
    3928                 :             :   /* Assume there are no access declarations.  */
    3929                 :    37061824 :   *access_decls = NULL_TREE;
    3930                 :             :   /* Effective C has things to say about classes with pointer members.  */
    3931                 :    37061824 :   tree pointer_member = NULL_TREE;
    3932                 :             :   /* Default initialized members affect the whole class.  */
    3933                 :    37061824 :   tree default_init_member = NULL_TREE;
    3934                 :             :   /* Lack of any non-static data member of non-volatile literal
    3935                 :             :      type affects a union.  */
    3936                 :    37061824 :   bool found_nv_literal_p = false;
    3937                 :             :   /* Standard layout requires all FIELDS have same access.  */
    3938                 :    37061824 :   int field_access = -1;
    3939                 :             : 
    3940                 :   260575625 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3941                 :             :     {
    3942                 :   223513801 :       tree type = TREE_TYPE (field);
    3943                 :             : 
    3944                 :   223513801 :       switch (TREE_CODE (field))
    3945                 :             :         {
    3946                 :           0 :         default:
    3947                 :           0 :           gcc_unreachable ();
    3948                 :             : 
    3949                 :     2032914 :         case USING_DECL:
    3950                 :             :           /* Save the access declarations for our caller.  */
    3951                 :     2032914 :           *access_decls = tree_cons (NULL_TREE, field, *access_decls);
    3952                 :     2032914 :           break;
    3953                 :             : 
    3954                 :             :         case TYPE_DECL:
    3955                 :             :         case TEMPLATE_DECL:
    3956                 :             :           break;
    3957                 :             : 
    3958                 :             :         case FUNCTION_DECL:
    3959                 :             :           /* FIXME: We should fold in the checking from check_methods.  */
    3960                 :             :           break;
    3961                 :             : 
    3962                 :     1618166 :         case CONST_DECL:
    3963                 :     1618166 :           DECL_NONLOCAL (field) = 1;
    3964                 :     1618166 :           break;
    3965                 :             : 
    3966                 :     9948098 :         case VAR_DECL:
    3967                 :     9948098 :           if (TREE_CODE (t) == UNION_TYPE
    3968                 :          36 :               && cxx_dialect < cxx11)
    3969                 :             :             {
    3970                 :             :               /* [class.union]
    3971                 :             : 
    3972                 :             :                  (C++98) If a union contains a static data member,
    3973                 :             :                  ... the program is ill-formed.  */
    3974                 :           1 :               if (cxx_dialect < cxx11)
    3975                 :           1 :                 error ("in C++98 %q+D may not be static because it is "
    3976                 :             :                        "a member of a union", field);
    3977                 :             :             }
    3978                 :     9948098 :           goto data_member;
    3979                 :             : 
    3980                 :    15476914 :         case FIELD_DECL:
    3981                 :    15476914 :           if (TREE_CODE (t) == UNION_TYPE)
    3982                 :             :             {
    3983                 :             :               /* [class.union]
    3984                 :             : 
    3985                 :             :                  If a union contains ... or a [non-static data] member
    3986                 :             :                  of reference type, the program is ill-formed.  */
    3987                 :     1029377 :               if (TYPE_REF_P (type))
    3988                 :          33 :                 error ("non-static data member %q+D in a union may not "
    3989                 :             :                        "have reference type %qT", field, type);
    3990                 :             :             }
    3991                 :             : 
    3992                 :    14447537 :         data_member:
    3993                 :             :           /* Common VAR_DECL & FIELD_DECL processing.  */
    3994                 :    25425012 :           DECL_CONTEXT (field) = t;
    3995                 :    25425012 :           DECL_NONLOCAL (field) = 1;
    3996                 :             : 
    3997                 :             :           /* Template instantiation can cause this.  Perhaps this
    3998                 :             :              should be a specific instantiation check?  */
    3999                 :    25425012 :           if (TREE_CODE (type) == FUNCTION_TYPE)
    4000                 :             :             {
    4001                 :          10 :               error ("data member %q+D invalidly declared function type", field);
    4002                 :          10 :               type = build_pointer_type (type);
    4003                 :          10 :               TREE_TYPE (field) = type;
    4004                 :             :             }
    4005                 :    25425002 :           else if (TREE_CODE (type) == METHOD_TYPE)
    4006                 :             :             {
    4007                 :           0 :               error ("data member %q+D invalidly declared method type", field);
    4008                 :           0 :               type = build_pointer_type (type);
    4009                 :           0 :               TREE_TYPE (field) = type;
    4010                 :             :             }
    4011                 :             : 
    4012                 :             :           break;
    4013                 :             :         }
    4014                 :             : 
    4015                 :   223513801 :       if (TREE_CODE (field) != FIELD_DECL)
    4016                 :   208036887 :         continue;
    4017                 :             : 
    4018                 :    15476914 :       if (type == error_mark_node)
    4019                 :         158 :         continue;
    4020                 :             : 
    4021                 :             :       /* If it is not a union and at least one non-static data member is
    4022                 :             :          non-literal, the whole class becomes non-literal.  Per Core/1453,
    4023                 :             :          volatile non-static data members and base classes are also not allowed.
    4024                 :             :          If it is a union, we might set CLASSTYPE_LITERAL_P after we've seen all
    4025                 :             :          members.
    4026                 :             :          Note: if the type is incomplete we will complain later on.  */
    4027                 :    15476756 :       if (COMPLETE_TYPE_P (type))
    4028                 :             :         {
    4029                 :    15475372 :           if (!literal_type_p (type) || CP_TYPE_VOLATILE_P (type))
    4030                 :     1078790 :             CLASSTYPE_LITERAL_P (t) = false;
    4031                 :             :           else
    4032                 :             :             found_nv_literal_p = true;
    4033                 :             :         }
    4034                 :             : 
    4035                 :    15476756 :       int this_field_access = (TREE_PROTECTED (field) ? 1
    4036                 :    13830889 :                                : TREE_PRIVATE (field) ? 2 : 0);
    4037                 :    15476756 :       if (field_access != this_field_access)
    4038                 :             :         {
    4039                 :             :           /* A standard-layout class is a class that:
    4040                 :             : 
    4041                 :             :              ... has the same access control (Clause 11) for all
    4042                 :             :              non-static data members, */
    4043                 :     5962497 :           if (field_access < 0)
    4044                 :             :             field_access = this_field_access;
    4045                 :             :           else
    4046                 :       32870 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4047                 :             : 
    4048                 :             :           /* Aggregates must be public.  */
    4049                 :     5962497 :           if (this_field_access)
    4050                 :     2863263 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    4051                 :             :         }
    4052                 :             : 
    4053                 :             :       /* If this is of reference type, check if it needs an init.  */
    4054                 :    15476756 :       if (TYPE_REF_P (type))
    4055                 :             :         {
    4056                 :      459108 :           CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4057                 :      459108 :           CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4058                 :      459108 :           if (DECL_INITIAL (field) == NULL_TREE)
    4059                 :      459026 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    4060                 :      459108 :           if (cxx_dialect < cxx11)
    4061                 :             :             {
    4062                 :             :               /* ARM $12.6.2: [A member initializer list] (or, for an
    4063                 :             :                  aggregate, initialization by a brace-enclosed list) is the
    4064                 :             :                  only way to initialize non-static const and reference
    4065                 :             :                  members.  */
    4066                 :        1017 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    4067                 :        1017 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    4068                 :             :             }
    4069                 :             :         }
    4070                 :             : 
    4071                 :    15476756 :       type = strip_array_types (type);
    4072                 :             : 
    4073                 :    15476756 :       if (TYPE_PACKED (t))
    4074                 :             :         {
    4075                 :        1047 :           if (!layout_pod_type_p (type) && !TYPE_PACKED (type))
    4076                 :             :             {
    4077                 :          18 :               warning_at (DECL_SOURCE_LOCATION (field), 0,
    4078                 :             :                           "ignoring packed attribute because of"
    4079                 :             :                           " unpacked non-POD field %q#D", field);
    4080                 :          18 :               cant_pack = 1;
    4081                 :             :             }
    4082                 :        1029 :           else if (DECL_C_BIT_FIELD (field)
    4083                 :        1029 :                    || TYPE_ALIGN (TREE_TYPE (field)) > BITS_PER_UNIT)
    4084                 :         794 :             DECL_PACKED (field) = 1;
    4085                 :             :         }
    4086                 :             : 
    4087                 :    15476756 :       if (DECL_C_BIT_FIELD (field)
    4088                 :    15476756 :           && integer_zerop (DECL_BIT_FIELD_REPRESENTATIVE (field)))
    4089                 :             :         /* We don't treat zero-width bitfields as making a class
    4090                 :             :            non-empty.  */
    4091                 :             :         ;
    4092                 :    15475627 :       else if (field_poverlapping_p (field)
    4093                 :    15475627 :                && is_empty_class (TREE_TYPE (field)))
    4094                 :             :         /* Empty data members also don't make a class non-empty.  */
    4095                 :      171705 :         CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    4096                 :             :       else
    4097                 :             :         {
    4098                 :             :           /* The class is non-empty.  */
    4099                 :    15303922 :           CLASSTYPE_EMPTY_P (t) = 0;
    4100                 :             :           /* The class is not even nearly empty.  */
    4101                 :    15303922 :           CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4102                 :             :           /* If one of the data members contains an empty class, so
    4103                 :             :              does T.  */
    4104                 :     2734313 :           if (CLASS_TYPE_P (type)
    4105                 :    18026445 :               && CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    4106                 :      819189 :             CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    4107                 :             :         }
    4108                 :             : 
    4109                 :             :       /* This is used by -Weffc++ (see below). Warn only for pointers
    4110                 :             :          to members which might hold dynamic memory. So do not warn
    4111                 :             :          for pointers to functions or pointers to members.  */
    4112                 :    15476756 :       if (TYPE_PTR_P (type)
    4113                 :    15476756 :           && !TYPE_PTRFN_P (type))
    4114                 :             :         pointer_member = field;
    4115                 :             : 
    4116                 :    15476756 :       if (CLASS_TYPE_P (type))
    4117                 :             :         {
    4118                 :     2894228 :           if (CLASSTYPE_REF_FIELDS_NEED_INIT (type))
    4119                 :        3182 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    4120                 :     2894228 :           if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (type))
    4121                 :       29600 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    4122                 :             :         }
    4123                 :             : 
    4124                 :    15476756 :       if (DECL_MUTABLE_P (field) || TYPE_HAS_MUTABLE_P (type))
    4125                 :      214087 :         CLASSTYPE_HAS_MUTABLE (t) = 1;
    4126                 :             : 
    4127                 :    15476756 :       if (DECL_MUTABLE_P (field))
    4128                 :             :         {
    4129                 :      132233 :           if (TYPE_REF_P (type))
    4130                 :           3 :             error ("member %q+D cannot be declared as a %<mutable%> "
    4131                 :             :                    "reference", field);
    4132                 :      132230 :           else if (CP_TYPE_CONST_P (type))
    4133                 :           3 :             error ("member %q+D cannot be declared both %<const%> "
    4134                 :             :                    "and %<mutable%>", field);
    4135                 :             :         }
    4136                 :             : 
    4137                 :    15476756 :       if (! layout_pod_type_p (type))
    4138                 :             :         /* DR 148 now allows pointers to members (which are POD themselves),
    4139                 :             :            to be allowed in POD structs.  */
    4140                 :     2423190 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4141                 :             : 
    4142                 :    15476756 :       if (field_poverlapping_p (field))
    4143                 :             :         /* A potentially-overlapping non-static data member makes the class
    4144                 :             :            non-layout-POD.  */
    4145                 :      222865 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4146                 :             : 
    4147                 :    15476756 :       if (!std_layout_type_p (type))
    4148                 :      698345 :         CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4149                 :             : 
    4150                 :    15476756 :       if (! zero_init_p (type))
    4151                 :         167 :         CLASSTYPE_NON_ZERO_INIT_P (t) = 1;
    4152                 :             : 
    4153                 :             :       /* We set DECL_C_BIT_FIELD in grokbitfield.
    4154                 :             :          If the type and width are valid, we'll also set DECL_BIT_FIELD.  */
    4155                 :    15476756 :       if (DECL_C_BIT_FIELD (field))
    4156                 :      417323 :         check_bitfield_decl (field);
    4157                 :             : 
    4158                 :    15476756 :       if (check_field_decl (field, t,
    4159                 :             :                             cant_have_const_ctor_p, no_const_asn_ref_p))
    4160                 :             :         {
    4161                 :      866418 :           if (default_init_member
    4162                 :      354299 :               && TREE_CODE (t) == UNION_TYPE)
    4163                 :             :             {
    4164                 :          12 :               auto_diagnostic_group d;
    4165                 :          12 :               error ("multiple fields in union %qT initialized", t);
    4166                 :          12 :               inform (DECL_SOURCE_LOCATION (default_init_member),
    4167                 :             :                       "initialized member %q+D declared here",
    4168                 :             :                       default_init_member);
    4169                 :          12 :             }
    4170                 :             :           default_init_member = field;
    4171                 :             :         }
    4172                 :             : 
    4173                 :             :       /* Now that we've removed bit-field widths from DECL_INITIAL,
    4174                 :             :          anything left in DECL_INITIAL is an NSDMI that makes the class
    4175                 :             :          non-aggregate in C++11, and non-layout-POD always.  */
    4176                 :    15476756 :       if (DECL_INITIAL (field))
    4177                 :             :         {
    4178                 :      863888 :           if (cxx_dialect < cxx14)
    4179                 :         953 :             CLASSTYPE_NON_AGGREGATE (t) = true;
    4180                 :             :           else
    4181                 :      862935 :             CLASSTYPE_NON_POD_AGGREGATE (t) = true;
    4182                 :             :         }
    4183                 :             : 
    4184                 :    15476756 :       if (CP_TYPE_CONST_P (type))
    4185                 :             :         {
    4186                 :             :           /* If any field is const, the structure type is pseudo-const.  */
    4187                 :      273420 :           C_TYPE_FIELDS_READONLY (t) = 1;
    4188                 :      273420 :           if (DECL_INITIAL (field) == NULL_TREE)
    4189                 :      225498 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    4190                 :      273420 :           if (cxx_dialect < cxx11)
    4191                 :             :             {
    4192                 :             :               /* ARM $12.6.2: [A member initializer list] (or, for an
    4193                 :             :                  aggregate, initialization by a brace-enclosed list) is the
    4194                 :             :                  only way to initialize non-static const and reference
    4195                 :             :                  members.  */
    4196                 :         668 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    4197                 :         668 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    4198                 :             :             }
    4199                 :             :         }
    4200                 :             :       /* A field that is pseudo-const makes the structure likewise.  */
    4201                 :    15203336 :       else if (CLASS_TYPE_P (type))
    4202                 :             :         {
    4203                 :     2845430 :           C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type);
    4204                 :     2845430 :           SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t,
    4205                 :             :             CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
    4206                 :             :             | CLASSTYPE_READONLY_FIELDS_NEED_INIT (type));
    4207                 :             :         }
    4208                 :             : 
    4209                 :             :       /* Core issue 80: A non-static data member is required to have a
    4210                 :             :          different name from the class iff the class has a
    4211                 :             :          user-declared constructor.  */
    4212                 :    15476756 :       if (constructor_name_p (DECL_NAME (field), t)
    4213                 :    15476756 :           && TYPE_HAS_USER_CONSTRUCTOR (t))
    4214                 :          12 :         permerror (DECL_SOURCE_LOCATION (field),
    4215                 :             :                    "field %q#D with same name as class", field);
    4216                 :             :     }
    4217                 :             : 
    4218                 :             :   /* Per CWG 2096, a type is a literal type if it is a union, and at least
    4219                 :             :      one of its non-static data members is of non-volatile literal type.  */
    4220                 :    37061824 :   if (TREE_CODE (t) == UNION_TYPE && found_nv_literal_p)
    4221                 :      383533 :     CLASSTYPE_LITERAL_P (t) = true;
    4222                 :             : 
    4223                 :             :   /* Effective C++ rule 11: if a class has dynamic memory held by pointers,
    4224                 :             :      it should also define a copy constructor and an assignment operator to
    4225                 :             :      implement the correct copy semantic (deep vs shallow, etc.). As it is
    4226                 :             :      not feasible to check whether the constructors do allocate dynamic memory
    4227                 :             :      and store it within members, we approximate the warning like this:
    4228                 :             : 
    4229                 :             :      -- Warn only if there are members which are pointers
    4230                 :             :      -- Warn only if there is a non-trivial constructor (otherwise,
    4231                 :             :         there cannot be memory allocated).
    4232                 :             :      -- Warn only if there is a non-trivial destructor. We assume that the
    4233                 :             :         user at least implemented the cleanup correctly, and a destructor
    4234                 :             :         is needed to free dynamic memory.
    4235                 :             : 
    4236                 :             :      This seems enough for practical purposes.  */
    4237                 :    37061824 :   if (warn_ecpp
    4238                 :         138 :       && pointer_member
    4239                 :          15 :       && TYPE_HAS_USER_CONSTRUCTOR (t)
    4240                 :          15 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    4241                 :    37061836 :       && !(TYPE_HAS_COPY_CTOR (t) && TYPE_HAS_COPY_ASSIGN (t)))
    4242                 :             :     {
    4243                 :           9 :       auto_diagnostic_group d;
    4244                 :           9 :       if (warning (OPT_Weffc__, "%q#T has pointer data members", t))
    4245                 :             :         {
    4246                 :           9 :           if (! TYPE_HAS_COPY_CTOR (t))
    4247                 :             :             {
    4248                 :           6 :               warning (OPT_Weffc__,
    4249                 :             :                        "  but does not declare %<%T(const %T&)%>", t, t);
    4250                 :           6 :               if (!TYPE_HAS_COPY_ASSIGN (t))
    4251                 :           3 :                 warning (OPT_Weffc__, "  or %<operator=(const %T&)%>", t);
    4252                 :             :             }
    4253                 :           3 :           else if (! TYPE_HAS_COPY_ASSIGN (t))
    4254                 :           3 :             warning (OPT_Weffc__,
    4255                 :             :                      "  but does not declare %<operator=(const %T&)%>", t);
    4256                 :           9 :           inform (DECL_SOURCE_LOCATION (pointer_member),
    4257                 :             :                   "pointer member %q+D declared here", pointer_member);
    4258                 :             :         }
    4259                 :           9 :     }
    4260                 :             : 
    4261                 :             :   /* Non-static data member initializers make the default constructor
    4262                 :             :      non-trivial.  */
    4263                 :    37061824 :   if (default_init_member)
    4264                 :             :     {
    4265                 :      512119 :       TYPE_NEEDS_CONSTRUCTING (t) = true;
    4266                 :      512119 :       TYPE_HAS_COMPLEX_DFLT (t) = true;
    4267                 :             :     }
    4268                 :             : 
    4269                 :             :   /* If any of the fields couldn't be packed, unset TYPE_PACKED.  */
    4270                 :    37061824 :   if (cant_pack)
    4271                 :          12 :     TYPE_PACKED (t) = 0;
    4272                 :             : 
    4273                 :             :   /* Check anonymous struct/anonymous union fields.  */
    4274                 :    37061824 :   finish_struct_anon (t);
    4275                 :             : 
    4276                 :             :   /* We've built up the list of access declarations in reverse order.
    4277                 :             :      Fix that now.  */
    4278                 :    37061824 :   *access_decls = nreverse (*access_decls);
    4279                 :    37061824 : }
    4280                 :             : 
    4281                 :             : /* If TYPE is an empty class type, records its OFFSET in the table of
    4282                 :             :    OFFSETS.  */
    4283                 :             : 
    4284                 :             : static int
    4285                 :    24516808 : record_subobject_offset (tree type, tree offset, splay_tree offsets)
    4286                 :             : {
    4287                 :    24516808 :   splay_tree_node n;
    4288                 :             : 
    4289                 :    24516808 :   if (!is_empty_class (type))
    4290                 :             :     return 0;
    4291                 :             : 
    4292                 :             :   /* Record the location of this empty object in OFFSETS.  */
    4293                 :    21913799 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    4294                 :    21913799 :   if (!n)
    4295                 :    18373583 :     n = splay_tree_insert (offsets,
    4296                 :             :                            (splay_tree_key) offset,
    4297                 :             :                            (splay_tree_value) NULL_TREE);
    4298                 :    43827598 :   n->value = ((splay_tree_value)
    4299                 :    21913799 :               tree_cons (NULL_TREE,
    4300                 :             :                          type,
    4301                 :    21913799 :                          (tree) n->value));
    4302                 :             : 
    4303                 :    21913799 :   return 0;
    4304                 :             : }
    4305                 :             : 
    4306                 :             : /* Returns nonzero if TYPE is an empty class type and there is
    4307                 :             :    already an entry in OFFSETS for the same TYPE as the same OFFSET.  */
    4308                 :             : 
    4309                 :             : static int
    4310                 :      584641 : check_subobject_offset (tree type, tree offset, splay_tree offsets)
    4311                 :             : {
    4312                 :      584641 :   splay_tree_node n;
    4313                 :      584641 :   tree t;
    4314                 :             : 
    4315                 :      584641 :   if (!is_empty_class (type))
    4316                 :             :     return 0;
    4317                 :             : 
    4318                 :             :   /* Record the location of this empty object in OFFSETS.  */
    4319                 :      500804 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    4320                 :      500804 :   if (!n)
    4321                 :             :     return 0;
    4322                 :             : 
    4323                 :      500720 :   enum { ignore, fast, slow, warn }
    4324                 :      500720 :   cv_check = (abi_version_crosses (19) ? slow
    4325                 :      500687 :               : abi_version_at_least (19) ? fast
    4326                 :           0 :               : ignore);
    4327                 :     3945442 :   for (t = (tree) n->value; t; t = TREE_CHAIN (t))
    4328                 :             :     {
    4329                 :     3446340 :       tree elt = TREE_VALUE (t);
    4330                 :             : 
    4331                 :     3446340 :       if (same_type_p (elt, type))
    4332                 :             :         return 1;
    4333                 :             : 
    4334                 :     3444722 :       if (cv_check != ignore
    4335                 :     3444722 :           && similar_type_p (elt, type))
    4336                 :             :         {
    4337                 :          12 :           if (cv_check == fast)
    4338                 :             :             return 1;
    4339                 :             :           cv_check = warn;
    4340                 :             :         }
    4341                 :             :     }
    4342                 :             : 
    4343                 :      499102 :   if (cv_check == warn)
    4344                 :             :     {
    4345                 :          12 :       warning (OPT_Wabi, "layout of %qs member of type %qT changes in %qs",
    4346                 :             :                "[[no_unique_address]]", type, "-fabi-version=19");
    4347                 :          12 :       if (abi_version_at_least (19))
    4348                 :             :         return 1;
    4349                 :             :     }
    4350                 :             : 
    4351                 :             :   return 0;
    4352                 :             : }
    4353                 :             : 
    4354                 :             : /* Walk through all the subobjects of TYPE (located at OFFSET).  Call
    4355                 :             :    F for every subobject, passing it the type, offset, and table of
    4356                 :             :    OFFSETS.  If VBASES_P is one, then virtual non-primary bases should
    4357                 :             :    be traversed.
    4358                 :             : 
    4359                 :             :    If MAX_OFFSET is non-NULL, then subobjects with an offset greater
    4360                 :             :    than MAX_OFFSET will not be walked.
    4361                 :             : 
    4362                 :             :    If F returns a nonzero value, the traversal ceases, and that value
    4363                 :             :    is returned.  Otherwise, returns zero.  */
    4364                 :             : 
    4365                 :             : static int
    4366                 :    47230286 : walk_subobject_offsets (tree type,
    4367                 :             :                         subobject_offset_fn f,
    4368                 :             :                         tree offset,
    4369                 :             :                         splay_tree offsets,
    4370                 :             :                         tree max_offset,
    4371                 :             :                         int vbases_p)
    4372                 :             : {
    4373                 :    47230286 :   int r = 0;
    4374                 :    47230286 :   tree type_binfo = NULL_TREE;
    4375                 :             : 
    4376                 :             :   /* If this OFFSET is bigger than the MAX_OFFSET, then we should
    4377                 :             :      stop.  */
    4378                 :    47230286 :   if (max_offset && tree_int_cst_lt (max_offset, offset))
    4379                 :             :     return 0;
    4380                 :             : 
    4381                 :    39113938 :   if (type == error_mark_node)
    4382                 :             :     return 0;
    4383                 :             : 
    4384                 :    39113938 :   if (!TYPE_P (type))
    4385                 :             :     {
    4386                 :     5069457 :       type_binfo = type;
    4387                 :     5069457 :       type = BINFO_TYPE (type);
    4388                 :             :     }
    4389                 :             : 
    4390                 :    39113938 :   if (CLASS_TYPE_P (type))
    4391                 :             :     {
    4392                 :    29163695 :       tree field;
    4393                 :    29163695 :       tree binfo;
    4394                 :    29163695 :       int i;
    4395                 :             : 
    4396                 :             :       /* Avoid recursing into objects that are not interesting.  */
    4397                 :    29163695 :       if (!CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    4398                 :             :         return 0;
    4399                 :             : 
    4400                 :             :       /* Record the location of TYPE.  */
    4401                 :    25101882 :       r = (*f) (type, offset, offsets);
    4402                 :    25101882 :       if (r)
    4403                 :             :         return r;
    4404                 :             : 
    4405                 :             :       /* Iterate through the direct base classes of TYPE.  */
    4406                 :    25100252 :       if (!type_binfo)
    4407                 :    20915002 :         type_binfo = TYPE_BINFO (type);
    4408                 :    30040112 :       for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, binfo); i++)
    4409                 :             :         {
    4410                 :     4940802 :           tree binfo_offset;
    4411                 :             : 
    4412                 :     4940802 :           if (BINFO_VIRTUAL_P (binfo))
    4413                 :        1587 :             continue;
    4414                 :             : 
    4415                 :     4939215 :           tree orig_binfo;
    4416                 :             :           /* We cannot rely on BINFO_OFFSET being set for the base
    4417                 :             :              class yet, but the offsets for direct non-virtual
    4418                 :             :              bases can be calculated by going back to the TYPE.  */
    4419                 :     4939215 :           orig_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
    4420                 :     4939215 :           binfo_offset = size_binop (PLUS_EXPR,
    4421                 :             :                                      offset,
    4422                 :             :                                      BINFO_OFFSET (orig_binfo));
    4423                 :             : 
    4424                 :     4939215 :           r = walk_subobject_offsets (binfo,
    4425                 :             :                                       f,
    4426                 :             :                                       binfo_offset,
    4427                 :             :                                       offsets,
    4428                 :             :                                       max_offset,
    4429                 :             :                                       /*vbases_p=*/0);
    4430                 :     4939215 :           if (r)
    4431                 :             :             return r;
    4432                 :             :         }
    4433                 :             : 
    4434                 :    25099310 :       if (CLASSTYPE_VBASECLASSES (type))
    4435                 :             :         {
    4436                 :        1298 :           unsigned ix;
    4437                 :        1298 :           vec<tree, va_gc> *vbases;
    4438                 :             : 
    4439                 :             :           /* Iterate through the virtual base classes of TYPE.  In G++
    4440                 :             :              3.2, we included virtual bases in the direct base class
    4441                 :             :              loop above, which results in incorrect results; the
    4442                 :             :              correct offsets for virtual bases are only known when
    4443                 :             :              working with the most derived type.  */
    4444                 :        1298 :           if (vbases_p)
    4445                 :          30 :             for (vbases = CLASSTYPE_VBASECLASSES (type), ix = 0;
    4446                 :          30 :                  vec_safe_iterate (vbases, ix, &binfo); ix++)
    4447                 :             :               {
    4448                 :          15 :                 r = walk_subobject_offsets (binfo,
    4449                 :             :                                             f,
    4450                 :          15 :                                             size_binop (PLUS_EXPR,
    4451                 :             :                                                         offset,
    4452                 :             :                                                         BINFO_OFFSET (binfo)),
    4453                 :             :                                             offsets,
    4454                 :             :                                             max_offset,
    4455                 :             :                                             /*vbases_p=*/0);
    4456                 :          15 :                 if (r)
    4457                 :             :                   return r;
    4458                 :             :               }
    4459                 :             :           else
    4460                 :             :             {
    4461                 :             :               /* We still have to walk the primary base, if it is
    4462                 :             :                  virtual.  (If it is non-virtual, then it was walked
    4463                 :             :                  above.)  */
    4464                 :        1283 :               tree vbase = get_primary_binfo (type_binfo);
    4465                 :             : 
    4466                 :         395 :               if (vbase && BINFO_VIRTUAL_P (vbase)
    4467                 :         234 :                   && BINFO_PRIMARY_P (vbase)
    4468                 :        1517 :                   && BINFO_INHERITANCE_CHAIN (vbase) == type_binfo)
    4469                 :             :                 {
    4470                 :         200 :                   r = (walk_subobject_offsets
    4471                 :         200 :                        (vbase, f, offset,
    4472                 :             :                         offsets, max_offset, /*vbases_p=*/0));
    4473                 :         200 :                   if (r)
    4474                 :             :                     return r;
    4475                 :             :                 }
    4476                 :             :             }
    4477                 :             :         }
    4478                 :             : 
    4479                 :             :       /* Iterate through the fields of TYPE.  */
    4480                 :   485518479 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    4481                 :   460419384 :         if (TREE_CODE (field) == FIELD_DECL
    4482                 :    10162345 :             && TREE_TYPE (field) != error_mark_node
    4483                 :   470581703 :             && !DECL_ARTIFICIAL (field))
    4484                 :             :           {
    4485                 :     5192325 :             tree field_offset;
    4486                 :             : 
    4487                 :     5192325 :             field_offset = byte_position (field);
    4488                 :             : 
    4489                 :     5192325 :             r = walk_subobject_offsets (TREE_TYPE (field),
    4490                 :             :                                         f,
    4491                 :             :                                         size_binop (PLUS_EXPR,
    4492                 :             :                                                     offset,
    4493                 :             :                                                     field_offset),
    4494                 :             :                                         offsets,
    4495                 :             :                                         max_offset,
    4496                 :             :                                         /*vbases_p=*/1);
    4497                 :     5192325 :             if (r)
    4498                 :             :               return r;
    4499                 :             :           }
    4500                 :             :     }
    4501                 :     9950243 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    4502                 :             :     {
    4503                 :      635491 :       tree element_type = strip_array_types (type);
    4504                 :      635491 :       tree domain = TYPE_DOMAIN (type);
    4505                 :      635491 :       tree index;
    4506                 :             : 
    4507                 :             :       /* Avoid recursing into objects that are not interesting.  */
    4508                 :       27029 :       if (!CLASS_TYPE_P (element_type)
    4509                 :       27018 :           || !CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type)
    4510                 :       12610 :           || !domain
    4511                 :      648082 :           || integer_minus_onep (TYPE_MAX_VALUE (domain)))
    4512                 :      623117 :         return 0;
    4513                 :             : 
    4514                 :             :       /* Step through each of the elements in the array.  */
    4515                 :       12374 :       for (index = size_zero_node;
    4516                 :       35948 :            !tree_int_cst_lt (TYPE_MAX_VALUE (domain), index);
    4517                 :       23574 :            index = size_binop (PLUS_EXPR, index, size_one_node))
    4518                 :             :         {
    4519                 :       34808 :           r = walk_subobject_offsets (TREE_TYPE (type),
    4520                 :             :                                       f,
    4521                 :             :                                       offset,
    4522                 :             :                                       offsets,
    4523                 :             :                                       max_offset,
    4524                 :             :                                       /*vbases_p=*/1);
    4525                 :       34808 :           if (r)
    4526                 :             :             return r;
    4527                 :       34808 :           offset = size_binop (PLUS_EXPR, offset,
    4528                 :             :                                TYPE_SIZE_UNIT (TREE_TYPE (type)));
    4529                 :             :           /* If this new OFFSET is bigger than the MAX_OFFSET, then
    4530                 :             :              there's no point in iterating through the remaining
    4531                 :             :              elements of the array.  */
    4532                 :       34808 :           if (max_offset && tree_int_cst_lt (max_offset, offset))
    4533                 :             :             break;
    4534                 :             :         }
    4535                 :             :     }
    4536                 :             : 
    4537                 :             :   return 0;
    4538                 :             : }
    4539                 :             : 
    4540                 :             : /* Return true iff FIELD_DECL DECL is potentially overlapping.  */
    4541                 :             : 
    4542                 :             : static bool
    4543                 :    66930289 : field_poverlapping_p (tree decl)
    4544                 :             : {
    4545                 :             :   /* Base fields are actually potentially overlapping, but C++ bases go through
    4546                 :             :      a different code path based on binfos, and ObjC++ base fields are laid out
    4547                 :             :      in objc-act, so we don't want layout_class_type to mess with them.  */
    4548                 :    66930289 :   if (DECL_FIELD_IS_BASE (decl))
    4549                 :             :     {
    4550                 :           0 :       gcc_checking_assert (c_dialect_objc ());
    4551                 :             :       return false;
    4552                 :             :     }
    4553                 :             : 
    4554                 :    66930289 :   return lookup_attribute ("no_unique_address",
    4555                 :   133860578 :                            DECL_ATTRIBUTES (decl));
    4556                 :             : }
    4557                 :             : 
    4558                 :             : /* Return true iff DECL is an empty field, either for an empty base or a
    4559                 :             :    [[no_unique_address]] data member.  */
    4560                 :             : 
    4561                 :             : bool
    4562                 :   206720313 : is_empty_field (tree decl)
    4563                 :             : {
    4564                 :   206720313 :   if (!decl || TREE_CODE (decl) != FIELD_DECL)
    4565                 :             :     return false;
    4566                 :             : 
    4567                 :    92817842 :   bool r = (is_empty_class (TREE_TYPE (decl))
    4568                 :    95030431 :             && (DECL_FIELD_IS_BASE (decl)
    4569                 :      496052 :                 || field_poverlapping_p (decl)));
    4570                 :             : 
    4571                 :             :   /* Empty fields should have size zero.  */
    4572                 :     2083674 :   gcc_checking_assert (!r || integer_zerop (DECL_SIZE (decl)));
    4573                 :             : 
    4574                 :             :   return r;
    4575                 :             : }
    4576                 :             : 
    4577                 :             : /* Record all of the empty subobjects of DECL_OR_BINFO.  */
    4578                 :             : 
    4579                 :             : static void
    4580                 :    35009076 : record_subobject_offsets (tree decl_or_binfo,
    4581                 :             :                           splay_tree offsets)
    4582                 :             : {
    4583                 :    35009076 :   tree type, offset;
    4584                 :    35009076 :   bool overlapping, vbases_p;
    4585                 :             : 
    4586                 :    35009076 :   if (DECL_P (decl_or_binfo))
    4587                 :             :     {
    4588                 :    15476756 :       tree decl = decl_or_binfo;
    4589                 :    15476756 :       type = TREE_TYPE (decl);
    4590                 :    15476756 :       offset = byte_position (decl);
    4591                 :    15476756 :       overlapping = field_poverlapping_p (decl);
    4592                 :    15476756 :       vbases_p = true;
    4593                 :             :     }
    4594                 :             :   else
    4595                 :             :     {
    4596                 :    19532320 :       type = BINFO_TYPE (decl_or_binfo);
    4597                 :    19532320 :       offset = BINFO_OFFSET (decl_or_binfo);
    4598                 :    19532320 :       overlapping = true;
    4599                 :    19532320 :       vbases_p = false;
    4600                 :             :     }
    4601                 :             : 
    4602                 :    35009076 :   tree max_offset;
    4603                 :             :   /* If recording subobjects for a non-static data member or a
    4604                 :             :      non-empty base class, we do not need to record offsets beyond
    4605                 :             :      the size of the biggest empty class.  Additional data members
    4606                 :             :      will go at the end of the class.  Additional base classes will go
    4607                 :             :      either at offset zero (if empty, in which case they cannot
    4608                 :             :      overlap with offsets past the size of the biggest empty class) or
    4609                 :             :      at the end of the class.
    4610                 :             : 
    4611                 :             :      However, if we are placing an empty base class, then we must record
    4612                 :             :      all offsets, as either the empty class is at offset zero (where
    4613                 :             :      other empty classes might later be placed) or at the end of the
    4614                 :             :      class (where other objects might then be placed, so other empty
    4615                 :             :      subobjects might later overlap).  */
    4616                 :    19532320 :   if (!overlapping
    4617                 :    35009076 :       || !is_empty_class (type))
    4618                 :    17661924 :     max_offset = sizeof_biggest_empty_class;
    4619                 :             :   else
    4620                 :             :     max_offset = NULL_TREE;
    4621                 :    35009076 :   walk_subobject_offsets (type, record_subobject_offset, offset,
    4622                 :             :                           offsets, max_offset, vbases_p);
    4623                 :    35009076 : }
    4624                 :             : 
    4625                 :             : /* Returns nonzero if any of the empty subobjects of TYPE (located at
    4626                 :             :    OFFSET) conflict with entries in OFFSETS.  If VBASES_P is nonzero,
    4627                 :             :    virtual bases of TYPE are examined.  */
    4628                 :             : 
    4629                 :             : static int
    4630                 :    33982039 : layout_conflict_p (tree type,
    4631                 :             :                    tree offset,
    4632                 :             :                    splay_tree offsets,
    4633                 :             :                    int vbases_p)
    4634                 :             : {
    4635                 :    33982039 :   splay_tree_node max_node;
    4636                 :             : 
    4637                 :             :   /* Get the node in OFFSETS that indicates the maximum offset where
    4638                 :             :      an empty subobject is located.  */
    4639                 :    33982039 :   max_node = splay_tree_max (offsets);
    4640                 :             :   /* If there aren't any empty subobjects, then there's no point in
    4641                 :             :      performing this check.  */
    4642                 :    33982039 :   if (!max_node)
    4643                 :             :     return 0;
    4644                 :             : 
    4645                 :     2054317 :   return walk_subobject_offsets (type, check_subobject_offset, offset,
    4646                 :     2054317 :                                  offsets, (tree) (max_node->key),
    4647                 :     2054317 :                                  vbases_p);
    4648                 :             : }
    4649                 :             : 
    4650                 :             : /* DECL is a FIELD_DECL corresponding either to a base subobject of a
    4651                 :             :    non-static data member of the type indicated by RLI.  BINFO is the
    4652                 :             :    binfo corresponding to the base subobject, OFFSETS maps offsets to
    4653                 :             :    types already located at those offsets.  This function determines
    4654                 :             :    the position of the DECL.  */
    4655                 :             : 
    4656                 :             : static void
    4657                 :    17662692 : layout_nonempty_base_or_field (record_layout_info rli,
    4658                 :             :                                tree decl,
    4659                 :             :                                tree binfo,
    4660                 :             :                                splay_tree offsets)
    4661                 :             : {
    4662                 :    17662692 :   tree offset = NULL_TREE;
    4663                 :    17662692 :   bool field_p;
    4664                 :    17662692 :   tree type;
    4665                 :             : 
    4666                 :    17662692 :   if (binfo)
    4667                 :             :     {
    4668                 :             :       /* For the purposes of determining layout conflicts, we want to
    4669                 :             :          use the class type of BINFO; TREE_TYPE (DECL) will be the
    4670                 :             :          CLASSTYPE_AS_BASE version, which does not contain entries for
    4671                 :             :          zero-sized bases.  */
    4672                 :     2356873 :       type = TREE_TYPE (binfo);
    4673                 :     2356873 :       field_p = false;
    4674                 :             :     }
    4675                 :             :   else
    4676                 :             :     {
    4677                 :    15305819 :       type = TREE_TYPE (decl);
    4678                 :    15305819 :       field_p = true;
    4679                 :             :     }
    4680                 :             : 
    4681                 :             :   /* Try to place the field.  It may take more than one try if we have
    4682                 :             :      a hard time placing the field without putting two objects of the
    4683                 :             :      same type at the same address.  */
    4684                 :         230 :   while (1)
    4685                 :             :     {
    4686                 :    17662922 :       struct record_layout_info_s old_rli = *rli;
    4687                 :             : 
    4688                 :             :       /* Place this field.  */
    4689                 :    17662922 :       place_field (rli, decl);
    4690                 :    17662922 :       offset = byte_position (decl);
    4691                 :             : 
    4692                 :             :       /* We have to check to see whether or not there is already
    4693                 :             :          something of the same type at the offset we're about to use.
    4694                 :             :          For example, consider:
    4695                 :             : 
    4696                 :             :            struct S {};
    4697                 :             :            struct T : public S { int i; };
    4698                 :             :            struct U : public S, public T {};
    4699                 :             : 
    4700                 :             :          Here, we put S at offset zero in U.  Then, we can't put T at
    4701                 :             :          offset zero -- its S component would be at the same address
    4702                 :             :          as the S we already allocated.  So, we have to skip ahead.
    4703                 :             :          Since all data members, including those whose type is an
    4704                 :             :          empty class, have nonzero size, any overlap can happen only
    4705                 :             :          with a direct or indirect base-class -- it can't happen with
    4706                 :             :          a data member.  */
    4707                 :             :       /* In a union, overlap is permitted; all members are placed at
    4708                 :             :          offset zero.  */
    4709                 :    17662922 :       if (TREE_CODE (rli->t) == UNION_TYPE)
    4710                 :             :         break;
    4711                 :    18991555 :       if (layout_conflict_p (field_p ? type : binfo, offset,
    4712                 :             :                              offsets, field_p))
    4713                 :             :         {
    4714                 :             :           /* Strip off the size allocated to this field.  That puts us
    4715                 :             :              at the first place we could have put the field with
    4716                 :             :              proper alignment.  */
    4717                 :         230 :           *rli = old_rli;
    4718                 :             : 
    4719                 :             :           /* Bump up by the alignment required for the type.  */
    4720                 :         230 :           rli->bitpos
    4721                 :         230 :             = size_binop (PLUS_EXPR, rli->bitpos,
    4722                 :             :                           bitsize_int (binfo
    4723                 :             :                                        ? CLASSTYPE_ALIGN (type)
    4724                 :             :                                        : TYPE_ALIGN (type)));
    4725                 :         230 :           normalize_rli (rli);
    4726                 :             :         }
    4727                 :    16634393 :       else if (TREE_CODE (type) == NULLPTR_TYPE
    4728                 :       88084 :                && warn_abi && abi_version_crosses (9))
    4729                 :             :         {
    4730                 :             :           /* Before ABI v9, we were giving nullptr_t alignment of 1; if
    4731                 :             :              the offset wasn't aligned like a pointer when we started to
    4732                 :             :              layout this field, that affects its position.  */
    4733                 :          12 :           tree pos = rli_size_unit_so_far (&old_rli);
    4734                 :          12 :           if (int_cst_value (pos) % TYPE_ALIGN_UNIT (ptr_type_node) != 0)
    4735                 :             :             {
    4736                 :           3 :               if (abi_version_at_least (9))
    4737                 :           3 :                 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wabi,
    4738                 :             :                             "alignment of %qD increased in %<-fabi-version=9%> "
    4739                 :             :                             "(GCC 5.2)", decl);
    4740                 :             :               else
    4741                 :           0 :                 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wabi, "alignment "
    4742                 :             :                             "of %qD will increase in %<-fabi-version=9%>",
    4743                 :             :                             decl);
    4744                 :             :             }
    4745                 :             :           break;
    4746                 :             :         }
    4747                 :             :       else
    4748                 :             :         /* There was no conflict.  We're done laying out this field.  */
    4749                 :             :         break;
    4750                 :             :     }
    4751                 :             : 
    4752                 :             :   /* Now that we know where it will be placed, update its
    4753                 :             :      BINFO_OFFSET.  */
    4754                 :    20019565 :   if (binfo && CLASS_TYPE_P (BINFO_TYPE (binfo)))
    4755                 :             :     /* Indirect virtual bases may have a nonzero BINFO_OFFSET at
    4756                 :             :        this point because their BINFO_OFFSET is copied from another
    4757                 :             :        hierarchy.  Therefore, we may not need to add the entire
    4758                 :             :        OFFSET.  */
    4759                 :     2356873 :     propagate_binfo_offsets (binfo,
    4760                 :             :                              size_diffop_loc (input_location,
    4761                 :             :                                           fold_convert (ssizetype, offset),
    4762                 :     2356873 :                                           fold_convert (ssizetype,
    4763                 :             :                                                    BINFO_OFFSET (binfo))));
    4764                 :    17662692 : }
    4765                 :             : 
    4766                 :             : /* Returns true if TYPE is empty and OFFSET is nonzero.  */
    4767                 :             : 
    4768                 :             : static int
    4769                 :         433 : empty_base_at_nonzero_offset_p (tree type,
    4770                 :             :                                 tree offset,
    4771                 :             :                                 splay_tree /*offsets*/)
    4772                 :             : {
    4773                 :         433 :   return is_empty_class (type) && !integer_zerop (offset);
    4774                 :             : }
    4775                 :             : 
    4776                 :             : /* Layout the empty base BINFO.  EOC indicates the byte currently just
    4777                 :             :    past the end of the class, and should be correctly aligned for a
    4778                 :             :    class of the type indicated by BINFO; OFFSETS gives the offsets of
    4779                 :             :    the empty bases allocated so far. T is the most derived
    4780                 :             :    type.  Return nonzero iff we added it at the end.  */
    4781                 :             : 
    4782                 :             : static bool
    4783                 :    17347152 : layout_empty_base_or_field (record_layout_info rli, tree binfo_or_decl,
    4784                 :             :                             splay_tree offsets)
    4785                 :             : {
    4786                 :    17347152 :   tree alignment;
    4787                 :    17347152 :   bool atend = false;
    4788                 :    17347152 :   tree binfo = NULL_TREE;
    4789                 :    17347152 :   tree decl = NULL_TREE;
    4790                 :    17347152 :   tree type;
    4791                 :    17347152 :   if (TREE_CODE (binfo_or_decl) == TREE_BINFO)
    4792                 :             :     {
    4793                 :    17175447 :       binfo = binfo_or_decl;
    4794                 :    17175447 :       type = BINFO_TYPE (binfo);
    4795                 :             :     }
    4796                 :             :   else
    4797                 :             :     {
    4798                 :      171705 :       decl = binfo_or_decl;
    4799                 :      171705 :       type = TREE_TYPE (decl);
    4800                 :             :     }
    4801                 :             : 
    4802                 :             :   /* On some platforms (ARM), even empty classes will not be
    4803                 :             :      byte-aligned.  */
    4804                 :    17347152 :   tree eoc = round_up_loc (input_location,
    4805                 :             :                            rli_size_unit_so_far (rli),
    4806                 :    17347152 :                            CLASSTYPE_ALIGN_UNIT (type));
    4807                 :             : 
    4808                 :             :   /* This routine should only be used for empty classes.  */
    4809                 :    17347152 :   gcc_assert (is_empty_class (type));
    4810                 :             : 
    4811                 :    17347152 :   if (decl && DECL_USER_ALIGN (decl))
    4812                 :           3 :     alignment = size_int (DECL_ALIGN_UNIT (decl));
    4813                 :             :   else
    4814                 :    17347149 :     alignment = size_int (CLASSTYPE_ALIGN_UNIT (type));
    4815                 :             : 
    4816                 :             :   /* This is an empty base class.  We first try to put it at offset
    4817                 :             :      zero.  */
    4818                 :    17347152 :   tree offset = size_zero_node;
    4819                 :    17347152 :   if (TREE_CODE (rli->t) != UNION_TYPE
    4820                 :    17347152 :       && layout_conflict_p (type,
    4821                 :             :                             offset,
    4822                 :             :                             offsets,
    4823                 :             :                             /*vbases_p=*/0))
    4824                 :             :     {
    4825                 :             :       /* That didn't work.  Now, we move forward from the next
    4826                 :             :          available spot in the class.  */
    4827                 :        1394 :       atend = true;
    4828                 :             :       offset = eoc;
    4829                 :        2006 :       while (1)
    4830                 :             :         {
    4831                 :        1394 :           if (!layout_conflict_p (type,
    4832                 :             :                                   offset,
    4833                 :             :                                   offsets,
    4834                 :             :                                   /*vbases_p=*/0))
    4835                 :             :             /* We finally found a spot where there's no overlap.  */
    4836                 :             :             break;
    4837                 :             : 
    4838                 :             :           /* There's overlap here, too.  Bump along to the next spot.  */
    4839                 :         612 :           offset = size_binop (PLUS_EXPR, offset, alignment);
    4840                 :             :         }
    4841                 :             :     }
    4842                 :             : 
    4843                 :    17347152 :   if (decl && DECL_USER_ALIGN (decl))
    4844                 :             :     {
    4845                 :           3 :       rli->record_align = MAX (rli->record_align, DECL_ALIGN (decl));
    4846                 :           3 :       if (warn_packed)
    4847                 :           0 :         rli->unpacked_align = MAX (rli->unpacked_align, DECL_ALIGN (decl));
    4848                 :           3 :       TYPE_USER_ALIGN (rli->t) = 1;
    4849                 :             :     }
    4850                 :    17347149 :   else if (CLASSTYPE_USER_ALIGN (type))
    4851                 :             :     {
    4852                 :          21 :       rli->record_align = MAX (rli->record_align, CLASSTYPE_ALIGN (type));
    4853                 :          21 :       if (warn_packed)
    4854                 :           0 :         rli->unpacked_align = MAX (rli->unpacked_align, CLASSTYPE_ALIGN (type));
    4855                 :          21 :       TYPE_USER_ALIGN (rli->t) = 1;
    4856                 :             :     }
    4857                 :             : 
    4858                 :    17347152 :   if (binfo)
    4859                 :             :     /* Adjust BINFO_OFFSET (binfo) to be exactly OFFSET.  */
    4860                 :    34350894 :     propagate_binfo_offsets (binfo,
    4861                 :    17175447 :                              size_diffop (offset, BINFO_OFFSET (binfo)));
    4862                 :             :   else
    4863                 :             :     {
    4864                 :      171705 :       DECL_FIELD_OFFSET (decl) = offset;
    4865                 :      171705 :       DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    4866                 :      171705 :       SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    4867                 :             :     }
    4868                 :             : 
    4869                 :    17347152 :   return atend;
    4870                 :             : }
    4871                 :             : 
    4872                 :             : /* Build the FIELD_DECL for BASETYPE as a base of T, add it to the chain of
    4873                 :             :    fields at NEXT_FIELD, and return it.  */
    4874                 :             : 
    4875                 :             : static tree
    4876                 :    19459306 : build_base_field_1 (tree t, tree binfo, tree access, tree *&next_field)
    4877                 :             : {
    4878                 :             :   /* Create the FIELD_DECL.  */
    4879                 :    19459306 :   tree basetype = BINFO_TYPE (binfo);
    4880                 :    19459306 :   tree as_base = CLASSTYPE_AS_BASE (basetype);
    4881                 :    19459306 :   gcc_assert (as_base);
    4882                 :    19459306 :   tree decl = build_decl (input_location, FIELD_DECL, NULL_TREE, as_base);
    4883                 :             : 
    4884                 :    19459306 :   DECL_ARTIFICIAL (decl) = 1;
    4885                 :    19459306 :   DECL_IGNORED_P (decl) = 1;
    4886                 :    19459306 :   DECL_FIELD_CONTEXT (decl) = t;
    4887                 :    19459306 :   if (is_empty_class (basetype))
    4888                 :             :     /* CLASSTYPE_SIZE is one byte, but the field needs to have size zero.  */
    4889                 :    17102433 :     DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = size_zero_node;
    4890                 :             :   else
    4891                 :             :     {
    4892                 :     2356873 :       DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
    4893                 :     2356873 :       DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
    4894                 :             :     }
    4895                 :    19459306 :   SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype));
    4896                 :    19459306 :   DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
    4897                 :    19459306 :   SET_DECL_MODE (decl, TYPE_MODE (basetype));
    4898                 :    19459306 :   DECL_FIELD_IS_BASE (decl) = 1;
    4899                 :             : 
    4900                 :    19459306 :   if (access == access_private_node)
    4901                 :      614701 :     TREE_PRIVATE (decl) = true;
    4902                 :    18844605 :   else if (access == access_protected_node)
    4903                 :       69009 :     TREE_PROTECTED (decl) = true;
    4904                 :             : 
    4905                 :             :   /* Add the new FIELD_DECL to the list of fields for T.  */
    4906                 :    19459306 :   DECL_CHAIN (decl) = *next_field;
    4907                 :    19459306 :   *next_field = decl;
    4908                 :    19459306 :   next_field = &DECL_CHAIN (decl);
    4909                 :             : 
    4910                 :    19459306 :   return decl;
    4911                 :             : }
    4912                 :             : 
    4913                 :             : /* Layout the base given by BINFO in the class indicated by RLI.
    4914                 :             :    *BASE_ALIGN is a running maximum of the alignments of
    4915                 :             :    any base class.  OFFSETS gives the location of empty base
    4916                 :             :    subobjects.  T is the most derived type.  Return nonzero if the new
    4917                 :             :    object cannot be nearly-empty.  A new FIELD_DECL is inserted at
    4918                 :             :    *NEXT_FIELD, unless BINFO is for an empty base class.
    4919                 :             : 
    4920                 :             :    Returns the location at which the next field should be inserted.  */
    4921                 :             : 
    4922                 :             : static tree *
    4923                 :    19532320 : build_base_field (record_layout_info rli, tree binfo, tree access,
    4924                 :             :                   splay_tree offsets, tree *next_field)
    4925                 :             : {
    4926                 :    19532320 :   tree t = rli->t;
    4927                 :    19532320 :   tree basetype = BINFO_TYPE (binfo);
    4928                 :             : 
    4929                 :    19532320 :   if (!COMPLETE_TYPE_P (basetype))
    4930                 :             :     /* This error is now reported in xref_tag, thus giving better
    4931                 :             :        location information.  */
    4932                 :           0 :     return next_field;
    4933                 :             : 
    4934                 :             :   /* Place the base class.  */
    4935                 :    19532320 :   if (!is_empty_class (basetype))
    4936                 :             :     {
    4937                 :     2356873 :       tree decl;
    4938                 :             : 
    4939                 :             :       /* The containing class is non-empty because it has a non-empty
    4940                 :             :          base class.  */
    4941                 :     2356873 :       CLASSTYPE_EMPTY_P (t) = 0;
    4942                 :             : 
    4943                 :             :       /* Create the FIELD_DECL.  */
    4944                 :     2356873 :       decl = build_base_field_1 (t, binfo, access, next_field);
    4945                 :             : 
    4946                 :             :       /* Try to place the field.  It may take more than one try if we
    4947                 :             :          have a hard time placing the field without putting two
    4948                 :             :          objects of the same type at the same address.  */
    4949                 :     2356873 :       layout_nonempty_base_or_field (rli, decl, binfo, offsets);
    4950                 :             :     }
    4951                 :             :   else
    4952                 :             :     {
    4953                 :    17175447 :       bool atend = layout_empty_base_or_field (rli, binfo, offsets);
    4954                 :             :       /* A nearly-empty class "has no proper base class that is empty,
    4955                 :             :          not morally virtual, and at an offset other than zero."  */
    4956                 :    17175447 :       if (!BINFO_VIRTUAL_P (binfo) && CLASSTYPE_NEARLY_EMPTY_P (t))
    4957                 :             :         {
    4958                 :         424 :           if (atend)
    4959                 :          94 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4960                 :             :           /* The check above (used in G++ 3.2) is insufficient because
    4961                 :             :              an empty class placed at offset zero might itself have an
    4962                 :             :              empty base at a nonzero offset.  */
    4963                 :         330 :           else if (walk_subobject_offsets (basetype,
    4964                 :             :                                            empty_base_at_nonzero_offset_p,
    4965                 :             :                                            size_zero_node,
    4966                 :             :                                            /*offsets=*/NULL,
    4967                 :             :                                            /*max_offset=*/NULL_TREE,
    4968                 :             :                                            /*vbases_p=*/true))
    4969                 :           6 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4970                 :             :         }
    4971                 :             : 
    4972                 :             :       /* We used to not create a FIELD_DECL for empty base classes because of
    4973                 :             :          back end issues with overlapping FIELD_DECLs, but that doesn't seem to
    4974                 :             :          be a problem anymore.  We need them to handle initialization of C++17
    4975                 :             :          aggregate bases.  */
    4976                 :    34279527 :       if (cxx_dialect >= cxx17 && !BINFO_VIRTUAL_P (binfo))
    4977                 :             :         {
    4978                 :    17102433 :           tree decl = build_base_field_1 (t, binfo, access, next_field);
    4979                 :    17102433 :           DECL_FIELD_OFFSET (decl) = BINFO_OFFSET (binfo);
    4980                 :    17102433 :           DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    4981                 :    17102433 :           SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    4982                 :    17102433 :           SET_DECL_FIELD_ABI_IGNORED (decl, 1);
    4983                 :             :         }
    4984                 :             : 
    4985                 :             :       /* An empty virtual base causes a class to be non-empty
    4986                 :             :          -- but in that case we do not need to clear CLASSTYPE_EMPTY_P
    4987                 :             :          here because that was already done when the virtual table
    4988                 :             :          pointer was created.  */
    4989                 :             :     }
    4990                 :             : 
    4991                 :             :   /* Record the offsets of BINFO and its base subobjects.  */
    4992                 :    19532320 :   record_subobject_offsets (binfo, offsets);
    4993                 :             : 
    4994                 :    19532320 :   return next_field;
    4995                 :             : }
    4996                 :             : 
    4997                 :             : /* Layout all of the non-virtual base classes.  Record empty
    4998                 :             :    subobjects in OFFSETS.  T is the most derived type.  Return nonzero
    4999                 :             :    if the type cannot be nearly empty.  The fields created
    5000                 :             :    corresponding to the base classes will be inserted at
    5001                 :             :    *NEXT_FIELD.  */
    5002                 :             : 
    5003                 :             : static void
    5004                 :    37061824 : build_base_fields (record_layout_info rli,
    5005                 :             :                    splay_tree offsets, tree *next_field)
    5006                 :             : {
    5007                 :             :   /* Chain to hold all the new FIELD_DECLs which stand in for base class
    5008                 :             :      subobjects.  */
    5009                 :    37061824 :   tree t = rli->t;
    5010                 :    37061824 :   tree binfo = TYPE_BINFO (t);
    5011                 :    37061824 :   int n_baseclasses = BINFO_N_BASE_BINFOS (binfo);
    5012                 :             : 
    5013                 :             :   /* The primary base class is always allocated first.  */
    5014                 :    37061824 :   const tree primary_binfo = CLASSTYPE_PRIMARY_BINFO (t);
    5015                 :    37061824 :   if (primary_binfo)
    5016                 :             :     {
    5017                 :             :       /* We need to walk BINFO_BASE_BINFO to find the access of the primary
    5018                 :             :          base, if it is direct.  Indirect base fields are private.  */
    5019                 :     1417870 :       tree primary_access = access_private_node;
    5020                 :     1418740 :       for (int i = 0; i < n_baseclasses; ++i)
    5021                 :             :         {
    5022                 :     1418671 :           tree base_binfo = BINFO_BASE_BINFO (binfo, i);
    5023                 :     1418671 :           if (base_binfo == primary_binfo)
    5024                 :             :             {
    5025                 :     1417801 :               primary_access = BINFO_BASE_ACCESS (binfo, i);
    5026                 :     1417801 :               break;
    5027                 :             :             }
    5028                 :             :         }
    5029                 :     1417870 :       next_field = build_base_field (rli, primary_binfo,
    5030                 :             :                                      primary_access,
    5031                 :             :                                      offsets, next_field);
    5032                 :             :     }
    5033                 :             : 
    5034                 :             :   /* Now allocate the rest of the bases.  */
    5035                 :    56447374 :   for (int i = 0; i < n_baseclasses; ++i)
    5036                 :             :     {
    5037                 :    19385550 :       tree base_binfo = BINFO_BASE_BINFO (binfo, i);
    5038                 :             : 
    5039                 :             :       /* The primary base was already allocated above, so we don't
    5040                 :             :          need to allocate it again here.  */
    5041                 :    19385550 :       if (base_binfo == primary_binfo)
    5042                 :     1417801 :        continue;
    5043                 :             : 
    5044                 :             :       /* Virtual bases are added at the end (a primary virtual base
    5045                 :             :          will have already been added).  */
    5046                 :    17967749 :       if (BINFO_VIRTUAL_P (base_binfo))
    5047                 :       45836 :         continue;
    5048                 :             : 
    5049                 :    17921913 :       next_field = build_base_field (rli, base_binfo,
    5050                 :    17921913 :                                      BINFO_BASE_ACCESS (binfo, i),
    5051                 :             :                                      offsets, next_field);
    5052                 :             :     }
    5053                 :    37061824 : }
    5054                 :             : 
    5055                 :             : /* Go through the TYPE_FIELDS of T issuing any appropriate
    5056                 :             :    diagnostics, figuring out which methods override which other
    5057                 :             :    methods, and so forth.  */
    5058                 :             : 
    5059                 :             : static void
    5060                 :    37061824 : check_methods (tree t)
    5061                 :             : {
    5062                 :   260575625 :   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    5063                 :   223513801 :     if (DECL_DECLARES_FUNCTION_P (x))
    5064                 :             :       {
    5065                 :   114921751 :         check_for_override (x, t);
    5066                 :             : 
    5067                 :   114921751 :         if (DECL_PURE_VIRTUAL_P (x)
    5068                 :   114921751 :             && (TREE_CODE (x) != FUNCTION_DECL || ! DECL_VINDEX (x)))
    5069                 :           3 :           error ("initializer specified for non-virtual method %q+D", x);
    5070                 :             :         /* The name of the field is the original field name
    5071                 :             :            Save this in auxiliary field for later overloading.  */
    5072                 :   114921751 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_VINDEX (x))
    5073                 :             :           {
    5074                 :     5861150 :             TYPE_POLYMORPHIC_P (t) = 1;
    5075                 :     5861150 :             if (DECL_PURE_VIRTUAL_P (x))
    5076                 :      632520 :               vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    5077                 :             :           }
    5078                 :             : 
    5079                 :   114921751 :         if (!DECL_VIRTUAL_P (x)
    5080                 :   223982368 :             && lookup_attribute ("transaction_safe_dynamic",
    5081                 :   109060617 :                                  DECL_ATTRIBUTES (x)))
    5082                 :           2 :           error_at (DECL_SOURCE_LOCATION (x),
    5083                 :             :                     "%<transaction_safe_dynamic%> may only be specified for "
    5084                 :             :                     "a virtual function");
    5085                 :             :       }
    5086                 :             : 
    5087                 :             :   /* Check whether the eligible special member functions (P0848) are
    5088                 :             :      user-provided.  add_method arranged that the CLASSTYPE_MEMBER_VEC only
    5089                 :             :      has the eligible ones, unless none are eligible; TYPE_FIELDS also contains
    5090                 :             :      ineligible overloads, which is why this needs to be separate from the loop
    5091                 :             :      above.  */
    5092                 :             : 
    5093                 :    37061824 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    5094                 :             :     {
    5095                 :     3568863 :       if (TREE_CODE (dtor) == OVERLOAD)
    5096                 :             :         {
    5097                 :             :           /* P0848: At the end of the definition of a class, overload
    5098                 :             :              resolution is performed among the prospective destructors declared
    5099                 :             :              in that class with an empty argument list to select the destructor
    5100                 :             :              for the class, also known as the selected destructor. The program
    5101                 :             :              is ill-formed if overload resolution fails. */
    5102                 :           6 :           int viable = 0;
    5103                 :          24 :           for (tree fn : ovl_range (dtor))
    5104                 :          12 :             if (constraints_satisfied_p (fn))
    5105                 :           6 :               ++viable;
    5106                 :           6 :           gcc_checking_assert (viable != 1);
    5107                 :             : 
    5108                 :           6 :           auto_diagnostic_group d;
    5109                 :           6 :           if (viable == 0)
    5110                 :           3 :             error_at (location_of (t), "no viable destructor for %qT", t);
    5111                 :             :           else
    5112                 :           3 :             error_at (location_of (t), "destructor for %qT is ambiguous", t);
    5113                 :           6 :           print_candidates (dtor);
    5114                 :             : 
    5115                 :             :           /* Arbitrarily prune the overload set to a single function for
    5116                 :             :              sake of error recovery.  */
    5117                 :           6 :           tree *slot = find_member_slot (t, dtor_identifier);
    5118                 :           6 :           *slot = get_first_fn (dtor);
    5119                 :           6 :         }
    5120                 :     3568857 :       else if (user_provided_p (dtor))
    5121                 :     2800930 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = true;
    5122                 :             :     }
    5123                 :             : 
    5124                 :    79904272 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5125                 :             :     {
    5126                 :    24323808 :       if (!user_provided_p (fn))
    5127                 :             :         /* Might be trivial.  */;
    5128                 :    19549515 :       else if (TREE_CODE (fn) == TEMPLATE_DECL)
    5129                 :             :         /* Templates are never special members.  */;
    5130                 :    12358643 :       else if (copy_fn_p (fn)
    5131                 :    12358643 :                && constraints_satisfied_p (fn))
    5132                 :      930991 :         TYPE_HAS_COMPLEX_COPY_CTOR (t) = true;
    5133                 :    11427652 :       else if (move_fn_p (fn)
    5134                 :    11427652 :                && constraints_satisfied_p (fn))
    5135                 :      849184 :         TYPE_HAS_COMPLEX_MOVE_CTOR (t) = true;
    5136                 :             :     }
    5137                 :             : 
    5138                 :    48113695 :   for (tree fn : ovl_range (get_class_binding_direct (t, assign_op_identifier)))
    5139                 :             :     {
    5140                 :     7066473 :       if (!user_provided_p (fn))
    5141                 :             :         /* Might be trivial.  */;
    5142                 :     3756675 :       else if (TREE_CODE (fn) == TEMPLATE_DECL)
    5143                 :             :         /* Templates are never special members.  */;
    5144                 :     2743423 :       else if (copy_fn_p (fn)
    5145                 :     2743423 :                && constraints_satisfied_p (fn))
    5146                 :      595297 :         TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = true;
    5147                 :     2148126 :       else if (move_fn_p (fn)
    5148                 :     2148126 :                && constraints_satisfied_p (fn))
    5149                 :      799591 :         TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = true;
    5150                 :             :     }
    5151                 :    37061824 : }
    5152                 :             : 
    5153                 :             : /* FN is constructor, destructor or operator function.  Clone the
    5154                 :             :    declaration to create a NAME'd variant.  NEED_VTT_PARM_P and
    5155                 :             :    OMIT_INHERITED_PARMS_P are relevant if it's a cdtor.  */
    5156                 :             : 
    5157                 :             : static tree
    5158                 :   103635082 : copy_fndecl_with_name (tree fn, tree name, tree_code code,
    5159                 :             :                        bool need_vtt_parm_p, bool omit_inherited_parms_p)
    5160                 :             : {
    5161                 :             :   /* Copy the function.  */
    5162                 :   103635082 :   tree clone = copy_decl (fn);
    5163                 :             :   /* Reset the function name.  */
    5164                 :   103635082 :   DECL_NAME (clone) = name;
    5165                 :             : 
    5166                 :   103635082 :   if (flag_concepts)
    5167                 :             :     /* Clone constraints.  */
    5168                 :    37881981 :     if (tree ci = get_constraints (fn))
    5169                 :     4771168 :       set_constraints (clone, copy_node (ci));
    5170                 :             : 
    5171                 :   103635082 :   SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
    5172                 :   103635082 :   DECL_ABSTRACT_P (clone) = false;
    5173                 :             :   /* There's no pending inline data for this function.  */
    5174                 :   103635082 :   DECL_PENDING_INLINE_INFO (clone) = NULL;
    5175                 :   103635082 :   DECL_PENDING_INLINE_P (clone) = 0;
    5176                 :             : 
    5177                 :   103635082 :   if (name == base_dtor_identifier)
    5178                 :             :     {
    5179                 :             :       /* The base-class destructor is not virtual.  */
    5180                 :     8577309 :       DECL_VIRTUAL_P (clone) = 0;
    5181                 :     8577309 :       DECL_VINDEX (clone) = NULL_TREE;
    5182                 :             :     }
    5183                 :    95057773 :   else if (code != ERROR_MARK)
    5184                 :             :     {
    5185                 :             :       /* Set the operator code.  */
    5186                 :         226 :       const ovl_op_info_t *ovl_op = OVL_OP_INFO (false, code);
    5187                 :         226 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (clone) = ovl_op->ovl_op_code;
    5188                 :             : 
    5189                 :             :       /* The operator could be virtual.  */
    5190                 :         226 :       if (DECL_VIRTUAL_P (clone))
    5191                 :          12 :         IDENTIFIER_VIRTUAL_P (name) = true;
    5192                 :             :    }
    5193                 :             : 
    5194                 :   103635082 :   if (omit_inherited_parms_p)
    5195                 :         120 :     gcc_assert (DECL_HAS_IN_CHARGE_PARM_P (clone));
    5196                 :             : 
    5197                 :             :   /* If there was an in-charge parameter, drop it from the function
    5198                 :             :      type.  */
    5199                 :   103635082 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    5200                 :             :     {
    5201                 :     2359011 :       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
    5202                 :     2359011 :       tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
    5203                 :             :       /* Skip the `this' parameter.  */
    5204                 :     2359011 :       parmtypes = TREE_CHAIN (parmtypes);
    5205                 :             :       /* Skip the in-charge parameter.  */
    5206                 :     2359011 :       parmtypes = TREE_CHAIN (parmtypes);
    5207                 :             :       /* And the VTT parm, in a complete [cd]tor.  */
    5208                 :     2359011 :       if (DECL_HAS_VTT_PARM_P (fn) && !need_vtt_parm_p)
    5209                 :     1271205 :         parmtypes = TREE_CHAIN (parmtypes);
    5210                 :     2359011 :       if (omit_inherited_parms_p)
    5211                 :             :         {
    5212                 :             :           /* If we're omitting inherited parms, that just leaves the VTT.  */
    5213                 :         120 :           gcc_assert (need_vtt_parm_p);
    5214                 :         120 :           parmtypes = tree_cons (NULL_TREE, vtt_parm_type, void_list_node);
    5215                 :             :         }
    5216                 :     2359011 :       TREE_TYPE (clone)
    5217                 :     2359011 :         = build_method_type_directly (basetype,
    5218                 :     2359011 :                                       TREE_TYPE (TREE_TYPE (clone)),
    5219                 :             :                                       parmtypes);
    5220                 :     2359011 :       TREE_TYPE (clone)
    5221                 :     2359011 :         = cp_build_type_attribute_variant (TREE_TYPE (clone),
    5222                 :     2359011 :                                            TYPE_ATTRIBUTES (TREE_TYPE (fn)));
    5223                 :     2359011 :       TREE_TYPE (clone)
    5224                 :     4718022 :         = cxx_copy_lang_qualifiers (TREE_TYPE (clone), TREE_TYPE (fn));
    5225                 :             :     }
    5226                 :             : 
    5227                 :             :   /* Copy the function parameters.  */
    5228                 :   103635082 :   DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
    5229                 :             : 
    5230                 :             :   /* Remove the in-charge parameter.  */
    5231                 :   103635082 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    5232                 :             :     {
    5233                 :     2359011 :       DECL_CHAIN (DECL_ARGUMENTS (clone))
    5234                 :     2359011 :         = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    5235                 :     2359011 :       DECL_HAS_IN_CHARGE_PARM_P (clone) = 0;
    5236                 :             :     }
    5237                 :             : 
    5238                 :             :   /* And the VTT parm, in a complete [cd]tor.  */
    5239                 :   103635082 :   if (DECL_HAS_VTT_PARM_P (fn))
    5240                 :             :     {
    5241                 :     2359011 :       if (need_vtt_parm_p)
    5242                 :     1087806 :         DECL_HAS_VTT_PARM_P (clone) = 1;
    5243                 :             :       else
    5244                 :             :         {
    5245                 :     2542410 :           DECL_CHAIN (DECL_ARGUMENTS (clone))
    5246                 :     1271205 :             = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    5247                 :     1271205 :           DECL_HAS_VTT_PARM_P (clone) = 0;
    5248                 :             :         }
    5249                 :             :     }
    5250                 :             : 
    5251                 :             :   /* A base constructor inheriting from a virtual base doesn't get the
    5252                 :             :      arguments.  */
    5253                 :   103635082 :   if (omit_inherited_parms_p)
    5254                 :         120 :     DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone))) = NULL_TREE;
    5255                 :             : 
    5256                 :   323214249 :   for (tree parms = DECL_ARGUMENTS (clone); parms; parms = DECL_CHAIN (parms))
    5257                 :             :     {
    5258                 :   219579167 :       DECL_CONTEXT (parms) = clone;
    5259                 :   219579167 :       cxx_dup_lang_specific_decl (parms);
    5260                 :             :     }
    5261                 :             : 
    5262                 :             :   /* Create the RTL for this function.  */
    5263                 :   103635082 :   SET_DECL_RTL (clone, NULL);
    5264                 :             : 
    5265                 :             :   /* Regardless of the current scope, this is a member function, so
    5266                 :             :      not at namespace scope.  */
    5267                 :   103635082 :   rest_of_decl_compilation (clone, /*top_level=*/0, at_eof);
    5268                 :             : 
    5269                 :   103635082 :   return clone;
    5270                 :             : }
    5271                 :             : 
    5272                 :             : /* FN is an operator function, create a variant for CODE.  */
    5273                 :             : 
    5274                 :             : tree
    5275                 :         226 : copy_operator_fn (tree fn, tree_code code)
    5276                 :             : {
    5277                 :         226 :   return copy_fndecl_with_name (fn, ovl_op_identifier (code),
    5278                 :         226 :                                 code, false, false);
    5279                 :             : }
    5280                 :             : 
    5281                 :             : /* FN is a constructor or destructor.  Clone the declaration to create
    5282                 :             :    a specialized in-charge or not-in-charge version, as indicated by
    5283                 :             :    NAME.  */
    5284                 :             : 
    5285                 :             : static tree
    5286                 :   118878858 : build_clone (tree fn, tree name, bool need_vtt_parm_p,
    5287                 :             :              bool omit_inherited_parms_p)
    5288                 :             : {
    5289                 :   118878858 :   tree clone;
    5290                 :             : 
    5291                 :             :   /* If this is a template, do the rest on the DECL_TEMPLATE_RESULT.  */
    5292                 :   118878858 :   if (TREE_CODE (fn) == TEMPLATE_DECL)
    5293                 :             :     {
    5294                 :    15244002 :       clone = copy_decl (fn);
    5295                 :    15244002 :       DECL_NAME (clone) = name;
    5296                 :             : 
    5297                 :    15244002 :       tree result = build_clone (DECL_TEMPLATE_RESULT (clone), name,
    5298                 :             :                                  need_vtt_parm_p, omit_inherited_parms_p);
    5299                 :    15244002 :       DECL_TEMPLATE_RESULT (clone) = result;
    5300                 :             : 
    5301                 :    15244002 :       DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
    5302                 :    15244002 :       DECL_TI_TEMPLATE (result) = clone;
    5303                 :             : 
    5304                 :    15244002 :       TREE_TYPE (clone) = TREE_TYPE (result);
    5305                 :             :     }
    5306                 :             :   else
    5307                 :             :     {
    5308                 :   103634856 :       clone = copy_fndecl_with_name (fn, name, ERROR_MARK,
    5309                 :             :                                      need_vtt_parm_p, omit_inherited_parms_p);
    5310                 :   103634856 :       DECL_CLONED_FUNCTION (clone) = fn;
    5311                 :             : 
    5312                 :   103634856 :       maybe_prepare_return_this (clone);
    5313                 :             :     }
    5314                 :             : 
    5315                 :             :   /* Remember where this function came from.  */
    5316                 :   118878858 :   DECL_ABSTRACT_ORIGIN (clone) = fn;
    5317                 :             : 
    5318                 :             :   /* Make it easy to find the CLONE given the FN.  Note the
    5319                 :             :      template_result of a template will be chained this way too.  */
    5320                 :   118878858 :   DECL_CHAIN (clone) = DECL_CHAIN (fn);
    5321                 :   118878858 :   DECL_CHAIN (fn) = clone;
    5322                 :             : 
    5323                 :   118878858 :   return clone;
    5324                 :             : }
    5325                 :             : 
    5326                 :             : /* Build the clones of FN, return the number of clones built.  These
    5327                 :             :    will be inserted onto DECL_CHAIN of FN.  */
    5328                 :             : 
    5329                 :             : void
    5330                 :    51021073 : build_cdtor_clones (tree fn, bool needs_vtt_p, bool base_omits_inherited_p,
    5331                 :             :                     bool update_methods)
    5332                 :             : {
    5333                 :    51021073 :   unsigned count = 0;
    5334                 :             : 
    5335                 :    51021073 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
    5336                 :             :     {
    5337                 :             :       /* For each constructor, we need two variants: an in-charge version
    5338                 :             :          and a not-in-charge version.  */
    5339                 :    42443764 :       build_clone (fn, complete_ctor_identifier, false, false);
    5340                 :    42443764 :       build_clone (fn, base_ctor_identifier, needs_vtt_p,
    5341                 :             :                    base_omits_inherited_p);
    5342                 :    42443764 :       count += 2;
    5343                 :             :     }
    5344                 :             :   else
    5345                 :             :     {
    5346                 :     8577309 :       gcc_assert (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn));
    5347                 :             : 
    5348                 :             :       /* For each destructor, we need three variants: an in-charge
    5349                 :             :          version, a not-in-charge version, and an in-charge deleting
    5350                 :             :          version.  We clone the deleting version first because that
    5351                 :             :          means it will go second on the TYPE_FIELDS list -- and that
    5352                 :             :          corresponds to the correct layout order in the virtual
    5353                 :             :          function table.
    5354                 :             : 
    5355                 :             :          For a non-virtual destructor, we do not build a deleting
    5356                 :             :          destructor.  */
    5357                 :     8577309 :       if (DECL_VIRTUAL_P (fn))
    5358                 :             :         {
    5359                 :     1592710 :           build_clone (fn, deleting_dtor_identifier, false, false);
    5360                 :     1592710 :           count++;
    5361                 :             :         }
    5362                 :     8577309 :       build_clone (fn, complete_dtor_identifier, false, false);
    5363                 :     8577309 :       build_clone (fn, base_dtor_identifier, needs_vtt_p, false);
    5364                 :     8577309 :       count += 2;
    5365                 :             :     }
    5366                 :             : 
    5367                 :             :   /* The original is now an abstract function that is never
    5368                 :             :      emitted.  */
    5369                 :    51021073 :   DECL_ABSTRACT_P (fn) = true;
    5370                 :             : 
    5371                 :    51021073 :   if (update_methods)
    5372                 :   129431146 :     for (tree clone = fn; count--;)
    5373                 :             :       {
    5374                 :    86818049 :         clone = DECL_CHAIN (clone);
    5375                 :    86818049 :         add_method (DECL_CONTEXT (clone), clone, false);
    5376                 :             :       }
    5377                 :    51021073 : }
    5378                 :             : 
    5379                 :             : /* Produce declarations for all appropriate clones of FN.  If
    5380                 :             :    UPDATE_METHODS is true, the clones are added to the
    5381                 :             :    CLASSTYPE_MEMBER_VEC.  */
    5382                 :             : 
    5383                 :             : void
    5384                 :    51267995 : clone_cdtor (tree fn, bool update_methods)
    5385                 :             : {
    5386                 :             :   /* Avoid inappropriate cloning.  */
    5387                 :    51267995 :   if (DECL_CHAIN (fn)
    5388                 :    51267995 :       && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn)))
    5389                 :             :     return;
    5390                 :             : 
    5391                 :             :   /* Base cdtors need a vtt parm if there are virtual bases.  */
    5392                 :    50998349 :   bool vtt = CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn));
    5393                 :             : 
    5394                 :             :   /* Base ctor omits inherited parms it needs a vttparm and inherited
    5395                 :             :      from a virtual nase ctor.  */
    5396                 :    50998349 :   bool base_omits_inherited = (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
    5397                 :    50998349 :                                && base_ctor_omit_inherited_parms (fn));
    5398                 :             : 
    5399                 :    50998349 :   build_cdtor_clones (fn, vtt, base_omits_inherited, update_methods);
    5400                 :             : }
    5401                 :             : 
    5402                 :             : /* DECL is an in charge constructor, which is being defined. This will
    5403                 :             :    have had an in class declaration, from whence clones were
    5404                 :             :    declared. An out-of-class definition can specify additional default
    5405                 :             :    arguments. As it is the clones that are involved in overload
    5406                 :             :    resolution, we must propagate the information from the DECL to its
    5407                 :             :    clones.  */
    5408                 :             : 
    5409                 :             : void
    5410                 :    18352719 : adjust_clone_args (tree decl)
    5411                 :             : {
    5412                 :    18352719 :   tree clone;
    5413                 :             : 
    5414                 :    29201833 :   for (clone = DECL_CHAIN (decl); clone && DECL_CLONED_FUNCTION_P (clone);
    5415                 :    10849114 :        clone = DECL_CHAIN (clone))
    5416                 :             :     {
    5417                 :    10849114 :       tree orig_clone_parms = TYPE_ARG_TYPES (TREE_TYPE (clone));
    5418                 :    10849114 :       tree orig_decl_parms = TYPE_ARG_TYPES (TREE_TYPE (decl));
    5419                 :    10849114 :       tree decl_parms, clone_parms;
    5420                 :             : 
    5421                 :             :       /* Skip the 'this' parameter.  */
    5422                 :    10849114 :       orig_clone_parms = TREE_CHAIN (orig_clone_parms);
    5423                 :    10849114 :       orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5424                 :             : 
    5425                 :    10849114 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl))
    5426                 :       21642 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5427                 :    10849114 :       if (DECL_HAS_VTT_PARM_P (decl))
    5428                 :       21642 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5429                 :             : 
    5430                 :    10849114 :       clone_parms = orig_clone_parms;
    5431                 :    10849114 :       if (DECL_HAS_VTT_PARM_P (clone))
    5432                 :       10821 :         clone_parms = TREE_CHAIN (clone_parms);
    5433                 :             : 
    5434                 :    21541150 :       for (decl_parms = orig_decl_parms; decl_parms;
    5435                 :    10692036 :            decl_parms = TREE_CHAIN (decl_parms),
    5436                 :    10692036 :              clone_parms = TREE_CHAIN (clone_parms))
    5437                 :             :         {
    5438                 :    21539510 :           if (clone_parms == void_list_node)
    5439                 :             :             {
    5440                 :    10847450 :               gcc_assert (decl_parms == clone_parms
    5441                 :             :                           || ctor_omit_inherited_parms (clone));
    5442                 :             :               break;
    5443                 :             :             }
    5444                 :             : 
    5445                 :    10692060 :           gcc_checking_assert (same_type_p (TREE_VALUE (decl_parms),
    5446                 :             :                                             TREE_VALUE (clone_parms)));
    5447                 :             : 
    5448                 :    11632184 :           if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms))
    5449                 :             :             {
    5450                 :             :               /* A default parameter has been added. Adjust the
    5451                 :             :                  clone's parameters.  */
    5452                 :          24 :               clone_parms = orig_decl_parms;
    5453                 :             : 
    5454                 :          24 :               if (DECL_HAS_VTT_PARM_P (clone))
    5455                 :             :                 {
    5456                 :           3 :                   clone_parms = tree_cons (TREE_PURPOSE (orig_clone_parms),
    5457                 :           3 :                                            TREE_VALUE (orig_clone_parms),
    5458                 :             :                                            clone_parms);
    5459                 :           3 :                   TREE_TYPE (clone_parms) = TREE_TYPE (orig_clone_parms);
    5460                 :             :                 }
    5461                 :             : 
    5462                 :          24 :               tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
    5463                 :          24 :               tree type
    5464                 :          24 :                 = build_method_type_directly (basetype,
    5465                 :          24 :                                               TREE_TYPE (TREE_TYPE (clone)),
    5466                 :             :                                               clone_parms);
    5467                 :          24 :               if (tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (clone)))
    5468                 :           0 :                 type = cp_build_type_attribute_variant (type, attrs);
    5469                 :          24 :               type = cxx_copy_lang_qualifiers (type, TREE_TYPE (clone));
    5470                 :          24 :               TREE_TYPE (clone) = type;
    5471                 :             : 
    5472                 :          24 :               clone_parms = NULL_TREE;
    5473                 :          24 :               break;
    5474                 :             :             }
    5475                 :             :         }
    5476                 :    10849114 :       gcc_assert (!clone_parms || clone_parms == void_list_node);
    5477                 :             :     }
    5478                 :    18352719 : }
    5479                 :             : 
    5480                 :             : /* For each of the constructors and destructors in T, create an
    5481                 :             :    in-charge and not-in-charge variant.  */
    5482                 :             : 
    5483                 :             : static void
    5484                 :    37061824 : clone_constructors_and_destructors (tree t)
    5485                 :             : {
    5486                 :             :   /* We do not need to propagate the usingness to the clone, at this
    5487                 :             :      point that is not needed.  */
    5488                 :    80431515 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5489                 :    24587434 :     clone_cdtor (fn, /*update_methods=*/true);
    5490                 :             : 
    5491                 :    37061824 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    5492                 :     3738521 :     clone_cdtor (dtor, /*update_methods=*/true);
    5493                 :    37061824 : }
    5494                 :             : 
    5495                 :             : /* Deduce noexcept for a destructor DTOR.  */
    5496                 :             : 
    5497                 :             : void
    5498                 :     3634691 : deduce_noexcept_on_destructor (tree dtor)
    5499                 :             : {
    5500                 :     3634691 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (dtor)))
    5501                 :     2364147 :     TREE_TYPE (dtor) = build_exception_variant (TREE_TYPE (dtor),
    5502                 :             :                                                 noexcept_deferred_spec);
    5503                 :     3634691 : }
    5504                 :             : 
    5505                 :             : /* Subroutine of set_one_vmethod_tm_attributes.  Search base classes
    5506                 :             :    of TYPE for virtual functions which FNDECL overrides.  Return a
    5507                 :             :    mask of the tm attributes found therein.  */
    5508                 :             : 
    5509                 :             : static int
    5510                 :         925 : look_for_tm_attr_overrides (tree type, tree fndecl)
    5511                 :             : {
    5512                 :         925 :   tree binfo = TYPE_BINFO (type);
    5513                 :         925 :   tree base_binfo;
    5514                 :         925 :   int ix, found = 0;
    5515                 :             : 
    5516                 :        1549 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ++ix)
    5517                 :             :     {
    5518                 :         624 :       tree o, basetype = BINFO_TYPE (base_binfo);
    5519                 :             : 
    5520                 :         624 :       if (!TYPE_POLYMORPHIC_P (basetype))
    5521                 :          48 :         continue;
    5522                 :             : 
    5523                 :         576 :       o = look_for_overrides_here (basetype, fndecl);
    5524                 :         576 :       if (o)
    5525                 :             :         {
    5526                 :         411 :           if (lookup_attribute ("transaction_safe_dynamic",
    5527                 :         411 :                                 DECL_ATTRIBUTES (o)))
    5528                 :             :             /* transaction_safe_dynamic is not inherited.  */;
    5529                 :             :           else
    5530                 :         311 :             found |= tm_attr_to_mask (find_tm_attribute
    5531                 :         311 :                                       (TYPE_ATTRIBUTES (TREE_TYPE (o))));
    5532                 :             :         }
    5533                 :             :       else
    5534                 :         165 :         found |= look_for_tm_attr_overrides (basetype, fndecl);
    5535                 :             :     }
    5536                 :             : 
    5537                 :         925 :   return found;
    5538                 :             : }
    5539                 :             : 
    5540                 :             : /* Subroutine of set_method_tm_attributes.  Handle the checks and
    5541                 :             :    inheritance for one virtual method FNDECL.  */
    5542                 :             : 
    5543                 :             : static void
    5544                 :         760 : set_one_vmethod_tm_attributes (tree type, tree fndecl)
    5545                 :             : {
    5546                 :         760 :   tree tm_attr;
    5547                 :         760 :   int found, have;
    5548                 :             : 
    5549                 :         760 :   found = look_for_tm_attr_overrides (type, fndecl);
    5550                 :             : 
    5551                 :             :   /* If FNDECL doesn't actually override anything (i.e. T is the
    5552                 :             :      class that first declares FNDECL virtual), then we're done.  */
    5553                 :         760 :   if (found == 0)
    5554                 :             :     return;
    5555                 :             : 
    5556                 :          45 :   tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (TREE_TYPE (fndecl)));
    5557                 :          45 :   have = tm_attr_to_mask (tm_attr);
    5558                 :             : 
    5559                 :             :   /* Intel STM Language Extension 3.0, Section 4.2 table 4:
    5560                 :             :      tm_pure must match exactly, otherwise no weakening of
    5561                 :             :      tm_safe > tm_callable > nothing.  */
    5562                 :             :   /* ??? The tm_pure attribute didn't make the transition to the
    5563                 :             :      multivendor language spec.  */
    5564                 :          45 :   if (have == TM_ATTR_PURE)
    5565                 :             :     {
    5566                 :           0 :       if (found != TM_ATTR_PURE)
    5567                 :             :         {
    5568                 :           0 :           found &= -found;
    5569                 :           0 :           goto err_override;
    5570                 :             :         }
    5571                 :             :     }
    5572                 :             :   /* If the overridden function is tm_pure, then FNDECL must be.  */
    5573                 :          45 :   else if (found == TM_ATTR_PURE && tm_attr)
    5574                 :           6 :     goto err_override;
    5575                 :             :   /* Look for base class combinations that cannot be satisfied.  */
    5576                 :          39 :   else if (found != TM_ATTR_PURE && (found & TM_ATTR_PURE))
    5577                 :             :     {
    5578                 :           0 :       found &= ~TM_ATTR_PURE;
    5579                 :           0 :       found &= -found;
    5580                 :           0 :       error_at (DECL_SOURCE_LOCATION (fndecl),
    5581                 :             :                 "method overrides both %<transaction_pure%> and %qE methods",
    5582                 :             :                 tm_mask_to_attr (found));
    5583                 :             :     }
    5584                 :             :   /* If FNDECL did not declare an attribute, then inherit the most
    5585                 :             :      restrictive one.  */
    5586                 :          39 :   else if (tm_attr == NULL)
    5587                 :             :     {
    5588                 :          14 :       apply_tm_attr (fndecl, tm_mask_to_attr (least_bit_hwi (found)));
    5589                 :             :     }
    5590                 :             :   /* Otherwise validate that we're not weaker than a function
    5591                 :             :      that is being overridden.  */
    5592                 :             :   else
    5593                 :             :     {
    5594                 :          25 :       found &= -found;
    5595                 :          25 :       if (found <= TM_ATTR_CALLABLE && have > found)
    5596                 :           9 :         goto err_override;
    5597                 :             :     }
    5598                 :             :   return;
    5599                 :             : 
    5600                 :          15 :  err_override:
    5601                 :          15 :   error_at (DECL_SOURCE_LOCATION (fndecl),
    5602                 :             :             "method declared %qE overriding %qE method",
    5603                 :             :             tm_attr, tm_mask_to_attr (found));
    5604                 :             : }
    5605                 :             : 
    5606                 :             : /* For each of the methods in T, propagate a class-level tm attribute.  */
    5607                 :             : 
    5608                 :             : static void
    5609                 :    37061824 : set_method_tm_attributes (tree t)
    5610                 :             : {
    5611                 :    37061824 :   tree class_tm_attr, fndecl;
    5612                 :             : 
    5613                 :             :   /* Don't bother collecting tm attributes if transactional memory
    5614                 :             :      support is not enabled.  */
    5615                 :    37061824 :   if (!flag_tm)
    5616                 :             :     return;
    5617                 :             : 
    5618                 :             :   /* Process virtual methods first, as they inherit directly from the
    5619                 :             :      base virtual function and also require validation of new attributes.  */
    5620                 :        3609 :   if (TYPE_CONTAINS_VPTR_P (t))
    5621                 :             :     {
    5622                 :         200 :       tree vchain;
    5623                 :         960 :       for (vchain = BINFO_VIRTUALS (TYPE_BINFO (t)); vchain;
    5624                 :         760 :            vchain = TREE_CHAIN (vchain))
    5625                 :             :         {
    5626                 :         760 :           fndecl = BV_FN (vchain);
    5627                 :         760 :           if (DECL_THUNK_P (fndecl))
    5628                 :           3 :             fndecl = THUNK_TARGET (fndecl);
    5629                 :         760 :           set_one_vmethod_tm_attributes (t, fndecl);
    5630                 :             :         }
    5631                 :             :     }
    5632                 :             : 
    5633                 :             :   /* If the class doesn't have an attribute, nothing more to do.  */
    5634                 :        3609 :   class_tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (t));
    5635                 :        3609 :   if (class_tm_attr == NULL)
    5636                 :             :     return;
    5637                 :             : 
    5638                 :             :   /* Any method that does not yet have a tm attribute inherits
    5639                 :             :      the one from the class.  */
    5640                 :         108 :   for (fndecl = TYPE_FIELDS (t); fndecl; fndecl = DECL_CHAIN (fndecl))
    5641                 :          45 :     if (DECL_DECLARES_FUNCTION_P (fndecl)
    5642                 :          81 :         && !find_tm_attribute (TYPE_ATTRIBUTES (TREE_TYPE (fndecl))))
    5643                 :          21 :       apply_tm_attr (fndecl, class_tm_attr);
    5644                 :             : }
    5645                 :             : 
    5646                 :             : /* Returns true if FN is a default constructor.  */
    5647                 :             : 
    5648                 :             : bool
    5649                 :    16610978 : default_ctor_p (const_tree fn)
    5650                 :             : {
    5651                 :    16610978 :   return (DECL_CONSTRUCTOR_P (fn)
    5652                 :    16610978 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
    5653                 :             : }
    5654                 :             : 
    5655                 :             : /* Returns true iff class T has a user-provided constructor that can be called
    5656                 :             :    with more than zero arguments.  */
    5657                 :             : 
    5658                 :             : bool
    5659                 :          55 : type_has_user_nondefault_constructor (tree t)
    5660                 :             : {
    5661                 :          55 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5662                 :             :     return false;
    5663                 :             : 
    5664                 :          65 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5665                 :             :     {
    5666                 :          34 :       if (user_provided_p (fn)
    5667                 :          34 :           && (TREE_CODE (fn) == TEMPLATE_DECL
    5668                 :          18 :               || (skip_artificial_parms_for (fn, DECL_ARGUMENTS (fn))
    5669                 :             :                   != NULL_TREE)))
    5670                 :           3 :         return true;
    5671                 :             :     }
    5672                 :             : 
    5673                 :          18 :   return false;
    5674                 :             : }
    5675                 :             : 
    5676                 :             : /* Returns the defaulted constructor if T has one. Otherwise, returns
    5677                 :             :    NULL_TREE.  */
    5678                 :             : 
    5679                 :             : tree
    5680                 :          62 : in_class_defaulted_default_constructor (tree t)
    5681                 :             : {
    5682                 :          62 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5683                 :             :     return NULL_TREE;
    5684                 :             : 
    5685                 :         123 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5686                 :             :     {
    5687                 :          78 :       tree fn = *iter;
    5688                 :             : 
    5689                 :         156 :       if (DECL_DEFAULTED_IN_CLASS_P (fn)
    5690                 :         114 :           && default_ctor_p (fn))
    5691                 :          33 :         return fn;
    5692                 :             :     }
    5693                 :             : 
    5694                 :           0 :   return NULL_TREE;
    5695                 :             : }
    5696                 :             : 
    5697                 :             : /* Returns true iff FN is a user-provided function, i.e. user-declared
    5698                 :             :    and not defaulted at its first declaration.  */
    5699                 :             : 
    5700                 :             : bool
    5701                 :    89621065 : user_provided_p (tree fn)
    5702                 :             : {
    5703                 :    89621065 :   fn = STRIP_TEMPLATE (fn);
    5704                 :    89621065 :   return (!DECL_ARTIFICIAL (fn)
    5705                 :    89621065 :           && !(DECL_INITIALIZED_IN_CLASS_P (fn)
    5706                 :    74143642 :                && (DECL_DEFAULTED_FN (fn) || DECL_DELETED_FN (fn))));
    5707                 :             : }
    5708                 :             : 
    5709                 :             : /* Returns true iff class T has a user-provided constructor.  */
    5710                 :             : 
    5711                 :             : bool
    5712                 :    37061962 : type_has_user_provided_constructor (tree t)
    5713                 :             : {
    5714                 :    37061962 :   if (!CLASS_TYPE_P (t))
    5715                 :             :     return false;
    5716                 :             : 
    5717                 :    37061906 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5718                 :             :     return false;
    5719                 :             : 
    5720                 :     8325588 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5721                 :     6907522 :     if (user_provided_p (*iter))
    5722                 :     5489934 :       return true;
    5723                 :             : 
    5724                 :      462265 :   return false;
    5725                 :             : }
    5726                 :             : 
    5727                 :             : /* Returns true iff class T has a constructor that accepts a single argument
    5728                 :             :    and does not have a single parameter of type reference to T.
    5729                 :             : 
    5730                 :             :    This does not exclude explicit constructors because they are still
    5731                 :             :    considered for conversions within { } even though choosing one is
    5732                 :             :    ill-formed.  */
    5733                 :             : 
    5734                 :             : bool
    5735                 :      597667 : type_has_converting_constructor (tree t)
    5736                 :             : {
    5737                 :      597667 :   if (!CLASS_TYPE_P (t))
    5738                 :             :     return false;
    5739                 :             : 
    5740                 :      597667 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5741                 :             :     return false;
    5742                 :             : 
    5743                 :     1741103 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5744                 :             :     {
    5745                 :     1021109 :       tree fn = *iter;
    5746                 :     1021109 :       tree parm = FUNCTION_FIRST_USER_PARMTYPE (fn);
    5747                 :     1021109 :       if (parm == NULL_TREE)
    5748                 :             :         /* Varargs.  */
    5749                 :      301115 :         return true;
    5750                 :     1294361 :       if (parm == void_list_node
    5751                 :     1021108 :           || !sufficient_parms_p (TREE_CHAIN (parm)))
    5752                 :             :         /* Can't accept a single argument, so won't be considered for
    5753                 :             :            conversion.  */
    5754                 :      273253 :         continue;
    5755                 :      747855 :       if (TREE_CODE (fn) == TEMPLATE_DECL
    5756                 :      747855 :           || TREE_CHAIN (parm) != void_list_node)
    5757                 :             :         /* Not a simple single parameter.  */
    5758                 :             :         return true;
    5759                 :      605414 :       if (TYPE_MAIN_VARIANT (non_reference (TREE_VALUE (parm)))
    5760                 :      605414 :           != DECL_CONTEXT (fn))
    5761                 :             :         /* The single parameter has the wrong type.  */
    5762                 :             :         return true;
    5763                 :      446741 :       if (get_constraints (fn))
    5764                 :             :         /* Constrained.  */
    5765                 :             :         return true;
    5766                 :             :     }
    5767                 :             : 
    5768                 :      106518 :   return false;
    5769                 :             : }
    5770                 :             : 
    5771                 :             : /* Returns true iff class T has a user-provided or explicit constructor.  */
    5772                 :             : 
    5773                 :             : bool
    5774                 :    46341702 : type_has_user_provided_or_explicit_constructor (tree t)
    5775                 :             : {
    5776                 :    46341702 :   if (!CLASS_TYPE_P (t))
    5777                 :             :     return false;
    5778                 :             : 
    5779                 :    46341702 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5780                 :             :     return false;
    5781                 :             : 
    5782                 :    10678640 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5783                 :             :     {
    5784                 :     8814132 :       tree fn = *iter;
    5785                 :     8814132 :       if (user_provided_p (fn) || DECL_NONCONVERTING_P (fn))
    5786                 :     6950103 :         return true;
    5787                 :             :     }
    5788                 :             : 
    5789                 :      489418 :   return false;
    5790                 :             : }
    5791                 :             : 
    5792                 :             : /* Returns true iff class T has a non-user-provided (i.e. implicitly
    5793                 :             :    declared or explicitly defaulted in the class body) default
    5794                 :             :    constructor.  */
    5795                 :             : 
    5796                 :             : bool
    5797                 :     2997182 : type_has_non_user_provided_default_constructor (tree t)
    5798                 :             : {
    5799                 :     2997182 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t))
    5800                 :             :     return false;
    5801                 :     2997135 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5802                 :             :     return true;
    5803                 :             : 
    5804                 :    21084404 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5805                 :             :     {
    5806                 :    11183044 :       tree fn = *iter;
    5807                 :    11183044 :       if (TREE_CODE (fn) == FUNCTION_DECL
    5808                 :     7754409 :           && default_ctor_p (fn)
    5809                 :    14138858 :           && !user_provided_p (fn))
    5810                 :     1282925 :         return true;
    5811                 :             :     }
    5812                 :             : 
    5813                 :     1713285 :   return false;
    5814                 :             : }
    5815                 :             : 
    5816                 :             : /* TYPE is being used as a virtual base, and has a non-trivial move
    5817                 :             :    assignment.  Return true if this is due to there being a user-provided
    5818                 :             :    move assignment in TYPE or one of its subobjects; if there isn't, then
    5819                 :             :    multiple move assignment can't cause any harm.  */
    5820                 :             : 
    5821                 :             : bool
    5822                 :          27 : vbase_has_user_provided_move_assign (tree type)
    5823                 :             : {
    5824                 :             :   /* Does the type itself have a user-provided move assignment operator?  */
    5825                 :          27 :   if (!CLASSTYPE_LAZY_MOVE_ASSIGN (type))
    5826                 :          30 :     for (ovl_iterator iter (get_class_binding_direct
    5827                 :          27 :                             (type, assign_op_identifier));
    5828                 :          57 :          iter; ++iter)
    5829                 :          48 :       if (user_provided_p (*iter) && move_fn_p (*iter))
    5830                 :          18 :         return true;
    5831                 :             : 
    5832                 :             :   /* Do any of its bases?  */
    5833                 :           9 :   tree binfo = TYPE_BINFO (type);
    5834                 :           9 :   tree base_binfo;
    5835                 :          12 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    5836                 :           6 :     if (vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo)))
    5837                 :             :       return true;
    5838                 :             : 
    5839                 :             :   /* Or non-static data members?  */
    5840                 :          27 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    5841                 :             :     {
    5842                 :          21 :       if (TREE_CODE (field) == FIELD_DECL
    5843                 :           3 :           && CLASS_TYPE_P (TREE_TYPE (field))
    5844                 :          21 :           && vbase_has_user_provided_move_assign (TREE_TYPE (field)))
    5845                 :             :         return true;
    5846                 :             :     }
    5847                 :             : 
    5848                 :             :   /* Seems not.  */
    5849                 :             :   return false;
    5850                 :             : }
    5851                 :             : 
    5852                 :             : /* If default-initialization leaves part of TYPE uninitialized, returns
    5853                 :             :    a DECL for the field or TYPE itself (DR 253).  */
    5854                 :             : 
    5855                 :             : tree
    5856                 :      801783 : default_init_uninitialized_part (tree type)
    5857                 :             : {
    5858                 :      801783 :   tree t, r, binfo;
    5859                 :      801783 :   int i;
    5860                 :             : 
    5861                 :      801783 :   type = strip_array_types (type);
    5862                 :      801783 :   if (!CLASS_TYPE_P (type))
    5863                 :             :     return type;
    5864                 :      688474 :   if (!type_has_non_user_provided_default_constructor (type))
    5865                 :             :     return NULL_TREE;
    5866                 :      550415 :   for (binfo = TYPE_BINFO (type), i = 0;
    5867                 :      550415 :        BINFO_BASE_ITERATE (binfo, i, t); ++i)
    5868                 :             :     {
    5869                 :       49250 :       r = default_init_uninitialized_part (BINFO_TYPE (t));
    5870                 :       49250 :       if (r)
    5871                 :             :         return r;
    5872                 :             :     }
    5873                 :      550899 :   for (t = next_aggregate_field (TYPE_FIELDS (type)); t;
    5874                 :       49734 :        t = next_aggregate_field (DECL_CHAIN (t)))
    5875                 :      158852 :     if (!DECL_INITIAL (t) && !DECL_ARTIFICIAL (t))
    5876                 :             :       {
    5877                 :      109191 :         r = default_init_uninitialized_part (TREE_TYPE (t));
    5878                 :      109191 :         if (r)
    5879                 :      218222 :           return DECL_P (r) ? r : t;
    5880                 :             :       }
    5881                 :             : 
    5882                 :             :   return NULL_TREE;
    5883                 :             : }
    5884                 :             : 
    5885                 :             : /* Returns true iff for class T, a trivial synthesized default constructor
    5886                 :             :    would be constexpr.  */
    5887                 :             : 
    5888                 :             : bool
    5889                 :    33328135 : trivial_default_constructor_is_constexpr (tree t)
    5890                 :             : {
    5891                 :             :   /* A defaulted trivial default constructor is constexpr
    5892                 :             :      if there is nothing to initialize.  */
    5893                 :    33328135 :   gcc_assert (!TYPE_HAS_COMPLEX_DFLT (t));
    5894                 :             :   /* A class with a vptr doesn't have a trivial default ctor.
    5895                 :             :      In C++20, a class can have transient uninitialized members, e.g.:
    5896                 :             : 
    5897                 :             :        struct S { int i; constexpr S() = default; };
    5898                 :             : 
    5899                 :             :      should work.  */
    5900                 :    33328135 :   return (cxx_dialect >= cxx20
    5901                 :    33328135 :           || is_really_empty_class (t, /*ignore_vptr*/true));
    5902                 :             : }
    5903                 :             : 
    5904                 :             : /* Returns true iff class T has a constexpr default constructor.  */
    5905                 :             : 
    5906                 :             : bool
    5907                 :    30744737 : type_has_constexpr_default_constructor (tree t)
    5908                 :             : {
    5909                 :    30744737 :   tree fns;
    5910                 :             : 
    5911                 :    30744737 :   if (!CLASS_TYPE_P (t))
    5912                 :             :     {
    5913                 :             :       /* The caller should have stripped an enclosing array.  */
    5914                 :         234 :       gcc_assert (TREE_CODE (t) != ARRAY_TYPE);
    5915                 :             :       return false;
    5916                 :             :     }
    5917                 :    30744503 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5918                 :             :     {
    5919                 :    30742971 :       if (!TYPE_HAS_COMPLEX_DFLT (t))
    5920                 :    30742913 :         return trivial_default_constructor_is_constexpr (t);
    5921                 :             :       /* Non-trivial, we need to check subobject constructors.  */
    5922                 :          58 :       lazily_declare_fn (sfk_constructor, t);
    5923                 :             :     }
    5924                 :        1590 :   fns = locate_ctor (t);
    5925                 :        1590 :   return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
    5926                 :             : }
    5927                 :             : 
    5928                 :             : /* Returns true iff class T has a constexpr default constructor or has an
    5929                 :             :    implicitly declared default constructor that we can't tell if it's constexpr
    5930                 :             :    without forcing a lazy declaration (which might cause undesired
    5931                 :             :    instantiations).  */
    5932                 :             : 
    5933                 :             : static bool
    5934                 :    31073485 : type_maybe_constexpr_default_constructor (tree t)
    5935                 :             : {
    5936                 :    31073485 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DEFAULT_CTOR (t)
    5937                 :    62146970 :       && TYPE_HAS_COMPLEX_DFLT (t))
    5938                 :             :     /* Assume it's constexpr.  */
    5939                 :             :     return true;
    5940                 :    30742913 :   return type_has_constexpr_default_constructor (t);
    5941                 :             : }
    5942                 :             : 
    5943                 :             : /* Returns true iff class T has a constexpr destructor.  */
    5944                 :             : 
    5945                 :             : bool
    5946                 :         291 : type_has_constexpr_destructor (tree t)
    5947                 :             : {
    5948                 :         291 :   tree fns;
    5949                 :             : 
    5950                 :         291 :   if (CLASSTYPE_LAZY_DESTRUCTOR (t))
    5951                 :             :     /* Non-trivial, we need to check subobject destructors.  */
    5952                 :          10 :     lazily_declare_fn (sfk_destructor, t);
    5953                 :         291 :   fns = CLASSTYPE_DESTRUCTOR (t);
    5954                 :         291 :   return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
    5955                 :             : }
    5956                 :             : 
    5957                 :             : /* Returns true iff class T has a constexpr destructor or has an
    5958                 :             :    implicitly declared destructor that we can't tell if it's constexpr
    5959                 :             :    without forcing a lazy declaration (which might cause undesired
    5960                 :             :    instantiations).  */
    5961                 :             : 
    5962                 :             : static bool
    5963                 :    34472779 : type_maybe_constexpr_destructor (tree t)
    5964                 :             : {
    5965                 :             :   /* Until C++20, only trivial destruction is constexpr.  */
    5966                 :    34472779 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (t))
    5967                 :             :     return true;
    5968                 :     1181878 :   if (cxx_dialect < cxx20)
    5969                 :             :     return false;
    5970                 :      419841 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DESTRUCTOR (t))
    5971                 :             :     /* Assume it's constexpr.  */
    5972                 :             :     return true;
    5973                 :      360873 :   tree fn = CLASSTYPE_DESTRUCTOR (t);
    5974                 :      360873 :   return (fn && maybe_constexpr_fn (fn));
    5975                 :             : }
    5976                 :             : 
    5977                 :             : /* Returns true iff class TYPE has a virtual destructor.  */
    5978                 :             : 
    5979                 :             : bool
    5980                 :     3053369 : type_has_virtual_destructor (tree type)
    5981                 :             : {
    5982                 :     3053369 :   tree dtor;
    5983                 :             : 
    5984                 :     3053369 :   if (!NON_UNION_CLASS_TYPE_P (type))
    5985                 :             :     return false;
    5986                 :             : 
    5987                 :     3053250 :   gcc_assert (COMPLETE_TYPE_P (type));
    5988                 :     3053250 :   dtor = CLASSTYPE_DESTRUCTOR (type);
    5989                 :     3053250 :   return (dtor && DECL_VIRTUAL_P (dtor));
    5990                 :             : }
    5991                 :             : 
    5992                 :             : /* True iff class TYPE has a non-deleted trivial default
    5993                 :             :    constructor.  */
    5994                 :             : 
    5995                 :             : bool
    5996                 :       19783 : type_has_non_deleted_trivial_default_ctor (tree type)
    5997                 :             : {
    5998                 :       19783 :   return TYPE_HAS_TRIVIAL_DFLT (type) && locate_ctor (type);
    5999                 :             : }
    6000                 :             : 
    6001                 :             : /* Returns true iff T, a class, has a move-assignment or
    6002                 :             :    move-constructor.  Does not lazily declare either.
    6003                 :             :    If USER_P is false, any move function will do.  If it is true, the
    6004                 :             :    move function must be user-declared.
    6005                 :             : 
    6006                 :             :    Note that user-declared here is different from "user-provided",
    6007                 :             :    which doesn't include functions that are defaulted in the
    6008                 :             :    class.  */
    6009                 :             : 
    6010                 :             : bool
    6011                 :    38207184 : classtype_has_move_assign_or_move_ctor_p (tree t, bool user_p)
    6012                 :             : {
    6013                 :    38207184 :   gcc_assert (user_p
    6014                 :             :               || (!CLASSTYPE_LAZY_MOVE_CTOR (t)
    6015                 :             :                   && !CLASSTYPE_LAZY_MOVE_ASSIGN (t)));
    6016                 :             : 
    6017                 :    38207184 :   if (!CLASSTYPE_LAZY_MOVE_CTOR (t))
    6018                 :    45971664 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    6019                 :     7951500 :       if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter))
    6020                 :      964703 :         return true;
    6021                 :             : 
    6022                 :    37242481 :   if (!CLASSTYPE_LAZY_MOVE_ASSIGN (t))
    6023                 :      759893 :     for (ovl_iterator iter (get_class_binding_direct
    6024                 :    33762796 :                             (t, assign_op_identifier));
    6025                 :    34522689 :          iter; ++iter)
    6026                 :      717895 :       if ((!user_p || !DECL_ARTIFICIAL (*iter))
    6027                 :      129965 :           && DECL_CONTEXT (*iter) == t
    6028                 :      835654 :           && move_fn_p (*iter))
    6029                 :        1579 :         return true;
    6030                 :             : 
    6031                 :             :   return false;
    6032                 :             : }
    6033                 :             : 
    6034                 :             : /* True iff T has a move constructor that is not deleted.  */
    6035                 :             : 
    6036                 :             : bool
    6037                 :           6 : classtype_has_non_deleted_move_ctor (tree t)
    6038                 :             : {
    6039                 :           6 :   if (CLASSTYPE_LAZY_MOVE_CTOR (t))
    6040                 :           0 :     lazily_declare_fn (sfk_move_constructor, t);
    6041                 :           6 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    6042                 :           6 :     if (move_fn_p (*iter) && !DECL_DELETED_FN (*iter))
    6043                 :           6 :       return true;
    6044                 :           0 :   return false;
    6045                 :             : }
    6046                 :             : 
    6047                 :             : /* If T, a class, has a user-provided copy constructor, copy assignment
    6048                 :             :    operator, or destructor, returns that function.  Otherwise, null.  */
    6049                 :             : 
    6050                 :             : tree
    6051                 :     4538671 : classtype_has_depr_implicit_copy (tree t)
    6052                 :             : {
    6053                 :     4538671 :   if (!CLASSTYPE_LAZY_COPY_CTOR (t))
    6054                 :    11988516 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    6055                 :             :       {
    6056                 :     5971755 :         tree fn = *iter;
    6057                 :     5971755 :         if (user_provided_p (fn) && copy_fn_p (fn))
    6058                 :         709 :           return fn;
    6059                 :             :       }
    6060                 :             : 
    6061                 :     4537962 :   if (!CLASSTYPE_LAZY_COPY_ASSIGN (t))
    6062                 :      641969 :     for (ovl_iterator iter (get_class_binding_direct
    6063                 :     1150027 :                             (t, assign_op_identifier));
    6064                 :     1791996 :          iter; ++iter)
    6065                 :             :       {
    6066                 :      642363 :         tree fn = *iter;
    6067                 :      642363 :         if (DECL_CONTEXT (fn) == t
    6068                 :      642363 :             && user_provided_p (fn) && copy_fn_p (fn))
    6069                 :         394 :           return fn;
    6070                 :             :       }
    6071                 :             : 
    6072                 :     4537568 :   if (!CLASSTYPE_LAZY_DESTRUCTOR (t))
    6073                 :             :     {
    6074                 :     1629259 :       tree fn = CLASSTYPE_DESTRUCTOR (t);
    6075                 :     1629259 :       if (user_provided_p (fn))
    6076                 :             :         return fn;
    6077                 :             :     }
    6078                 :             : 
    6079                 :             :   return NULL_TREE;
    6080                 :             : }
    6081                 :             : 
    6082                 :             : /* True iff T has a member or friend declaration of operator OP.  */
    6083                 :             : 
    6084                 :             : bool
    6085                 :    37061824 : classtype_has_op (tree t, tree_code op)
    6086                 :             : {
    6087                 :    37061824 :   tree name = ovl_op_identifier (op);
    6088                 :    37061824 :   if (get_class_binding (t, name))
    6089                 :             :     return true;
    6090                 :    38458995 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    6091                 :     2261641 :     if (FRIEND_NAME (f) == name)
    6092                 :             :       return true;
    6093                 :             :   return false;
    6094                 :             : }
    6095                 :             : 
    6096                 :             : 
    6097                 :             : /* If T has a defaulted member or friend declaration of OP, return it.  */
    6098                 :             : 
    6099                 :             : tree
    6100                 :    36197354 : classtype_has_defaulted_op (tree t, tree_code op)
    6101                 :             : {
    6102                 :    36197354 :   tree name = ovl_op_identifier (op);
    6103                 :    36197392 :   for (ovl_iterator oi (get_class_binding (t, name)); oi; ++oi)
    6104                 :             :     {
    6105                 :         224 :       tree fn = *oi;
    6106                 :         224 :       if (DECL_DEFAULTED_FN (fn))
    6107                 :         191 :         return fn;
    6108                 :             :     }
    6109                 :    36799118 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    6110                 :      601990 :     if (FRIEND_NAME (f) == name)
    6111                 :         441 :       for (tree l = FRIEND_DECLS (f); l; l = TREE_CHAIN (l))
    6112                 :             :         {
    6113                 :         243 :           tree fn = TREE_VALUE (l);
    6114                 :         243 :           if (DECL_DEFAULTED_FN (fn))
    6115                 :             :             return fn;
    6116                 :             :         }
    6117                 :             :   return NULL_TREE;
    6118                 :             : }
    6119                 :             : 
    6120                 :             : /* Nonzero if we need to build up a constructor call when initializing an
    6121                 :             :    object of this class, either because it has a user-declared constructor
    6122                 :             :    or because it doesn't have a default constructor (so we need to give an
    6123                 :             :    error if no initializer is provided).  Use TYPE_NEEDS_CONSTRUCTING when
    6124                 :             :    what you care about is whether or not an object can be produced by a
    6125                 :             :    constructor (e.g. so we don't set TREE_READONLY on const variables of
    6126                 :             :    such type); use this function when what you care about is whether or not
    6127                 :             :    to try to call a constructor to create an object.  The latter case is
    6128                 :             :    the former plus some cases of constructors that cannot be called.  */
    6129                 :             : 
    6130                 :             : bool
    6131                 :    50414732 : type_build_ctor_call (tree t)
    6132                 :             : {
    6133                 :    50414732 :   tree inner;
    6134                 :    50414732 :   if (TYPE_NEEDS_CONSTRUCTING (t))
    6135                 :             :     return true;
    6136                 :    44553119 :   inner = strip_array_types (t);
    6137                 :    44553119 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner))
    6138                 :             :     return false;
    6139                 :     3716793 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (inner))
    6140                 :             :     return true;
    6141                 :     3338252 :   if (cxx_dialect < cxx11)
    6142                 :             :     return false;
    6143                 :             :   /* A user-declared constructor might be private, and a constructor might
    6144                 :             :      be trivial but deleted.  */
    6145                 :    12660273 :   for (ovl_iterator iter (get_class_binding (inner, complete_ctor_identifier));
    6146                 :    12660273 :        iter; ++iter)
    6147                 :             :     {
    6148                 :     9754323 :       tree fn = *iter;
    6149                 :     9754323 :       if (!DECL_ARTIFICIAL (fn)
    6150                 :     9583993 :           || TREE_DEPRECATED (fn)
    6151                 :     9469342 :           || TREE_UNAVAILABLE (fn)
    6152                 :    19223665 :           || DECL_DELETED_FN (fn))
    6153                 :      422522 :         return true;
    6154                 :             :     }
    6155                 :     2905950 :   return false;
    6156                 :             : }
    6157                 :             : 
    6158                 :             : /* Like type_build_ctor_call, but for destructors.  */
    6159                 :             : 
    6160                 :             : bool
    6161                 :    95705487 : type_build_dtor_call (tree t)
    6162                 :             : {
    6163                 :    95705487 :   tree inner;
    6164                 :    95705487 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    6165                 :             :     return true;
    6166                 :    71336366 :   inner = strip_array_types (t);
    6167                 :    29536819 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner)
    6168                 :   100695702 :       || !COMPLETE_TYPE_P (inner))
    6169                 :             :     return false;
    6170                 :    29359313 :   if (cxx_dialect < cxx11)
    6171                 :             :     return false;
    6172                 :             :   /* A user-declared destructor might be private, and a destructor might
    6173                 :             :      be trivial but deleted.  */
    6174                 :    52191598 :   for (ovl_iterator iter (get_class_binding (inner, complete_dtor_identifier));
    6175                 :    52191598 :        iter; ++iter)
    6176                 :             :     {
    6177                 :    28946211 :       tree fn = *iter;
    6178                 :    28946211 :       if (!DECL_ARTIFICIAL (fn)
    6179                 :    22869463 :           || TREE_DEPRECATED (fn)
    6180                 :    22869463 :           || TREE_UNAVAILABLE (fn)
    6181                 :    51815674 :           || DECL_DELETED_FN (fn))
    6182                 :     6076751 :         return true;
    6183                 :             :     }
    6184                 :    23245387 :   return false;
    6185                 :             : }
    6186                 :             : 
    6187                 :             : /* Returns TRUE iff we need a cookie when dynamically allocating an
    6188                 :             :    array whose elements have the indicated class TYPE.  */
    6189                 :             : 
    6190                 :             : static bool
    6191                 :    37061824 : type_requires_array_cookie (tree type)
    6192                 :             : {
    6193                 :    37061824 :   tree fns;
    6194                 :    37061824 :   bool has_two_argument_delete_p = false;
    6195                 :             : 
    6196                 :    37061824 :   gcc_assert (CLASS_TYPE_P (type));
    6197                 :             : 
    6198                 :             :   /* If there's a non-trivial destructor, we need a cookie.  In order
    6199                 :             :      to iterate through the array calling the destructor for each
    6200                 :             :      element, we'll have to know how many elements there are.  */
    6201                 :    37061824 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    6202                 :             :     return true;
    6203                 :             : 
    6204                 :             :   /* If the usual deallocation function is a two-argument whose second
    6205                 :             :      argument is of type `size_t', then we have to pass the size of
    6206                 :             :      the array to the deallocation function, so we will need to store
    6207                 :             :      a cookie.  */
    6208                 :    33540449 :   fns = lookup_fnfields (TYPE_BINFO (type),
    6209                 :             :                          ovl_op_identifier (false, VEC_DELETE_EXPR),
    6210                 :             :                          /*protect=*/0, tf_warning_or_error);
    6211                 :             :   /* If there are no `operator []' members, or the lookup is
    6212                 :             :      ambiguous, then we don't need a cookie.  */
    6213                 :    33540449 :   if (!fns || fns == error_mark_node)
    6214                 :             :     return false;
    6215                 :             :   /* Loop through all of the functions.  */
    6216                 :         236 :   for (lkp_iterator iter (BASELINK_FUNCTIONS (fns)); iter; ++iter)
    6217                 :             :     {
    6218                 :         224 :       tree fn = *iter;
    6219                 :             : 
    6220                 :             :       /* See if this function is a one-argument delete function.  If
    6221                 :             :          it is, then it will be the usual deallocation function.  */
    6222                 :         224 :       tree second_parm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)));
    6223                 :         224 :       if (second_parm == void_list_node)
    6224                 :         101 :         return false;
    6225                 :             :       /* Do not consider this function if its second argument is an
    6226                 :             :          ellipsis.  */
    6227                 :         123 :       if (!second_parm)
    6228                 :           3 :         continue;
    6229                 :             :       /* Otherwise, if we have a two-argument function and the second
    6230                 :             :          argument is `size_t', it will be the usual deallocation
    6231                 :             :          function -- unless there is one-argument function, too.  */
    6232                 :         120 :       if (TREE_CHAIN (second_parm) == void_list_node
    6233                 :         120 :           && same_type_p (TREE_VALUE (second_parm), size_type_node))
    6234                 :             :         has_two_argument_delete_p = true;
    6235                 :             :     }
    6236                 :             : 
    6237                 :          12 :   return has_two_argument_delete_p;
    6238                 :             : }
    6239                 :             : 
    6240                 :             : /* Finish computing the `literal type' property of class type T.
    6241                 :             : 
    6242                 :             :    At this point, we have already processed base classes and
    6243                 :             :    non-static data members.  We need to check whether the copy
    6244                 :             :    constructor is trivial, the destructor is trivial, and there
    6245                 :             :    is a trivial default constructor or at least one constexpr
    6246                 :             :    constructor other than the copy constructor.  */
    6247                 :             : 
    6248                 :             : static void
    6249                 :    37061824 : finalize_literal_type_property (tree t)
    6250                 :             : {
    6251                 :    37061824 :   tree fn;
    6252                 :             : 
    6253                 :    37061824 :   if (cxx_dialect < cxx11)
    6254                 :      107990 :     CLASSTYPE_LITERAL_P (t) = false;
    6255                 :    36953834 :   else if (CLASSTYPE_LITERAL_P (t)
    6256                 :    36953834 :            && !type_maybe_constexpr_destructor (t))
    6257                 :      922231 :     CLASSTYPE_LITERAL_P (t) = false;
    6258                 :    69205900 :   else if (CLASSTYPE_LITERAL_P (t) && LAMBDA_TYPE_P (t))
    6259                 :      290652 :     CLASSTYPE_LITERAL_P (t) = (cxx_dialect >= cxx17);
    6260                 :    69000834 :   else if (CLASSTYPE_LITERAL_P (t) && !TYPE_HAS_TRIVIAL_DFLT (t)
    6261                 :     2199269 :            && CLASSTYPE_NON_AGGREGATE (t)
    6262                 :    37859545 :            && !TYPE_HAS_CONSTEXPR_CTOR (t))
    6263                 :      560736 :     CLASSTYPE_LITERAL_P (t) = false;
    6264                 :             : 
    6265                 :             :   /* C++14 DR 1684 removed this restriction.  */
    6266                 :    37061824 :   if (cxx_dialect < cxx14
    6267                 :    37184142 :       && !CLASSTYPE_LITERAL_P (t) && !LAMBDA_TYPE_P (t))
    6268                 :     1283742 :     for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6269                 :     1155211 :       if (TREE_CODE (fn) == FUNCTION_DECL
    6270                 :      554668 :           && DECL_DECLARED_CONSTEXPR_P (fn)
    6271                 :        2583 :           && DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    6272                 :     1157466 :           && !DECL_CONSTRUCTOR_P (fn))
    6273                 :             :         {
    6274                 :         568 :           DECL_DECLARED_CONSTEXPR_P (fn) = false;
    6275                 :         568 :           if (!DECL_GENERATED_P (fn))
    6276                 :             :             {
    6277                 :           5 :               auto_diagnostic_group d;
    6278                 :           5 :               if (pedwarn (DECL_SOURCE_LOCATION (fn), OPT_Wpedantic,
    6279                 :             :                              "enclosing class of %<constexpr%> non-static "
    6280                 :             :                              "member function %q+#D is not a literal type", fn))
    6281                 :           5 :                 explain_non_literal_class (t);
    6282                 :           5 :             }
    6283                 :             :         }
    6284                 :    37061824 : }
    6285                 :             : 
    6286                 :             : /* T is a non-literal type used in a context which requires a constant
    6287                 :             :    expression.  Explain why it isn't literal.  */
    6288                 :             : 
    6289                 :             : void
    6290                 :         135 : explain_non_literal_class (tree t)
    6291                 :             : {
    6292                 :         135 :   static hash_set<tree> *diagnosed;
    6293                 :             : 
    6294                 :         135 :   if (!CLASS_TYPE_P (t))
    6295                 :          51 :     return;
    6296                 :         132 :   t = TYPE_MAIN_VARIANT (t);
    6297                 :             : 
    6298                 :         132 :   if (diagnosed == NULL)
    6299                 :          72 :     diagnosed = new hash_set<tree>;
    6300                 :         132 :   if (diagnosed->add (t))
    6301                 :             :     /* Already explained.  */
    6302                 :             :     return;
    6303                 :             : 
    6304                 :          99 :   auto_diagnostic_group d;
    6305                 :          99 :   inform (UNKNOWN_LOCATION, "%q+T is not literal because:", t);
    6306                 :         128 :   if (cxx_dialect < cxx17 && LAMBDA_TYPE_P (t))
    6307                 :           1 :     inform (UNKNOWN_LOCATION,
    6308                 :             :             "  %qT is a closure type, which is only literal in "
    6309                 :             :             "C++17 and later", t);
    6310                 :          98 :   else if (cxx_dialect < cxx20 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    6311                 :           8 :     inform (UNKNOWN_LOCATION, "  %q+T has a non-trivial destructor", t);
    6312                 :          90 :   else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    6313                 :          90 :            && !type_maybe_constexpr_destructor (t))
    6314                 :          13 :     inform (UNKNOWN_LOCATION, "  %q+T does not have %<constexpr%> destructor",
    6315                 :             :             t);
    6316                 :          77 :   else if (CLASSTYPE_NON_AGGREGATE (t)
    6317                 :          67 :            && !TYPE_HAS_TRIVIAL_DFLT (t)
    6318                 :         131 :            && !LAMBDA_TYPE_P (t)
    6319                 :         144 :            && !TYPE_HAS_CONSTEXPR_CTOR (t))
    6320                 :             :     {
    6321                 :          44 :       inform (UNKNOWN_LOCATION,
    6322                 :             :               "  %q+T is not an aggregate, does not have a trivial "
    6323                 :             :               "default constructor, and has no %<constexpr%> constructor that "
    6324                 :             :               "is not a copy or move constructor", t);
    6325                 :          44 :       if (type_has_non_user_provided_default_constructor (t))
    6326                 :             :         /* Note that we can't simply call locate_ctor because when the
    6327                 :             :            constructor is deleted it just returns NULL_TREE.  */
    6328                 :           0 :         for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    6329                 :             :           {
    6330                 :           0 :             tree fn = *iter;
    6331                 :           0 :             tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
    6332                 :             : 
    6333                 :           0 :             parms = skip_artificial_parms_for (fn, parms);
    6334                 :             : 
    6335                 :           0 :             if (sufficient_parms_p (parms))
    6336                 :             :               {
    6337                 :           0 :                 if (DECL_DELETED_FN (fn))
    6338                 :           0 :                   maybe_explain_implicit_delete (fn);
    6339                 :             :                 else
    6340                 :           0 :                   explain_invalid_constexpr_fn (fn);
    6341                 :             :                 break;
    6342                 :             :               }
    6343                 :             :         }
    6344                 :             :     }
    6345                 :             :   else
    6346                 :             :     {
    6347                 :          33 :       tree binfo, base_binfo, field; int i;
    6348                 :          33 :       for (binfo = TYPE_BINFO (t), i = 0;
    6349                 :          33 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    6350                 :             :         {
    6351                 :          15 :           tree basetype = TREE_TYPE (base_binfo);
    6352                 :          15 :           if (!CLASSTYPE_LITERAL_P (basetype))
    6353                 :             :             {
    6354                 :          15 :               inform (UNKNOWN_LOCATION,
    6355                 :             :                       "  base class %qT of %q+T is non-literal",
    6356                 :             :                       basetype, t);
    6357                 :          15 :               explain_non_literal_class (basetype);
    6358                 :          15 :               return;
    6359                 :             :             }
    6360                 :             :         }
    6361                 :         138 :       for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
    6362                 :             :         {
    6363                 :         120 :           tree ftype;
    6364                 :         120 :           if (TREE_CODE (field) != FIELD_DECL)
    6365                 :         102 :             continue;
    6366                 :          18 :           ftype = TREE_TYPE (field);
    6367                 :          18 :           if (!literal_type_p (ftype))
    6368                 :             :             {
    6369                 :           6 :               inform (DECL_SOURCE_LOCATION (field),
    6370                 :             :                       "  non-static data member %qD has non-literal type",
    6371                 :             :                       field);
    6372                 :           6 :               if (CLASS_TYPE_P (ftype))
    6373                 :           6 :                 explain_non_literal_class (ftype);
    6374                 :             :             }
    6375                 :          18 :           if (CP_TYPE_VOLATILE_P (ftype))
    6376                 :          12 :             inform (DECL_SOURCE_LOCATION (field),
    6377                 :             :                     "  non-static data member %qD has volatile type", field);
    6378                 :             :         }
    6379                 :             :     }
    6380                 :          99 : }
    6381                 :             : 
    6382                 :             : /* Check the validity of the bases and members declared in T.  Add any
    6383                 :             :    implicitly-generated functions (like copy-constructors and
    6384                 :             :    assignment operators).  Compute various flag bits (like
    6385                 :             :    CLASSTYPE_NON_LAYOUT_POD_T) for T.  This routine works purely at the C++
    6386                 :             :    level: i.e., independently of the ABI in use.  */
    6387                 :             : 
    6388                 :             : static void
    6389                 :    37061824 : check_bases_and_members (tree t)
    6390                 :             : {
    6391                 :             :   /* Nonzero if the implicitly generated copy constructor should take
    6392                 :             :      a non-const reference argument.  */
    6393                 :    37061824 :   int cant_have_const_ctor;
    6394                 :             :   /* Nonzero if the implicitly generated assignment operator
    6395                 :             :      should take a non-const reference argument.  */
    6396                 :    37061824 :   int no_const_asn_ref;
    6397                 :    37061824 :   tree access_decls;
    6398                 :    37061824 :   bool saved_complex_asn_ref;
    6399                 :    37061824 :   bool saved_nontrivial_dtor;
    6400                 :    37061824 :   tree fn;
    6401                 :             : 
    6402                 :             :   /* By default, we use const reference arguments and generate default
    6403                 :             :      constructors.  */
    6404                 :    37061824 :   cant_have_const_ctor = 0;
    6405                 :    37061824 :   no_const_asn_ref = 0;
    6406                 :             : 
    6407                 :             :   /* Check all the base-classes and set FMEM members to point to arrays
    6408                 :             :      of potential interest.  */
    6409                 :    37061824 :   check_bases (t, &cant_have_const_ctor, &no_const_asn_ref);
    6410                 :             : 
    6411                 :             :   /* Deduce noexcept on destructor.  This needs to happen after we've set
    6412                 :             :      triviality flags appropriately for our bases, and before checking
    6413                 :             :      overriden virtual functions via check_methods.  */
    6414                 :    37061824 :   if (cxx_dialect >= cxx11)
    6415                 :    36953834 :     if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    6416                 :     7098670 :       for (tree fn : ovl_range (dtor))
    6417                 :     3549335 :         deduce_noexcept_on_destructor (fn);
    6418                 :             : 
    6419                 :             :   /* Check all the method declarations.  */
    6420                 :    37061824 :   check_methods (t);
    6421                 :             : 
    6422                 :             :   /* Save the initial values of these flags which only indicate whether
    6423                 :             :      or not the class has user-provided functions.  As we analyze the
    6424                 :             :      bases and members we can set these flags for other reasons.  */
    6425                 :    37061824 :   saved_complex_asn_ref = TYPE_HAS_COMPLEX_COPY_ASSIGN (t);
    6426                 :    37061824 :   saved_nontrivial_dtor = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
    6427                 :             : 
    6428                 :             :   /* Check all the data member declarations.  We cannot call
    6429                 :             :      check_field_decls until we have called check_bases check_methods,
    6430                 :             :      as check_field_decls depends on TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    6431                 :             :      being set appropriately.  */
    6432                 :    37061824 :   check_field_decls (t, &access_decls,
    6433                 :             :                      &cant_have_const_ctor,
    6434                 :             :                      &no_const_asn_ref);
    6435                 :             : 
    6436                 :             :   /* A nearly-empty class has to be vptr-containing; a nearly empty
    6437                 :             :      class contains just a vptr.  */
    6438                 :    37061824 :   if (!TYPE_CONTAINS_VPTR_P (t))
    6439                 :    35404109 :     CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    6440                 :             : 
    6441                 :             :   /* Do some bookkeeping that will guide the generation of implicitly
    6442                 :             :      declared member functions.  */
    6443                 :    38719539 :   TYPE_HAS_COMPLEX_COPY_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
    6444                 :    38719539 :   TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
    6445                 :             :   /* We need to call a constructor for this class if it has a
    6446                 :             :      user-provided constructor, or if the default constructor is going
    6447                 :             :      to initialize the vptr.  (This is not an if-and-only-if;
    6448                 :             :      TYPE_NEEDS_CONSTRUCTING is set elsewhere if bases or members
    6449                 :             :      themselves need constructing.)  */
    6450                 :    37061824 :   TYPE_NEEDS_CONSTRUCTING (t)
    6451                 :    37061824 :     |= (type_has_user_provided_constructor (t) || TYPE_CONTAINS_VPTR_P (t));
    6452                 :             :   /* [dcl.init.aggr]
    6453                 :             : 
    6454                 :             :      An aggregate is an array or a class with no user-provided
    6455                 :             :      constructors ... and no virtual functions.
    6456                 :             : 
    6457                 :             :      Again, other conditions for being an aggregate are checked
    6458                 :             :      elsewhere.  */
    6459                 :    37061824 :   CLASSTYPE_NON_AGGREGATE (t)
    6460                 :    37061824 :     |= (type_has_user_provided_or_explicit_constructor (t)
    6461                 :    37061824 :         || TYPE_POLYMORPHIC_P (t));
    6462                 :             :   /* This is the C++98/03 definition of POD; it changed in C++0x, but we
    6463                 :             :      retain the old definition internally for ABI reasons.  */
    6464                 :    37061824 :   CLASSTYPE_NON_LAYOUT_POD_P (t)
    6465                 :    37061824 :     |= (CLASSTYPE_NON_AGGREGATE (t)
    6466                 :    37061824 :         || saved_nontrivial_dtor || saved_complex_asn_ref);
    6467                 :    38719539 :   CLASSTYPE_NON_STD_LAYOUT (t) |= TYPE_CONTAINS_VPTR_P (t);
    6468                 :    38719539 :   TYPE_HAS_COMPLEX_COPY_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    6469                 :    38719539 :   TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    6470                 :    38719539 :   TYPE_HAS_COMPLEX_DFLT (t) |= TYPE_CONTAINS_VPTR_P (t);
    6471                 :             : 
    6472                 :             :   /* Is this class non-layout-POD because it wasn't an aggregate in C++98?  */
    6473                 :    37061824 :   if (CLASSTYPE_NON_POD_AGGREGATE (t))
    6474                 :             :     {
    6475                 :      511286 :       if (CLASSTYPE_NON_LAYOUT_POD_P (t))
    6476                 :             :         /* It's non-POD for another reason.  */
    6477                 :      484465 :         CLASSTYPE_NON_POD_AGGREGATE (t) = false;
    6478                 :       26821 :       else if (abi_version_at_least (17))
    6479                 :       26819 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = true;
    6480                 :             :     }
    6481                 :             : 
    6482                 :             :   /* P1008: Prohibit aggregates with user-declared constructors.  */
    6483                 :    37061824 :   if (cxx_dialect >= cxx20 && TYPE_HAS_USER_CONSTRUCTOR (t))
    6484                 :             :     {
    6485                 :     1918092 :       CLASSTYPE_NON_AGGREGATE (t) = true;
    6486                 :     1918092 :       if (!CLASSTYPE_NON_LAYOUT_POD_P (t))
    6487                 :             :         {
    6488                 :             :           /* c++/120012: The C++20 aggregate change affected layout.  */
    6489                 :        1969 :           if (!abi_version_at_least (21))
    6490                 :           3 :             CLASSTYPE_NON_LAYOUT_POD_P (t) = true;
    6491                 :        4258 :           if (abi_version_crosses (21))
    6492                 :        1649 :             CLASSTYPE_NON_AGGREGATE_POD (t) = true;
    6493                 :             :         }
    6494                 :             :     }
    6495                 :             : 
    6496                 :             :   /* If the only explicitly declared default constructor is user-provided,
    6497                 :             :      set TYPE_HAS_COMPLEX_DFLT.  */
    6498                 :    37061824 :   if (!TYPE_HAS_COMPLEX_DFLT (t)
    6499                 :    33262151 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (t)
    6500                 :    39042511 :       && !type_has_non_user_provided_default_constructor (t))
    6501                 :     1309598 :     TYPE_HAS_COMPLEX_DFLT (t) = true;
    6502                 :             : 
    6503                 :             :   /* Warn if a public base of a polymorphic type has an accessible
    6504                 :             :      non-virtual destructor.  It is only now that we know the class is
    6505                 :             :      polymorphic.  Although a polymorphic base will have a already
    6506                 :             :      been diagnosed during its definition, we warn on use too.  */
    6507                 :    37061824 :   if (TYPE_POLYMORPHIC_P (t) && warn_nonvdtor)
    6508                 :             :     {
    6509                 :          84 :       tree binfo = TYPE_BINFO (t);
    6510                 :          84 :       vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
    6511                 :          84 :       tree base_binfo;
    6512                 :          84 :       unsigned i;
    6513                 :             : 
    6514                 :         114 :       for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    6515                 :             :         {
    6516                 :          30 :           tree basetype = TREE_TYPE (base_binfo);
    6517                 :             : 
    6518                 :          30 :           if ((*accesses)[i] == access_public_node
    6519                 :          18 :               && (TYPE_POLYMORPHIC_P (basetype) || warn_ecpp)
    6520                 :          45 :               && accessible_nvdtor_p (basetype))
    6521                 :           9 :             warning (OPT_Wnon_virtual_dtor,
    6522                 :             :                      "base class %q#T has accessible non-virtual destructor",
    6523                 :             :                      basetype);
    6524                 :             :         }
    6525                 :             :     }
    6526                 :             : 
    6527                 :             :   /* If the class has no user-declared constructor, but does have
    6528                 :             :      non-static const or reference data members that can never be
    6529                 :             :      initialized, issue a warning.  */
    6530                 :    37061824 :   if (warn_uninitialized
    6531                 :             :       /* Classes with user-declared constructors are presumed to
    6532                 :             :          initialize these members.  */
    6533                 :      361099 :       && !TYPE_HAS_USER_CONSTRUCTOR (t)
    6534                 :             :       /* Aggregates can be initialized with brace-enclosed
    6535                 :             :          initializers.  */
    6536                 :    37359112 :       && CLASSTYPE_NON_AGGREGATE (t))
    6537                 :             :     {
    6538                 :       37746 :       tree field;
    6539                 :             : 
    6540                 :      237458 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6541                 :             :         {
    6542                 :      199712 :           tree type;
    6543                 :             : 
    6544                 :      378247 :           if (TREE_CODE (field) != FIELD_DECL
    6545                 :      199712 :               || DECL_INITIAL (field) != NULL_TREE)
    6546                 :      178535 :             continue;
    6547                 :             : 
    6548                 :       21177 :           type = TREE_TYPE (field);
    6549                 :       21177 :           if (TYPE_REF_P (type))
    6550                 :           6 :             warning_at (DECL_SOURCE_LOCATION (field),
    6551                 :           6 :                         OPT_Wuninitialized, "non-static reference %q#D "
    6552                 :             :                         "in class without a constructor", field);
    6553                 :       21171 :           else if (CP_TYPE_CONST_P (type)
    6554                 :       21171 :                    && (!CLASS_TYPE_P (type)
    6555                 :           3 :                        || !TYPE_HAS_DEFAULT_CONSTRUCTOR (type)))
    6556                 :           9 :             warning_at (DECL_SOURCE_LOCATION (field),
    6557                 :           9 :                         OPT_Wuninitialized, "non-static const member %q#D "
    6558                 :             :                         "in class without a constructor", field);
    6559                 :             :         }
    6560                 :             :     }
    6561                 :             : 
    6562                 :             :   /* Synthesize any needed methods.  */
    6563                 :    37061824 :   add_implicitly_declared_members (t, &access_decls,
    6564                 :             :                                    cant_have_const_ctor,
    6565                 :             :                                    no_const_asn_ref);
    6566                 :             : 
    6567                 :             :   /* Check defaulted declarations here so we have cant_have_const_ctor
    6568                 :             :      and don't need to worry about clones.  */
    6569                 :   261254510 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6570                 :   130087734 :     if (DECL_DECLARES_FUNCTION_P (fn)
    6571                 :   115600636 :         && !DECL_ARTIFICIAL (fn)
    6572                 :   114658367 :         && DECL_DEFAULTED_IN_CLASS_P (fn)
    6573                 :             :         /* ...except handle comparisons later, in finish_struct_1.  */
    6574                 :   229585578 :         && special_function_p (fn) != sfk_comparison)
    6575                 :             :       {
    6576                 :     5381533 :         bool imp_const_p
    6577                 :    10763066 :           = (DECL_CONSTRUCTOR_P (fn) ? !cant_have_const_ctor
    6578                 :     5381533 :              : !no_const_asn_ref);
    6579                 :     5381613 :         defaulted_late_check (fn, imp_const_p);
    6580                 :             :       }
    6581                 :             : 
    6582                 :    73736999 :   if (LAMBDA_TYPE_P (t))
    6583                 :             :     /* "This class type is not an aggregate."  */
    6584                 :      290824 :     CLASSTYPE_NON_AGGREGATE (t) = 1;
    6585                 :             : 
    6586                 :             :   /* Compute the 'literal type' property before we
    6587                 :             :      do anything with non-static member functions.  */
    6588                 :    37061824 :   finalize_literal_type_property (t);
    6589                 :             : 
    6590                 :             :   /* Create the in-charge and not-in-charge variants of constructors
    6591                 :             :      and destructors.  */
    6592                 :    37061824 :   clone_constructors_and_destructors (t);
    6593                 :             : 
    6594                 :             :   /* Process the using-declarations.  */
    6595                 :    76102382 :   for (; access_decls; access_decls = TREE_CHAIN (access_decls))
    6596                 :     1978734 :     handle_using_decl (TREE_VALUE (access_decls), t);
    6597                 :             : 
    6598                 :             :   /* Figure out whether or not we will need a cookie when dynamically
    6599                 :             :      allocating an array of this type.  */
    6600                 :    37061824 :   LANG_TYPE_CLASS_CHECK (t)->vec_new_uses_cookie
    6601                 :    37061824 :     = type_requires_array_cookie (t);
    6602                 :             : 
    6603                 :             :   /* Classes marked hot or cold propagate the attribute to all members.  We
    6604                 :             :      may do this now that methods are declared.  This does miss some lazily
    6605                 :             :      declared special member functions (CLASSTYPE_LAZY_*), which are handled
    6606                 :             :      in lazily_declare_fn later on.  */
    6607                 :    37061824 :   propagate_class_warmth_attribute (t);
    6608                 :    37061824 : }
    6609                 :             : 
    6610                 :             : /* If T needs a pointer to its virtual function table, set TYPE_VFIELD
    6611                 :             :    accordingly.  If a new vfield was created (because T doesn't have a
    6612                 :             :    primary base class), then the newly created field is returned.  It
    6613                 :             :    is not added to the TYPE_FIELDS list; it is the caller's
    6614                 :             :    responsibility to do that.  Accumulate declared virtual functions
    6615                 :             :    on VIRTUALS_P.  */
    6616                 :             : 
    6617                 :             : static tree
    6618                 :    37061824 : create_vtable_ptr (tree t, tree* virtuals_p)
    6619                 :             : {
    6620                 :    37061824 :   tree fn;
    6621                 :             : 
    6622                 :             :   /* Collect the virtual functions declared in T.  */
    6623                 :   318821058 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6624                 :   281759234 :     if (TREE_CODE (fn) == FUNCTION_DECL
    6625                 :   136171623 :         && DECL_VINDEX (fn) && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)
    6626                 :   289381912 :         && TREE_CODE (DECL_VINDEX (fn)) != INTEGER_CST)
    6627                 :             :       {
    6628                 :     7622678 :         tree new_virtual = make_node (TREE_LIST);
    6629                 :             : 
    6630                 :     7622678 :         BV_FN (new_virtual) = fn;
    6631                 :     7622678 :         BV_DELTA (new_virtual) = integer_zero_node;
    6632                 :     7622678 :         BV_VCALL_INDEX (new_virtual) = NULL_TREE;
    6633                 :             : 
    6634                 :     7622678 :         TREE_CHAIN (new_virtual) = *virtuals_p;
    6635                 :     7622678 :         *virtuals_p = new_virtual;
    6636                 :             :       }
    6637                 :             : 
    6638                 :             :   /* If we couldn't find an appropriate base class, create a new field
    6639                 :             :      here.  Even if there weren't any new virtual functions, we might need a
    6640                 :             :      new virtual function table if we're supposed to include vptrs in
    6641                 :             :      all classes that need them.  */
    6642                 :    37061824 :   if (!TYPE_VFIELD (t) && (*virtuals_p || TYPE_CONTAINS_VPTR_P (t)))
    6643                 :             :     {
    6644                 :             :       /* We build this decl with vtbl_ptr_type_node, which is a
    6645                 :             :          `vtable_entry_type*'.  It might seem more precise to use
    6646                 :             :          `vtable_entry_type (*)[N]' where N is the number of virtual
    6647                 :             :          functions.  However, that would require the vtable pointer in
    6648                 :             :          base classes to have a different type than the vtable pointer
    6649                 :             :          in derived classes.  We could make that happen, but that
    6650                 :             :          still wouldn't solve all the problems.  In particular, the
    6651                 :             :          type-based alias analysis code would decide that assignments
    6652                 :             :          to the base class vtable pointer can't alias assignments to
    6653                 :             :          the derived class vtable pointer, since they have different
    6654                 :             :          types.  Thus, in a derived class destructor, where the base
    6655                 :             :          class constructor was inlined, we could generate bad code for
    6656                 :             :          setting up the vtable pointer.
    6657                 :             : 
    6658                 :             :          Therefore, we use one type for all vtable pointers.  We still
    6659                 :             :          use a type-correct type; it's just doesn't indicate the array
    6660                 :             :          bounds.  That's better than using `void*' or some such; it's
    6661                 :             :          cleaner, and it let's the alias analysis code know that these
    6662                 :             :          stores cannot alias stores to void*!  */
    6663                 :      239845 :       tree field;
    6664                 :             : 
    6665                 :      239845 :       field = build_decl (input_location,
    6666                 :             :                           FIELD_DECL, get_vfield_name (t), vtbl_ptr_type_node);
    6667                 :      239845 :       DECL_VIRTUAL_P (field) = 1;
    6668                 :      239845 :       DECL_ARTIFICIAL (field) = 1;
    6669                 :      239845 :       DECL_FIELD_CONTEXT (field) = t;
    6670                 :      239845 :       DECL_FCONTEXT (field) = t;
    6671                 :      239845 :       if (TYPE_PACKED (t))
    6672                 :           3 :         DECL_PACKED (field) = 1;
    6673                 :             : 
    6674                 :      239845 :       TYPE_VFIELD (t) = field;
    6675                 :             : 
    6676                 :             :       /* This class is non-empty.  */
    6677                 :      239845 :       CLASSTYPE_EMPTY_P (t) = 0;
    6678                 :             : 
    6679                 :      239845 :       return field;
    6680                 :             :     }
    6681                 :             : 
    6682                 :             :   return NULL_TREE;
    6683                 :             : }
    6684                 :             : 
    6685                 :             : /* Add OFFSET to all base types of BINFO which is a base in the
    6686                 :             :    hierarchy dominated by T.
    6687                 :             : 
    6688                 :             :    OFFSET, which is a type offset, is number of bytes.  */
    6689                 :             : 
    6690                 :             : static void
    6691                 :    22517393 : propagate_binfo_offsets (tree binfo, tree offset)
    6692                 :             : {
    6693                 :    22517393 :   int i;
    6694                 :    22517393 :   tree primary_binfo;
    6695                 :    22517393 :   tree base_binfo;
    6696                 :             : 
    6697                 :             :   /* Update BINFO's offset.  */
    6698                 :    22517393 :   BINFO_OFFSET (binfo)
    6699                 :    22517393 :     = fold_convert (sizetype,
    6700                 :             :                size_binop (PLUS_EXPR,
    6701                 :             :                            fold_convert (ssizetype, BINFO_OFFSET (binfo)),
    6702                 :             :                            offset));
    6703                 :             : 
    6704                 :             :   /* Find the primary base class.  */
    6705                 :    22517393 :   primary_binfo = get_primary_binfo (binfo);
    6706                 :             : 
    6707                 :    23572040 :   if (primary_binfo && BINFO_INHERITANCE_CHAIN (primary_binfo) == binfo)
    6708                 :     1053655 :     propagate_binfo_offsets (primary_binfo, offset);
    6709                 :             : 
    6710                 :             :   /* Scan all of the bases, pushing the BINFO_OFFSET adjust
    6711                 :             :      downwards.  */
    6712                 :    25717939 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6713                 :             :     {
    6714                 :             :       /* Don't do the primary base twice.  */
    6715                 :     4255119 :       if (base_binfo == primary_binfo)
    6716                 :     1054573 :         continue;
    6717                 :             : 
    6718                 :     2145973 :       if (BINFO_VIRTUAL_P (base_binfo))
    6719                 :      222656 :         continue;
    6720                 :             : 
    6721                 :     1923317 :       propagate_binfo_offsets (base_binfo, offset);
    6722                 :             :     }
    6723                 :    22517393 : }
    6724                 :             : 
    6725                 :             : /* Set BINFO_OFFSET for all of the virtual bases for RLI->T.  Update
    6726                 :             :    TYPE_ALIGN and TYPE_SIZE for T.  OFFSETS gives the location of
    6727                 :             :    empty subobjects of T.  */
    6728                 :             : 
    6729                 :             : static void
    6730                 :    37061824 : layout_virtual_bases (record_layout_info rli, splay_tree offsets)
    6731                 :             : {
    6732                 :    37061824 :   tree vbase;
    6733                 :    37061824 :   tree t = rli->t;
    6734                 :    37061824 :   tree *next_field;
    6735                 :             : 
    6736                 :    37061824 :   if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) == 0)
    6737                 :             :     return;
    6738                 :             : 
    6739                 :             :   /* Find the last field.  The artificial fields created for virtual
    6740                 :             :      bases will go after the last extant field to date.  */
    6741                 :    18856389 :   next_field = &TYPE_FIELDS (t);
    6742                 :   153432580 :   while (*next_field)
    6743                 :   134576191 :     next_field = &DECL_CHAIN (*next_field);
    6744                 :             : 
    6745                 :             :   /* Go through the virtual bases, allocating space for each virtual
    6746                 :             :      base that is not already a primary base class.  These are
    6747                 :             :      allocated in inheritance graph order.  */
    6748                 :    60221202 :   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
    6749                 :             :     {
    6750                 :    41364813 :       if (!BINFO_VIRTUAL_P (vbase))
    6751                 :    41164256 :         continue;
    6752                 :             : 
    6753                 :      200557 :       if (!BINFO_PRIMARY_P (vbase))
    6754                 :             :         {
    6755                 :             :           /* This virtual base is not a primary base of any class in the
    6756                 :             :              hierarchy, so we have to add space for it.  */
    6757                 :      192537 :           next_field = build_base_field (rli, vbase,
    6758                 :             :                                          access_private_node,
    6759                 :             :                                          offsets, next_field);
    6760                 :             :         }
    6761                 :             :     }
    6762                 :             : }
    6763                 :             : 
    6764                 :             : /* Returns the offset of the byte just past the end of the base class
    6765                 :             :    BINFO.  */
    6766                 :             : 
    6767                 :             : static tree
    6768                 :    38881369 : end_of_base (tree binfo)
    6769                 :             : {
    6770                 :    38881369 :   tree size;
    6771                 :             : 
    6772                 :    38881369 :   if (!CLASSTYPE_AS_BASE (BINFO_TYPE (binfo)))
    6773                 :           0 :     size = TYPE_SIZE_UNIT (char_type_node);
    6774                 :    38881369 :   else if (is_empty_class (BINFO_TYPE (binfo)))
    6775                 :             :     /* An empty class has zero CLASSTYPE_SIZE_UNIT, but we need to
    6776                 :             :        allocate some space for it. It cannot have virtual bases, so
    6777                 :             :        TYPE_SIZE_UNIT is fine.  */
    6778                 :    34349267 :     size = TYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6779                 :             :   else
    6780                 :     4532102 :     size = CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6781                 :             : 
    6782                 :    38881369 :   return size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), size);
    6783                 :             : }
    6784                 :             : 
    6785                 :             : /* Returns one of three variations of the ending offset of T.  If MODE is
    6786                 :             :    eoc_nvsize, the result is the ABI "nvsize" (i.e. sizeof before allocating
    6787                 :             :    vbases).  If MODE is eoc_vsize, the result is the sizeof after allocating
    6788                 :             :    vbases but before rounding, which is not named in the ABI.  If MODE is
    6789                 :             :    eoc_nv_or_dsize, the result is the greater of "nvsize" and "dsize" (the size
    6790                 :             :    of the actual data in the class, kinda), as used for allocation of
    6791                 :             :    potentially-overlapping fields.  */
    6792                 :             : 
    6793                 :             : enum eoc_mode { eoc_nvsize, eoc_vsize, eoc_nv_or_dsize };
    6794                 :             : static tree
    6795                 :    72562844 : end_of_class (tree t, eoc_mode mode)
    6796                 :             : {
    6797                 :    72562844 :   tree result = size_zero_node;
    6798                 :    72562844 :   vec<tree, va_gc> *vbases;
    6799                 :    72562844 :   tree binfo;
    6800                 :    72562844 :   tree base_binfo;
    6801                 :    72562844 :   tree offset;
    6802                 :    72562844 :   int i;
    6803                 :             : 
    6804                 :    72562844 :   for (binfo = TYPE_BINFO (t), i = 0;
    6805                 :   111335337 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6806                 :             :     {
    6807                 :    38772493 :       if (BINFO_VIRTUAL_P (base_binfo)
    6808                 :    38772493 :           && (!BINFO_PRIMARY_P (base_binfo)
    6809                 :        3358 :               || BINFO_INHERITANCE_CHAIN (base_binfo) != TYPE_BINFO (t)))
    6810                 :       91681 :         continue;
    6811                 :             : 
    6812                 :    38680812 :       offset = end_of_base (base_binfo);
    6813                 :    38680812 :       if (tree_int_cst_lt (result, offset))
    6814                 :    38772493 :         result = offset;
    6815                 :             :     }
    6816                 :             : 
    6817                 :   667333447 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6818                 :   594770603 :     if (TREE_CODE (field) == FIELD_DECL
    6819                 :   594770603 :         && !DECL_FIELD_IS_BASE (field))
    6820                 :             :       {
    6821                 :    25218754 :         tree size = DECL_SIZE_UNIT (field);
    6822                 :    25218754 :         if (!size)
    6823                 :             :           /* DECL_SIZE_UNIT can be null for a flexible array.  */
    6824                 :        1974 :           continue;
    6825                 :             : 
    6826                 :    25216780 :         if (is_empty_field (field))
    6827                 :             :           /* For empty fields DECL_SIZE_UNIT is 0, but we want the
    6828                 :             :              size of the type (usually 1) for computing nvsize.  */
    6829                 :      343442 :           size = TYPE_SIZE_UNIT (TREE_TYPE (field));
    6830                 :             : 
    6831                 :    25216780 :         if (DECL_BIT_FIELD_TYPE (field))
    6832                 :             :           {
    6833                 :      499194 :             offset = size_binop (PLUS_EXPR, bit_position (field),
    6834                 :             :                                  DECL_SIZE (field));
    6835                 :      499194 :             offset = size_binop (CEIL_DIV_EXPR, offset, bitsize_unit_node);
    6836                 :      499194 :             offset = fold_convert (sizetype, offset);
    6837                 :             :           }
    6838                 :             :         else
    6839                 :    24717586 :           offset = size_binop (PLUS_EXPR, byte_position (field), size);
    6840                 :    25216780 :         if (tree_int_cst_lt (result, offset))
    6841                 :   594770603 :           result = offset;
    6842                 :             :       }
    6843                 :             : 
    6844                 :    72562844 :   if (mode != eoc_nvsize)
    6845                 :    37292073 :     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    6846                 :    37292073 :          vec_safe_iterate (vbases, i, &base_binfo); i++)
    6847                 :             :       {
    6848                 :      200566 :         if (mode == eoc_nv_or_dsize)
    6849                 :             :           /* For dsize, don't count trailing empty bases.  */
    6850                 :           9 :           offset = size_binop (PLUS_EXPR, BINFO_OFFSET (base_binfo),
    6851                 :             :                                CLASSTYPE_SIZE_UNIT (BINFO_TYPE (base_binfo)));
    6852                 :             :         else
    6853                 :      200557 :           offset = end_of_base (base_binfo);
    6854                 :      200566 :         if (tree_int_cst_lt (result, offset))
    6855                 :      190245 :           result = offset;
    6856                 :             :       }
    6857                 :             : 
    6858                 :    72562844 :   return result;
    6859                 :             : }
    6860                 :             : 
    6861                 :             : /* Warn as appropriate about the change in whether we pack into the tail
    6862                 :             :    padding of FIELD, a base field which has a C++14 aggregate type with default
    6863                 :             :    member initializers.  */
    6864                 :             : 
    6865                 :             : static void
    6866                 :   301268017 : check_non_pod_aggregate (tree field)
    6867                 :             : {
    6868                 :   903635806 :   if ((!abi_version_crosses (17) || cxx_dialect < cxx14)
    6869                 :   613641522 :       && (!abi_version_crosses (21) || cxx_dialect < cxx20))
    6870                 :             :     return;
    6871                 :    94614020 :   if (TREE_CODE (field) != FIELD_DECL
    6872                 :    94614020 :       || (!DECL_FIELD_IS_BASE (field)
    6873                 :     4528342 :           && !field_poverlapping_p (field)))
    6874                 :    87935912 :     return;
    6875                 :     6678108 :   tree next = DECL_CHAIN (field);
    6876                 :    31523956 :   while (next && TREE_CODE (next) != FIELD_DECL) next = DECL_CHAIN (next);
    6877                 :     6678108 :   if (!next)
    6878                 :             :     return;
    6879                 :      477697 :   tree type = TREE_TYPE (field);
    6880                 :      477697 :   if (TYPE_IDENTIFIER (type) == as_base_identifier)
    6881                 :      262813 :     type = TYPE_CONTEXT (type);
    6882                 :      467910 :   if (!CLASS_TYPE_P (type)
    6883                 :      467908 :       || is_empty_class (type)
    6884                 :      718578 :       || (!CLASSTYPE_NON_POD_AGGREGATE (type)
    6885                 :      236255 :           && !CLASSTYPE_NON_AGGREGATE_POD (type)))
    6886                 :      473069 :     return;
    6887                 :        4638 :   tree size = end_of_class (type, (DECL_FIELD_IS_BASE (field)
    6888                 :             :                                    ? eoc_nvsize : eoc_nv_or_dsize));
    6889                 :        4628 :   tree rounded = round_up_loc (input_location, size, DECL_ALIGN_UNIT (next));
    6890                 :        4628 :   if (tree_int_cst_lt (rounded, TYPE_SIZE_UNIT (type)))
    6891                 :             :     {
    6892                 :          18 :       location_t loc = DECL_SOURCE_LOCATION (next);
    6893                 :          18 :       if (DECL_FIELD_IS_BASE (next))
    6894                 :             :         {
    6895                 :           9 :           if (abi_version_crosses (17)
    6896                 :           6 :               && CLASSTYPE_NON_POD_AGGREGATE (type))
    6897                 :           6 :             warning_at (loc, OPT_Wabi,"offset of %qT base class for "
    6898                 :             :                         "%<-std=c++14%> and up changes in "
    6899                 :           6 :                         "%<-fabi-version=17%> (GCC 12)", TREE_TYPE (next));
    6900                 :           0 :           else if (abi_version_crosses (21)
    6901                 :           0 :                    && CLASSTYPE_NON_AGGREGATE_POD (type))
    6902                 :           0 :             warning_at (loc, OPT_Wabi,"offset of %qT base class for "
    6903                 :             :                         "%<-std=c++20%> and up changes in "
    6904                 :           0 :                         "%<-fabi-version=21%> (GCC 16)", TREE_TYPE (next));
    6905                 :             :         }
    6906                 :             :       else
    6907                 :             :         {
    6908                 :          21 :           if (abi_version_crosses (17)
    6909                 :          12 :               && CLASSTYPE_NON_POD_AGGREGATE (type))
    6910                 :           6 :             warning_at (loc, OPT_Wabi, "offset of %qD for "
    6911                 :             :                         "%<-std=c++14%> and up changes in "
    6912                 :             :                         "%<-fabi-version=17%> (GCC 12)", next);
    6913                 :          11 :           else if (abi_version_crosses (21)
    6914                 :           6 :                    && CLASSTYPE_NON_AGGREGATE_POD (type))
    6915                 :           2 :             warning_at (loc, OPT_Wabi, "offset of %qD for "
    6916                 :             :                         "%<-std=c++20%> and up changes in "
    6917                 :             :                         "%<-fabi-version=21%> (GCC 16)", next);
    6918                 :             :         }
    6919                 :             :     }
    6920                 :             : }
    6921                 :             : 
    6922                 :             : /* Warn about bases of T that are inaccessible because they are
    6923                 :             :    ambiguous.  For example:
    6924                 :             : 
    6925                 :             :      struct S {};
    6926                 :             :      struct T : public S {};
    6927                 :             :      struct U : public S, public T {};
    6928                 :             : 
    6929                 :             :    Here, `(S*) new U' is not allowed because there are two `S'
    6930                 :             :    subobjects of U.  */
    6931                 :             : 
    6932                 :             : static void
    6933                 :    37061824 : maybe_warn_about_inaccessible_bases (tree t)
    6934                 :             : {
    6935                 :    37061824 :   int i;
    6936                 :    37061824 :   vec<tree, va_gc> *vbases;
    6937                 :    37061824 :   tree basetype;
    6938                 :    37061824 :   tree binfo;
    6939                 :    37061824 :   tree base_binfo;
    6940                 :             : 
    6941                 :             :   /* If not checking for warning then return early.  */
    6942                 :    37061824 :   if (!warn_inaccessible_base)
    6943                 :    37061824 :     return;
    6944                 :             : 
    6945                 :             :   /* If there are no repeated bases, nothing can be ambiguous.  */
    6946                 :    37061692 :   if (!CLASSTYPE_REPEATED_BASE_P (t))
    6947                 :             :     return;
    6948                 :             : 
    6949                 :             :   /* Check direct bases.  */
    6950                 :        3806 :   for (binfo = TYPE_BINFO (t), i = 0;
    6951                 :        3806 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6952                 :             :     {
    6953                 :        2754 :       basetype = BINFO_TYPE (base_binfo);
    6954                 :             : 
    6955                 :        2754 :       if (!uniquely_derived_from_p (basetype, t))
    6956                 :         781 :         warning (OPT_Winaccessible_base, "direct base %qT inaccessible "
    6957                 :             :                  "in %qT due to ambiguity", basetype, t);
    6958                 :             :     }
    6959                 :             : 
    6960                 :             :   /* Check for ambiguous virtual bases.  */
    6961                 :        1052 :   if (extra_warnings)
    6962                 :           6 :     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    6963                 :           6 :          vec_safe_iterate (vbases, i, &binfo); i++)
    6964                 :             :       {
    6965                 :           3 :         basetype = BINFO_TYPE (binfo);
    6966                 :             : 
    6967                 :           3 :         if (!uniquely_derived_from_p (basetype, t))
    6968                 :           3 :           warning (OPT_Winaccessible_base, "virtual base %qT inaccessible in "
    6969                 :             :                    "%qT due to ambiguity", basetype, t);
    6970                 :             :       }
    6971                 :             : }
    6972                 :             : 
    6973                 :             : /* Compare two INTEGER_CSTs K1 and K2.  */
    6974                 :             : 
    6975                 :             : static int
    6976                 :     8399779 : splay_tree_compare_integer_csts (splay_tree_key k1, splay_tree_key k2)
    6977                 :             : {
    6978                 :     8399779 :   return tree_int_cst_compare ((tree) k1, (tree) k2);
    6979                 :             : }
    6980                 :             : 
    6981                 :             : /* Increase the size indicated in RLI to account for empty classes
    6982                 :             :    that are "off the end" of the class.  */
    6983                 :             : 
    6984                 :             : static void
    6985                 :    37061824 : include_empty_classes (record_layout_info rli)
    6986                 :             : {
    6987                 :    37061824 :   tree eoc;
    6988                 :    37061824 :   tree rli_size;
    6989                 :             : 
    6990                 :             :   /* It might be the case that we grew the class to allocate a
    6991                 :             :      zero-sized base class.  That won't be reflected in RLI, yet,
    6992                 :             :      because we are willing to overlay multiple bases at the same
    6993                 :             :      offset.  However, now we need to make sure that RLI is big enough
    6994                 :             :      to reflect the entire class.  */
    6995                 :    37061824 :   eoc = end_of_class (rli->t, eoc_vsize);
    6996                 :    37061824 :   rli_size = rli_size_unit_so_far (rli);
    6997                 :    37061824 :   if (TREE_CODE (rli_size) == INTEGER_CST
    6998                 :    37061824 :       && tree_int_cst_lt (rli_size, eoc))
    6999                 :             :     {
    7000                 :             :       /* The size should have been rounded to a whole byte.  */
    7001                 :    16462219 :       gcc_assert (tree_int_cst_equal
    7002                 :             :                   (rli->bitpos, round_down (rli->bitpos, BITS_PER_UNIT)));
    7003                 :    16462219 :       rli->bitpos
    7004                 :    16462219 :         = size_binop (PLUS_EXPR,
    7005                 :             :                       rli->bitpos,
    7006                 :             :                       size_binop (MULT_EXPR,
    7007                 :             :                                   fold_convert (bitsizetype,
    7008                 :             :                                            size_binop (MINUS_EXPR,
    7009                 :             :                                                        eoc, rli_size)),
    7010                 :             :                                   bitsize_int (BITS_PER_UNIT)));
    7011                 :    16462219 :       normalize_rli (rli);
    7012                 :             :     }
    7013                 :    37061824 : }
    7014                 :             : 
    7015                 :             : /* Calculate the TYPE_SIZE, TYPE_ALIGN, etc for T.  Calculate
    7016                 :             :    BINFO_OFFSETs for all of the base-classes.  Position the vtable
    7017                 :             :    pointer.  Accumulate declared virtual functions on VIRTUALS_P.  */
    7018                 :             : 
    7019                 :             : static void
    7020                 :    37061824 : layout_class_type (tree t, tree *virtuals_p)
    7021                 :             : {
    7022                 :    37061824 :   tree non_static_data_members;
    7023                 :    37061824 :   tree field;
    7024                 :    37061824 :   tree vptr;
    7025                 :    37061824 :   record_layout_info rli;
    7026                 :             :   /* Maps offsets (represented as INTEGER_CSTs) to a TREE_LIST of
    7027                 :             :      types that appear at that offset.  */
    7028                 :    37061824 :   splay_tree empty_base_offsets;
    7029                 :             :   /* True if the last field laid out was a bit-field.  */
    7030                 :    37061824 :   bool last_field_was_bitfield = false;
    7031                 :             :   /* The location at which the next field should be inserted.  */
    7032                 :    37061824 :   tree *next_field;
    7033                 :             : 
    7034                 :             :   /* Keep track of the first non-static data member.  */
    7035                 :    37061824 :   non_static_data_members = TYPE_FIELDS (t);
    7036                 :             : 
    7037                 :             :   /* Start laying out the record.  */
    7038                 :    37061824 :   rli = start_record_layout (t);
    7039                 :             : 
    7040                 :             :   /* Mark all the primary bases in the hierarchy.  */
    7041                 :    37061824 :   determine_primary_bases (t);
    7042                 :             : 
    7043                 :             :   /* Create a pointer to our virtual function table.  */
    7044                 :    37061824 :   vptr = create_vtable_ptr (t, virtuals_p);
    7045                 :             : 
    7046                 :             :   /* The vptr is always the first thing in the class.  */
    7047                 :    37061824 :   if (vptr)
    7048                 :             :     {
    7049                 :      239845 :       DECL_CHAIN (vptr) = TYPE_FIELDS (t);
    7050                 :      239845 :       TYPE_FIELDS (t) = vptr;
    7051                 :      239845 :       next_field = &DECL_CHAIN (vptr);
    7052                 :      239845 :       place_field (rli, vptr);
    7053                 :             :     }
    7054                 :             :   else
    7055                 :    36821979 :     next_field = &TYPE_FIELDS (t);
    7056                 :             : 
    7057                 :             :   /* Build FIELD_DECLs for all of the non-virtual base-types.  */
    7058                 :    37061824 :   empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
    7059                 :             :                                        NULL, NULL);
    7060                 :    37061824 :   build_base_fields (rli, empty_base_offsets, next_field);
    7061                 :             : 
    7062                 :             :   /* Layout the non-static data members.  */
    7063                 :   318821058 :   for (field = non_static_data_members; field; field = DECL_CHAIN (field))
    7064                 :             :     {
    7065                 :   281759234 :       tree type;
    7066                 :   281759234 :       tree padding;
    7067                 :             : 
    7068                 :             :       /* We still pass things that aren't non-static data members to
    7069                 :             :          the back end, in case it wants to do something with them.  */
    7070                 :   281759234 :       if (TREE_CODE (field) != FIELD_DECL)
    7071                 :             :         {
    7072                 :   266282320 :           place_field (rli, field);
    7073                 :             :           /* If the static data member has incomplete type, keep track
    7074                 :             :              of it so that it can be completed later.  (The handling
    7075                 :             :              of pending statics in finish_record_layout is
    7076                 :             :              insufficient; consider:
    7077                 :             : 
    7078                 :             :                struct S1;
    7079                 :             :                struct S2 { static S1 s1; };
    7080                 :             : 
    7081                 :             :              At this point, finish_record_layout will be called, but
    7082                 :             :              S1 is still incomplete.)  */
    7083                 :   266282320 :           if (VAR_P (field))
    7084                 :             :             {
    7085                 :     9948098 :               maybe_register_incomplete_var (field);
    7086                 :             :               /* The visibility of static data members is determined
    7087                 :             :                  at their point of declaration, not their point of
    7088                 :             :                  definition.  */
    7089                 :     9948098 :               determine_visibility (field);
    7090                 :             :             }
    7091                 :   266282320 :           continue;
    7092                 :             :         }
    7093                 :             : 
    7094                 :    15476914 :       type = TREE_TYPE (field);
    7095                 :    15476914 :       if (type == error_mark_node)
    7096                 :         158 :         continue;
    7097                 :             : 
    7098                 :    15476756 :       padding = NULL_TREE;
    7099                 :             : 
    7100                 :    15476756 :       bool might_overlap = field_poverlapping_p (field);
    7101                 :             : 
    7102                 :      222865 :       if (might_overlap && CLASS_TYPE_P (type)
    7103                 :    15678284 :           && (CLASSTYPE_NON_LAYOUT_POD_P (type) || CLASSTYPE_EMPTY_P (type)))
    7104                 :             :         {
    7105                 :             :           /* if D is a potentially-overlapping data member, update sizeof(C) to
    7106                 :             :              max (sizeof(C), offset(D)+max (nvsize(D), dsize(D))).  */
    7107                 :      201378 :           if (CLASSTYPE_EMPTY_P (type))
    7108                 :      171705 :             DECL_SIZE (field) = DECL_SIZE_UNIT (field) = size_zero_node;
    7109                 :             :           else
    7110                 :             :             {
    7111                 :       29673 :               tree size = end_of_class (type, eoc_nv_or_dsize);
    7112                 :       29673 :               DECL_SIZE_UNIT (field) = size;
    7113                 :       29673 :               DECL_SIZE (field) = bit_from_pos (size, bitsize_zero_node);
    7114                 :             :             }
    7115                 :             :         }
    7116                 :             : 
    7117                 :             :       /* If this field is a bit-field whose width is greater than its
    7118                 :             :          type, then there are some special rules for allocating
    7119                 :             :          it.  */
    7120                 :    15476756 :       if (DECL_C_BIT_FIELD (field)
    7121                 :    15476756 :           && tree_int_cst_lt (TYPE_SIZE (type), DECL_SIZE (field)))
    7122                 :             :         {
    7123                 :         774 :           bool was_unnamed_p = false;
    7124                 :             :           /* We must allocate the bits as if suitably aligned for the
    7125                 :             :              longest integer type that fits in this many bits.  Then,
    7126                 :             :              we are supposed to use the left over bits as additional
    7127                 :             :              padding.  */
    7128                 :             : 
    7129                 :             :           /* Do not pick a type bigger than MAX_FIXED_MODE_SIZE.  */
    7130                 :        1548 :           tree limit = size_int (MAX_FIXED_MODE_SIZE);
    7131                 :         774 :           if (tree_int_cst_lt (DECL_SIZE (field), limit))
    7132                 :         753 :             limit = DECL_SIZE (field);
    7133                 :             : 
    7134                 :         774 :           tree integer_type = integer_types[itk_char];
    7135                 :        6620 :           for (unsigned itk = itk_char; itk != itk_none; itk++)
    7136                 :        6599 :             if (tree next = integer_types[itk])
    7137                 :             :               {
    7138                 :        6473 :                 if (tree_int_cst_lt (limit, TYPE_SIZE (next)))
    7139                 :             :                   /* Too big, so our current guess is what we want.  */
    7140                 :             :                   break;
    7141                 :             :                 /* Not bigger than limit, ok  */
    7142                 :             :                 integer_type = next;
    7143                 :             :               }
    7144                 :             : 
    7145                 :             :           /* Figure out how much additional padding is required.  */
    7146                 :         774 :           if (TREE_CODE (t) == UNION_TYPE)
    7147                 :             :             /* In a union, the padding field must have the full width
    7148                 :             :                of the bit-field; all fields start at offset zero.  */
    7149                 :          77 :             padding = DECL_SIZE (field);
    7150                 :             :           else
    7151                 :         697 :             padding = size_binop (MINUS_EXPR, DECL_SIZE (field),
    7152                 :             :                                   TYPE_SIZE (integer_type));
    7153                 :             : 
    7154                 :         774 :           if (integer_zerop (padding))
    7155                 :           6 :             padding = NULL_TREE;
    7156                 :             : 
    7157                 :             :           /* An unnamed bitfield does not normally affect the
    7158                 :             :              alignment of the containing class on a target where
    7159                 :             :              PCC_BITFIELD_TYPE_MATTERS.  But, the C++ ABI does not
    7160                 :             :              make any exceptions for unnamed bitfields when the
    7161                 :             :              bitfields are longer than their types.  Therefore, we
    7162                 :             :              temporarily give the field a name.  */
    7163                 :         774 :           if (PCC_BITFIELD_TYPE_MATTERS && !DECL_NAME (field))
    7164                 :             :             {
    7165                 :           0 :               was_unnamed_p = true;
    7166                 :           0 :               DECL_NAME (field) = make_anon_name ();
    7167                 :             :             }
    7168                 :             : 
    7169                 :         774 :           DECL_SIZE (field) = TYPE_SIZE (integer_type);
    7170                 :         774 :           SET_DECL_ALIGN (field, TYPE_ALIGN (integer_type));
    7171                 :         774 :           DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type);
    7172                 :         774 :           layout_nonempty_base_or_field (rli, field, NULL_TREE,
    7173                 :             :                                          empty_base_offsets);
    7174                 :         774 :           if (was_unnamed_p)
    7175                 :           0 :             DECL_NAME (field) = NULL_TREE;
    7176                 :             :           /* Now that layout has been performed, set the size of the
    7177                 :             :              field to the size of its declared type; the rest of the
    7178                 :             :              field is effectively invisible.  */
    7179                 :         774 :           DECL_SIZE (field) = TYPE_SIZE (type);
    7180                 :             :           /* We must also reset the DECL_MODE of the field.  */
    7181                 :         774 :           SET_DECL_MODE (field, TYPE_MODE (type));
    7182                 :             :         }
    7183                 :    15475982 :       else if (might_overlap && is_empty_class (type))
    7184                 :             :         {
    7185                 :      171705 :           SET_DECL_FIELD_ABI_IGNORED (field, 1);
    7186                 :      171705 :           layout_empty_base_or_field (rli, field, empty_base_offsets);
    7187                 :             :         }
    7188                 :             :       else
    7189                 :    15304277 :         layout_nonempty_base_or_field (rli, field, NULL_TREE,
    7190                 :             :                                        empty_base_offsets);
    7191                 :             : 
    7192                 :             :       /* Remember the location of any empty classes in FIELD.  */
    7193                 :    15476756 :       record_subobject_offsets (field, empty_base_offsets);
    7194                 :             : 
    7195                 :             :       /* If a bit-field does not immediately follow another bit-field,
    7196                 :             :          and yet it starts in the middle of a byte, we have failed to
    7197                 :             :          comply with the ABI.  */
    7198                 :    15476756 :       if (warn_abi
    7199                 :    14184581 :           && DECL_C_BIT_FIELD (field)
    7200                 :             :           /* The TREE_NO_WARNING flag gets set by Objective-C when
    7201                 :             :              laying out an Objective-C class.  The ObjC ABI differs
    7202                 :             :              from the C++ ABI, and so we do not want a warning
    7203                 :             :              here.  */
    7204                 :      370705 :           && !warning_suppressed_p (field, OPT_Wabi)
    7205                 :      370705 :           && !last_field_was_bitfield
    7206                 :    15537903 :           && !integer_zerop (size_binop (TRUNC_MOD_EXPR,
    7207                 :             :                                          DECL_FIELD_BIT_OFFSET (field),
    7208                 :             :                                          bitsize_unit_node)))
    7209                 :           0 :         warning_at (DECL_SOURCE_LOCATION (field), OPT_Wabi,
    7210                 :             :                     "offset of %qD is not ABI-compliant and may "
    7211                 :             :                     "change in a future version of GCC", field);
    7212                 :             : 
    7213                 :             :       /* The middle end uses the type of expressions to determine the
    7214                 :             :          possible range of expression values.  In order to optimize
    7215                 :             :          "x.i > 7" to "false" for a 2-bit bitfield "i", the middle end
    7216                 :             :          must be made aware of the width of "i", via its type.
    7217                 :             : 
    7218                 :             :          Because C++ does not have integer types of arbitrary width,
    7219                 :             :          we must (for the purposes of the front end) convert from the
    7220                 :             :          type assigned here to the declared type of the bitfield
    7221                 :             :          whenever a bitfield expression is used as an rvalue.
    7222                 :             :          Similarly, when assigning a value to a bitfield, the value
    7223                 :             :          must be converted to the type given the bitfield here.  */
    7224                 :    15476756 :       if (DECL_C_BIT_FIELD (field))
    7225                 :             :         {
    7226                 :      417290 :           unsigned HOST_WIDE_INT width;
    7227                 :      417290 :           tree ftype = TREE_TYPE (field);
    7228                 :      417290 :           width = tree_to_uhwi (DECL_SIZE (field));
    7229                 :      417290 :           if (width != TYPE_PRECISION (ftype))
    7230                 :             :             {
    7231                 :      278862 :               TREE_TYPE (field)
    7232                 :      557724 :                 = c_build_bitfield_integer_type (width,
    7233                 :      278862 :                                                  TYPE_UNSIGNED (ftype));
    7234                 :      278862 :               TREE_TYPE (field)
    7235                 :      557724 :                 = cp_build_qualified_type (TREE_TYPE (field),
    7236                 :             :                                            cp_type_quals (ftype));
    7237                 :             :             }
    7238                 :             :         }
    7239                 :             : 
    7240                 :             :       /* If we needed additional padding after this field, add it
    7241                 :             :          now.  */
    7242                 :    15476756 :       if (padding)
    7243                 :             :         {
    7244                 :         768 :           tree padding_field;
    7245                 :             : 
    7246                 :         768 :           padding_field = build_decl (input_location,
    7247                 :             :                                       FIELD_DECL,
    7248                 :             :                                       NULL_TREE,
    7249                 :             :                                       char_type_node);
    7250                 :         768 :           DECL_BIT_FIELD (padding_field) = 1;
    7251                 :         768 :           DECL_SIZE (padding_field) = padding;
    7252                 :         768 :           DECL_CONTEXT (padding_field) = t;
    7253                 :         768 :           DECL_ARTIFICIAL (padding_field) = 1;
    7254                 :         768 :           DECL_IGNORED_P (padding_field) = 1;
    7255                 :         768 :           DECL_PADDING_P (padding_field) = 1;
    7256                 :         768 :           layout_nonempty_base_or_field (rli, padding_field,
    7257                 :             :                                          NULL_TREE,
    7258                 :             :                                          empty_base_offsets);
    7259                 :             :         }
    7260                 :             : 
    7261                 :    15476756 :       last_field_was_bitfield = DECL_C_BIT_FIELD (field);
    7262                 :             :     }
    7263                 :             : 
    7264                 :    37061824 :   if (!integer_zerop (rli->bitpos))
    7265                 :             :     {
    7266                 :             :       /* Make sure that we are on a byte boundary so that the size of
    7267                 :             :          the class without virtual bases will always be a round number
    7268                 :             :          of bytes.  */
    7269                 :     4505743 :       rli->bitpos = round_up_loc (input_location, rli->bitpos, BITS_PER_UNIT);
    7270                 :     4505743 :       normalize_rli (rli);
    7271                 :             :     }
    7272                 :             : 
    7273                 :             :   /* We used to remove zero width bitfields at this point since PR42217,
    7274                 :             :      while the C FE never did that.  That caused ABI differences on various
    7275                 :             :      targets.  Set the DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD flag on them
    7276                 :             :      instead, so that the backends can emit -Wpsabi warnings in the cases
    7277                 :             :      where the ABI changed.  */
    7278                 :   338329841 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7279                 :             :     {
    7280                 :   301268017 :       if (TREE_CODE (field) == FIELD_DECL
    7281                 :    34985697 :           && DECL_C_BIT_FIELD (field)
    7282                 :             :           /* We should not be confused by the fact that grokbitfield
    7283                 :             :              temporarily sets the width of the bit field into
    7284                 :             :              DECL_BIT_FIELD_REPRESENTATIVE (field).
    7285                 :             :              check_bitfield_decl eventually sets DECL_SIZE (field)
    7286                 :             :              to that width.  */
    7287                 :      417290 :           && (DECL_SIZE (field) == NULL_TREE
    7288                 :      417290 :               || integer_zerop (DECL_SIZE (field)))
    7289                 :   301269146 :           && TREE_TYPE (field) != error_mark_node)
    7290                 :        1129 :         SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field, 1);
    7291                 :   301268017 :       check_non_pod_aggregate (field);
    7292                 :             :     }
    7293                 :             : 
    7294                 :    37061824 :   if (CLASSTYPE_NON_LAYOUT_POD_P (t) || CLASSTYPE_EMPTY_P (t))
    7295                 :             :     {
    7296                 :             :       /* T needs a different layout as a base (eliding virtual bases
    7297                 :             :          or whatever).  Create that version.  */
    7298                 :    35466719 :       tree base_t = make_node (TREE_CODE (t));
    7299                 :    35466719 :       tree base_d = create_implicit_typedef (as_base_identifier, base_t);
    7300                 :             : 
    7301                 :    35466719 :       TYPE_CONTEXT (base_t) = t;
    7302                 :    35466719 :       DECL_CONTEXT (base_d) = t;
    7303                 :             : 
    7304                 :    35466719 :       set_instantiating_module (base_d);
    7305                 :             : 
    7306                 :             :       /* If the ABI version is not at least two, and the last
    7307                 :             :          field was a bit-field, RLI may not be on a byte
    7308                 :             :          boundary.  In particular, rli_size_unit_so_far might
    7309                 :             :          indicate the last complete byte, while rli_size_so_far
    7310                 :             :          indicates the total number of bits used.  Therefore,
    7311                 :             :          rli_size_so_far, rather than rli_size_unit_so_far, is
    7312                 :             :          used to compute TYPE_SIZE_UNIT.  */
    7313                 :             : 
    7314                 :             :       /* Set the size and alignment for the new type.  */
    7315                 :    35466719 :       tree eoc = end_of_class (t, eoc_nvsize);
    7316                 :    35466719 :       TYPE_SIZE_UNIT (base_t)
    7317                 :    35466719 :         = size_binop (MAX_EXPR,
    7318                 :             :                       fold_convert (sizetype,
    7319                 :             :                                size_binop (CEIL_DIV_EXPR,
    7320                 :             :                                            rli_size_so_far (rli),
    7321                 :             :                                            bitsize_int (BITS_PER_UNIT))),
    7322                 :             :                       eoc);
    7323                 :    35466719 :       TYPE_SIZE (base_t)
    7324                 :    35466719 :         = size_binop (MAX_EXPR,
    7325                 :             :                       rli_size_so_far (rli),
    7326                 :             :                       size_binop (MULT_EXPR,
    7327                 :             :                                   fold_convert (bitsizetype, eoc),
    7328                 :             :                                   bitsize_int (BITS_PER_UNIT)));
    7329                 :    35466719 :       SET_TYPE_ALIGN (base_t, rli->record_align);
    7330                 :    35466719 :       TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t);
    7331                 :    35466719 :       TYPE_TYPELESS_STORAGE (base_t) = TYPE_TYPELESS_STORAGE (t);
    7332                 :    35466719 :       TYPE_CXX_ODR_P (base_t) = TYPE_CXX_ODR_P (t);
    7333                 :             : 
    7334                 :             :       /* Copy the non-static data members of T. This will include its
    7335                 :             :          direct non-virtual bases & vtable.  */
    7336                 :    35466719 :       next_field = &TYPE_FIELDS (base_t);
    7337                 :   327919244 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7338                 :   292452525 :         if (TREE_CODE (field) == FIELD_DECL)
    7339                 :             :           {
    7340                 :    28718766 :             *next_field = copy_node (field);
    7341                 :             :             /* Zap any NSDMI, it's not needed and might be a deferred
    7342                 :             :                parse.  */
    7343                 :    28718766 :             DECL_INITIAL (*next_field) = NULL_TREE;
    7344                 :    28718766 :             DECL_CONTEXT (*next_field) = base_t;
    7345                 :    28718766 :             next_field = &DECL_CHAIN (*next_field);
    7346                 :             :           }
    7347                 :    35466719 :       *next_field = NULL_TREE;
    7348                 :             : 
    7349                 :             :       /* We use the base type for trivial assignments, and hence it
    7350                 :             :          needs a mode.  */
    7351                 :    35466719 :       compute_record_mode (base_t);
    7352                 :             : 
    7353                 :             :       /* Record the base version of the type.  */
    7354                 :    35466719 :       CLASSTYPE_AS_BASE (t) = base_t;
    7355                 :             :     }
    7356                 :             :   else
    7357                 :     1595105 :     CLASSTYPE_AS_BASE (t) = t;
    7358                 :             : 
    7359                 :             :   /* Every empty class contains an empty class.  */
    7360                 :    37061824 :   if (CLASSTYPE_EMPTY_P (t))
    7361                 :    29822998 :     CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    7362                 :             : 
    7363                 :             :   /* Set the TYPE_DECL for this type to contain the right
    7364                 :             :      value for DECL_OFFSET, so that we can use it as part
    7365                 :             :      of a COMPONENT_REF for multiple inheritance.  */
    7366                 :    37061824 :   layout_decl (TYPE_MAIN_DECL (t), 0);
    7367                 :             : 
    7368                 :             :   /* Now fix up any virtual base class types that we left lying
    7369                 :             :      around.  We must get these done before we try to lay out the
    7370                 :             :      virtual function table.  As a side-effect, this will remove the
    7371                 :             :      base subobject fields.  */
    7372                 :    37061824 :   layout_virtual_bases (rli, empty_base_offsets);
    7373                 :             : 
    7374                 :             :   /* Make sure that empty classes are reflected in RLI at this
    7375                 :             :      point.  */
    7376                 :    37061824 :   include_empty_classes (rli);
    7377                 :             : 
    7378                 :             :   /* Make sure not to create any structures with zero size.  */
    7379                 :    37061824 :   if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
    7380                 :    13360994 :     place_field (rli,
    7381                 :             :                  build_decl (input_location,
    7382                 :             :                              FIELD_DECL, NULL_TREE, char_type_node));
    7383                 :             : 
    7384                 :             :   /* If this is a non-POD, declaring it packed makes a difference to how it
    7385                 :             :      can be used as a field; don't let finalize_record_size undo it.  */
    7386                 :    37061824 :   if (TYPE_PACKED (t) && !layout_pod_type_p (t))
    7387                 :          78 :     rli->packed_maybe_necessary = true;
    7388                 :             : 
    7389                 :             :   /* Let the back end lay out the type.  */
    7390                 :    37061824 :   finish_record_layout (rli, /*free_p=*/true);
    7391                 :             : 
    7392                 :             :   /* If we didn't end up needing an as-base type, don't use it.  */
    7393                 :    37061824 :   if (CLASSTYPE_AS_BASE (t) != t
    7394                 :             :       /* If T's CLASSTYPE_AS_BASE is TYPE_USER_ALIGN, but T is not,
    7395                 :             :          replacing the as-base type would change CLASSTYPE_USER_ALIGN,
    7396                 :             :          causing us to lose the user-specified alignment as in PR94050.  */
    7397                 :    35466719 :       && TYPE_USER_ALIGN (t) == TYPE_USER_ALIGN (CLASSTYPE_AS_BASE (t))
    7398                 :    72528529 :       && tree_int_cst_equal (TYPE_SIZE (t),
    7399                 :    35466705 :                              TYPE_SIZE (CLASSTYPE_AS_BASE (t))))
    7400                 :    21225347 :     CLASSTYPE_AS_BASE (t) = t;
    7401                 :             : 
    7402                 :    37061824 :   if (TYPE_SIZE_UNIT (t)
    7403                 :    37061824 :       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
    7404                 :    37061824 :       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
    7405                 :    74123639 :       && !valid_constant_size_p (TYPE_SIZE_UNIT (t)))
    7406                 :           0 :     error ("size of type %qT is too large (%qE bytes)", t, TYPE_SIZE_UNIT (t));
    7407                 :             : 
    7408                 :             :   /* Warn about bases that can't be talked about due to ambiguity.  */
    7409                 :    37061824 :   maybe_warn_about_inaccessible_bases (t);
    7410                 :             : 
    7411                 :             :   /* Now that we're done with layout, give the base fields the real types.  */
    7412                 :   338520209 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7413                 :   301458385 :     if (DECL_ARTIFICIAL (field) && IS_FAKE_BASE_TYPE (TREE_TYPE (field)))
    7414                 :    16999566 :       TREE_TYPE (field) = TYPE_CONTEXT (TREE_TYPE (field));
    7415                 :             : 
    7416                 :             :   /* Clean up.  */
    7417                 :    37061824 :   splay_tree_delete (empty_base_offsets);
    7418                 :             : 
    7419                 :    37061824 :   if (CLASSTYPE_EMPTY_P (t)
    7420                 :    66884822 :       && tree_int_cst_lt (sizeof_biggest_empty_class,
    7421                 :    29822998 :                           TYPE_SIZE_UNIT (t)))
    7422                 :       59469 :     sizeof_biggest_empty_class = TYPE_SIZE_UNIT (t);
    7423                 :    37061824 : }
    7424                 :             : 
    7425                 :             : /* Determine the "key method" for the class type indicated by TYPE,
    7426                 :             :    and set CLASSTYPE_KEY_METHOD accordingly.  */
    7427                 :             : 
    7428                 :             : void
    7429                 :     1657715 : determine_key_method (tree type)
    7430                 :             : {
    7431                 :     1657715 :   tree method;
    7432                 :             : 
    7433                 :     1657715 :   if (processing_template_decl
    7434                 :     1657715 :       || CLASSTYPE_TEMPLATE_INSTANTIATION (type)
    7435                 :     2378368 :       || CLASSTYPE_INTERFACE_KNOWN (type))
    7436                 :             :     return;
    7437                 :             : 
    7438                 :             :   /* The key method is the first non-pure virtual function that is not
    7439                 :             :      inline at the point of class definition.  On some targets the
    7440                 :             :      key function may not be inline; those targets should not call
    7441                 :             :      this function until the end of the translation unit.  */
    7442                 :     7346295 :   for (method = TYPE_FIELDS (type); method; method = DECL_CHAIN (method))
    7443                 :     7187644 :     if (TREE_CODE (method) == FUNCTION_DECL
    7444                 :     5876198 :         && DECL_VINDEX (method) != NULL_TREE
    7445                 :     1156738 :         && ! DECL_DECLARED_INLINE_P (method)
    7446                 :     7771528 :         && ! DECL_PURE_VIRTUAL_P (method))
    7447                 :             :       {
    7448                 :      561973 :         CLASSTYPE_KEY_METHOD (type) = method;
    7449                 :      561973 :         break;
    7450                 :             :       }
    7451                 :             : 
    7452                 :             :   return;
    7453                 :             : }
    7454                 :             : 
    7455                 :             : /* Helper of find_flexarrays.  Return true when FLD refers to a non-static
    7456                 :             :    class data member of non-zero size, otherwise false.  */
    7457                 :             : 
    7458                 :             : static inline bool
    7459                 :    38359272 : field_nonempty_p (const_tree fld)
    7460                 :             : {
    7461                 :    38359272 :   if (TREE_CODE (fld) == ERROR_MARK)
    7462                 :             :     return false;
    7463                 :             : 
    7464                 :    38359272 :   tree type = TREE_TYPE (fld);
    7465                 :    38359272 :   if (TREE_CODE (fld) == FIELD_DECL
    7466                 :    38359272 :       && TREE_CODE (type) != ERROR_MARK
    7467                 :    76718544 :       && (DECL_NAME (fld) || RECORD_OR_UNION_TYPE_P (type)))
    7468                 :    38225394 :     return TYPE_SIZE (type) && !integer_zerop (TYPE_SIZE (type));
    7469                 :             : 
    7470                 :             :   return false;
    7471                 :             : }
    7472                 :             : 
    7473                 :             : /* Used by find_flexarrays and related functions.  */
    7474                 :             : 
    7475                 :             : struct flexmems_t
    7476                 :             : {
    7477                 :             :   /* The first flexible array member or non-zero array member found
    7478                 :             :      in the order of layout.  */
    7479                 :             :   tree array;
    7480                 :             :   /* True if there is a non-static non-empty data member in the class or
    7481                 :             :      its bases.  */
    7482                 :             :   bool first;
    7483                 :             :   /* The first non-static non-empty data member following either
    7484                 :             :      the flexible array member, if found, or the zero-length array member
    7485                 :             :      otherwise.  AFTER[1] refers to the first such data member of a union
    7486                 :             :      of which the struct containing the flexible array member or zero-length
    7487                 :             :      array is a member, or NULL when no such union exists.  This element is
    7488                 :             :      only used during searching, not for diagnosing problems.  AFTER[0]
    7489                 :             :      refers to the first such data member that is not a member of such
    7490                 :             :      a union.  */
    7491                 :             :   tree after[2];
    7492                 :             : 
    7493                 :             :   /* Refers to a struct (not union) in which the struct of which the flexible
    7494                 :             :      array is member is defined.  Used to diagnose strictly (according to C)
    7495                 :             :      invalid uses of the latter structs.  */
    7496                 :             :   tree enclosing;
    7497                 :             : };
    7498                 :             : 
    7499                 :             : /* Find either the first flexible array member or the first zero-length
    7500                 :             :    array, in that order of preference, among members of class T (but not
    7501                 :             :    its base classes), and set members of FMEM accordingly.
    7502                 :             :    BASE_P is true if T is a base class of another class.
    7503                 :             :    PUN is true when inside of a union (perhaps recursively).
    7504                 :             :    PSTR is set to a data member of the outermost struct of
    7505                 :             :    which the flexible array is a member if one such struct exists,
    7506                 :             :    otherwise to NULL.  NESTED_P is true for recursive calls except ones
    7507                 :             :    handling anonymous aggregates.  Those types are expected to be diagnosed
    7508                 :             :    on its own already and so only the last member is checked vs. what
    7509                 :             :    follows it in the outer type.  */
    7510                 :             : 
    7511                 :             : static void
    7512                 :    64952155 : find_flexarrays (tree t, flexmems_t *fmem, bool base_p,
    7513                 :             :                  bool nested_p /* = false */, bool pun /* = false */,
    7514                 :             :                  tree pstr /* = NULL_TREE */)
    7515                 :             : {
    7516                 :    64952155 :   if (TREE_CODE (t) == UNION_TYPE)
    7517                 :     1175256 :     pun = true;
    7518                 :             : 
    7519                 :    64952155 :   tree fld = TYPE_FIELDS (t);
    7520                 :    64952155 :   if ((base_p || nested_p) && TREE_CODE (t) == RECORD_TYPE)
    7521                 :             :     {
    7522                 :             :       /* In bases or in nested structures, only process the last
    7523                 :             :          non-static data member.  If we have say
    7524                 :             :          struct A { int a; int b[]; int c; };
    7525                 :             :          struct B { int d; int e[]; int f; };
    7526                 :             :          struct C : A { int g; B h, i; int j; };
    7527                 :             :          then the A::b followed by A::c should have been diagnosed
    7528                 :             :          already when completing struct A, and B::e followed by B::f
    7529                 :             :          when completing struct B, so no need to repeat that when completing
    7530                 :             :          struct C.  So, only look at the last member so we cover e.g.
    7531                 :             :          struct D { int k; int l[]; };
    7532                 :             :          struct E : D { int m; };
    7533                 :             :          struct F { D n; int o; };
    7534                 :             :          where flexible array member at the end of D is fine, but it isn't
    7535                 :             :          correct that E::m in E or F::o in F follows it.  */
    7536                 :             :       tree last_fld = NULL_TREE;
    7537                 :    50045126 :       for (; (fld = next_subobject_field (fld)); fld = DECL_CHAIN (fld))
    7538                 :    22979433 :         if (DECL_ARTIFICIAL (fld))
    7539                 :     6553823 :           continue;
    7540                 :    16425610 :         else if (TREE_TYPE (fld) == error_mark_node)
    7541                 :             :           return;
    7542                 :    16425589 :         else if (TREE_CODE (TREE_TYPE (fld)) == ARRAY_TYPE
    7543                 :    16425589 :                  || field_nonempty_p (fld))
    7544                 :             :           last_fld = fld;
    7545                 :             :       fld = last_fld;
    7546                 :             :     }
    7547                 :   527512936 :   for (; fld; fld = DECL_CHAIN (fld))
    7548                 :             :     {
    7549                 :   462561365 :       if (fld == error_mark_node)
    7550                 :             :         return;
    7551                 :             : 
    7552                 :             :       /* Is FLD a typedef for an anonymous struct?  */
    7553                 :             : 
    7554                 :             :       /* FIXME: Note that typedefs (as well as arrays) need to be fully
    7555                 :             :          handled elsewhere so that errors like the following are detected
    7556                 :             :          as well:
    7557                 :             :            typedef struct { int i, a[], j; } S;   // bug c++/72753
    7558                 :             :            S s [2];                               // bug c++/68489
    7559                 :             :       */
    7560                 :   463280305 :       if (TREE_CODE (fld) == TYPE_DECL
    7561                 :   102374083 :           && DECL_IMPLICIT_TYPEDEF_P (fld)
    7562                 :     7124259 :           && CLASS_TYPE_P (TREE_TYPE (fld))
    7563                 :   467867684 :           && IDENTIFIER_ANON_P (DECL_NAME (fld)))
    7564                 :             :         {
    7565                 :             :           /* Check the nested unnamed type referenced via a typedef
    7566                 :             :              independently of FMEM (since it's not a data member of
    7567                 :             :              the enclosing class).  */
    7568                 :      718940 :           check_flexarrays (TREE_TYPE (fld));
    7569                 :      718940 :           continue;
    7570                 :             :         }
    7571                 :             : 
    7572                 :             :       /* Skip anything that's GCC-generated or not a (non-static) data
    7573                 :             :          member.  */
    7574                 :   461842425 :       if (DECL_ARTIFICIAL (fld) || TREE_CODE (fld) != FIELD_DECL)
    7575                 :   438192319 :         continue;
    7576                 :             : 
    7577                 :             :       /* Type of the member.  */
    7578                 :    23650106 :       tree fldtype = TREE_TYPE (fld);
    7579                 :    23650106 :       if (fldtype == error_mark_node)
    7580                 :             :         return;
    7581                 :             : 
    7582                 :             :       /* Determine the type of the array element or object referenced
    7583                 :             :          by the member so that it can be checked for flexible array
    7584                 :             :          members if it hasn't been yet.  */
    7585                 :             :       tree eltype = fldtype;
    7586                 :    32715223 :       while (TREE_CODE (eltype) == ARRAY_TYPE
    7587                 :    32715223 :              || INDIRECT_TYPE_P (eltype))
    7588                 :     9065255 :         eltype = TREE_TYPE (eltype);
    7589                 :             : 
    7590                 :    23649968 :       if (RECORD_OR_UNION_TYPE_P (eltype))
    7591                 :             :         {
    7592                 :     8768711 :           if (fmem->array && !fmem->after[pun])
    7593                 :             :             {
    7594                 :             :               /* Once the member after the flexible array has been found
    7595                 :             :                  we're done.  */
    7596                 :         425 :               fmem->after[pun] = fld;
    7597                 :         425 :               break;
    7598                 :             :             }
    7599                 :             : 
    7600                 :    11904178 :           if (eltype == fldtype || TYPE_UNNAMED_P (eltype))
    7601                 :             :             {
    7602                 :             :               /* Descend into the non-static member struct or union and try
    7603                 :             :                  to find a flexible array member or zero-length array among
    7604                 :             :                  its members.  This is only necessary for anonymous types
    7605                 :             :                  and types in whose context the current type T has not been
    7606                 :             :                  defined (the latter must not be checked again because they
    7607                 :             :                  are already in the process of being checked by one of the
    7608                 :             :                  recursive calls).  */
    7609                 :             : 
    7610                 :     5662858 :               bool first = fmem->first;
    7611                 :     5662858 :               tree array = fmem->array;
    7612                 :    12002221 :               bool maybe_anon_p = TYPE_UNNAMED_P (eltype);
    7613                 :      706112 :               if (tree ctx = maybe_anon_p ? TYPE_CONTEXT (eltype) : NULL_TREE)
    7614                 :      706112 :                 maybe_anon_p = RECORD_OR_UNION_TYPE_P (ctx);
    7615                 :             : 
    7616                 :             :               /* If this member isn't anonymous and a prior non-flexible array
    7617                 :             :                  member has been seen in one of the enclosing structs, clear
    7618                 :             :                  the FIRST member since it doesn't contribute to the flexible
    7619                 :             :                  array struct's members.  */
    7620                 :     5662858 :               if (first && !array && !ANON_AGGR_TYPE_P (eltype))
    7621                 :     1718934 :                 fmem->first = false;
    7622                 :             : 
    7623                 :     9654621 :               find_flexarrays (eltype, fmem, false, !maybe_anon_p, pun,
    7624                 :     3991763 :                                !pstr && TREE_CODE (t) == RECORD_TYPE
    7625                 :             :                                ? fld : pstr);
    7626                 :             : 
    7627                 :     5662858 :               if (fmem->array != array)
    7628                 :             :                 {
    7629                 :             :                   /* If the recursive call passed true to nested_p,
    7630                 :             :                      it only looked at the last field and we do not
    7631                 :             :                      want to diagnose in that case the "in otherwise empty"
    7632                 :             :                      case, just if it is followed by some other non-empty
    7633                 :             :                      member.  So set fmem->first.  */
    7634                 :        1033 :                   if (!maybe_anon_p)
    7635                 :         252 :                     fmem->first = true;
    7636                 :        1033 :                   continue;
    7637                 :             :                 }
    7638                 :             : 
    7639                 :     5661825 :               if (first && !array && !ANON_AGGR_TYPE_P (eltype))
    7640                 :             :                 /* Restore the FIRST member reset above if no flexible
    7641                 :             :                    array member has been found in this member's struct.  */
    7642                 :     1718554 :                 fmem->first = first;
    7643                 :             : 
    7644                 :             :               /* If the member struct contains the first flexible array
    7645                 :             :                  member, or if this member is a base class, continue to
    7646                 :             :                  the next member and avoid setting the FMEM->AFTER pointer
    7647                 :             :                  to point to it.  */
    7648                 :     5661825 :               if (base_p)
    7649                 :     1038188 :                 continue;
    7650                 :             :             }
    7651                 :             :         }
    7652                 :             : 
    7653                 :    22610322 :       if (field_nonempty_p (fld))
    7654                 :             :         {
    7655                 :             :           /* Remember the first non-static data member.  */
    7656                 :    22472087 :           if (!fmem->first)
    7657                 :     8398771 :             fmem->first = true;
    7658                 :             : 
    7659                 :             :           /* Remember the first non-static data member after the flexible
    7660                 :             :              array member, if one has been found, or the zero-length array
    7661                 :             :              if it has been found.  */
    7662                 :    22472087 :           if (fmem->array && !fmem->after[pun])
    7663                 :        1507 :             fmem->after[pun] = fld;
    7664                 :             :         }
    7665                 :             : 
    7666                 :             :       /* Skip non-arrays.  */
    7667                 :    22610322 :       if (TREE_CODE (fldtype) != ARRAY_TYPE)
    7668                 :    20743027 :         continue;
    7669                 :             : 
    7670                 :             :       /* Determine the upper bound of the array if it has one.  */
    7671                 :     1867295 :       if (TYPE_DOMAIN (fldtype))
    7672                 :             :         {
    7673                 :     1865681 :           if (fmem->array)
    7674                 :             :             {
    7675                 :             :               /* Make a record of the zero-length array if either one
    7676                 :             :                  such field or a flexible array member has been seen to
    7677                 :             :                  handle the pathological and unlikely case of multiple
    7678                 :             :                  such members.  */
    7679                 :        1040 :               if (!fmem->after[pun])
    7680                 :          83 :                 fmem->after[pun] = fld;
    7681                 :             :             }
    7682                 :     1864641 :           else if (integer_all_onesp (TYPE_MAX_VALUE (TYPE_DOMAIN (fldtype))))
    7683                 :             :             {
    7684                 :             :               /* Remember the first zero-length array unless a flexible array
    7685                 :             :                  member has already been seen.  */
    7686                 :        2436 :               fmem->array = fld;
    7687                 :        2436 :               fmem->enclosing = pstr;
    7688                 :             :             }
    7689                 :             :         }
    7690                 :             :       else
    7691                 :             :         {
    7692                 :             :           /* Flexible array members have no upper bound.  */
    7693                 :        1614 :           if (fmem->array)
    7694                 :             :             {
    7695                 :          79 :               if (TYPE_DOMAIN (TREE_TYPE (fmem->array)))
    7696                 :             :                 {
    7697                 :             :                   /* Replace the zero-length array if it's been stored and
    7698                 :             :                      reset the after pointer.  */
    7699                 :          31 :                   fmem->after[pun] = NULL_TREE;
    7700                 :          31 :                   fmem->array = fld;
    7701                 :          31 :                   fmem->enclosing = pstr;
    7702                 :             :                 }
    7703                 :          48 :               else if (!fmem->after[pun])
    7704                 :             :                 /* Make a record of another flexible array member.  */
    7705                 :          39 :                 fmem->after[pun] = fld;
    7706                 :             :             }
    7707                 :             :           else
    7708                 :             :             {
    7709                 :        1535 :               fmem->array = fld;
    7710                 :        1535 :               fmem->enclosing = pstr;
    7711                 :             :             }
    7712                 :             :         }
    7713                 :             :     }
    7714                 :             : }
    7715                 :             : 
    7716                 :             : /* Diagnose a strictly (by the C standard) invalid use of a struct with
    7717                 :             :    a flexible array member (or the zero-length array extension).  */
    7718                 :             : 
    7719                 :             : static void
    7720                 :        2125 : diagnose_invalid_flexarray (const flexmems_t *fmem)
    7721                 :             : {
    7722                 :        2125 :   if (fmem->array && fmem->enclosing)
    7723                 :             :     {
    7724                 :         655 :       auto_diagnostic_group d;
    7725                 :         655 :       if (pedwarn (location_of (fmem->enclosing), OPT_Wpedantic,
    7726                 :         655 :                    TYPE_DOMAIN (TREE_TYPE (fmem->array))
    7727                 :             :                    ? G_("invalid use of %q#T with a zero-size array in %q#D")
    7728                 :             :                    : G_("invalid use of %q#T with a flexible array member "
    7729                 :             :                         "in %q#T"),
    7730                 :         655 :                    DECL_CONTEXT (fmem->array),
    7731                 :         655 :                    DECL_CONTEXT (fmem->enclosing)))
    7732                 :          78 :         inform (DECL_SOURCE_LOCATION (fmem->array),
    7733                 :          78 :                 "array member %q#D declared here", fmem->array);
    7734                 :         655 :     }
    7735                 :        2125 : }
    7736                 :             : 
    7737                 :             : /* Issue diagnostics for invalid flexible array members or zero-length
    7738                 :             :    arrays that are not the last elements of the containing class or its
    7739                 :             :    base classes or that are its sole members.  */
    7740                 :             : 
    7741                 :             : static void
    7742                 :    36769097 : diagnose_flexarrays (tree t, const flexmems_t *fmem)
    7743                 :             : {
    7744                 :    36769097 :   if (!fmem->array)
    7745                 :             :     return;
    7746                 :             : 
    7747                 :        3971 :   if (fmem->first && !fmem->after[0])
    7748                 :             :     {
    7749                 :        1843 :       diagnose_invalid_flexarray (fmem);
    7750                 :        1843 :       return;
    7751                 :             :     }
    7752                 :             : 
    7753                 :             :   /* Has a diagnostic been issued?  */
    7754                 :        2128 :   bool diagd = false;
    7755                 :             : 
    7756                 :        2128 :   const char *msg = 0;
    7757                 :        2128 :   const char *msg_fam = 0;
    7758                 :             : 
    7759                 :        2128 :   if (TYPE_DOMAIN (TREE_TYPE (fmem->array)))
    7760                 :             :     {
    7761                 :        1615 :       if (fmem->after[0])
    7762                 :             :         msg = G_("zero-size array member %qD not at end of %q#T");
    7763                 :         256 :       else if (!fmem->first)
    7764                 :             :         msg = G_("zero-size array member %qD in an otherwise empty %q#T");
    7765                 :             : 
    7766                 :             :       if (msg)
    7767                 :             :         {
    7768                 :        1615 :           location_t loc = DECL_SOURCE_LOCATION (fmem->array);
    7769                 :             : 
    7770                 :        1615 :           auto_diagnostic_group d;
    7771                 :        1615 :           if (pedwarn (loc, OPT_Wpedantic, msg, fmem->array, t))
    7772                 :             :             {
    7773                 :         138 :               inform (location_of (t), "in the definition of %q#T", t);
    7774                 :         138 :               diagd = true;
    7775                 :             :             }
    7776                 :        1615 :         }
    7777                 :             :     }
    7778                 :             :   else
    7779                 :             :     {
    7780                 :         513 :       if (fmem->after[0])
    7781                 :             :         msg = G_("flexible array member %qD not at end of %q#T");
    7782                 :         316 :       else if (!fmem->first)
    7783                 :         316 :         msg_fam = G_("flexible array member %qD in an otherwise"
    7784                 :             :                      " empty %q#T is a GCC extension");
    7785                 :             : 
    7786                 :         513 :       if (msg || msg_fam)
    7787                 :             :         {
    7788                 :         513 :           location_t loc = DECL_SOURCE_LOCATION (fmem->array);
    7789                 :         513 :           diagd = true;
    7790                 :             : 
    7791                 :         513 :           auto_diagnostic_group d;
    7792                 :         513 :           if (msg)
    7793                 :         197 :             error_at (loc, msg, fmem->array, t);
    7794                 :             :           else
    7795                 :         316 :             pedwarn (loc, OPT_Wpedantic, msg_fam, fmem->array, t);
    7796                 :             : 
    7797                 :             :           /* In the unlikely event that the member following the flexible
    7798                 :             :              array member is declared in a different class, or the member
    7799                 :             :              overlaps another member of a common union, point to it.
    7800                 :             :              Otherwise it should be obvious.  */
    7801                 :         513 :           if (fmem->after[0]
    7802                 :         513 :               && (DECL_CONTEXT (fmem->after[0])
    7803                 :         197 :                   != DECL_CONTEXT (fmem->array)))
    7804                 :             :             {
    7805                 :          77 :               inform (DECL_SOURCE_LOCATION (fmem->after[0]),
    7806                 :             :                       "next member %q#D declared here",
    7807                 :             :                       fmem->after[0]);
    7808                 :          77 :               inform (location_of (t), "in the definition of %q#T", t);
    7809                 :             :             }
    7810                 :         513 :         }
    7811                 :             :     }
    7812                 :             : 
    7813                 :        2128 :   if (!diagd && fmem->array && fmem->enclosing)
    7814                 :         282 :     diagnose_invalid_flexarray (fmem);
    7815                 :             : }
    7816                 :             : 
    7817                 :             : 
    7818                 :             : /* Recursively check to make sure that any flexible array or zero-length
    7819                 :             :    array members of class T or its bases are valid (i.e., not the sole
    7820                 :             :    non-static data member of T and, if one exists, that it is the last
    7821                 :             :    non-static data member of T and its base classes.  FMEM is expected
    7822                 :             :    to be initially null and is used internally by recursive calls to
    7823                 :             :    the function.  Issue the appropriate diagnostics for the array member
    7824                 :             :    that fails the checks.  */
    7825                 :             : 
    7826                 :             : static void
    7827                 :    60300964 : check_flexarrays (tree t, flexmems_t *fmem /* = NULL */,
    7828                 :             :                   bool base_p /* = false */)
    7829                 :             : {
    7830                 :             :   /* Initialize the result of a search for flexible array and zero-length
    7831                 :             :      array members.  Avoid doing any work if the most interesting FMEM data
    7832                 :             :      have already been populated.  */
    7833                 :    60300964 :   flexmems_t flexmems = flexmems_t ();
    7834                 :    60300964 :   if (!fmem)
    7835                 :             :     fmem = &flexmems;
    7836                 :    22520200 :   else if (fmem->array && fmem->first && fmem->after[0])
    7837                 :           0 :     return;
    7838                 :             : 
    7839                 :    60300964 :   tree fam = fmem->array;
    7840                 :             : 
    7841                 :             :   /* Recursively check the primary base class first.  */
    7842                 :    60300964 :   if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    7843                 :             :     {
    7844                 :     2472893 :       tree basetype = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (t));
    7845                 :     2472893 :       check_flexarrays (basetype, fmem, true);
    7846                 :             :     }
    7847                 :             : 
    7848                 :             :   /* Recursively check the base classes.  */
    7849                 :    60300964 :   int nbases = TYPE_BINFO (t) ? BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) : 0;
    7850                 :    82889230 :   for (int i = 0; i < nbases; ++i)
    7851                 :             :     {
    7852                 :    22588266 :       tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (t), i);
    7853                 :             : 
    7854                 :             :       /* The primary base class was already checked above.  */
    7855                 :    22588266 :       if (base_binfo == CLASSTYPE_PRIMARY_BINFO (t))
    7856                 :     2472750 :         continue;
    7857                 :             : 
    7858                 :             :       /* Virtual base classes are at the end.  */
    7859                 :    20115516 :       if (BINFO_VIRTUAL_P (base_binfo))
    7860                 :      268769 :         continue;
    7861                 :             : 
    7862                 :             :       /* Check the base class.  */
    7863                 :    19846747 :       check_flexarrays (BINFO_TYPE (base_binfo), fmem, /*base_p=*/true);
    7864                 :             :     }
    7865                 :             : 
    7866                 :    60300964 :   if (fmem == &flexmems)
    7867                 :             :     {
    7868                 :             :       /* Check virtual base classes only once per derived class.
    7869                 :             :          I.e., this check is not performed recursively for base
    7870                 :             :          classes.  */
    7871                 :    37780764 :       int i;
    7872                 :    37780764 :       tree base_binfo;
    7873                 :    37780764 :       vec<tree, va_gc> *vbases;
    7874                 :    37981324 :       for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    7875                 :    37981324 :            vec_safe_iterate (vbases, i, &base_binfo); i++)
    7876                 :             :         {
    7877                 :             :           /* Check the virtual base class.  */
    7878                 :      200560 :           tree basetype = TREE_TYPE (base_binfo);
    7879                 :             : 
    7880                 :      200560 :           check_flexarrays (basetype, fmem, /*base_p=*/true);
    7881                 :             :         }
    7882                 :             :     }
    7883                 :             : 
    7884                 :             :   /* Is the type unnamed (and therefore a member of it potentially
    7885                 :             :      an anonymous struct or union)?  */
    7886                 :   122293648 :   bool maybe_anon_p = TYPE_UNNAMED_P (t);
    7887                 :     1396424 :   if (tree ctx = maybe_anon_p ? TYPE_CONTEXT (t) : NULL_TREE)
    7888                 :     1396424 :     maybe_anon_p = RECORD_OR_UNION_TYPE_P (ctx);
    7889                 :             : 
    7890                 :             :   /* Search the members of the current (possibly derived) class, skipping
    7891                 :             :      unnamed structs and unions since those could be anonymous.  */
    7892                 :    60300964 :   if (fmem != &flexmems || !maybe_anon_p)
    7893                 :    81809675 :     find_flexarrays (t, fmem, base_p || fam != fmem->array);
    7894                 :             : 
    7895                 :    60300964 :   if (fmem == &flexmems && !maybe_anon_p)
    7896                 :             :     /* Issue diagnostics for invalid flexible and zero-length array
    7897                 :             :        members found in base classes or among the members of the current
    7898                 :             :        class.  Ignore anonymous structs and unions whose members are
    7899                 :             :        considered to be members of the enclosing class and thus will
    7900                 :             :        be diagnosed when checking it.  */
    7901                 :    36769097 :     diagnose_flexarrays (t, fmem);
    7902                 :             : }
    7903                 :             : 
    7904                 :             : /* Perform processing required when the definition of T (a class type)
    7905                 :             :    is complete.  Diagnose invalid definitions of flexible array members
    7906                 :             :    and zero-size arrays.  */
    7907                 :             : 
    7908                 :             : void
    7909                 :    37061824 : finish_struct_1 (tree t)
    7910                 :             : {
    7911                 :    37061824 :   tree x;
    7912                 :             :   /* A TREE_LIST.  The TREE_VALUE of each node is a FUNCTION_DECL.  */
    7913                 :    37061824 :   tree virtuals = NULL_TREE;
    7914                 :             : 
    7915                 :    37061824 :   if (COMPLETE_TYPE_P (t))
    7916                 :             :     {
    7917                 :           0 :       gcc_assert (MAYBE_CLASS_TYPE_P (t));
    7918                 :           0 :       error ("redefinition of %q#T", t);
    7919                 :           0 :       popclass ();
    7920                 :           0 :       return;
    7921                 :             :     }
    7922                 :             : 
    7923                 :    37061824 :   if (location_t fcloc = failed_completion_location (t))
    7924                 :             :     {
    7925                 :          11 :       auto_diagnostic_group adg;
    7926                 :          11 :       if (warning (OPT_Wsfinae_incomplete_,
    7927                 :             :                    "defining %qT, which previously failed to be complete "
    7928                 :             :                    "in a SFINAE context", t)
    7929                 :          11 :           && warn_sfinae_incomplete == 1)
    7930                 :          11 :         inform (fcloc, "here.  Use %qs for a diagnostic at that point",
    7931                 :             :                 "-Wsfinae-incomplete=2");
    7932                 :          11 :     }
    7933                 :             : 
    7934                 :             :   /* If this type was previously laid out as a forward reference,
    7935                 :             :      make sure we lay it out again.  */
    7936                 :    37061824 :   TYPE_SIZE (t) = NULL_TREE;
    7937                 :    37061824 :   CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
    7938                 :             : 
    7939                 :             :   /* Make assumptions about the class; we'll reset the flags if
    7940                 :             :      necessary.  */
    7941                 :    37061824 :   CLASSTYPE_EMPTY_P (t) = 1;
    7942                 :    37061824 :   CLASSTYPE_NEARLY_EMPTY_P (t) = 1;
    7943                 :    37061824 :   CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 0;
    7944                 :    37061824 :   CLASSTYPE_LITERAL_P (t) = true;
    7945                 :             : 
    7946                 :             :   /* Do end-of-class semantic processing: checking the validity of the
    7947                 :             :      bases and members and add implicitly generated methods.  */
    7948                 :    37061824 :   check_bases_and_members (t);
    7949                 :             : 
    7950                 :             :   /* Find the key method.  */
    7951                 :    37061824 :   if (TYPE_CONTAINS_VPTR_P (t))
    7952                 :             :     {
    7953                 :             :       /* The Itanium C++ ABI permits the key method to be chosen when
    7954                 :             :          the class is defined -- even though the key method so
    7955                 :             :          selected may later turn out to be an inline function.  On
    7956                 :             :          some systems (such as ARM Symbian OS) the key method cannot
    7957                 :             :          be determined until the end of the translation unit.  On such
    7958                 :             :          systems, we leave CLASSTYPE_KEY_METHOD set to NULL, which
    7959                 :             :          will cause the class to be added to KEYED_CLASSES.  Then, in
    7960                 :             :          finish_file we will determine the key method.  */
    7961                 :     1657715 :       if (targetm.cxx.key_method_may_be_inline ())
    7962                 :     1657715 :         determine_key_method (t);
    7963                 :             : 
    7964                 :             :       /* If a polymorphic class has no key method, we may emit the vtable
    7965                 :             :          in every translation unit where the class definition appears.  If
    7966                 :             :          we're devirtualizing, we can look into the vtable even if we
    7967                 :             :          aren't emitting it.
    7968                 :             : 
    7969                 :             :          Additionally, if the class is attached to a named module, make sure
    7970                 :             :          to always emit the vtable in this TU.  */
    7971                 :     1657715 :       if (!CLASSTYPE_KEY_METHOD (t) || module_attach_p ())
    7972                 :     1095787 :         vec_safe_push (keyed_classes, t);
    7973                 :             :     }
    7974                 :             : 
    7975                 :             :   /* Layout the class itself.  */
    7976                 :    37061824 :   layout_class_type (t, &virtuals);
    7977                 :             :   /* COMPLETE_TYPE_P is now true.  */
    7978                 :             : 
    7979                 :    37061824 :   set_class_bindings (t);
    7980                 :             : 
    7981                 :             :   /* With the layout complete, check for flexible array members and
    7982                 :             :      zero-length arrays that might overlap other members in the final
    7983                 :             :      layout.  */
    7984                 :    37061824 :   check_flexarrays (t);
    7985                 :             : 
    7986                 :    37061824 :   virtuals = modify_all_vtables (t, nreverse (virtuals));
    7987                 :             : 
    7988                 :             :   /* If necessary, create the primary vtable for this class.  */
    7989                 :    37061824 :   if (virtuals || TYPE_CONTAINS_VPTR_P (t))
    7990                 :             :     {
    7991                 :             :       /* We must enter these virtuals into the table.  */
    7992                 :     1657715 :       if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    7993                 :      239845 :         build_primary_vtable (NULL_TREE, t);
    7994                 :     1417870 :       else if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
    7995                 :             :         /* Here we know enough to change the type of our virtual
    7996                 :             :            function table, but we will wait until later this function.  */
    7997                 :           0 :         build_primary_vtable (CLASSTYPE_PRIMARY_BINFO (t), t);
    7998                 :             : 
    7999                 :             :       /* If we're warning about ABI tags, check the types of the new
    8000                 :             :          virtual functions.  */
    8001                 :     1657715 :       if (warn_abi_tag)
    8002                 :           6 :         for (tree v = virtuals; v; v = TREE_CHAIN (v))
    8003                 :           3 :           check_abi_tags (t, TREE_VALUE (v));
    8004                 :             :     }
    8005                 :             : 
    8006                 :    37061824 :   if (TYPE_CONTAINS_VPTR_P (t))
    8007                 :             :     {
    8008                 :     1657715 :       int vindex;
    8009                 :     1657715 :       tree fn;
    8010                 :             : 
    8011                 :     1657715 :       if (BINFO_VTABLE (TYPE_BINFO (t)))
    8012                 :     1657715 :         gcc_assert (DECL_VIRTUAL_P (BINFO_VTABLE (TYPE_BINFO (t))));
    8013                 :     1657715 :       if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    8014                 :      239845 :         gcc_assert (BINFO_VIRTUALS (TYPE_BINFO (t)) == NULL_TREE);
    8015                 :             : 
    8016                 :             :       /* Add entries for virtual functions introduced by this class.  */
    8017                 :     1657715 :       BINFO_VIRTUALS (TYPE_BINFO (t))
    8018                 :     1657715 :         = chainon (BINFO_VIRTUALS (TYPE_BINFO (t)), virtuals);
    8019                 :             : 
    8020                 :             :       /* Set DECL_VINDEX for all functions declared in this class.  */
    8021                 :     1657715 :       for (vindex = 0, fn = BINFO_VIRTUALS (TYPE_BINFO (t));
    8022                 :    11209155 :            fn;
    8023                 :     9551440 :            fn = TREE_CHAIN (fn),
    8024                 :     9551440 :              vindex += (TARGET_VTABLE_USES_DESCRIPTORS
    8025                 :             :                         ? TARGET_VTABLE_USES_DESCRIPTORS : 1))
    8026                 :             :         {
    8027                 :     9551440 :           tree fndecl = BV_FN (fn);
    8028                 :             : 
    8029                 :     9551440 :           if (DECL_THUNK_P (fndecl))
    8030                 :             :             /* A thunk. We should never be calling this entry directly
    8031                 :             :                from this vtable -- we'd use the entry for the non
    8032                 :             :                thunk base function.  */
    8033                 :         126 :             DECL_VINDEX (fndecl) = NULL_TREE;
    8034                 :     9551314 :           else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
    8035                 :     7622678 :             DECL_VINDEX (fndecl) = build_int_cst (NULL_TREE, vindex);
    8036                 :             :         }
    8037                 :             :     }
    8038                 :             : 
    8039                 :    37061824 :   finish_struct_bits (t);
    8040                 :             : 
    8041                 :    37061824 :   set_method_tm_attributes (t);
    8042                 :    37061824 :   if (flag_openmp || flag_openmp_simd)
    8043                 :       92528 :     finish_omp_declare_simd_methods (t);
    8044                 :             : 
    8045                 :             :   /* Clear DECL_IN_AGGR_P for all member functions.  Complete the rtl
    8046                 :             :      for any static member objects of the type we're working on.  */
    8047                 :   338520209 :   for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    8048                 :   301458385 :     if (DECL_DECLARES_FUNCTION_P (x))
    8049                 :             :       {
    8050                 :             :         /* Synthesize constexpr defaulted comparisons.  */
    8051                 :   172808229 :         if (!DECL_ARTIFICIAL (x)
    8052                 :   171865906 :             && DECL_DEFAULTED_IN_CLASS_P (x)
    8053                 :   186243417 :             && special_function_p (x) == sfk_comparison)
    8054                 :       11359 :           defaulted_late_check (x);
    8055                 :   172808229 :         DECL_IN_AGGR_P (x) = false;
    8056                 :             :       }
    8057                 :     9948098 :     else if (VAR_P (x) && TREE_STATIC (x)
    8058                 :     9948098 :              && TREE_TYPE (x) != error_mark_node
    8059                 :   138598189 :              && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t))
    8060                 :       40559 :       SET_DECL_MODE (x, TYPE_MODE (t));
    8061                 :             : 
    8062                 :             :   /* Complain if one of the field types requires lower visibility.  */
    8063                 :    37061824 :   constrain_class_visibility (t);
    8064                 :             : 
    8065                 :             :   /* Make the rtl for any new vtables we have created, and unmark
    8066                 :             :      the base types we marked.  */
    8067                 :    37061824 :   finish_vtbls (t);
    8068                 :             : 
    8069                 :             :   /* Build the VTT for T.  */
    8070                 :    37061824 :   build_vtt (t);
    8071                 :             : 
    8072                 :    37061824 :   if (warn_nonvdtor
    8073                 :         147 :       && TYPE_POLYMORPHIC_P (t) && accessible_nvdtor_p (t)
    8074                 :    37061860 :       && !CLASSTYPE_FINAL (t))
    8075                 :          33 :     warning (OPT_Wnon_virtual_dtor,
    8076                 :             :              "%q#T has virtual functions and accessible"
    8077                 :             :              " non-virtual destructor", t);
    8078                 :             : 
    8079                 :    37061824 :   complete_vars (t);
    8080                 :             : 
    8081                 :    37061824 :   if (warn_overloaded_virtual)
    8082                 :      353333 :     warn_hidden (t);
    8083                 :             : 
    8084                 :             :   /* Class layout, assignment of virtual table slots, etc., is now
    8085                 :             :      complete.  Give the back end a chance to tweak the visibility of
    8086                 :             :      the class or perform any other required target modifications.  */
    8087                 :    37061824 :   targetm.cxx.adjust_class_at_definition (t);
    8088                 :             : 
    8089                 :    37061824 :   maybe_suppress_debug_info (t);
    8090                 :             : 
    8091                 :    37061824 :   if (flag_vtable_verify)
    8092                 :          12 :     vtv_save_class_info (t);
    8093                 :             : 
    8094                 :    37061824 :   dump_class_hierarchy (t);
    8095                 :             : 
    8096                 :             :   /* Finish debugging output for this type.  */
    8097                 :    37061824 :   rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
    8098                 :             : 
    8099                 :    37061824 :   if (TYPE_TRANSPARENT_AGGR (t))
    8100                 :             :     {
    8101                 :         163 :       tree field = first_field (t);
    8102                 :         163 :       if (field == NULL_TREE || error_operand_p (field))
    8103                 :             :         {
    8104                 :           9 :           error ("type transparent %q#T does not have any fields", t);
    8105                 :           9 :           TYPE_TRANSPARENT_AGGR (t) = 0;
    8106                 :             :         }
    8107                 :         154 :       else if (DECL_ARTIFICIAL (field))
    8108                 :             :         {
    8109                 :           3 :           if (DECL_FIELD_IS_BASE (field))
    8110                 :           3 :             error ("type transparent class %qT has base classes", t);
    8111                 :             :           else
    8112                 :             :             {
    8113                 :           0 :               gcc_checking_assert (DECL_VIRTUAL_P (field));
    8114                 :           0 :               error ("type transparent class %qT has virtual functions", t);
    8115                 :             :             }
    8116                 :           3 :           TYPE_TRANSPARENT_AGGR (t) = 0;
    8117                 :             :         }
    8118                 :         151 :       else if (TYPE_MODE (t) != DECL_MODE (field))
    8119                 :             :         {
    8120                 :           3 :           error ("type transparent %q#T cannot be made transparent because "
    8121                 :             :                  "the type of the first field has a different ABI from the "
    8122                 :             :                  "class overall", t);
    8123                 :           3 :           TYPE_TRANSPARENT_AGGR (t) = 0;
    8124                 :             :         }
    8125                 :             :     }
    8126                 :             : }
    8127                 :             : 
    8128                 :             : /* When T was built up, the member declarations were added in reverse
    8129                 :             :    order.  Rearrange them to declaration order.  */
    8130                 :             : 
    8131                 :             : void
    8132                 :    53697083 : unreverse_member_declarations (tree t)
    8133                 :             : {
    8134                 :    53697083 :   tree next;
    8135                 :    53697083 :   tree prev;
    8136                 :    53697083 :   tree x;
    8137                 :             : 
    8138                 :             :   /* The following lists are all in reverse order.  Put them in
    8139                 :             :      declaration order now.  */
    8140                 :    53697083 :   CLASSTYPE_DECL_LIST (t) = nreverse (CLASSTYPE_DECL_LIST (t));
    8141                 :             : 
    8142                 :             :   /* For the TYPE_FIELDS, only the non TYPE_DECLs are in reverse
    8143                 :             :      order, so we can't just use nreverse.  Due to stat_hack
    8144                 :             :      chicanery in finish_member_declaration.  */
    8145                 :    53697083 :   prev = NULL_TREE;
    8146                 :    53697083 :   for (x = TYPE_FIELDS (t);
    8147                 :   280265984 :        x && TREE_CODE (x) != TYPE_DECL;
    8148                 :   226568901 :        x = next)
    8149                 :             :     {
    8150                 :   226568901 :       next = DECL_CHAIN (x);
    8151                 :   226568901 :       DECL_CHAIN (x) = prev;
    8152                 :   226568901 :       prev = x;
    8153                 :             :     }
    8154                 :             : 
    8155                 :    53697083 :   if (prev)
    8156                 :             :     {
    8157                 :    22110573 :       DECL_CHAIN (TYPE_FIELDS (t)) = x;
    8158                 :    22110573 :       TYPE_FIELDS (t) = prev;
    8159                 :             :     }
    8160                 :    53697083 : }
    8161                 :             : 
    8162                 :             : /* Classes, structs or unions T marked with hotness attributes propagate
    8163                 :             :    the attribute to all methods.  */
    8164                 :             : 
    8165                 :             : void
    8166                 :    37061824 : propagate_class_warmth_attribute (tree t)
    8167                 :             : {
    8168                 :    37061824 :   if (t == NULL_TREE
    8169                 :    37061824 :       || !(TREE_CODE (t) == RECORD_TYPE
    8170                 :             :            || TREE_CODE (t) == UNION_TYPE))
    8171                 :             :     return;
    8172                 :             : 
    8173                 :    37061824 :   tree class_has_cold_attr
    8174                 :    37061824 :     = lookup_attribute ("cold", TYPE_ATTRIBUTES (t));
    8175                 :    37061824 :   tree class_has_hot_attr
    8176                 :    37061824 :     = lookup_attribute ("hot", TYPE_ATTRIBUTES (t));
    8177                 :             : 
    8178                 :    37061824 :   if (class_has_cold_attr || class_has_hot_attr)
    8179                 :          42 :     for (tree f = TYPE_FIELDS (t); f; f = DECL_CHAIN (f))
    8180                 :          30 :       if (DECL_DECLARES_FUNCTION_P (f))
    8181                 :          18 :         maybe_propagate_warmth_attributes (STRIP_TEMPLATE (f), t);
    8182                 :             : }
    8183                 :             : 
    8184                 :             : tree
    8185                 :    25333445 : finish_struct (tree t, tree attributes)
    8186                 :             : {
    8187                 :    25333445 :   location_t saved_loc = input_location;
    8188                 :             : 
    8189                 :             :   /* Now that we've got all the field declarations, reverse everything
    8190                 :             :      as necessary.  */
    8191                 :    25333445 :   unreverse_member_declarations (t);
    8192                 :             : 
    8193                 :    25333445 :   cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8194                 :    25333445 :   fixup_attribute_variants (t);
    8195                 :             : 
    8196                 :             :   /* Nadger the current location so that diagnostics point to the start of
    8197                 :             :      the struct, not the end.  */
    8198                 :    25333445 :   input_location = DECL_SOURCE_LOCATION (TYPE_NAME (t));
    8199                 :             : 
    8200                 :    25333445 :   if (processing_template_decl)
    8201                 :             :     {
    8202                 :    16635259 :       tree x;
    8203                 :             : 
    8204                 :   131307902 :       for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    8205                 :   114672643 :         if (DECL_DECLARES_FUNCTION_P (x))
    8206                 :             :           {
    8207                 :    64966150 :             DECL_IN_AGGR_P (x) = false;
    8208                 :    64966150 :             if (DECL_VIRTUAL_P (x))
    8209                 :     1817296 :               CLASSTYPE_NON_AGGREGATE (t) = true;
    8210                 :             :           }
    8211                 :    49706493 :         else if (TREE_CODE (x) == FIELD_DECL)
    8212                 :             :           {
    8213                 :     9111794 :             if (TREE_PROTECTED (x) || TREE_PRIVATE (x))
    8214                 :     4958090 :               CLASSTYPE_NON_AGGREGATE (t) = true;
    8215                 :             :           }
    8216                 :             : 
    8217                 :             :       /* Also add a USING_DECL for operator=.  We know there'll be (at
    8218                 :             :          least) one, but we don't know the signature(s).  We want name
    8219                 :             :          lookup not to fail or recurse into bases.  This isn't added
    8220                 :             :          to the template decl list so we drop this at instantiation
    8221                 :             :          time.  */
    8222                 :    16635259 :       tree ass_op = build_lang_decl (USING_DECL, assign_op_identifier,
    8223                 :             :                                      NULL_TREE);
    8224                 :    16635259 :       DECL_CONTEXT (ass_op) = t;
    8225                 :    16635259 :       USING_DECL_SCOPE (ass_op) = t;
    8226                 :    16635259 :       DECL_DEPENDENT_P (ass_op) = true;
    8227                 :    16635259 :       DECL_ARTIFICIAL (ass_op) = true;
    8228                 :    16635259 :       DECL_CHAIN (ass_op) = TYPE_FIELDS (t);
    8229                 :    16635259 :       TYPE_FIELDS (t) = ass_op;
    8230                 :             : 
    8231                 :    16635259 :       TYPE_SIZE (t) = bitsize_zero_node;
    8232                 :    16635259 :       TYPE_SIZE_UNIT (t) = size_zero_node;
    8233                 :             :       /* COMPLETE_TYPE_P is now true.  */
    8234                 :             : 
    8235                 :    16635259 :       set_class_bindings (t);
    8236                 :             : 
    8237                 :             :       /* We need to emit an error message if this type was used as a parameter
    8238                 :             :          and it is an abstract type, even if it is a template. We construct
    8239                 :             :          a simple CLASSTYPE_PURE_VIRTUALS list without taking bases into
    8240                 :             :          account and we call complete_vars with this type, which will check
    8241                 :             :          the PARM_DECLS. Note that while the type is being defined,
    8242                 :             :          CLASSTYPE_PURE_VIRTUALS contains the list of the inline friends
    8243                 :             :          (see CLASSTYPE_INLINE_FRIENDS) so we need to clear it.  */
    8244                 :    16635259 :       CLASSTYPE_PURE_VIRTUALS (t) = NULL;
    8245                 :   147943161 :       for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    8246                 :   131307902 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_PURE_VIRTUAL_P (x))
    8247                 :      261874 :           vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    8248                 :    16635259 :       complete_vars (t);
    8249                 :             : 
    8250                 :             :       /* Remember current #pragma pack value.  */
    8251                 :    16635259 :       TYPE_PRECISION (t) = maximum_field_alignment;
    8252                 :             : 
    8253                 :    16635259 :       if (cxx_dialect < cxx20)
    8254                 :             :         {
    8255                 :    11550732 :           if (!CLASSTYPE_NON_AGGREGATE (t)
    8256                 :    11550732 :               && type_has_user_provided_or_explicit_constructor (t))
    8257                 :     1338942 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    8258                 :             :         }
    8259                 :     5084527 :       else if (TYPE_HAS_USER_CONSTRUCTOR (t))
    8260                 :     1542044 :         CLASSTYPE_NON_AGGREGATE (t) = 1;
    8261                 :             : 
    8262                 :             :       /* Fix up any variants we've already built.  */
    8263                 :    16635259 :       fixup_type_variants (t);
    8264                 :             :     }
    8265                 :             :   else
    8266                 :     8698186 :     finish_struct_1 (t);
    8267                 :             :   /* COMPLETE_TYPE_P is now true.  */
    8268                 :             : 
    8269                 :    25333445 :   maybe_warn_about_overly_private_class (t);
    8270                 :             : 
    8271                 :    25333445 :   if (is_std_init_list (t))
    8272                 :             :     {
    8273                 :             :       /* People keep complaining that the compiler crashes on an invalid
    8274                 :             :          definition of initializer_list, so I guess we should explicitly
    8275                 :             :          reject it.  What the compiler internals care about is that it's a
    8276                 :             :          template and has a pointer field followed by size_type field.  */
    8277                 :       13773 :       bool ok = false;
    8278                 :       13773 :       if (processing_template_decl)
    8279                 :             :         {
    8280                 :       13773 :           tree f = next_aggregate_field (TYPE_FIELDS (t));
    8281                 :       13773 :           if (f && TYPE_PTR_P (TREE_TYPE (f)))
    8282                 :             :             {
    8283                 :       13770 :               f = next_aggregate_field (DECL_CHAIN (f));
    8284                 :       13770 :               if (f && same_type_p (TREE_TYPE (f), size_type_node))
    8285                 :             :                 ok = true;
    8286                 :             :             }
    8287                 :             :         }
    8288                 :             :       /* It also cannot be a union.  */
    8289                 :       13773 :       ok &= NON_UNION_CLASS_TYPE_P (t);
    8290                 :       13770 :       if (!ok)
    8291                 :           9 :         fatal_error (input_location, "definition of %qD does not match "
    8292                 :           9 :                      "%<#include <initializer_list>%>", TYPE_NAME (t));
    8293                 :             :     }
    8294                 :             : 
    8295                 :    25333436 :   input_location = saved_loc;
    8296                 :             : 
    8297                 :    25333436 :   TYPE_BEING_DEFINED (t) = 0;
    8298                 :             : 
    8299                 :    25333436 :   if (current_class_type)
    8300                 :    25333436 :     popclass ();
    8301                 :             :   else
    8302                 :           0 :     error ("trying to finish struct, but kicked out due to previous parse errors");
    8303                 :             : 
    8304                 :    25333436 :   if (flag_openmp)
    8305                 :      633442 :     for (tree decl = TYPE_FIELDS (t); decl; decl = DECL_CHAIN (decl))
    8306                 :      524188 :       if (TREE_CODE (decl) == FUNCTION_DECL
    8307                 :      524188 :           && DECL_OBJECT_MEMBER_FUNCTION_P (decl))
    8308                 :      117215 :         if (tree attr = lookup_attribute ("omp declare variant base",
    8309                 :      117215 :                                           DECL_ATTRIBUTES (decl)))
    8310                 :         112 :           omp_declare_variant_finalize (decl, attr);
    8311                 :             : 
    8312                 :    16635250 :   if (processing_template_decl && at_function_scope_p ()
    8313                 :             :       /* Lambdas are defined by the LAMBDA_EXPR.  */
    8314                 :    26830209 :       && !LAMBDA_TYPE_P (t))
    8315                 :      200151 :     add_stmt (build_min (TAG_DEFN, t));
    8316                 :             : 
    8317                 :    25333436 :   return t;
    8318                 :             : }
    8319                 :             : 
    8320                 :             : /* Hash table to avoid endless recursion when handling references.  */
    8321                 :             : static hash_table<nofree_ptr_hash<tree_node> > *fixed_type_or_null_ref_ht;
    8322                 :             : 
    8323                 :             : /* Return the dynamic type of INSTANCE, if known.
    8324                 :             :    Used to determine whether the virtual function table is needed
    8325                 :             :    or not.
    8326                 :             : 
    8327                 :             :    *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
    8328                 :             :    of our knowledge of its type.  *NONNULL should be initialized
    8329                 :             :    before this function is called.  */
    8330                 :             : 
    8331                 :             : static tree
    8332                 :    10700540 : fixed_type_or_null (tree instance, int *nonnull, int *cdtorp)
    8333                 :             : {
    8334                 :             : #define RECUR(T) fixed_type_or_null((T), nonnull, cdtorp)
    8335                 :             : 
    8336                 :    10700540 :   switch (TREE_CODE (instance))
    8337                 :             :     {
    8338                 :      600622 :     case INDIRECT_REF:
    8339                 :      600622 :       if (INDIRECT_TYPE_P (TREE_TYPE (instance)))
    8340                 :             :         return NULL_TREE;
    8341                 :             :       else
    8342                 :      544843 :         return RECUR (TREE_OPERAND (instance, 0));
    8343                 :             : 
    8344                 :      223078 :     case CALL_EXPR:
    8345                 :             :       /* This is a call to a constructor, hence it's never zero.  */
    8346                 :      223078 :       if (CALL_EXPR_FN (instance)
    8347                 :      223078 :           && TREE_HAS_CONSTRUCTOR (instance))
    8348                 :             :         {
    8349                 :           0 :           if (nonnull)
    8350                 :           0 :             *nonnull = 1;
    8351                 :           0 :           return TREE_TYPE (instance);
    8352                 :             :         }
    8353                 :             :       return NULL_TREE;
    8354                 :             : 
    8355                 :       62620 :     case SAVE_EXPR:
    8356                 :             :       /* This is a call to a constructor, hence it's never zero.  */
    8357                 :       62620 :       if (TREE_HAS_CONSTRUCTOR (instance))
    8358                 :             :         {
    8359                 :           0 :           if (nonnull)
    8360                 :           0 :             *nonnull = 1;
    8361                 :           0 :           return TREE_TYPE (instance);
    8362                 :             :         }
    8363                 :       62620 :       return RECUR (TREE_OPERAND (instance, 0));
    8364                 :             : 
    8365                 :         198 :     case POINTER_PLUS_EXPR:
    8366                 :         198 :     case PLUS_EXPR:
    8367                 :         198 :     case MINUS_EXPR:
    8368                 :         198 :       if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
    8369                 :          24 :         return RECUR (TREE_OPERAND (instance, 0));
    8370                 :         174 :       if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
    8371                 :             :         /* Propagate nonnull.  */
    8372                 :           0 :         return RECUR (TREE_OPERAND (instance, 0));
    8373                 :             : 
    8374                 :             :       return NULL_TREE;
    8375                 :             : 
    8376                 :     2402223 :     CASE_CONVERT:
    8377                 :     2402223 :       return RECUR (TREE_OPERAND (instance, 0));
    8378                 :             : 
    8379                 :     1074771 :     case ADDR_EXPR:
    8380                 :     1074771 :       instance = TREE_OPERAND (instance, 0);
    8381                 :     1074771 :       if (nonnull)
    8382                 :             :         {
    8383                 :             :           /* Just because we see an ADDR_EXPR doesn't mean we're dealing
    8384                 :             :              with a real object -- given &p->f, p can still be null.  */
    8385                 :     1073480 :           tree t = get_base_address (instance);
    8386                 :             :           /* ??? Probably should check DECL_WEAK here.  */
    8387                 :     1073480 :           if (t && DECL_P (t))
    8388                 :       76498 :             *nonnull = 1;
    8389                 :             :         }
    8390                 :     1074771 :       return RECUR (instance);
    8391                 :             : 
    8392                 :      747974 :     case COMPONENT_REF:
    8393                 :             :       /* If this component is really a base class reference, then the field
    8394                 :             :          itself isn't definitive.  */
    8395                 :      747974 :       if (DECL_FIELD_IS_BASE (TREE_OPERAND (instance, 1)))
    8396                 :         988 :         return RECUR (TREE_OPERAND (instance, 0));
    8397                 :      746986 :       return RECUR (TREE_OPERAND (instance, 1));
    8398                 :             : 
    8399                 :      857362 :     case VAR_DECL:
    8400                 :      857362 :     case FIELD_DECL:
    8401                 :      857362 :       if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
    8402                 :      857362 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
    8403                 :             :         {
    8404                 :           6 :           if (nonnull)
    8405                 :           6 :             *nonnull = 1;
    8406                 :           6 :           return TREE_TYPE (TREE_TYPE (instance));
    8407                 :             :         }
    8408                 :             :       /* fall through.  */
    8409                 :     5281484 :     case TARGET_EXPR:
    8410                 :     5281484 :     case PARM_DECL:
    8411                 :     5281484 :     case RESULT_DECL:
    8412                 :     5281484 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (instance)))
    8413                 :             :         {
    8414                 :     1074597 :           if (nonnull)
    8415                 :     1073377 :             *nonnull = 1;
    8416                 :     1074597 :           return TREE_TYPE (instance);
    8417                 :             :         }
    8418                 :     4206887 :       else if (instance == current_class_ptr)
    8419                 :             :         {
    8420                 :     3535088 :           if (nonnull)
    8421                 :     2801436 :             *nonnull = 1;
    8422                 :             : 
    8423                 :             :           /* if we're in a ctor or dtor, we know our type.  If
    8424                 :             :              current_class_ptr is set but we aren't in a function, we're in
    8425                 :             :              an NSDMI (and therefore a constructor).  */
    8426                 :     3535088 :           if (current_scope () != current_function_decl
    8427                 :     3535088 :               || (DECL_LANG_SPECIFIC (current_function_decl)
    8428                 :     7070008 :                   && (DECL_CONSTRUCTOR_P (current_function_decl)
    8429                 :     1419276 :                       || DECL_DESTRUCTOR_P (current_function_decl))))
    8430                 :             :             {
    8431                 :     2162152 :               if (cdtorp)
    8432                 :     2162152 :                 *cdtorp = 1;
    8433                 :     2162152 :               return TREE_TYPE (TREE_TYPE (instance));
    8434                 :             :             }
    8435                 :             :         }
    8436                 :      671799 :       else if (TYPE_REF_P (TREE_TYPE (instance)))
    8437                 :             :         {
    8438                 :             :           /* We only need one hash table because it is always left empty.  */
    8439                 :      590920 :           if (!fixed_type_or_null_ref_ht)
    8440                 :       12873 :             fixed_type_or_null_ref_ht
    8441                 :       12873 :               = new hash_table<nofree_ptr_hash<tree_node> > (37);
    8442                 :             : 
    8443                 :             :           /* Reference variables should be references to objects.  */
    8444                 :      590920 :           if (nonnull)
    8445                 :      588837 :             *nonnull = 1;
    8446                 :             : 
    8447                 :             :           /* Enter the INSTANCE in a table to prevent recursion; a
    8448                 :             :              variable's initializer may refer to the variable
    8449                 :             :              itself.  */
    8450                 :      590920 :           if (VAR_P (instance)
    8451                 :       15248 :               && DECL_INITIAL (instance)
    8452                 :        1746 :               && !type_dependent_expression_p_push (DECL_INITIAL (instance))
    8453                 :      592666 :               && !fixed_type_or_null_ref_ht->find (instance))
    8454                 :             :             {
    8455                 :        1690 :               tree type;
    8456                 :        1690 :               tree_node **slot;
    8457                 :             : 
    8458                 :        1690 :               slot = fixed_type_or_null_ref_ht->find_slot (instance, INSERT);
    8459                 :        1690 :               *slot = instance;
    8460                 :        1690 :               type = RECUR (DECL_INITIAL (instance));
    8461                 :        1690 :               fixed_type_or_null_ref_ht->remove_elt (instance);
    8462                 :             : 
    8463                 :        1690 :               return type;
    8464                 :             :             }
    8465                 :             :         }
    8466                 :             :       return NULL_TREE;
    8467                 :             : 
    8468                 :       51811 :     case VIEW_CONVERT_EXPR:
    8469                 :       51811 :       if (location_wrapper_p (instance))
    8470                 :       51811 :         return RECUR (TREE_OPERAND (instance, 0));
    8471                 :             :       else
    8472                 :             :         /* TODO: Recursion may be correct for some non-location-wrapper
    8473                 :             :            uses of VIEW_CONVERT_EXPR.  */
    8474                 :             :         return NULL_TREE;
    8475                 :             : 
    8476                 :             :     default:
    8477                 :             :       return NULL_TREE;
    8478                 :             :     }
    8479                 :             : #undef RECUR
    8480                 :             : }
    8481                 :             : 
    8482                 :             : /* Return nonzero if the dynamic type of INSTANCE is known, and
    8483                 :             :    equivalent to the static type.  We also handle the case where
    8484                 :             :    INSTANCE is really a pointer. Return negative if this is a
    8485                 :             :    ctor/dtor. There the dynamic type is known, but this might not be
    8486                 :             :    the most derived base of the original object, and hence virtual
    8487                 :             :    bases may not be laid out according to this type.
    8488                 :             : 
    8489                 :             :    Used to determine whether the virtual function table is needed
    8490                 :             :    or not.
    8491                 :             : 
    8492                 :             :    *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
    8493                 :             :    of our knowledge of its type.  *NONNULL should be initialized
    8494                 :             :    before this function is called.  */
    8495                 :             : 
    8496                 :             : int
    8497                 :     5628041 : resolves_to_fixed_type_p (tree instance, int* nonnull)
    8498                 :             : {
    8499                 :     5628041 :   tree t = TREE_TYPE (instance);
    8500                 :     5628041 :   int cdtorp = 0;
    8501                 :     5628041 :   tree fixed;
    8502                 :             : 
    8503                 :             :   /* processing_template_decl can be false in a template if we're in
    8504                 :             :      instantiate_non_dependent_expr, but we still want to suppress
    8505                 :             :      this check.  */
    8506                 :     5628041 :   if (in_template_context)
    8507                 :             :     {
    8508                 :             :       /* In a template we only care about the type of the result.  */
    8509                 :      357412 :       if (nonnull)
    8510                 :      357410 :         *nonnull = true;
    8511                 :      357412 :       return true;
    8512                 :             :     }
    8513                 :             : 
    8514                 :     5270629 :   fixed = fixed_type_or_null (instance, nonnull, &cdtorp);
    8515                 :     5270629 :   if (INDIRECT_TYPE_P (t))
    8516                 :     5269703 :     t = TREE_TYPE (t);
    8517                 :     5270629 :   if (CLASS_TYPE_P (t) && CLASSTYPE_FINAL (t))
    8518                 :             :     return 1;
    8519                 :     5200223 :   if (fixed == NULL_TREE)
    8520                 :             :     return 0;
    8521                 :     3196867 :   if (!same_type_ignoring_top_level_qualifiers_p (t, fixed))
    8522                 :             :     return 0;
    8523                 :     3196521 :   return cdtorp ? -1 : 1;
    8524                 :             : }
    8525                 :             : 
    8526                 :             : 
    8527                 :             : void
    8528                 :       95036 : init_class_processing (void)
    8529                 :             : {
    8530                 :       95036 :   current_class_depth = 0;
    8531                 :       95036 :   current_class_stack_size = 10;
    8532                 :       95036 :   current_class_stack
    8533                 :       95036 :     = XNEWVEC (struct class_stack_node, current_class_stack_size);
    8534                 :       95036 :   sizeof_biggest_empty_class = size_zero_node;
    8535                 :             : 
    8536                 :       95036 :   ridpointers[(int) RID_PUBLIC] = access_public_node;
    8537                 :       95036 :   ridpointers[(int) RID_PRIVATE] = access_private_node;
    8538                 :       95036 :   ridpointers[(int) RID_PROTECTED] = access_protected_node;
    8539                 :       95036 : }
    8540                 :             : 
    8541                 :             : /* Restore the cached PREVIOUS_CLASS_LEVEL.  */
    8542                 :             : 
    8543                 :             : static void
    8544                 :   176275257 : restore_class_cache (void)
    8545                 :             : {
    8546                 :   176275257 :   tree type;
    8547                 :             : 
    8548                 :             :   /* We are re-entering the same class we just left, so we don't
    8549                 :             :      have to search the whole inheritance matrix to find all the
    8550                 :             :      decls to bind again.  Instead, we install the cached
    8551                 :             :      class_shadowed list and walk through it binding names.  */
    8552                 :   176275257 :   push_binding_level (previous_class_level);
    8553                 :   176275257 :   class_binding_level = previous_class_level;
    8554                 :             :   /* Restore IDENTIFIER_TYPE_VALUE.  */
    8555                 :   176275257 :   for (type = class_binding_level->type_shadowed;
    8556                 :   967062629 :        type;
    8557                 :   790787372 :        type = TREE_CHAIN (type))
    8558                 :   790787372 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (type), TREE_TYPE (type));
    8559                 :   176275257 : }
    8560                 :             : 
    8561                 :             : /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE as
    8562                 :             :    appropriate for TYPE.
    8563                 :             : 
    8564                 :             :    So that we may avoid calls to lookup_name, we cache the _TYPE
    8565                 :             :    nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
    8566                 :             : 
    8567                 :             :    For multiple inheritance, we perform a two-pass depth-first search
    8568                 :             :    of the type lattice.  */
    8569                 :             : 
    8570                 :             : void
    8571                 :   360141579 : pushclass (tree type)
    8572                 :             : {
    8573                 :   360141579 :   class_stack_node_t csn;
    8574                 :             : 
    8575                 :   360141579 :   type = TYPE_MAIN_VARIANT (type);
    8576                 :             : 
    8577                 :             :   /* Make sure there is enough room for the new entry on the stack.  */
    8578                 :   360141579 :   if (current_class_depth + 1 >= current_class_stack_size)
    8579                 :             :     {
    8580                 :        3916 :       current_class_stack_size *= 2;
    8581                 :        3916 :       current_class_stack
    8582                 :        3916 :         = XRESIZEVEC (struct class_stack_node, current_class_stack,
    8583                 :             :                       current_class_stack_size);
    8584                 :             :     }
    8585                 :             : 
    8586                 :             :   /* Insert a new entry on the class stack.  */
    8587                 :   360141579 :   csn = current_class_stack + current_class_depth;
    8588                 :   360141579 :   csn->name = current_class_name;
    8589                 :   360141579 :   csn->type = current_class_type;
    8590                 :   360141579 :   csn->access = current_access_specifier;
    8591                 :   360141579 :   csn->names_used = 0;
    8592                 :   360141579 :   csn->hidden = 0;
    8593                 :   360141579 :   current_class_depth++;
    8594                 :             : 
    8595                 :             :   /* Now set up the new type.  */
    8596                 :   360141579 :   current_class_name = TYPE_NAME (type);
    8597                 :   360141579 :   if (TREE_CODE (current_class_name) == TYPE_DECL)
    8598                 :   360141579 :     current_class_name = DECL_NAME (current_class_name);
    8599                 :   360141579 :   current_class_type = type;
    8600                 :             : 
    8601                 :             :   /* By default, things in classes are private, while things in
    8602                 :             :      structures or unions are public.  */
    8603                 :   360141579 :   current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
    8604                 :   360141579 :                               ? access_private_node
    8605                 :             :                               : access_public_node);
    8606                 :             : 
    8607                 :   360141579 :   if (previous_class_level
    8608                 :   232693993 :       && type != previous_class_level->this_entity
    8609                 :    52310443 :       && current_class_depth == 1)
    8610                 :             :     {
    8611                 :             :       /* Forcibly remove any old class remnants.  */
    8612                 :    24675176 :       invalidate_class_lookup_cache ();
    8613                 :             :     }
    8614                 :             : 
    8615                 :   360141579 :   if (!previous_class_level
    8616                 :   208018817 :       || type != previous_class_level->this_entity
    8617                 :   180383550 :       || current_class_depth > 1)
    8618                 :   183866322 :     pushlevel_class ();
    8619                 :             :   else
    8620                 :   176275257 :     restore_class_cache ();
    8621                 :   360141579 : }
    8622                 :             : 
    8623                 :             : /* Get out of the current class scope. If we were in a class scope
    8624                 :             :    previously, that is the one popped to.  */
    8625                 :             : 
    8626                 :             : void
    8627                 :   360125316 : popclass (void)
    8628                 :             : {
    8629                 :   360125316 :   poplevel_class ();
    8630                 :             : 
    8631                 :   360125313 :   current_class_depth--;
    8632                 :   360125313 :   current_class_name = current_class_stack[current_class_depth].name;
    8633                 :   360125313 :   current_class_type = current_class_stack[current_class_depth].type;
    8634                 :   360125313 :   current_access_specifier = current_class_stack[current_class_depth].access;
    8635                 :   360125313 :   if (current_class_stack[current_class_depth].names_used)
    8636                 :    14064162 :     splay_tree_delete (current_class_stack[current_class_depth].names_used);
    8637                 :   360125313 : }
    8638                 :             : 
    8639                 :             : /* Mark the top of the class stack as hidden.  */
    8640                 :             : 
    8641                 :             : void
    8642                 :   355533850 : push_class_stack (void)
    8643                 :             : {
    8644                 :   355533850 :   if (current_class_depth)
    8645                 :   245305778 :     ++current_class_stack[current_class_depth - 1].hidden;
    8646                 :   355533850 : }
    8647                 :             : 
    8648                 :             : /* Mark the top of the class stack as un-hidden.  */
    8649                 :             : 
    8650                 :             : void
    8651                 :   355411724 : pop_class_stack (void)
    8652                 :             : {
    8653                 :   355411724 :   if (current_class_depth)
    8654                 :   245292242 :     --current_class_stack[current_class_depth - 1].hidden;
    8655                 :   355411724 : }
    8656                 :             : 
    8657                 :             : /* If the class type currently being defined is either T or
    8658                 :             :    a nested type of T, returns the type from the current_class_stack,
    8659                 :             :    which might be equivalent to but not equal to T in case of
    8660                 :             :    constrained partial specializations.  */
    8661                 :             : 
    8662                 :             : tree
    8663                 :  4370676949 : currently_open_class (tree t)
    8664                 :             : {
    8665                 :  4370676949 :   int i;
    8666                 :             : 
    8667                 :  4370676949 :   if (!CLASS_TYPE_P (t))
    8668                 :             :     return NULL_TREE;
    8669                 :             : 
    8670                 :  4209467966 :   t = TYPE_MAIN_VARIANT (t);
    8671                 :             : 
    8672                 :             :   /* We start looking from 1 because entry 0 is from global scope,
    8673                 :             :      and has no type.  */
    8674                 :  5203496420 :   for (i = current_class_depth; i > 0; --i)
    8675                 :             :     {
    8676                 :  4356923215 :       tree c;
    8677                 :  4356923215 :       if (i == current_class_depth)
    8678                 :  3871438136 :         c = current_class_type;
    8679                 :             :       else
    8680                 :             :         {
    8681                 :   485485079 :           if (current_class_stack[i].hidden)
    8682                 :             :             break;
    8683                 :   362017772 :           c = current_class_stack[i].type;
    8684                 :             :         }
    8685                 :  4233455908 :       if (!c)
    8686                 :   254132851 :         continue;
    8687                 :  3979323057 :       if (same_type_p (c, t))
    8688                 :             :         return c;
    8689                 :             :     }
    8690                 :             :   return NULL_TREE;
    8691                 :             : }
    8692                 :             : 
    8693                 :             : /* If either current_class_type or one of its enclosing classes are derived
    8694                 :             :    from T, return the appropriate type.  Used to determine how we found
    8695                 :             :    something via unqualified lookup.  */
    8696                 :             : 
    8697                 :             : tree
    8698                 :   122021979 : currently_open_derived_class (tree t)
    8699                 :             : {
    8700                 :   122021979 :   int i;
    8701                 :             : 
    8702                 :             :   /* The bases of a dependent type are unknown.  */
    8703                 :   122021979 :   if (dependent_type_p (t))
    8704                 :             :     return NULL_TREE;
    8705                 :             : 
    8706                 :   117661093 :   if (!current_class_type)
    8707                 :             :     return NULL_TREE;
    8708                 :             : 
    8709                 :   117483438 :   if (DERIVED_FROM_P (t, current_class_type))
    8710                 :   113158904 :     return current_class_type;
    8711                 :             : 
    8712                 :     4722725 :   for (i = current_class_depth - 1; i > 0; --i)
    8713                 :             :     {
    8714                 :     3079833 :       if (current_class_stack[i].hidden)
    8715                 :             :         break;
    8716                 :     3079833 :       if (DERIVED_FROM_P (t, current_class_stack[i].type))
    8717                 :     2681642 :         return current_class_stack[i].type;
    8718                 :             :     }
    8719                 :             : 
    8720                 :             :   return NULL_TREE;
    8721                 :             : }
    8722                 :             : 
    8723                 :             : /* Return the outermost enclosing class type that is still open, or
    8724                 :             :    NULL_TREE.  */
    8725                 :             : 
    8726                 :             : tree
    8727                 :          13 : outermost_open_class (void)
    8728                 :             : {
    8729                 :          13 :   if (!current_class_type)
    8730                 :             :     return NULL_TREE;
    8731                 :          13 :   tree r = NULL_TREE;
    8732                 :          13 :   if (TYPE_BEING_DEFINED (current_class_type))
    8733                 :          13 :     r = current_class_type;
    8734                 :          13 :   for (int i = current_class_depth - 1; i > 0; --i)
    8735                 :             :     {
    8736                 :           0 :       if (current_class_stack[i].hidden)
    8737                 :             :         break;
    8738                 :           0 :       tree t = current_class_stack[i].type;
    8739                 :           0 :       if (!TYPE_BEING_DEFINED (t))
    8740                 :             :         break;
    8741                 :           0 :       r = t;
    8742                 :             :     }
    8743                 :             :   return r;
    8744                 :             : }
    8745                 :             : 
    8746                 :             : /* Returns the innermost class type which is not a lambda closure type.  */
    8747                 :             : 
    8748                 :             : tree
    8749                 :  1099052059 : current_nonlambda_class_type (void)
    8750                 :             : {
    8751                 :  1099052059 :   tree type = current_class_type;
    8752                 :  1974810167 :   while (type && LAMBDA_TYPE_P (type))
    8753                 :     2571989 :     type = decl_type_context (TYPE_NAME (type));
    8754                 :  1099052059 :   return type;
    8755                 :             : }
    8756                 :             : 
    8757                 :             : /* When entering a class scope, all enclosing class scopes' names with
    8758                 :             :    static meaning (static variables, static functions, types and
    8759                 :             :    enumerators) have to be visible.  This recursive function calls
    8760                 :             :    pushclass for all enclosing class contexts until global or a local
    8761                 :             :    scope is reached.  TYPE is the enclosed class.  */
    8762                 :             : 
    8763                 :             : void
    8764                 :   583396985 : push_nested_class (tree type)
    8765                 :             : {
    8766                 :             :   /* A namespace might be passed in error cases, like A::B:C.  */
    8767                 :   583396985 :   if (type == NULL_TREE
    8768                 :   583396985 :       || !CLASS_TYPE_P (type))
    8769                 :             :     return;
    8770                 :             : 
    8771                 :   299876044 :   push_nested_class (DECL_CONTEXT (TYPE_MAIN_DECL (type)));
    8772                 :             : 
    8773                 :   299876044 :   pushclass (type);
    8774                 :             : }
    8775                 :             : 
    8776                 :             : /* Undoes a push_nested_class call.  */
    8777                 :             : 
    8778                 :             : void
    8779                 :   283507393 : pop_nested_class (void)
    8780                 :             : {
    8781                 :   299859796 :   tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
    8782                 :             : 
    8783                 :   299859796 :   popclass ();
    8784                 :   299859796 :   if (context && CLASS_TYPE_P (context))
    8785                 :             :     pop_nested_class ();
    8786                 :   283507393 : }
    8787                 :             : 
    8788                 :             : /* Returns the number of extern "LANG" blocks we are nested within.  */
    8789                 :             : 
    8790                 :             : int
    8791                 :       36005 : current_lang_depth (void)
    8792                 :             : {
    8793                 :       36005 :   return vec_safe_length (current_lang_base);
    8794                 :             : }
    8795                 :             : 
    8796                 :             : /* Set global variables CURRENT_LANG_NAME to appropriate value
    8797                 :             :    so that behavior of name-mangling machinery is correct.  */
    8798                 :             : 
    8799                 :             : void
    8800                 :     1161925 : push_lang_context (tree name)
    8801                 :             : {
    8802                 :     1161925 :   vec_safe_push (current_lang_base, current_lang_name);
    8803                 :             : 
    8804                 :     1161925 :   if (name == lang_name_cplusplus)
    8805                 :      603855 :     current_lang_name = name;
    8806                 :      558070 :   else if (name == lang_name_c)
    8807                 :      558070 :     current_lang_name = name;
    8808                 :             :   else
    8809                 :           0 :     error ("language string %<\"%E\"%> not recognized", name);
    8810                 :     1161925 : }
    8811                 :             : 
    8812                 :             : /* Get out of the current language scope.  */
    8813                 :             : 
    8814                 :             : void
    8815                 :     1161925 : pop_lang_context (void)
    8816                 :             : {
    8817                 :     1161925 :   current_lang_name = current_lang_base->pop ();
    8818                 :     1161925 : }
    8819                 :             : 
    8820                 :             : /* Type instantiation routines.  */
    8821                 :             : 
    8822                 :             : /* Given an OVERLOAD and a TARGET_TYPE, return the function that
    8823                 :             :    matches the TARGET_TYPE.  If there is no satisfactory match, return
    8824                 :             :    error_mark_node, and issue an error & warning messages under
    8825                 :             :    control of FLAGS.  Permit pointers to member function if FLAGS
    8826                 :             :    permits.  If TEMPLATE_ONLY, the name of the overloaded function was
    8827                 :             :    a template-id, and EXPLICIT_TARGS are the explicitly provided
    8828                 :             :    template arguments.
    8829                 :             : 
    8830                 :             :    If OVERLOAD is for one or more member functions, then ACCESS_PATH
    8831                 :             :    is the base path used to reference those member functions.  If
    8832                 :             :    the address is resolved to a member function, access checks will be
    8833                 :             :    performed and errors issued if appropriate.  */
    8834                 :             : 
    8835                 :             : static tree
    8836                 :      302616 : resolve_address_of_overloaded_function (tree target_type,
    8837                 :             :                                         tree overload,
    8838                 :             :                                         tsubst_flags_t complain,
    8839                 :             :                                         bool template_only,
    8840                 :             :                                         tree explicit_targs,
    8841                 :             :                                         tree access_path)
    8842                 :             : {
    8843                 :             :   /* Here's what the standard says:
    8844                 :             : 
    8845                 :             :        [over.over]
    8846                 :             : 
    8847                 :             :        If the name is a function template, template argument deduction
    8848                 :             :        is done, and if the argument deduction succeeds, the deduced
    8849                 :             :        arguments are used to generate a single template function, which
    8850                 :             :        is added to the set of overloaded functions considered.
    8851                 :             : 
    8852                 :             :        Non-member functions and static member functions match targets of
    8853                 :             :        type "pointer-to-function" or "reference-to-function."  Nonstatic
    8854                 :             :        member functions match targets of type "pointer-to-member
    8855                 :             :        function;" the function type of the pointer to member is used to
    8856                 :             :        select the member function from the set of overloaded member
    8857                 :             :        functions.  If a non-static member function is selected, the
    8858                 :             :        reference to the overloaded function name is required to have the
    8859                 :             :        form of a pointer to member as described in 5.3.1.
    8860                 :             : 
    8861                 :             :        If more than one function is selected, any template functions in
    8862                 :             :        the set are eliminated if the set also contains a non-template
    8863                 :             :        function, and any given template function is eliminated if the
    8864                 :             :        set contains a second template function that is more specialized
    8865                 :             :        than the first according to the partial ordering rules 14.5.5.2.
    8866                 :             :        After such eliminations, if any, there shall remain exactly one
    8867                 :             :        selected function.  */
    8868                 :             : 
    8869                 :      302616 :   int is_ptrmem = 0;
    8870                 :             :   /* We store the matches in a TREE_LIST rooted here.  The functions
    8871                 :             :      are the TREE_PURPOSE, not the TREE_VALUE, in this list, for easy
    8872                 :             :      interoperability with most_specialized_instantiation.  */
    8873                 :      302616 :   tree matches = NULL_TREE;
    8874                 :      302616 :   tree fn;
    8875                 :      302616 :   tree target_fn_type;
    8876                 :             : 
    8877                 :             :   /* By the time we get here, we should be seeing only real
    8878                 :             :      pointer-to-member types, not the internal POINTER_TYPE to
    8879                 :             :      METHOD_TYPE representation.  */
    8880                 :      302616 :   gcc_assert (!TYPE_PTR_P (target_type)
    8881                 :             :               || TREE_CODE (TREE_TYPE (target_type)) != METHOD_TYPE);
    8882                 :             : 
    8883                 :      302616 :   gcc_assert (is_overloaded_fn (overload));
    8884                 :             : 
    8885                 :             :   /* Check that the TARGET_TYPE is reasonable.  */
    8886                 :       45831 :   if (TYPE_PTRFN_P (target_type)
    8887                 :      302620 :       || TYPE_REFFN_P (target_type))
    8888                 :             :     /* This is OK.  */;
    8889                 :      256787 :   else if (TYPE_PTRMEMFUNC_P (target_type))
    8890                 :             :     /* This is OK, too.  */
    8891                 :             :     is_ptrmem = 1;
    8892                 :      255529 :   else if (TREE_CODE (target_type) == FUNCTION_TYPE)
    8893                 :             :     /* This is OK, too.  This comes from a conversion to reference
    8894                 :             :        type.  */
    8895                 :      255483 :     target_type = build_reference_type (target_type);
    8896                 :             :   else
    8897                 :             :     {
    8898                 :          46 :       if (complain & tf_error)
    8899                 :          37 :         error ("cannot resolve overloaded function %qD based on"
    8900                 :             :                " conversion to type %qT",
    8901                 :          37 :                OVL_NAME (overload), target_type);
    8902                 :          46 :       return error_mark_node;
    8903                 :             :     }
    8904                 :             : 
    8905                 :             :   /* Non-member functions and static member functions match targets of type
    8906                 :             :      "pointer-to-function" or "reference-to-function."  Nonstatic member
    8907                 :             :      functions match targets of type "pointer-to-member-function;" the
    8908                 :             :      function type of the pointer to member is used to select the member
    8909                 :             :      function from the set of overloaded member functions.
    8910                 :             : 
    8911                 :             :      So figure out the FUNCTION_TYPE that we want to match against.  */
    8912                 :      302570 :   target_fn_type = static_fn_type (target_type);
    8913                 :             : 
    8914                 :             :   /* If we can find a non-template function that matches, we can just
    8915                 :             :      use it.  There's no point in generating template instantiations
    8916                 :             :      if we're just going to throw them out anyhow.  But, of course, we
    8917                 :             :      can only do this when we don't *need* a template function.  */
    8918                 :      302570 :   if (!template_only)
    8919                 :     2086858 :     for (lkp_iterator iter (overload); iter; ++iter)
    8920                 :             :       {
    8921                 :     1810048 :         tree fn = *iter;
    8922                 :             : 
    8923                 :     1810048 :         if (TREE_CODE (fn) == TEMPLATE_DECL)
    8924                 :             :           /* We're not looking for templates just yet.  */
    8925                 :       20155 :           continue;
    8926                 :             : 
    8927                 :     1789893 :         if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE) != is_ptrmem)
    8928                 :             :           /* We're looking for a non-static member, and this isn't
    8929                 :             :              one, or vice versa.  */
    8930                 :         580 :           continue;
    8931                 :             : 
    8932                 :             :         /* Constraints must be satisfied. This is done before
    8933                 :             :            return type deduction since that instantiates the
    8934                 :             :            function. */
    8935                 :     1789313 :         if (!constraints_satisfied_p (fn))
    8936                 :          27 :           continue;
    8937                 :             : 
    8938                 :     1789286 :         if (undeduced_auto_decl (fn))
    8939                 :             :           {
    8940                 :             :             /* Force instantiation to do return type deduction.  */
    8941                 :          18 :             maybe_instantiate_decl (fn);
    8942                 :          18 :             require_deduced_type (fn);
    8943                 :             :           }
    8944                 :             : 
    8945                 :             :         /* In C++17 we need the noexcept-qualifier to compare types.  */
    8946                 :     1789286 :         if (flag_noexcept_type
    8947                 :     1789286 :             && !maybe_instantiate_noexcept (fn, complain))
    8948                 :           0 :           continue;
    8949                 :             : 
    8950                 :             :         /* See if there's a match.  */
    8951                 :     1789286 :         tree fntype = static_fn_type (fn);
    8952                 :     1789286 :         if (same_type_p (target_fn_type, fntype)
    8953                 :     1789286 :             || fnptr_conv_p (target_fn_type, fntype))
    8954                 :      257315 :           matches = tree_cons (fn, NULL_TREE, matches);
    8955                 :             :       }
    8956                 :             : 
    8957                 :             :   /* Now, if we've already got a match (or matches), there's no need
    8958                 :             :      to proceed to the template functions.  But, if we don't have a
    8959                 :             :      match we need to look at them, too.  */
    8960                 :      276810 :   if (!matches)
    8961                 :             :     {
    8962                 :       45828 :       tree target_arg_types;
    8963                 :       45828 :       tree target_ret_type;
    8964                 :       45828 :       tree *args;
    8965                 :       45828 :       unsigned int nargs, ia;
    8966                 :       45828 :       tree arg;
    8967                 :             : 
    8968                 :       45828 :       target_arg_types = TYPE_ARG_TYPES (target_fn_type);
    8969                 :       45828 :       target_ret_type = TREE_TYPE (target_fn_type);
    8970                 :             : 
    8971                 :       45828 :       nargs = list_length (target_arg_types);
    8972                 :       45828 :       args = XALLOCAVEC (tree, nargs);
    8973                 :       45828 :       for (arg = target_arg_types, ia = 0;
    8974                 :      146030 :            arg != NULL_TREE;
    8975                 :      100202 :            arg = TREE_CHAIN (arg), ++ia)
    8976                 :      100202 :         args[ia] = TREE_VALUE (arg);
    8977                 :       45828 :       nargs = ia;
    8978                 :             : 
    8979                 :       94548 :       for (lkp_iterator iter (overload); iter; ++iter)
    8980                 :             :         {
    8981                 :       48720 :           tree fn = *iter;
    8982                 :       48720 :           tree instantiation;
    8983                 :       48720 :           tree targs;
    8984                 :             : 
    8985                 :       48720 :           if (TREE_CODE (fn) != TEMPLATE_DECL)
    8986                 :             :             /* We're only looking for templates.  */
    8987                 :        3052 :             continue;
    8988                 :             : 
    8989                 :       45668 :           if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
    8990                 :             :               != is_ptrmem)
    8991                 :             :             /* We're not looking for a non-static member, and this is
    8992                 :             :                one, or vice versa.  */
    8993                 :          12 :             continue;
    8994                 :             : 
    8995                 :       45656 :           tree ret = target_ret_type;
    8996                 :             : 
    8997                 :             :           /* If the template has a deduced return type, don't expose it to
    8998                 :             :              template argument deduction.  */
    8999                 :       45656 :           if (undeduced_auto_decl (fn))
    9000                 :         230 :             ret = NULL_TREE;
    9001                 :             : 
    9002                 :             :           /* Try to do argument deduction.  */
    9003                 :       45656 :           targs = make_tree_vec (DECL_NTPARMS (fn));
    9004                 :       45656 :           instantiation = fn_type_unification (fn, explicit_targs, targs, args,
    9005                 :             :                                                nargs, ret,
    9006                 :             :                                               DEDUCE_EXACT, LOOKUP_NORMAL,
    9007                 :             :                                                NULL, false, false);
    9008                 :       45656 :           if (instantiation == error_mark_node)
    9009                 :             :             /* Instantiation failed.  */
    9010                 :        9652 :             continue;
    9011                 :             : 
    9012                 :             :           /* Constraints must be satisfied. This is done before
    9013                 :             :              return type deduction since that instantiates the
    9014                 :             :              function. */
    9015                 :       36004 :           if (flag_concepts && !constraints_satisfied_p (instantiation))
    9016                 :           0 :             continue;
    9017                 :             : 
    9018                 :             :           /* And now force instantiation to do return type deduction.  */
    9019                 :       36004 :           if (undeduced_auto_decl (instantiation))
    9020                 :             :             {
    9021                 :          68 :               ++function_depth;
    9022                 :          68 :               instantiate_decl (instantiation, /*defer*/false, /*class*/false);
    9023                 :          68 :               --function_depth;
    9024                 :             : 
    9025                 :          68 :               require_deduced_type (instantiation);
    9026                 :             :             }
    9027                 :             : 
    9028                 :             :           /* In C++17 we need the noexcept-qualifier to compare types.  */
    9029                 :       36004 :           if (flag_noexcept_type)
    9030                 :       35177 :             maybe_instantiate_noexcept (instantiation, complain);
    9031                 :             : 
    9032                 :             :           /* See if there's a match.  */
    9033                 :       36004 :           tree fntype = static_fn_type (instantiation);
    9034                 :       36004 :           if (same_type_p (target_fn_type, fntype)
    9035                 :       36004 :               || fnptr_conv_p (target_fn_type, fntype))
    9036                 :       35986 :             matches = tree_cons (instantiation, fn, matches);
    9037                 :             :         }
    9038                 :             : 
    9039                 :             :       /* Now, remove all but the most specialized of the matches.  */
    9040                 :       45828 :       if (matches)
    9041                 :             :         {
    9042                 :       35881 :           tree match = most_specialized_instantiation (matches);
    9043                 :             : 
    9044                 :       35881 :           if (match != error_mark_node)
    9045                 :             :             {
    9046                 :       35854 :               matches = match;
    9047                 :       35854 :               TREE_CHAIN (match) = NULL_TREE;
    9048                 :             :             }
    9049                 :             :         }
    9050                 :             :     }
    9051                 :      256742 :   else if (flag_concepts && TREE_CHAIN (matches))
    9052                 :          53 :     if (tree match = most_constrained_function (matches))
    9053                 :             :       {
    9054                 :           9 :         matches = match;
    9055                 :           9 :         TREE_CHAIN (match) = NULL_TREE;
    9056                 :             :       }
    9057                 :             : 
    9058                 :             :   /* Now we should have exactly one function in MATCHES.  */
    9059                 :      292623 :   if (matches == NULL_TREE)
    9060                 :             :     {
    9061                 :             :       /* There were *no* matches.  */
    9062                 :        9947 :       if (complain & tf_error)
    9063                 :             :         {
    9064                 :          92 :           auto_diagnostic_group d;
    9065                 :         184 :           error ("no matches converting function %qD to type %q#T",
    9066                 :          92 :                  OVL_NAME (overload), target_type);
    9067                 :             : 
    9068                 :          92 :           print_candidates (overload);
    9069                 :          92 :         }
    9070                 :        9947 :       return error_mark_node;
    9071                 :             :     }
    9072                 :      292623 :   else if (TREE_CHAIN (matches))
    9073                 :             :     {
    9074                 :             :       /* There were too many matches.  First check if they're all
    9075                 :             :          the same function.  */
    9076                 :         159 :       tree match = NULL_TREE;
    9077                 :             : 
    9078                 :         159 :       fn = TREE_PURPOSE (matches);
    9079                 :             : 
    9080                 :             :       /* For multi-versioned functions, more than one match is just fine and
    9081                 :             :          decls_match will return false as they are different.  */
    9082                 :         723 :       for (match = TREE_CHAIN (matches); match; match = TREE_CHAIN (match))
    9083                 :         591 :         if (!decls_match (fn, TREE_PURPOSE (match))
    9084                 :        1167 :             && !targetm.target_option.function_versions
    9085                 :         576 :                (fn, TREE_PURPOSE (match)))
    9086                 :             :           break;
    9087                 :             : 
    9088                 :         159 :       if (match)
    9089                 :             :         {
    9090                 :          27 :           if (complain & tf_error)
    9091                 :             :             {
    9092                 :           9 :               auto_diagnostic_group d;
    9093                 :           9 :               error ("converting overloaded function %qD to type %q#T is ambiguous",
    9094                 :           9 :                      OVL_NAME (overload), target_type);
    9095                 :             : 
    9096                 :             :               /* Since print_candidates expects the functions in the
    9097                 :             :                  TREE_VALUE slot, we flip them here.  */
    9098                 :          36 :               for (match = matches; match; match = TREE_CHAIN (match))
    9099                 :          18 :                 TREE_VALUE (match) = TREE_PURPOSE (match);
    9100                 :             : 
    9101                 :           9 :               print_candidates (matches);
    9102                 :           9 :             }
    9103                 :             : 
    9104                 :          27 :           return error_mark_node;
    9105                 :             :         }
    9106                 :             :     }
    9107                 :             : 
    9108                 :             :   /* Good, exactly one match.  Now, convert it to the correct type.  */
    9109                 :      292596 :   fn = TREE_PURPOSE (matches);
    9110                 :             : 
    9111                 :      584018 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (fn)
    9112                 :      292860 :       && !(complain & tf_ptrmem_ok))
    9113                 :             :     {
    9114                 :             :       /* Previously we allowed this behavior for iobj member functions when the
    9115                 :             :          -fms-extensions flag is passed as MSVC allows this as a language
    9116                 :             :          extension.  MSVC also allows this for xobj member functions, but the
    9117                 :             :          documentation for -fms-extensions states it's purpose is to support
    9118                 :             :          the use of microsoft headers.  Until otherwise demonstrated, we should
    9119                 :             :          assume xobj member functions are not used in this manner in microsoft
    9120                 :             :          headers and forbid the incorrect syntax instead of supporting it for
    9121                 :             :          non-legacy uses.  This should hopefully encourage conformance going
    9122                 :             :          forward.
    9123                 :             :          This comment is referred to in typeck.cc:cp_build_addr_expr_1.  */
    9124                 :         270 :       if (DECL_IOBJ_MEMBER_FUNCTION_P (fn) && flag_ms_extensions)
    9125                 :             :         /* Early escape.  */;
    9126                 :         249 :       else if (!(complain & tf_error))
    9127                 :         179 :         return error_mark_node;
    9128                 :          70 :       else if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    9129                 :             :         {
    9130                 :          34 :           auto_diagnostic_group d;
    9131                 :             :           /* Should match the error in typeck.cc:cp_build_addr_expr_1.
    9132                 :             :              We seem to lack the details here to match that diagnostic exactly,
    9133                 :             :              perhaps this could be fixed in the future? See PR113075 bug 2.  */
    9134                 :          34 :           error_at (input_location,
    9135                 :             :                     "ISO C++ forbids taking the address of an unqualified"
    9136                 :             :                     " or parenthesized non-static member function to form"
    9137                 :             :                     " a pointer to explicit object member function.");
    9138                 :             :           /* This is incorrect, see PR113075 bug 3.  */
    9139                 :          34 :           inform (input_location,
    9140                 :             :                   "a pointer to explicit object member function can only be "
    9141                 :             :                   "formed with %<&%E%>", fn);
    9142                 :          34 :         }
    9143                 :             :       else
    9144                 :             :         {
    9145                 :          36 :           static int explained;
    9146                 :          36 :           gcc_assert (DECL_IOBJ_MEMBER_FUNCTION_P (fn) && !flag_ms_extensions);
    9147                 :             :           /* Is there a reason this error message doesn't match the one in
    9148                 :             :              typeck.cc:cp_build_addr_expr_1?  */
    9149                 :          36 :           auto_diagnostic_group d;
    9150                 :          36 :           if (permerror (input_location, "assuming pointer to member %qD", fn)
    9151                 :          36 :               && !explained)
    9152                 :             :             {
    9153                 :          18 :               inform (input_location, "(a pointer to member can only be "
    9154                 :             :                                       "formed with %<&%E%>)", fn);
    9155                 :          18 :               explained = 1;
    9156                 :             :             }
    9157                 :          36 :         }
    9158                 :             :     }
    9159                 :             : 
    9160                 :             :   /* If a pointer to a function that is multi-versioned is requested, the
    9161                 :             :      pointer to the dispatcher function is returned instead.  This works
    9162                 :             :      well because indirectly calling the function will dispatch the right
    9163                 :             :      function version at run-time.  */
    9164                 :      292417 :   if (DECL_FUNCTION_VERSIONED (fn))
    9165                 :             :     {
    9166                 :         117 :       fn = get_function_version_dispatcher (fn);
    9167                 :         117 :       if (fn == NULL)
    9168                 :           9 :         return error_mark_node;
    9169                 :             :       /* Mark all the versions corresponding to the dispatcher as used.  */
    9170                 :         108 :       if (!(complain & tf_conv))
    9171                 :          36 :         mark_versions_used (fn);
    9172                 :             :     }
    9173                 :             : 
    9174                 :             :   /* If we're doing overload resolution purely for the purpose of
    9175                 :             :      determining conversion sequences, we should not consider the
    9176                 :             :      function used.  If this conversion sequence is selected, the
    9177                 :             :      function will be marked as used at this point.  */
    9178                 :      292336 :   if (!(complain & tf_conv))
    9179                 :             :     {
    9180                 :             :       /* Make =delete work with SFINAE.  */
    9181                 :      272447 :       if (DECL_DELETED_FN (fn) && !(complain & tf_error))
    9182                 :           0 :         return error_mark_node;
    9183                 :      272447 :       if (!mark_used (fn, complain) && !(complain & tf_error))
    9184                 :           0 :         return error_mark_node;
    9185                 :             :     }
    9186                 :             : 
    9187                 :             :   /* We could not check access to member functions when this
    9188                 :             :      expression was originally created since we did not know at that
    9189                 :             :      time to which function the expression referred.  */
    9190                 :      292408 :   if (DECL_FUNCTION_MEMBER_P (fn))
    9191                 :             :     {
    9192                 :        6904 :       gcc_assert (access_path);
    9193                 :        6904 :       perform_or_defer_access_check (access_path, fn, fn, complain);
    9194                 :             :     }
    9195                 :             : 
    9196                 :      292408 :   if (TYPE_PTRFN_P (target_type) || TYPE_PTRMEMFUNC_P (target_type))
    9197                 :       37523 :     return cp_build_addr_expr (fn, complain);
    9198                 :             :   else
    9199                 :             :     {
    9200                 :             :       /* The target must be a REFERENCE_TYPE.  Above, cp_build_unary_op
    9201                 :             :          will mark the function as addressed, but here we must do it
    9202                 :             :          explicitly.  */
    9203                 :      254885 :       cxx_mark_addressable (fn);
    9204                 :             : 
    9205                 :      254885 :       return fn;
    9206                 :             :     }
    9207                 :             : }
    9208                 :             : 
    9209                 :             : /* This function will instantiate the type of the expression given in
    9210                 :             :    RHS to match the type of LHSTYPE.  If errors exist, then return
    9211                 :             :    error_mark_node. COMPLAIN is a bit mask.  If TF_ERROR is set, then
    9212                 :             :    we complain on errors.  If we are not complaining, never modify rhs,
    9213                 :             :    as overload resolution wants to try many possible instantiations, in
    9214                 :             :    the hope that at least one will work.
    9215                 :             : 
    9216                 :             :    For non-recursive calls, LHSTYPE should be a function, pointer to
    9217                 :             :    function, or a pointer to member function.  */
    9218                 :             : 
    9219                 :             : tree
    9220                 :      304969 : instantiate_type (tree lhstype, tree rhs, tsubst_flags_t complain)
    9221                 :             : {
    9222                 :      310967 :   tsubst_flags_t complain_in = complain;
    9223                 :      310967 :   tree access_path = NULL_TREE;
    9224                 :             : 
    9225                 :      310967 :   complain &= ~tf_ptrmem_ok;
    9226                 :             : 
    9227                 :      310967 :   STRIP_ANY_LOCATION_WRAPPER (rhs);
    9228                 :             : 
    9229                 :      310967 :   if (lhstype == unknown_type_node)
    9230                 :             :     {
    9231                 :           0 :       if (complain & tf_error)
    9232                 :           0 :         error ("not enough type information");
    9233                 :           0 :       return error_mark_node;
    9234                 :             :     }
    9235                 :             : 
    9236                 :      310967 :   if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
    9237                 :             :     {
    9238                 :        1762 :       tree fntype = non_reference (lhstype);
    9239                 :        1762 :       if (same_type_p (fntype, TREE_TYPE (rhs)))
    9240                 :             :         return rhs;
    9241                 :         321 :       if (fnptr_conv_p (fntype, TREE_TYPE (rhs)))
    9242                 :             :         return rhs;
    9243                 :         318 :       if (flag_ms_extensions
    9244                 :          18 :           && TYPE_PTRMEMFUNC_P (fntype)
    9245                 :         336 :           && !TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs)))
    9246                 :             :         /* Microsoft allows `A::f' to be resolved to a
    9247                 :             :            pointer-to-member.  */
    9248                 :             :         ;
    9249                 :             :       else
    9250                 :             :         {
    9251                 :         300 :           if (complain & tf_error)
    9252                 :          43 :             error ("cannot convert %qE from type %qT to type %qT",
    9253                 :          43 :                    rhs, TREE_TYPE (rhs), fntype);
    9254                 :         300 :           return error_mark_node;
    9255                 :             :         }
    9256                 :             :     }
    9257                 :             : 
    9258                 :             :   /* If we instantiate a template, and it is a A ?: C expression
    9259                 :             :      with omitted B, look through the SAVE_EXPR.  */
    9260                 :      309223 :   if (TREE_CODE (rhs) == SAVE_EXPR)
    9261                 :           9 :     rhs = TREE_OPERAND (rhs, 0);
    9262                 :             : 
    9263                 :      309223 :   if (BASELINK_P (rhs))
    9264                 :             :     {
    9265                 :        7252 :       access_path = BASELINK_ACCESS_BINFO (rhs);
    9266                 :        7252 :       rhs = BASELINK_FUNCTIONS (rhs);
    9267                 :             :     }
    9268                 :             : 
    9269                 :             :   /* There are only a few kinds of expressions that may have a type
    9270                 :             :      dependent on overload resolution.  */
    9271                 :      309223 :   gcc_assert (TREE_CODE (rhs) == ADDR_EXPR
    9272                 :             :               || TREE_CODE (rhs) == COMPONENT_REF
    9273                 :             :               || is_overloaded_fn (rhs)
    9274                 :             :               || (flag_ms_extensions && TREE_CODE (rhs) == FUNCTION_DECL));
    9275                 :             : 
    9276                 :             :   /* This should really only be used when attempting to distinguish
    9277                 :             :      what sort of a pointer to function we have.  For now, any
    9278                 :             :      arithmetic operation which is not supported on pointers
    9279                 :             :      is rejected as an error.  */
    9280                 :             : 
    9281                 :      309223 :   switch (TREE_CODE (rhs))
    9282                 :             :     {
    9283                 :         609 :     case COMPONENT_REF:
    9284                 :         609 :       {
    9285                 :         609 :         tree member = TREE_OPERAND (rhs, 1);
    9286                 :             : 
    9287                 :         609 :         member = instantiate_type (lhstype, member, complain);
    9288                 :         609 :         if (member != error_mark_node
    9289                 :         609 :             && TREE_SIDE_EFFECTS (TREE_OPERAND (rhs, 0)))
    9290                 :             :           /* Do not lose object's side effects.  */
    9291                 :          27 :           return build2 (COMPOUND_EXPR, TREE_TYPE (member),
    9292                 :          54 :                          TREE_OPERAND (rhs, 0), member);
    9293                 :             :         return member;
    9294                 :             :       }
    9295                 :             : 
    9296                 :        1951 :     case OFFSET_REF:
    9297                 :        1951 :       rhs = TREE_OPERAND (rhs, 1);
    9298                 :        1951 :       if (BASELINK_P (rhs))
    9299                 :             :         return instantiate_type (lhstype, rhs, complain_in);
    9300                 :             : 
    9301                 :             :       /* This can happen if we are forming a pointer-to-member for a
    9302                 :             :          member template.  */
    9303                 :           0 :       gcc_assert (TREE_CODE (rhs) == TEMPLATE_ID_EXPR);
    9304                 :             : 
    9305                 :             :       /* Fall through.  */
    9306                 :             : 
    9307                 :       25772 :     case TEMPLATE_ID_EXPR:
    9308                 :       25772 :       {
    9309                 :       25772 :         tree fns = TREE_OPERAND (rhs, 0);
    9310                 :       25772 :         tree args = TREE_OPERAND (rhs, 1);
    9311                 :             : 
    9312                 :       25772 :         return
    9313                 :       25772 :           resolve_address_of_overloaded_function (lhstype, fns, complain_in,
    9314                 :             :                                                   /*template_only=*/true,
    9315                 :       25772 :                                                   args, access_path);
    9316                 :             :       }
    9317                 :             : 
    9318                 :      276844 :     case OVERLOAD:
    9319                 :      276844 :     case FUNCTION_DECL:
    9320                 :      276844 :       return
    9321                 :      276844 :         resolve_address_of_overloaded_function (lhstype, rhs, complain_in,
    9322                 :             :                                                 /*template_only=*/false,
    9323                 :             :                                                 /*explicit_targs=*/NULL_TREE,
    9324                 :      276844 :                                                 access_path);
    9325                 :             : 
    9326                 :        4047 :     case ADDR_EXPR:
    9327                 :        4047 :     {
    9328                 :        4047 :       if (PTRMEM_OK_P (rhs))
    9329                 :        1951 :         complain |= tf_ptrmem_ok;
    9330                 :             : 
    9331                 :        4047 :       return instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
    9332                 :             :     }
    9333                 :             : 
    9334                 :           0 :     case ERROR_MARK:
    9335                 :           0 :       return error_mark_node;
    9336                 :             : 
    9337                 :           0 :     default:
    9338                 :           0 :       gcc_unreachable ();
    9339                 :             :     }
    9340                 :             :   return error_mark_node;
    9341                 :             : }
    9342                 :             : 
    9343                 :             : /* Return the name of the virtual function pointer field
    9344                 :             :    (as an IDENTIFIER_NODE) for the given TYPE.  Note that
    9345                 :             :    this may have to look back through base types to find the
    9346                 :             :    ultimate field name.  (For single inheritance, these could
    9347                 :             :    all be the same name.  Who knows for multiple inheritance).  */
    9348                 :             : 
    9349                 :             : static tree
    9350                 :      239845 : get_vfield_name (tree type)
    9351                 :             : {
    9352                 :      239845 :   tree binfo, base_binfo;
    9353                 :             : 
    9354                 :      239845 :   for (binfo = TYPE_BINFO (type);
    9355                 :      239845 :        BINFO_N_BASE_BINFOS (binfo);
    9356                 :             :        binfo = base_binfo)
    9357                 :             :     {
    9358                 :       74337 :       base_binfo = BINFO_BASE_BINFO (binfo, 0);
    9359                 :             : 
    9360                 :      148674 :       if (BINFO_VIRTUAL_P (base_binfo)
    9361                 :       74337 :           || !TYPE_CONTAINS_VPTR_P (BINFO_TYPE (base_binfo)))
    9362                 :             :         break;
    9363                 :             :     }
    9364                 :             : 
    9365                 :      239845 :   type = BINFO_TYPE (binfo);
    9366                 :      239845 :   tree ctor_name = constructor_name (type);
    9367                 :      239845 :   char *buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
    9368                 :             :                                + IDENTIFIER_LENGTH (ctor_name) + 2);
    9369                 :      239845 :   sprintf (buf, VFIELD_NAME_FORMAT, IDENTIFIER_POINTER (ctor_name));
    9370                 :      239845 :   return get_identifier (buf);
    9371                 :             : }
    9372                 :             : 
    9373                 :             : /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
    9374                 :             :    according to [class]:
    9375                 :             :                                           The class-name is also inserted
    9376                 :             :    into  the scope of the class itself.  For purposes of access checking,
    9377                 :             :    the inserted class name is treated as if it were a public member name.  */
    9378                 :             : 
    9379                 :             : void
    9380                 :    25333454 : build_self_reference (void)
    9381                 :             : {
    9382                 :    25333454 :   tree name = DECL_NAME (TYPE_NAME (current_class_type));
    9383                 :    25333454 :   tree decl = build_lang_decl (TYPE_DECL, name, current_class_type);
    9384                 :             : 
    9385                 :    25333454 :   DECL_NONLOCAL (decl) = 1;
    9386                 :    25333454 :   DECL_CONTEXT (decl) = current_class_type;
    9387                 :    25333454 :   DECL_ARTIFICIAL (decl) = 1;
    9388                 :    25333454 :   SET_DECL_SELF_REFERENCE_P (decl);
    9389                 :    25333454 :   set_underlying_type (decl);
    9390                 :    25333454 :   set_instantiating_module (decl);
    9391                 :             : 
    9392                 :    25333454 :   if (processing_template_decl)
    9393                 :    16635259 :     decl = push_template_decl (decl);
    9394                 :             : 
    9395                 :    25333454 :   tree saved_cas = current_access_specifier;
    9396                 :    25333454 :   current_access_specifier = access_public_node;
    9397                 :    25333454 :   finish_member_declaration (decl);
    9398                 :    25333454 :   current_access_specifier = saved_cas;
    9399                 :    25333454 : }
    9400                 :             : 
    9401                 :             : /* Returns 1 if TYPE contains only padding bytes.  */
    9402                 :             : 
    9403                 :             : int
    9404                 :   504239691 : is_empty_class (tree type)
    9405                 :             : {
    9406                 :   504239691 :   if (type == error_mark_node)
    9407                 :             :     return 0;
    9408                 :             : 
    9409                 :   504239688 :   if (! CLASS_TYPE_P (type))
    9410                 :             :     return 0;
    9411                 :             : 
    9412                 :   297968208 :   return CLASSTYPE_EMPTY_P (type);
    9413                 :             : }
    9414                 :             : 
    9415                 :             : /* Returns true if TYPE contains no actual data, just various
    9416                 :             :    possible combinations of empty classes.  If IGNORE_VPTR is true,
    9417                 :             :    a vptr doesn't prevent the class from being considered empty.  Typically
    9418                 :             :    we want to ignore the vptr on assignment, and not on initialization.  */
    9419                 :             : 
    9420                 :             : bool
    9421                 :   330444481 : is_really_empty_class (tree type, bool ignore_vptr)
    9422                 :             : {
    9423                 :   330444481 :   if (CLASS_TYPE_P (type))
    9424                 :             :     {
    9425                 :    56716231 :       tree field;
    9426                 :    56716231 :       tree binfo;
    9427                 :    56716231 :       tree base_binfo;
    9428                 :    56716231 :       int i;
    9429                 :             : 
    9430                 :             :       /* CLASSTYPE_EMPTY_P isn't set properly until the class is actually laid
    9431                 :             :          out, but we'd like to be able to check this before then.  */
    9432                 :    56716231 :       if (COMPLETE_TYPE_P (type) && is_empty_class (type))
    9433                 :             :         return true;
    9434                 :             : 
    9435                 :    40153465 :       if (!ignore_vptr && TYPE_CONTAINS_VPTR_P (type))
    9436                 :             :         return false;
    9437                 :             : 
    9438                 :    52158635 :       for (binfo = TYPE_BINFO (type), i = 0;
    9439                 :    52158635 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    9440                 :    13317106 :         if (!is_really_empty_class (BINFO_TYPE (base_binfo), ignore_vptr))
    9441                 :             :           return false;
    9442                 :   481505841 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    9443                 :   464254090 :         if (TREE_CODE (field) == FIELD_DECL
    9444                 :    23709649 :             && !DECL_ARTIFICIAL (field)
    9445                 :             :             /* An unnamed bit-field is not a data member.  */
    9446                 :    21757373 :             && !DECL_UNNAMED_BIT_FIELD (field)
    9447                 :   486008992 :             && !is_really_empty_class (TREE_TYPE (field), ignore_vptr))
    9448                 :             :           return false;
    9449                 :             :       return true;
    9450                 :             :     }
    9451                 :   273728250 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    9452                 :     1753467 :     return (integer_zerop (array_type_nelts_top (type))
    9453                 :     1753467 :             || is_really_empty_class (TREE_TYPE (type), ignore_vptr));
    9454                 :             :   return false;
    9455                 :             : }
    9456                 :             : 
    9457                 :             : /* Note that NAME was looked up while the current class was being
    9458                 :             :    defined and that the result of that lookup was DECL.  */
    9459                 :             : 
    9460                 :             : void
    9461                 :  1834713978 : maybe_note_name_used_in_class (tree name, tree decl)
    9462                 :             : {
    9463                 :             :   /* If we're not defining a class, there's nothing to do.  */
    9464                 :  1834713978 :   if (!(innermost_scope_kind() == sk_class
    9465                 :   257909101 :         && TYPE_BEING_DEFINED (current_class_type)
    9466                 :   453146758 :         && !LAMBDA_TYPE_P (current_class_type)))
    9467                 :             :     return;
    9468                 :             : 
    9469                 :   227289585 :   const cp_binding_level *blev = nullptr;
    9470                 :   227289585 :   if (const cxx_binding *binding = IDENTIFIER_BINDING (name))
    9471                 :   190266727 :     blev = binding->scope;
    9472                 :   227289585 :   const cp_binding_level *lev = current_binding_level;
    9473                 :             : 
    9474                 :             :   /* Record the binding in the names_used tables for classes inside blev.  */
    9475                 :   335191335 :   for (int i = current_class_depth; i > 0; --i)
    9476                 :             :     {
    9477                 :   481676536 :       tree type = (i == current_class_depth
    9478                 :   240838268 :                    ? current_class_type
    9479                 :    13548683 :                    : current_class_stack[i].type);
    9480                 :             : 
    9481                 :   258619494 :       for (; lev; lev = lev->level_chain)
    9482                 :             :         {
    9483                 :   258619494 :           if (lev == blev)
    9484                 :             :             /* We found the declaration.  */
    9485                 :             :             return;
    9486                 :   125682976 :           if (lev->kind == sk_class && lev->this_entity == type)
    9487                 :             :             /* This class is inside the declaration scope.  */
    9488                 :             :             break;
    9489                 :             :         }
    9490                 :             : 
    9491                 :   107901750 :       auto &names_used = current_class_stack[i-1].names_used;
    9492                 :   107901750 :       if (!names_used)
    9493                 :    14064171 :         names_used = splay_tree_new (splay_tree_compare_pointers, 0, 0);
    9494                 :             : 
    9495                 :   107901750 :       tree use = build1_loc (input_location, VIEW_CONVERT_EXPR,
    9496                 :   107901750 :                              TREE_TYPE (decl), decl);
    9497                 :   107901750 :       EXPR_LOCATION_WRAPPER_P (use) = 1;
    9498                 :   107901750 :       splay_tree_insert (names_used,
    9499                 :             :                          (splay_tree_key) name,
    9500                 :             :                          (splay_tree_value) use);
    9501                 :             :     }
    9502                 :             : }
    9503                 :             : 
    9504                 :             : /* Note that NAME was declared (as DECL) in the current class.  Check
    9505                 :             :    to see that the declaration is valid under [class.member.lookup]:
    9506                 :             : 
    9507                 :             :    If [the result of a search in T for N at point P] differs from the result of
    9508                 :             :    a search in T for N from immediately after the class-specifier of T, the
    9509                 :             :    program is ill-formed, no diagnostic required.  */
    9510                 :             : 
    9511                 :             : void
    9512                 :   270450270 : note_name_declared_in_class (tree name, tree decl)
    9513                 :             : {
    9514                 :   270450270 :   splay_tree names_used;
    9515                 :   270450270 :   splay_tree_node n;
    9516                 :             : 
    9517                 :             :   /* Look to see if we ever used this name.  */
    9518                 :   270450270 :   names_used
    9519                 :   270450270 :     = current_class_stack[current_class_depth - 1].names_used;
    9520                 :   270450270 :   if (!names_used)
    9521                 :             :     return;
    9522                 :             :   /* The C language allows members to be declared with a type of the same
    9523                 :             :      name, and the C++ standard says this diagnostic is not required.  So
    9524                 :             :      allow it in extern "C" blocks unless pedantic is specified.
    9525                 :             :      Allow it in all cases if -ms-extensions is specified.  */
    9526                 :    88243023 :   if ((!pedantic && current_lang_name == lang_name_c)
    9527                 :    86151075 :       || flag_ms_extensions)
    9528                 :             :     return;
    9529                 :    86151069 :   n = splay_tree_lookup (names_used, (splay_tree_key) name);
    9530                 :    86151069 :   if (n)
    9531                 :             :     {
    9532                 :          60 :       tree use = (tree) n->value;
    9533                 :          60 :       location_t loc = EXPR_LOCATION (use);
    9534                 :          60 :       tree olddecl = OVL_FIRST (TREE_OPERAND (use, 0));
    9535                 :             :       /* [basic.scope.class]
    9536                 :             : 
    9537                 :             :          A name N used in a class S shall refer to the same declaration
    9538                 :             :          in its context and when re-evaluated in the completed scope of
    9539                 :             :          S.  */
    9540                 :          60 :       auto ov = make_temp_override (global_dc->m_pedantic_errors);
    9541                 :          60 :       if (TREE_CODE (decl) == TYPE_DECL
    9542                 :          21 :           && TREE_CODE (olddecl) == TYPE_DECL
    9543                 :          81 :           && same_type_p (TREE_TYPE (decl), TREE_TYPE (olddecl)))
    9544                 :             :         /* Different declaration, but same meaning; just warn.  */;
    9545                 :          54 :       else if (flag_permissive)
    9546                 :             :         /* Let -fpermissive make it a warning like past versions.  */;
    9547                 :             :       else
    9548                 :             :         /* Make it an error.  */
    9549                 :          33 :         global_dc->m_pedantic_errors = 1;
    9550                 :             : 
    9551                 :          60 :       auto_diagnostic_group d;
    9552                 :         120 :       if (pedwarn (location_of (decl), OPT_Wchanges_meaning,
    9553                 :             :                    "declaration of %q#D changes meaning of %qD",
    9554                 :          60 :                    decl, OVL_NAME (decl)))
    9555                 :             :         {
    9556                 :          51 :           inform (loc, "used here to mean %q#D", olddecl);
    9557                 :          51 :           inform (location_of (olddecl), "declared here" );
    9558                 :             :         }
    9559                 :          60 :     }
    9560                 :             : }
    9561                 :             : 
    9562                 :             : /* Returns the VAR_DECL for the complete vtable associated with BINFO.
    9563                 :             :    Secondary vtables are merged with primary vtables; this function
    9564                 :             :    will return the VAR_DECL for the primary vtable.  */
    9565                 :             : 
    9566                 :             : tree
    9567                 :     5703643 : get_vtbl_decl_for_binfo (tree binfo)
    9568                 :             : {
    9569                 :     5703643 :   tree decl;
    9570                 :             : 
    9571                 :     5703643 :   decl = BINFO_VTABLE (binfo);
    9572                 :     5703643 :   if (decl && TREE_CODE (decl) == POINTER_PLUS_EXPR)
    9573                 :             :     {
    9574                 :     5703640 :       gcc_assert (TREE_CODE (TREE_OPERAND (decl, 0)) == ADDR_EXPR);
    9575                 :     5703640 :       decl = TREE_OPERAND (TREE_OPERAND (decl, 0), 0);
    9576                 :             :     }
    9577                 :     5703640 :   if (decl)
    9578                 :     5703640 :     gcc_assert (VAR_P (decl));
    9579                 :     5703643 :   return decl;
    9580                 :             : }
    9581                 :             : 
    9582                 :             : 
    9583                 :             : /* Returns the binfo for the primary base of BINFO.  If the resulting
    9584                 :             :    BINFO is a virtual base, and it is inherited elsewhere in the
    9585                 :             :    hierarchy, then the returned binfo might not be the primary base of
    9586                 :             :    BINFO in the complete object.  Check BINFO_PRIMARY_P or
    9587                 :             :    BINFO_LOST_PRIMARY_P to be sure.  */
    9588                 :             : 
    9589                 :             : static tree
    9590                 :    39055414 : get_primary_binfo (tree binfo)
    9591                 :             : {
    9592                 :    39055414 :   tree primary_base;
    9593                 :             : 
    9594                 :    39055414 :   primary_base = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (binfo));
    9595                 :    39055414 :   if (!primary_base)
    9596                 :             :     return NULL_TREE;
    9597                 :             : 
    9598                 :    12229129 :   return copied_binfo (primary_base, binfo);
    9599                 :             : }
    9600                 :             : 
    9601                 :             : /* As above, but iterate until we reach the binfo that actually provides the
    9602                 :             :    vptr for BINFO.  */
    9603                 :             : 
    9604                 :             : static tree
    9605                 :     2528916 : most_primary_binfo (tree binfo)
    9606                 :             : {
    9607                 :     2528916 :   tree b = binfo;
    9608                 :     7889993 :   while (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (b))
    9609                 :    10722154 :          && !BINFO_LOST_PRIMARY_P (b))
    9610                 :             :     {
    9611                 :     2832161 :       tree primary_base = get_primary_binfo (b);
    9612                 :     2832161 :       gcc_assert (BINFO_PRIMARY_P (primary_base)
    9613                 :             :                   && BINFO_INHERITANCE_CHAIN (primary_base) == b);
    9614                 :             :       b = primary_base;
    9615                 :             :     }
    9616                 :     2528916 :   return b;
    9617                 :             : }
    9618                 :             : 
    9619                 :             : /* Returns true if BINFO gets its vptr from a virtual base of the most derived
    9620                 :             :    type.  Note that the virtual inheritance might be above or below BINFO in
    9621                 :             :    the hierarchy.  */
    9622                 :             : 
    9623                 :             : bool
    9624                 :         149 : vptr_via_virtual_p (tree binfo)
    9625                 :             : {
    9626                 :         149 :   if (TYPE_P (binfo))
    9627                 :           0 :     binfo = TYPE_BINFO (binfo);
    9628                 :         149 :   tree primary = most_primary_binfo (binfo);
    9629                 :             :   /* Don't limit binfo_via_virtual, we want to return true when BINFO itself is
    9630                 :             :      a morally virtual base.  */
    9631                 :         149 :   tree virt = binfo_via_virtual (primary, NULL_TREE);
    9632                 :         149 :   return virt != NULL_TREE;
    9633                 :             : }
    9634                 :             : 
    9635                 :             : /* If INDENTED_P is zero, indent to INDENT. Return nonzero.  */
    9636                 :             : 
    9637                 :             : static int
    9638                 :         129 : maybe_indent_hierarchy (FILE * stream, int indent, int indented_p)
    9639                 :             : {
    9640                 :           0 :   if (!indented_p)
    9641                 :          39 :     fprintf (stream, "%*s", indent, "");
    9642                 :         129 :   return 1;
    9643                 :             : }
    9644                 :             : 
    9645                 :             : /* Dump the offsets of all the bases rooted at BINFO to STREAM.
    9646                 :             :    INDENT should be zero when called from the top level; it is
    9647                 :             :    incremented recursively.  IGO indicates the next expected BINFO in
    9648                 :             :    inheritance graph ordering.  */
    9649                 :             : 
    9650                 :             : static tree
    9651                 :         102 : dump_class_hierarchy_r (FILE *stream,
    9652                 :             :                         dump_flags_t flags,
    9653                 :             :                         tree binfo,
    9654                 :             :                         tree igo,
    9655                 :             :                         int indent)
    9656                 :             : {
    9657                 :         102 :   int indented = 0;
    9658                 :         102 :   tree base_binfo;
    9659                 :         102 :   int i;
    9660                 :             : 
    9661                 :         204 :   fprintf (stream, "%s (0x" HOST_WIDE_INT_PRINT_HEX ") ",
    9662                 :         102 :            type_as_string (BINFO_TYPE (binfo), TFF_PLAIN_IDENTIFIER),
    9663                 :             :            (HOST_WIDE_INT) (uintptr_t) binfo);
    9664                 :         102 :   if (binfo != igo)
    9665                 :             :     {
    9666                 :          27 :       fprintf (stream, "alternative-path\n");
    9667                 :          27 :       return igo;
    9668                 :             :     }
    9669                 :          75 :   igo = TREE_CHAIN (binfo);
    9670                 :             : 
    9671                 :          75 :   fprintf (stream, HOST_WIDE_INT_PRINT_DEC,
    9672                 :          75 :            tree_to_shwi (BINFO_OFFSET (binfo)));
    9673                 :          75 :   if (is_empty_class (BINFO_TYPE (binfo)))
    9674                 :          18 :     fprintf (stream, " empty");
    9675                 :          57 :   else if (CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (binfo)))
    9676                 :          12 :     fprintf (stream, " nearly-empty");
    9677                 :          75 :   if (BINFO_VIRTUAL_P (binfo))
    9678                 :          27 :     fprintf (stream, " virtual");
    9679                 :          75 :   fprintf (stream, "\n");
    9680                 :             : 
    9681                 :          75 :   if (BINFO_PRIMARY_P (binfo))
    9682                 :             :     {
    9683                 :          15 :       indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9684                 :          30 :       fprintf (stream, " primary-for %s (0x" HOST_WIDE_INT_PRINT_HEX ")",
    9685                 :          15 :                type_as_string (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo)),
    9686                 :             :                                TFF_PLAIN_IDENTIFIER),
    9687                 :          15 :                (HOST_WIDE_INT) (uintptr_t) BINFO_INHERITANCE_CHAIN (binfo));
    9688                 :             :     }
    9689                 :          75 :   if (BINFO_LOST_PRIMARY_P (binfo))
    9690                 :             :     {
    9691                 :           9 :       indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9692                 :           9 :       fprintf (stream, " lost-primary");
    9693                 :             :     }
    9694                 :          75 :   if (indented)
    9695                 :          24 :     fprintf (stream, "\n");
    9696                 :             : 
    9697                 :          75 :   if (!(flags & TDF_SLIM))
    9698                 :             :     {
    9699                 :          75 :       int indented = 0;
    9700                 :             : 
    9701                 :          75 :       if (BINFO_SUBVTT_INDEX (binfo))
    9702                 :             :         {
    9703                 :          21 :           indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9704                 :          42 :           fprintf (stream, " subvttidx=%s",
    9705                 :          21 :                    expr_as_string (BINFO_SUBVTT_INDEX (binfo),
    9706                 :             :                                    TFF_PLAIN_IDENTIFIER));
    9707                 :             :         }
    9708                 :          75 :       if (BINFO_VPTR_INDEX (binfo))
    9709                 :             :         {
    9710                 :          30 :           indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9711                 :          60 :           fprintf (stream, " vptridx=%s",
    9712                 :          30 :                    expr_as_string (BINFO_VPTR_INDEX (binfo),
    9713                 :             :                                    TFF_PLAIN_IDENTIFIER));
    9714                 :             :         }
    9715                 :          75 :       if (BINFO_VPTR_FIELD (binfo))
    9716                 :             :         {
    9717                 :          27 :           indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9718                 :          54 :           fprintf (stream, " vbaseoffset=%s",
    9719                 :          27 :                    expr_as_string (BINFO_VPTR_FIELD (binfo),
    9720                 :             :                                    TFF_PLAIN_IDENTIFIER));
    9721                 :             :         }
    9722                 :          75 :       if (BINFO_VTABLE (binfo))
    9723                 :             :         {
    9724                 :          27 :           indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9725                 :          27 :           fprintf (stream, " vptr=%s",
    9726                 :          27 :                    expr_as_string (BINFO_VTABLE (binfo),
    9727                 :             :                                    TFF_PLAIN_IDENTIFIER));
    9728                 :             :         }
    9729                 :             : 
    9730                 :          75 :       if (indented)
    9731                 :          51 :         fprintf (stream, "\n");
    9732                 :             :     }
    9733                 :             : 
    9734                 :         153 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    9735                 :          78 :     igo = dump_class_hierarchy_r (stream, flags, base_binfo, igo, indent + 2);
    9736                 :             : 
    9737                 :             :   return igo;
    9738                 :             : }
    9739                 :             : 
    9740                 :             : /* Dump the BINFO hierarchy for T.  */
    9741                 :             : 
    9742                 :             : static void
    9743                 :          24 : dump_class_hierarchy_1 (FILE *stream, dump_flags_t flags, tree t)
    9744                 :             : {
    9745                 :          24 :   fprintf (stream, "Class %s\n", type_as_string (t, TFF_PLAIN_IDENTIFIER));
    9746                 :          96 :   fprintf (stream, "   size=" HOST_WIDE_INT_PRINT_UNSIGNED " align=%u\n",
    9747                 :          24 :            tree_to_shwi (TYPE_SIZE (t)) / BITS_PER_UNIT,
    9748                 :          24 :            TYPE_ALIGN (t) / BITS_PER_UNIT);
    9749                 :          24 :   if (tree as_base = CLASSTYPE_AS_BASE (t))
    9750                 :          96 :     fprintf (stream, "   base size=" HOST_WIDE_INT_PRINT_UNSIGNED
    9751                 :             :              " base align=%u\n",
    9752                 :          24 :              tree_to_shwi (TYPE_SIZE (as_base)) / BITS_PER_UNIT,
    9753                 :          24 :              TYPE_ALIGN (as_base) / BITS_PER_UNIT);
    9754                 :          24 :   dump_class_hierarchy_r (stream, flags, TYPE_BINFO (t), TYPE_BINFO (t), 0);
    9755                 :          24 :   fprintf (stream, "\n");
    9756                 :          24 : }
    9757                 :             : 
    9758                 :             : /* Debug interface to hierarchy dumping.  */
    9759                 :             : 
    9760                 :             : void
    9761                 :           0 : debug_class (tree t)
    9762                 :             : {
    9763                 :           0 :   dump_class_hierarchy_1 (stderr, TDF_SLIM, t);
    9764                 :           0 : }
    9765                 :             : 
    9766                 :             : static void
    9767                 :    37061824 : dump_class_hierarchy (tree t)
    9768                 :             : {
    9769                 :    37061824 :   dump_flags_t flags;
    9770                 :    37061824 :   if (FILE *stream = dump_begin (class_dump_id, &flags))
    9771                 :             :     {
    9772                 :          24 :       dump_class_hierarchy_1 (stream, flags, t);
    9773                 :          24 :       dump_end (class_dump_id, stream);
    9774                 :             :     }
    9775                 :    37061824 : }
    9776                 :             : 
    9777                 :             : static void
    9778                 :          51 : dump_array (FILE * stream, tree decl)
    9779                 :             : {
    9780                 :          51 :   tree value;
    9781                 :          51 :   unsigned HOST_WIDE_INT ix;
    9782                 :          51 :   HOST_WIDE_INT elt;
    9783                 :          51 :   tree size = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (decl)));
    9784                 :             : 
    9785                 :          51 :   elt = (tree_to_shwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))))
    9786                 :             :          / BITS_PER_UNIT);
    9787                 :          51 :   fprintf (stream, "%s:", decl_as_string (decl, TFF_PLAIN_IDENTIFIER));
    9788                 :          51 :   fprintf (stream, " %s entries",
    9789                 :             :            expr_as_string (size_binop (PLUS_EXPR, size, size_one_node),
    9790                 :             :                            TFF_PLAIN_IDENTIFIER));
    9791                 :          51 :   fprintf (stream, "\n");
    9792                 :             : 
    9793                 :         519 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)),
    9794                 :             :                               ix, value)
    9795                 :         417 :     fprintf (stream, "%-4ld  %s\n", (long)(ix * elt),
    9796                 :             :              expr_as_string (value, TFF_PLAIN_IDENTIFIER));
    9797                 :          51 : }
    9798                 :             : 
    9799                 :             : static void
    9800                 :     1914793 : dump_vtable (tree t, tree binfo, tree vtable)
    9801                 :             : {
    9802                 :     1914793 :   dump_flags_t flags;
    9803                 :     1914793 :   FILE *stream = dump_begin (class_dump_id, &flags);
    9804                 :             : 
    9805                 :     1914793 :   if (!stream)
    9806                 :     1914754 :     return;
    9807                 :             : 
    9808                 :          39 :   if (!(flags & TDF_SLIM))
    9809                 :             :     {
    9810                 :          39 :       int ctor_vtbl_p = TYPE_BINFO (t) != binfo;
    9811                 :             : 
    9812                 :          96 :       fprintf (stream, "%s for %s",
    9813                 :             :                ctor_vtbl_p ? "Construction vtable" : "Vtable",
    9814                 :          39 :                type_as_string (BINFO_TYPE (binfo), TFF_PLAIN_IDENTIFIER));
    9815                 :          39 :       if (ctor_vtbl_p)
    9816                 :             :         {
    9817                 :          21 :           if (!BINFO_VIRTUAL_P (binfo))
    9818                 :           6 :             fprintf (stream, " (0x" HOST_WIDE_INT_PRINT_HEX " instance)",
    9819                 :             :                      (HOST_WIDE_INT) (uintptr_t) binfo);
    9820                 :          21 :           fprintf (stream, " in %s", type_as_string (t, TFF_PLAIN_IDENTIFIER));
    9821                 :             :         }
    9822                 :          39 :       fprintf (stream, "\n");
    9823                 :          39 :       dump_array (stream, vtable);
    9824                 :          39 :       fprintf (stream, "\n");
    9825                 :             :     }
    9826                 :             : 
    9827                 :          39 :   dump_end (class_dump_id, stream);
    9828                 :             : }
    9829                 :             : 
    9830                 :             : static void
    9831                 :      187059 : dump_vtt (tree t, tree vtt)
    9832                 :             : {
    9833                 :      187059 :   dump_flags_t flags;
    9834                 :      187059 :   FILE *stream = dump_begin (class_dump_id, &flags);
    9835                 :             : 
    9836                 :      187059 :   if (!stream)
    9837                 :      187047 :     return;
    9838                 :             : 
    9839                 :          12 :   if (!(flags & TDF_SLIM))
    9840                 :             :     {
    9841                 :          12 :       fprintf (stream, "VTT for %s\n",
    9842                 :             :                type_as_string (t, TFF_PLAIN_IDENTIFIER));
    9843                 :          12 :       dump_array (stream, vtt);
    9844                 :          12 :       fprintf (stream, "\n");
    9845                 :             :     }
    9846                 :             : 
    9847                 :          12 :   dump_end (class_dump_id, stream);
    9848                 :             : }
    9849                 :             : 
    9850                 :             : /* Dump a function or thunk and its thunkees.  */
    9851                 :             : 
    9852                 :             : static void
    9853                 :           0 : dump_thunk (FILE *stream, int indent, tree thunk)
    9854                 :             : {
    9855                 :           0 :   static const char spaces[] = "        ";
    9856                 :           0 :   tree name = DECL_NAME (thunk);
    9857                 :           0 :   tree thunks;
    9858                 :             : 
    9859                 :           0 :   fprintf (stream, "%.*s%p %s %s", indent, spaces,
    9860                 :             :            (void *)thunk,
    9861                 :           0 :            !DECL_THUNK_P (thunk) ? "function"
    9862                 :           0 :            : DECL_THIS_THUNK_P (thunk) ? "this-thunk" : "covariant-thunk",
    9863                 :           0 :            name ? IDENTIFIER_POINTER (name) : "<unset>");
    9864                 :           0 :   if (DECL_THUNK_P (thunk))
    9865                 :             :     {
    9866                 :           0 :       HOST_WIDE_INT fixed_adjust = THUNK_FIXED_OFFSET (thunk);
    9867                 :           0 :       tree virtual_adjust = THUNK_VIRTUAL_OFFSET (thunk);
    9868                 :             : 
    9869                 :           0 :       fprintf (stream, " fixed=" HOST_WIDE_INT_PRINT_DEC, fixed_adjust);
    9870                 :           0 :       if (!virtual_adjust)
    9871                 :             :         /*NOP*/;
    9872                 :           0 :       else if (DECL_THIS_THUNK_P (thunk))
    9873                 :           0 :         fprintf (stream, " vcall="  HOST_WIDE_INT_PRINT_DEC,
    9874                 :             :                  tree_to_shwi (virtual_adjust));
    9875                 :             :       else
    9876                 :           0 :         fprintf (stream, " vbase=" HOST_WIDE_INT_PRINT_DEC "(%s)",
    9877                 :           0 :                  tree_to_shwi (BINFO_VPTR_FIELD (virtual_adjust)),
    9878                 :           0 :                  type_as_string (BINFO_TYPE (virtual_adjust), TFF_SCOPE));
    9879                 :           0 :       if (THUNK_ALIAS (thunk))
    9880                 :           0 :         fprintf (stream, " alias to %p", (void *)THUNK_ALIAS (thunk));
    9881                 :             :     }
    9882                 :           0 :   fprintf (stream, "\n");
    9883                 :           0 :   for (thunks = DECL_THUNKS (thunk); thunks; thunks = TREE_CHAIN (thunks))
    9884                 :           0 :     dump_thunk (stream, indent + 2, thunks);
    9885                 :           0 : }
    9886                 :             : 
    9887                 :             : /* Dump the thunks for FN.  */
    9888                 :             : 
    9889                 :             : void
    9890                 :           0 : debug_thunks (tree fn)
    9891                 :             : {
    9892                 :           0 :   dump_thunk (stderr, 0, fn);
    9893                 :           0 : }
    9894                 :             : 
    9895                 :             : /* Virtual function table initialization.  */
    9896                 :             : 
    9897                 :             : /* Create all the necessary vtables for T and its base classes.  */
    9898                 :             : 
    9899                 :             : static void
    9900                 :    37061824 : finish_vtbls (tree t)
    9901                 :             : {
    9902                 :    37061824 :   tree vbase;
    9903                 :    37061824 :   vec<constructor_elt, va_gc> *v = NULL;
    9904                 :    37061824 :   tree vtable = BINFO_VTABLE (TYPE_BINFO (t));
    9905                 :             : 
    9906                 :             :   /* We lay out the primary and secondary vtables in one contiguous
    9907                 :             :      vtable.  The primary vtable is first, followed by the non-virtual
    9908                 :             :      secondary vtables in inheritance graph order.  */
    9909                 :    37061824 :   accumulate_vtbl_inits (TYPE_BINFO (t), TYPE_BINFO (t), TYPE_BINFO (t),
    9910                 :             :                          vtable, t, &v);
    9911                 :             : 
    9912                 :             :   /* Then come the virtual bases, also in inheritance graph order.  */
    9913                 :    96632072 :   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
    9914                 :             :     {
    9915                 :    59570248 :       if (!BINFO_VIRTUAL_P (vbase))
    9916                 :    59369691 :         continue;
    9917                 :      200557 :       accumulate_vtbl_inits (vbase, vbase, TYPE_BINFO (t), vtable, t, &v);
    9918                 :             :     }
    9919                 :             : 
    9920                 :    37061824 :   if (BINFO_VTABLE (TYPE_BINFO (t)))
    9921                 :     1657715 :     initialize_vtable (TYPE_BINFO (t), v);
    9922                 :    37061824 : }
    9923                 :             : 
    9924                 :             : /* Initialize the vtable for BINFO with the INITS.  */
    9925                 :             : 
    9926                 :             : static void
    9927                 :     1657715 : initialize_vtable (tree binfo, vec<constructor_elt, va_gc> *inits)
    9928                 :             : {
    9929                 :     1657715 :   tree decl;
    9930                 :             : 
    9931                 :     3315430 :   layout_vtable_decl (binfo, vec_safe_length (inits));
    9932                 :     1657715 :   decl = get_vtbl_decl_for_binfo (binfo);
    9933                 :     1657715 :   initialize_artificial_var (decl, inits);
    9934                 :     1657715 :   dump_vtable (BINFO_TYPE (binfo), binfo, decl);
    9935                 :     1657715 : }
    9936                 :             : 
    9937                 :             : /* Build the VTT (virtual table table) for T.
    9938                 :             :    A class requires a VTT if it has virtual bases.
    9939                 :             : 
    9940                 :             :    This holds
    9941                 :             :    1 - primary virtual pointer for complete object T
    9942                 :             :    2 - secondary VTTs for each direct non-virtual base of T which requires a
    9943                 :             :        VTT
    9944                 :             :    3 - secondary virtual pointers for each direct or indirect base of T which
    9945                 :             :        has virtual bases or is reachable via a virtual path from T.
    9946                 :             :    4 - secondary VTTs for each direct or indirect virtual base of T.
    9947                 :             : 
    9948                 :             :    Secondary VTTs look like complete object VTTs without part 4.  */
    9949                 :             : 
    9950                 :             : static void
    9951                 :    37061824 : build_vtt (tree t)
    9952                 :             : {
    9953                 :    37061824 :   tree type;
    9954                 :    37061824 :   tree vtt;
    9955                 :    37061824 :   tree index;
    9956                 :    37061824 :   vec<constructor_elt, va_gc> *inits;
    9957                 :             : 
    9958                 :             :   /* Build up the initializers for the VTT.  */
    9959                 :    37061824 :   inits = NULL;
    9960                 :    37061824 :   index = size_zero_node;
    9961                 :    37061824 :   build_vtt_inits (TYPE_BINFO (t), t, &inits, &index);
    9962                 :             : 
    9963                 :             :   /* If we didn't need a VTT, we're done.  */
    9964                 :    37061824 :   if (!inits)
    9965                 :    36874765 :     return;
    9966                 :             : 
    9967                 :             :   /* Figure out the type of the VTT.  */
    9968                 :      374118 :   type = build_array_of_n_type (const_ptr_type_node,
    9969                 :      187059 :                                 inits->length ());
    9970                 :             : 
    9971                 :             :   /* Now, build the VTT object itself.  */
    9972                 :      187059 :   vtt = build_vtable (t, mangle_vtt_for_type (t), type);
    9973                 :      187059 :   initialize_artificial_var (vtt, inits);
    9974                 :             :   /* Add the VTT to the vtables list.  */
    9975                 :      187059 :   DECL_CHAIN (vtt) = DECL_CHAIN (CLASSTYPE_VTABLES (t));
    9976                 :      187059 :   DECL_CHAIN (CLASSTYPE_VTABLES (t)) = vtt;
    9977                 :             : 
    9978                 :      187059 :   dump_vtt (t, vtt);
    9979                 :             : }
    9980                 :             : 
    9981                 :             : /* When building a secondary VTT, BINFO_VTABLE is set to a TREE_LIST with
    9982                 :             :    PURPOSE the RTTI_BINFO, VALUE the real vtable pointer for this binfo,
    9983                 :             :    and CHAIN the vtable pointer for this binfo after construction is
    9984                 :             :    complete.  VALUE can also be another BINFO, in which case we recurse.  */
    9985                 :             : 
    9986                 :             : static tree
    9987                 :     1128306 : binfo_ctor_vtable (tree binfo)
    9988                 :             : {
    9989                 :     1200205 :   tree vt;
    9990                 :             : 
    9991                 :     1200205 :   while (1)
    9992                 :             :     {
    9993                 :     1200205 :       vt = BINFO_VTABLE (binfo);
    9994                 :     1200205 :       if (TREE_CODE (vt) == TREE_LIST)
    9995                 :      753580 :         vt = TREE_VALUE (vt);
    9996                 :     1200205 :       if (TREE_CODE (vt) == TREE_BINFO)
    9997                 :             :         binfo = vt;
    9998                 :             :       else
    9999                 :             :         break;
   10000                 :             :     }
   10001                 :             : 
   10002                 :     1128306 :   return vt;
   10003                 :             : }
   10004                 :             : 
   10005                 :             : /* Data for secondary VTT initialization.  */
   10006                 :             : struct secondary_vptr_vtt_init_data
   10007                 :             : {
   10008                 :             :   /* Is this the primary VTT? */
   10009                 :             :   bool top_level_p;
   10010                 :             : 
   10011                 :             :   /* Current index into the VTT.  */
   10012                 :             :   tree index;
   10013                 :             : 
   10014                 :             :   /* Vector of initializers built up.  */
   10015                 :             :   vec<constructor_elt, va_gc> *inits;
   10016                 :             : 
   10017                 :             :   /* The type being constructed by this secondary VTT.  */
   10018                 :             :   tree type_being_constructed;
   10019                 :             : };
   10020                 :             : 
   10021                 :             : /* Recursively build the VTT-initializer for BINFO (which is in the
   10022                 :             :    hierarchy dominated by T).  INITS points to the end of the initializer
   10023                 :             :    list to date.  INDEX is the VTT index where the next element will be
   10024                 :             :    replaced.  Iff BINFO is the binfo for T, this is the top level VTT (i.e.
   10025                 :             :    not a subvtt for some base of T).  When that is so, we emit the sub-VTTs
   10026                 :             :    for virtual bases of T. When it is not so, we build the constructor
   10027                 :             :    vtables for the BINFO-in-T variant.  */
   10028                 :             : 
   10029                 :             : static void
   10030                 :    37508227 : build_vtt_inits (tree binfo, tree t, vec<constructor_elt, va_gc> **inits,
   10031                 :             :                  tree *index)
   10032                 :             : {
   10033                 :    37508227 :   int i;
   10034                 :    37508227 :   tree b;
   10035                 :    37508227 :   tree init;
   10036                 :    37508227 :   secondary_vptr_vtt_init_data data;
   10037                 :    37508227 :   int top_level_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
   10038                 :             : 
   10039                 :             :   /* We only need VTTs for subobjects with virtual bases.  */
   10040                 :    37508227 :   if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
   10041                 :    37064090 :     return;
   10042                 :             : 
   10043                 :             :   /* We need to use a construction vtable if this is not the primary
   10044                 :             :      VTT.  */
   10045                 :      444137 :   if (!top_level_p)
   10046                 :             :     {
   10047                 :      257078 :       build_ctor_vtbl_group (binfo, t);
   10048                 :             : 
   10049                 :             :       /* Record the offset in the VTT where this sub-VTT can be found.  */
   10050                 :      257078 :       BINFO_SUBVTT_INDEX (binfo) = *index;
   10051                 :             :     }
   10052                 :             : 
   10053                 :             :   /* Add the address of the primary vtable for the complete object.  */
   10054                 :      444137 :   init = binfo_ctor_vtable (binfo);
   10055                 :      444137 :   CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init);
   10056                 :      444137 :   if (top_level_p)
   10057                 :             :     {
   10058                 :      187059 :       gcc_assert (!BINFO_VPTR_INDEX (binfo));
   10059                 :      187059 :       BINFO_VPTR_INDEX (binfo) = *index;
   10060                 :             :     }
   10061                 :      444137 :   *index = size_binop (PLUS_EXPR, *index, TYPE_SIZE_UNIT (ptr_type_node));
   10062                 :             : 
   10063                 :             :   /* Recursively add the secondary VTTs for non-virtual bases.  */
   10064                 :      960914 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, b); ++i)
   10065                 :      516777 :     if (!BINFO_VIRTUAL_P (b))
   10066                 :      245846 :       build_vtt_inits (b, t, inits, index);
   10067                 :             : 
   10068                 :             :   /* Add secondary virtual pointers for all subobjects of BINFO with
   10069                 :             :      either virtual bases or reachable along a virtual path, except
   10070                 :             :      subobjects that are non-virtual primary bases.  */
   10071                 :      444137 :   data.top_level_p = top_level_p;
   10072                 :      444137 :   data.index = *index;
   10073                 :      444137 :   data.inits = *inits;
   10074                 :      444137 :   data.type_being_constructed = BINFO_TYPE (binfo);
   10075                 :             : 
   10076                 :      444137 :   dfs_walk_once (binfo, dfs_build_secondary_vptr_vtt_inits, NULL, &data);
   10077                 :             : 
   10078                 :      444137 :   *index = data.index;
   10079                 :             : 
   10080                 :             :   /* data.inits might have grown as we added secondary virtual pointers.
   10081                 :             :      Make sure our caller knows about the new vector.  */
   10082                 :      444137 :   *inits = data.inits;
   10083                 :             : 
   10084                 :      444137 :   if (top_level_p)
   10085                 :             :     /* Add the secondary VTTs for virtual bases in inheritance graph
   10086                 :             :        order.  */
   10087                 :     1004583 :     for (b = TYPE_BINFO (BINFO_TYPE (binfo)); b; b = TREE_CHAIN (b))
   10088                 :             :       {
   10089                 :      817524 :         if (!BINFO_VIRTUAL_P (b))
   10090                 :      616967 :           continue;
   10091                 :             : 
   10092                 :      200557 :         build_vtt_inits (b, t, inits, index);
   10093                 :             :       }
   10094                 :             :   else
   10095                 :             :     /* Remove the ctor vtables we created.  */
   10096                 :      257078 :     dfs_walk_all (binfo, dfs_fixup_binfo_vtbls, NULL, binfo);
   10097                 :             : }
   10098                 :             : 
   10099                 :             : /* Called from build_vtt_inits via dfs_walk.  BINFO is the binfo for the base
   10100                 :             :    in most derived. DATA is a SECONDARY_VPTR_VTT_INIT_DATA structure.  */
   10101                 :             : 
   10102                 :             : static tree
   10103                 :     1805556 : dfs_build_secondary_vptr_vtt_inits (tree binfo, void *data_)
   10104                 :             : {
   10105                 :     1805556 :   secondary_vptr_vtt_init_data *data = (secondary_vptr_vtt_init_data *)data_;
   10106                 :             : 
   10107                 :             :   /* We don't care about bases that don't have vtables.  */
   10108                 :     1805556 :   if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
   10109                 :             :     return dfs_skip_bases;
   10110                 :             : 
   10111                 :             :   /* We're only interested in proper subobjects of the type being
   10112                 :             :      constructed.  */
   10113                 :     1782050 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->type_being_constructed))
   10114                 :             :     return NULL_TREE;
   10115                 :             : 
   10116                 :             :   /* We're only interested in bases with virtual bases or reachable
   10117                 :             :      via a virtual path from the type being constructed.  */
   10118                 :     2188615 :   if (!(CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
   10119                 :      850702 :         || binfo_via_virtual (binfo, data->type_being_constructed)))
   10120                 :             :     return dfs_skip_bases;
   10121                 :             : 
   10122                 :             :   /* We're not interested in non-virtual primary bases.  */
   10123                 :     1337387 :   if (!BINFO_VIRTUAL_P (binfo) && BINFO_PRIMARY_P (binfo))
   10124                 :             :     return NULL_TREE;
   10125                 :             : 
   10126                 :             :   /* Record the index where this secondary vptr can be found.  */
   10127                 :      684169 :   if (data->top_level_p)
   10128                 :             :     {
   10129                 :      259566 :       gcc_assert (!BINFO_VPTR_INDEX (binfo));
   10130                 :      259566 :       BINFO_VPTR_INDEX (binfo) = data->index;
   10131                 :             : 
   10132                 :      259566 :       if (BINFO_VIRTUAL_P (binfo))
   10133                 :             :         {
   10134                 :             :           /* It's a primary virtual base, and this is not a
   10135                 :             :              construction vtable.  Find the base this is primary of in
   10136                 :             :              the inheritance graph, and use that base's vtable
   10137                 :             :              now.  */
   10138                 :      207055 :           while (BINFO_PRIMARY_P (binfo))
   10139                 :        9415 :             binfo = BINFO_INHERITANCE_CHAIN (binfo);
   10140                 :             :         }
   10141                 :             :     }
   10142                 :             : 
   10143                 :             :   /* Add the initializer for the secondary vptr itself.  */
   10144                 :      684169 :   CONSTRUCTOR_APPEND_ELT (data->inits, NULL_TREE, binfo_ctor_vtable (binfo));
   10145                 :             : 
   10146                 :             :   /* Advance the vtt index.  */
   10147                 :      684169 :   data->index = size_binop (PLUS_EXPR, data->index,
   10148                 :             :                             TYPE_SIZE_UNIT (ptr_type_node));
   10149                 :             : 
   10150                 :      684169 :   return NULL_TREE;
   10151                 :             : }
   10152                 :             : 
   10153                 :             : /* Called from build_vtt_inits via dfs_walk. After building
   10154                 :             :    constructor vtables and generating the sub-vtt from them, we need
   10155                 :             :    to restore the BINFO_VTABLES that were scribbled on.  DATA is the
   10156                 :             :    binfo of the base whose sub vtt was generated.  */
   10157                 :             : 
   10158                 :             : static tree
   10159                 :     1148467 : dfs_fixup_binfo_vtbls (tree binfo, void* data)
   10160                 :             : {
   10161                 :     1148467 :   tree vtable = BINFO_VTABLE (binfo);
   10162                 :             : 
   10163                 :     1148467 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
   10164                 :             :     /* If this class has no vtable, none of its bases do.  */
   10165                 :             :     return dfs_skip_bases;
   10166                 :             : 
   10167                 :     1053288 :   if (!vtable)
   10168                 :             :     /* This might be a primary base, so have no vtable in this
   10169                 :             :        hierarchy.  */
   10170                 :             :     return NULL_TREE;
   10171                 :             : 
   10172                 :             :   /* If we scribbled the construction vtable vptr into BINFO, clear it
   10173                 :             :      out now.  */
   10174                 :      722679 :   if (TREE_CODE (vtable) == TREE_LIST
   10175                 :      722679 :       && (TREE_PURPOSE (vtable) == (tree) data))
   10176                 :      681681 :     BINFO_VTABLE (binfo) = TREE_CHAIN (vtable);
   10177                 :             : 
   10178                 :             :   return NULL_TREE;
   10179                 :             : }
   10180                 :             : 
   10181                 :             : /* Build the construction vtable group for BINFO which is in the
   10182                 :             :    hierarchy dominated by T.  */
   10183                 :             : 
   10184                 :             : static void
   10185                 :      257078 : build_ctor_vtbl_group (tree binfo, tree t)
   10186                 :             : {
   10187                 :      257078 :   tree type;
   10188                 :      257078 :   tree vtbl;
   10189                 :      257078 :   tree id;
   10190                 :      257078 :   tree vbase;
   10191                 :      257078 :   vec<constructor_elt, va_gc> *v;
   10192                 :             : 
   10193                 :             :   /* See if we've already created this construction vtable group.  */
   10194                 :      257078 :   id = mangle_ctor_vtbl_for_type (t, binfo);
   10195                 :      257078 :   if (get_global_binding (id))
   10196                 :           0 :     return;
   10197                 :             : 
   10198                 :      257078 :   gcc_assert (!SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t));
   10199                 :             :   /* Build a version of VTBL (with the wrong type) for use in
   10200                 :             :      constructing the addresses of secondary vtables in the
   10201                 :             :      construction vtable group.  */
   10202                 :      257078 :   vtbl = build_vtable (t, id, ptr_type_node);
   10203                 :             : 
   10204                 :             :   /* Don't export construction vtables from shared libraries.  Even on
   10205                 :             :      targets that don't support hidden visibility, this tells
   10206                 :             :      can_refer_decl_in_current_unit_p not to assume that it's safe to
   10207                 :             :      access from a different compilation unit (bz 54314).  */
   10208                 :      257078 :   DECL_VISIBILITY (vtbl) = VISIBILITY_HIDDEN;
   10209                 :      257078 :   DECL_VISIBILITY_SPECIFIED (vtbl) = true;
   10210                 :             : 
   10211                 :      257078 :   v = NULL;
   10212                 :      257078 :   accumulate_vtbl_inits (binfo, TYPE_BINFO (TREE_TYPE (binfo)),
   10213                 :             :                          binfo, vtbl, t, &v);
   10214                 :             : 
   10215                 :             :   /* Add the vtables for each of our virtual bases using the vbase in T
   10216                 :             :      binfo.  */
   10217                 :      257078 :   for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
   10218                 :     1249096 :        vbase;
   10219                 :      992018 :        vbase = TREE_CHAIN (vbase))
   10220                 :             :     {
   10221                 :      992018 :       tree b;
   10222                 :             : 
   10223                 :      992018 :       if (!BINFO_VIRTUAL_P (vbase))
   10224                 :      592691 :         continue;
   10225                 :      399327 :       b = copied_binfo (vbase, binfo);
   10226                 :             : 
   10227                 :      399327 :       accumulate_vtbl_inits (b, vbase, binfo, vtbl, t, &v);
   10228                 :             :     }
   10229                 :             : 
   10230                 :             :   /* Figure out the type of the construction vtable.  */
   10231                 :      257078 :   type = build_array_of_n_type (vtable_entry_type, v->length ());
   10232                 :      257078 :   layout_type (type);
   10233                 :      257078 :   TREE_TYPE (vtbl) = type;
   10234                 :      257078 :   DECL_SIZE (vtbl) = DECL_SIZE_UNIT (vtbl) = NULL_TREE;
   10235                 :      257078 :   layout_decl (vtbl, 0);
   10236                 :             : 
   10237                 :             :   /* Initialize the construction vtable.  */
   10238                 :      257078 :   CLASSTYPE_VTABLES (t) = chainon (CLASSTYPE_VTABLES (t), vtbl);
   10239                 :      257078 :   initialize_artificial_var (vtbl, v);
   10240                 :      257078 :   dump_vtable (t, binfo, vtbl);
   10241                 :             : }
   10242                 :             : 
   10243                 :             : /* Add the vtbl initializers for BINFO (and its bases other than
   10244                 :             :    non-virtual primaries) to the list of INITS.  BINFO is in the
   10245                 :             :    hierarchy dominated by T.  RTTI_BINFO is the binfo within T of
   10246                 :             :    the constructor the vtbl inits should be accumulated for. (If this
   10247                 :             :    is the complete object vtbl then RTTI_BINFO will be TYPE_BINFO (T).)
   10248                 :             :    ORIG_BINFO is the binfo for this object within BINFO_TYPE (RTTI_BINFO).
   10249                 :             :    BINFO is the active base equivalent of ORIG_BINFO in the inheritance
   10250                 :             :    graph of T. Both BINFO and ORIG_BINFO will have the same BINFO_TYPE,
   10251                 :             :    but are not necessarily the same in terms of layout.  */
   10252                 :             : 
   10253                 :             : static void
   10254                 :    41347703 : accumulate_vtbl_inits (tree binfo,
   10255                 :             :                        tree orig_binfo,
   10256                 :             :                        tree rtti_binfo,
   10257                 :             :                        tree vtbl,
   10258                 :             :                        tree t,
   10259                 :             :                        vec<constructor_elt, va_gc> **inits)
   10260                 :             : {
   10261                 :    41347703 :   int i;
   10262                 :    41347703 :   tree base_binfo;
   10263                 :    41347703 :   int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
   10264                 :             : 
   10265                 :    41347703 :   gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (orig_binfo)));
   10266                 :             : 
   10267                 :             :   /* If it doesn't have a vptr, we don't do anything.  */
   10268                 :    41347703 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
   10269                 :             :     return;
   10270                 :             : 
   10271                 :             :   /* If we're building a construction vtable, we're not interested in
   10272                 :             :      subobjects that don't require construction vtables.  */
   10273                 :     5351810 :   if (ctor_vtbl_p
   10274                 :      970511 :       && !CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
   10275                 :     5835110 :       && !binfo_via_virtual (orig_binfo, BINFO_TYPE (rtti_binfo)))
   10276                 :             :     return;
   10277                 :             : 
   10278                 :             :   /* Build the initializers for the BINFO-in-T vtable.  */
   10279                 :     5351609 :   dfs_accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, vtbl, t, inits);
   10280                 :             : 
   10281                 :             :   /* Walk the BINFO and its bases.  We walk in preorder so that as we
   10282                 :             :      initialize each vtable we can figure out at what offset the
   10283                 :             :      secondary vtable lies from the primary vtable.  We can't use
   10284                 :             :      dfs_walk here because we need to iterate through bases of BINFO
   10285                 :             :      and RTTI_BINFO simultaneously.  */
   10286                 :    14916715 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
   10287                 :             :     {
   10288                 :             :       /* Skip virtual bases.  */
   10289                 :     4213497 :       if (BINFO_VIRTUAL_P (base_binfo))
   10290                 :      784580 :         continue;
   10291                 :     6857834 :       accumulate_vtbl_inits (base_binfo,
   10292                 :     3428917 :                              BINFO_BASE_BINFO (orig_binfo, i),
   10293                 :             :                              rtti_binfo, vtbl, t,
   10294                 :             :                              inits);
   10295                 :             :     }
   10296                 :             : }
   10297                 :             : 
   10298                 :             : /* Called from accumulate_vtbl_inits.  Adds the initializers for the
   10299                 :             :    BINFO vtable to L.  */
   10300                 :             : 
   10301                 :             : static void
   10302                 :     5351609 : dfs_accumulate_vtbl_inits (tree binfo,
   10303                 :             :                            tree orig_binfo,
   10304                 :             :                            tree rtti_binfo,
   10305                 :             :                            tree orig_vtbl,
   10306                 :             :                            tree t,
   10307                 :             :                            vec<constructor_elt, va_gc> **l)
   10308                 :             : {
   10309                 :     5351609 :   tree vtbl = NULL_TREE;
   10310                 :     5351609 :   int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
   10311                 :     5351609 :   int n_inits;
   10312                 :             : 
   10313                 :     5351609 :   if (ctor_vtbl_p
   10314                 :     6321919 :       && BINFO_VIRTUAL_P (orig_binfo) && BINFO_PRIMARY_P (orig_binfo))
   10315                 :             :     {
   10316                 :             :       /* In the hierarchy of BINFO_TYPE (RTTI_BINFO), this is a
   10317                 :             :          primary virtual base.  If it is not the same primary in
   10318                 :             :          the hierarchy of T, we'll need to generate a ctor vtable
   10319                 :             :          for it, to place at its location in T.  If it is the same
   10320                 :             :          primary, we still need a VTT entry for the vtable, but it
   10321                 :             :          should point to the ctor vtable for the base it is a
   10322                 :             :          primary for within the sub-hierarchy of RTTI_BINFO.
   10323                 :             : 
   10324                 :             :          There are three possible cases:
   10325                 :             : 
   10326                 :             :          1) We are in the same place.
   10327                 :             :          2) We are a primary base within a lost primary virtual base of
   10328                 :             :          RTTI_BINFO.
   10329                 :             :          3) We are primary to something not a base of RTTI_BINFO.  */
   10330                 :             : 
   10331                 :             :       tree b;
   10332                 :             :       tree last = NULL_TREE;
   10333                 :             : 
   10334                 :             :       /* First, look through the bases we are primary to for RTTI_BINFO
   10335                 :             :          or a virtual base.  */
   10336                 :             :       b = binfo;
   10337                 :       73372 :       while (BINFO_PRIMARY_P (b))
   10338                 :             :         {
   10339                 :       72958 :           b = BINFO_INHERITANCE_CHAIN (b);
   10340                 :       72958 :           last = b;
   10341                 :      144855 :           if (BINFO_VIRTUAL_P (b) || b == rtti_binfo)
   10342                 :       71897 :             goto found;
   10343                 :             :         }
   10344                 :             :       /* If we run out of primary links, keep looking down our
   10345                 :             :          inheritance chain; we might be an indirect primary.  */
   10346                 :         861 :       for (b = last; b; b = BINFO_INHERITANCE_CHAIN (b))
   10347                 :         459 :         if (BINFO_VIRTUAL_P (b) || b == rtti_binfo)
   10348                 :             :           break;
   10349                 :         402 :     found:
   10350                 :             : 
   10351                 :             :       /* If we found RTTI_BINFO, this is case 1.  If we found a virtual
   10352                 :             :          base B and it is a base of RTTI_BINFO, this is case 2.  In
   10353                 :             :          either case, we share our vtable with LAST, i.e. the
   10354                 :             :          derived-most base within B of which we are a primary.  */
   10355                 :       72311 :       if (b == rtti_binfo
   10356                 :       72311 :           || (b && binfo_for_vbase (BINFO_TYPE (b), BINFO_TYPE (rtti_binfo))))
   10357                 :             :         /* Just set our BINFO_VTABLE to point to LAST, as we may not have
   10358                 :             :            set LAST's BINFO_VTABLE yet.  We'll extract the actual vptr in
   10359                 :             :            binfo_ctor_vtable after everything's been set up.  */
   10360                 :             :         vtbl = last;
   10361                 :             : 
   10362                 :             :       /* Otherwise, this is case 3 and we get our own.  */
   10363                 :             :     }
   10364                 :     5279298 :   else if (!BINFO_NEW_VTABLE_MARKED (orig_binfo))
   10365                 :             :     return;
   10366                 :             : 
   10367                 :     2600156 :   n_inits = vec_safe_length (*l);
   10368                 :             : 
   10369                 :     2600156 :   if (!vtbl)
   10370                 :             :     {
   10371                 :     2528767 :       tree index;
   10372                 :     2528767 :       int non_fn_entries;
   10373                 :             : 
   10374                 :             :       /* Add the initializer for this vtable.  */
   10375                 :     2528767 :       build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo,
   10376                 :             :                               &non_fn_entries, l);
   10377                 :             : 
   10378                 :             :       /* Figure out the position to which the VPTR should point.  */
   10379                 :     2528767 :       vtbl = build1 (ADDR_EXPR, vtbl_ptr_type_node, orig_vtbl);
   10380                 :     2528767 :       index = size_binop (MULT_EXPR,
   10381                 :             :                           TYPE_SIZE_UNIT (vtable_entry_type),
   10382                 :             :                           size_int (non_fn_entries + n_inits));
   10383                 :     2528767 :       vtbl = fold_build_pointer_plus (vtbl, index);
   10384                 :             :     }
   10385                 :             : 
   10386                 :     2600156 :   if (ctor_vtbl_p)
   10387                 :             :     /* For a construction vtable, we can't overwrite BINFO_VTABLE.
   10388                 :             :        So, we make a TREE_LIST.  Later, dfs_fixup_binfo_vtbls will
   10389                 :             :        straighten this out.  */
   10390                 :      681681 :     BINFO_VTABLE (binfo) = tree_cons (rtti_binfo, vtbl, BINFO_VTABLE (binfo));
   10391                 :     1918475 :   else if (BINFO_PRIMARY_P (binfo) && BINFO_VIRTUAL_P (binfo))
   10392                 :             :     /* Throw away any unneeded intializers.  */
   10393                 :        8020 :     (*l)->truncate (n_inits);
   10394                 :             :   else
   10395                 :             :      /* For an ordinary vtable, set BINFO_VTABLE.  */
   10396                 :     1910455 :     BINFO_VTABLE (binfo) = vtbl;
   10397                 :             : }
   10398                 :             : 
   10399                 :             : static GTY(()) tree abort_fndecl_addr;
   10400                 :             : static GTY(()) tree dvirt_fn;
   10401                 :             : 
   10402                 :             : /* Construct the initializer for BINFO's virtual function table.  BINFO
   10403                 :             :    is part of the hierarchy dominated by T.  If we're building a
   10404                 :             :    construction vtable, the ORIG_BINFO is the binfo we should use to
   10405                 :             :    find the actual function pointers to put in the vtable - but they
   10406                 :             :    can be overridden on the path to most-derived in the graph that
   10407                 :             :    ORIG_BINFO belongs.  Otherwise,
   10408                 :             :    ORIG_BINFO should be the same as BINFO.  The RTTI_BINFO is the
   10409                 :             :    BINFO that should be indicated by the RTTI information in the
   10410                 :             :    vtable; it will be a base class of T, rather than T itself, if we
   10411                 :             :    are building a construction vtable.
   10412                 :             : 
   10413                 :             :    The value returned is a TREE_LIST suitable for wrapping in a
   10414                 :             :    CONSTRUCTOR to use as the DECL_INITIAL for a vtable.  If
   10415                 :             :    NON_FN_ENTRIES_P is not NULL, *NON_FN_ENTRIES_P is set to the
   10416                 :             :    number of non-function entries in the vtable.
   10417                 :             : 
   10418                 :             :    It might seem that this function should never be called with a
   10419                 :             :    BINFO for which BINFO_PRIMARY_P holds, the vtable for such a
   10420                 :             :    base is always subsumed by a derived class vtable.  However, when
   10421                 :             :    we are building construction vtables, we do build vtables for
   10422                 :             :    primary bases; we need these while the primary base is being
   10423                 :             :    constructed.  */
   10424                 :             : 
   10425                 :             : static void
   10426                 :     2528767 : build_vtbl_initializer (tree binfo,
   10427                 :             :                         tree orig_binfo,
   10428                 :             :                         tree t,
   10429                 :             :                         tree rtti_binfo,
   10430                 :             :                         int* non_fn_entries_p,
   10431                 :             :                         vec<constructor_elt, va_gc> **inits)
   10432                 :             : {
   10433                 :     2528767 :   tree v;
   10434                 :     2528767 :   vtbl_init_data vid;
   10435                 :     2528767 :   unsigned ix, jx;
   10436                 :     2528767 :   tree vbinfo;
   10437                 :     2528767 :   vec<tree, va_gc> *vbases;
   10438                 :     2528767 :   constructor_elt *e;
   10439                 :             : 
   10440                 :             :   /* Initialize VID.  */
   10441                 :     2528767 :   memset (&vid, 0, sizeof (vid));
   10442                 :     2528767 :   vid.binfo = binfo;
   10443                 :     2528767 :   vid.derived = t;
   10444                 :     2528767 :   vid.rtti_binfo = rtti_binfo;
   10445                 :     2528767 :   vid.primary_vtbl_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
   10446                 :     2528767 :   vid.ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
   10447                 :     2528767 :   vid.generate_vcall_entries = true;
   10448                 :             :   /* The first vbase or vcall offset is at index -3 in the vtable.  */
   10449                 :     2528767 :   vid.index = ssize_int(-3 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
   10450                 :             : 
   10451                 :             :   /* Add entries to the vtable for RTTI.  */
   10452                 :     2528767 :   build_rtti_vtbl_entries (binfo, &vid);
   10453                 :             : 
   10454                 :             :   /* Create an array for keeping track of the functions we've
   10455                 :             :      processed.  When we see multiple functions with the same
   10456                 :             :      signature, we share the vcall offsets.  */
   10457                 :     2528767 :   vec_alloc (vid.fns, 32);
   10458                 :             :   /* Add the vcall and vbase offset entries.  */
   10459                 :     2528767 :   build_vcall_and_vbase_vtbl_entries (binfo, &vid);
   10460                 :             : 
   10461                 :             :   /* Clear BINFO_VTABLE_PATH_MARKED; it's set by
   10462                 :             :      build_vbase_offset_vtbl_entries.  */
   10463                 :     2528767 :   for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
   10464                 :     8931135 :        vec_safe_iterate (vbases, ix, &vbinfo); ix++)
   10465                 :     6402368 :     BINFO_VTABLE_PATH_MARKED (vbinfo) = 0;
   10466                 :             : 
   10467                 :             :   /* If the target requires padding between data entries, add that now.  */
   10468                 :     2528767 :   if (TARGET_VTABLE_DATA_ENTRY_DISTANCE > 1)
   10469                 :             :     {
   10470                 :             :       int n_entries = vec_safe_length (vid.inits);
   10471                 :             : 
   10472                 :             :       vec_safe_grow (vid.inits, TARGET_VTABLE_DATA_ENTRY_DISTANCE * n_entries,
   10473                 :             :                      true);
   10474                 :             : 
   10475                 :             :       /* Move data entries into their new positions and add padding
   10476                 :             :          after the new positions.  Iterate backwards so we don't
   10477                 :             :          overwrite entries that we would need to process later.  */
   10478                 :             :       for (ix = n_entries - 1;
   10479                 :             :            vid.inits->iterate (ix, &e);
   10480                 :             :            ix--)
   10481                 :             :         {
   10482                 :             :           int j;
   10483                 :             :           int new_position = (TARGET_VTABLE_DATA_ENTRY_DISTANCE * ix
   10484                 :             :                               + (TARGET_VTABLE_DATA_ENTRY_DISTANCE - 1));
   10485                 :             : 
   10486                 :             :           (*vid.inits)[new_position] = *e;
   10487                 :             : 
   10488                 :             :           for (j = 1; j < TARGET_VTABLE_DATA_ENTRY_DISTANCE; ++j)
   10489                 :             :             {
   10490                 :             :               constructor_elt *f = &(*vid.inits)[new_position - j];
   10491                 :             :               f->index = NULL_TREE;
   10492                 :             :               f->value = build1 (NOP_EXPR, vtable_entry_type,
   10493                 :             :                                  null_pointer_node);
   10494                 :             :             }
   10495                 :             :         }
   10496                 :             :     }
   10497                 :             : 
   10498                 :     2528767 :   if (non_fn_entries_p)
   10499                 :     5057534 :     *non_fn_entries_p = vec_safe_length (vid.inits);
   10500                 :             : 
   10501                 :             :   /* The initializers for virtual functions were built up in reverse
   10502                 :             :      order.  Straighten them out and add them to the running list in one
   10503                 :             :      step.  */
   10504                 :     2528767 :   jx = vec_safe_length (*inits);
   10505                 :     2528767 :   vec_safe_grow (*inits, jx + vid.inits->length (), true);
   10506                 :             : 
   10507                 :     2528767 :   for (ix = vid.inits->length () - 1;
   10508                 :    10234711 :        vid.inits->iterate (ix, &e);
   10509                 :     7705944 :        ix--, jx++)
   10510                 :     7705944 :     (**inits)[jx] = *e;
   10511                 :             : 
   10512                 :             :   /* Go through all the ordinary virtual functions, building up
   10513                 :             :      initializers.  */
   10514                 :    13625975 :   for (v = BINFO_VIRTUALS (orig_binfo); v; v = TREE_CHAIN (v))
   10515                 :             :     {
   10516                 :    11097208 :       tree delta;
   10517                 :    11097208 :       tree vcall_index;
   10518                 :    11097208 :       tree fn, fn_original;
   10519                 :    11097208 :       tree init = NULL_TREE;
   10520                 :             : 
   10521                 :    11097208 :       fn = BV_FN (v);
   10522                 :    11097208 :       fn_original = fn;
   10523                 :    11097208 :       if (DECL_THUNK_P (fn))
   10524                 :             :         {
   10525                 :         476 :           if (!DECL_NAME (fn))
   10526                 :         214 :             finish_thunk (fn);
   10527                 :         476 :           if (THUNK_ALIAS (fn))
   10528                 :             :             {
   10529                 :           0 :               fn = THUNK_ALIAS (fn);
   10530                 :           0 :               BV_FN (v) = fn;
   10531                 :             :             }
   10532                 :         476 :           fn_original = THUNK_TARGET (fn);
   10533                 :             :         }
   10534                 :             : 
   10535                 :             :       /* If the only definition of this function signature along our
   10536                 :             :          primary base chain is from a lost primary, this vtable slot will
   10537                 :             :          never be used, so just zero it out.  This is important to avoid
   10538                 :             :          requiring extra thunks which cannot be generated with the function.
   10539                 :             : 
   10540                 :             :          We first check this in update_vtable_entry_for_fn, so we handle
   10541                 :             :          restored primary bases properly; we also need to do it here so we
   10542                 :             :          zero out unused slots in ctor vtables, rather than filling them
   10543                 :             :          with erroneous values (though harmless, apart from relocation
   10544                 :             :          costs).  */
   10545                 :    11097208 :       if (BV_LOST_PRIMARY (v))
   10546                 :         745 :         init = size_zero_node;
   10547                 :             : 
   10548                 :         745 :       if (! init)
   10549                 :             :         {
   10550                 :             :           /* Pull the offset for `this', and the function to call, out of
   10551                 :             :              the list.  */
   10552                 :    11096463 :           delta = BV_DELTA (v);
   10553                 :    11096463 :           vcall_index = BV_VCALL_INDEX (v);
   10554                 :             : 
   10555                 :    11096463 :           gcc_assert (TREE_CODE (delta) == INTEGER_CST);
   10556                 :    11096463 :           gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
   10557                 :             : 
   10558                 :             :           /* You can't call an abstract virtual function; it's abstract.
   10559                 :             :              So, we replace these functions with __pure_virtual.  */
   10560                 :    11096463 :           if (DECL_PURE_VIRTUAL_P (fn_original))
   10561                 :             :             {
   10562                 :      639436 :               fn = abort_fndecl;
   10563                 :      639436 :               if (!TARGET_VTABLE_USES_DESCRIPTORS)
   10564                 :             :                 {
   10565                 :      639436 :                   if (abort_fndecl_addr == NULL)
   10566                 :       13446 :                     abort_fndecl_addr
   10567                 :       13446 :                       = fold_convert (vfunc_ptr_type_node,
   10568                 :             :                                       build_fold_addr_expr (fn));
   10569                 :      639436 :                   init = abort_fndecl_addr;
   10570                 :             :                 }
   10571                 :             :             }
   10572                 :             :           /* Likewise for deleted virtuals.  */
   10573                 :    10457027 :           else if (DECL_DELETED_FN (fn_original))
   10574                 :             :             {
   10575                 :          45 :               if (!dvirt_fn)
   10576                 :             :                 {
   10577                 :          22 :                   tree name = get_identifier ("__cxa_deleted_virtual");
   10578                 :          22 :                   dvirt_fn = get_global_binding (name);
   10579                 :          22 :                   if (!dvirt_fn)
   10580                 :          22 :                     dvirt_fn = push_library_fn
   10581                 :          22 :                       (name,
   10582                 :             :                        build_function_type_list (void_type_node, NULL_TREE),
   10583                 :             :                        NULL_TREE, ECF_NORETURN | ECF_COLD);
   10584                 :             :                 }
   10585                 :          45 :               fn = dvirt_fn;
   10586                 :          45 :               if (!TARGET_VTABLE_USES_DESCRIPTORS)
   10587                 :          45 :                 init = fold_convert (vfunc_ptr_type_node,
   10588                 :             :                                      build_fold_addr_expr (fn));
   10589                 :             :             }
   10590                 :             :           else
   10591                 :             :             {
   10592                 :    10456982 :               if (!integer_zerop (delta) || vcall_index)
   10593                 :             :                 {
   10594                 :     1053478 :                   fn = make_thunk (fn, /*this_adjusting=*/1,
   10595                 :             :                                    delta, vcall_index);
   10596                 :     1053478 :                   if (!DECL_NAME (fn))
   10597                 :      490263 :                     finish_thunk (fn);
   10598                 :             :                 }
   10599                 :             :               /* Take the address of the function, considering it to be of an
   10600                 :             :                  appropriate generic type.  */
   10601                 :    10456982 :               if (!TARGET_VTABLE_USES_DESCRIPTORS)
   10602                 :    10456982 :                 init = fold_convert (vfunc_ptr_type_node,
   10603                 :             :                                      build_fold_addr_expr (fn));
   10604                 :             :               /* Don't refer to a virtual destructor from a constructor
   10605                 :             :                  vtable or a vtable for an abstract class, since destroying
   10606                 :             :                  an object under construction is undefined behavior and we
   10607                 :             :                  don't want it to be considered a candidate for speculative
   10608                 :             :                  devirtualization.  But do create the thunk for ABI
   10609                 :             :                  compliance.  */
   10610                 :    10456982 :               if (DECL_DESTRUCTOR_P (fn_original)
   10611                 :    10456982 :                   && (CLASSTYPE_PURE_VIRTUALS (DECL_CONTEXT (fn_original))
   10612                 :     4428732 :                       || orig_binfo != binfo))
   10613                 :     1327700 :                 init = size_zero_node;
   10614                 :             :             }
   10615                 :             :         }
   10616                 :             : 
   10617                 :             :       /* And add it to the chain of initializers.  */
   10618                 :    11097208 :       if (TARGET_VTABLE_USES_DESCRIPTORS)
   10619                 :             :         {
   10620                 :             :           int i;
   10621                 :             :           if (init == size_zero_node)
   10622                 :             :             for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
   10623                 :             :               CONSTRUCTOR_APPEND_ELT (*inits, size_int (jx++), init);
   10624                 :             :           else
   10625                 :             :             for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
   10626                 :             :               {
   10627                 :             :                 tree fdesc = build2 (FDESC_EXPR, vfunc_ptr_type_node,
   10628                 :             :                                      fn, build_int_cst (NULL_TREE, i));
   10629                 :             :                 TREE_CONSTANT (fdesc) = 1;
   10630                 :             : 
   10631                 :             :                 CONSTRUCTOR_APPEND_ELT (*inits, size_int (jx++), fdesc);
   10632                 :             :               }
   10633                 :             :         }
   10634                 :             :       else
   10635                 :    11097208 :         CONSTRUCTOR_APPEND_ELT (*inits, size_int (jx++), init);
   10636                 :             :     }
   10637                 :     2528767 : }
   10638                 :             : 
   10639                 :             : /* Adds to vid->inits the initializers for the vbase and vcall
   10640                 :             :    offsets in BINFO, which is in the hierarchy dominated by T.  */
   10641                 :             : 
   10642                 :             : static void
   10643                 :     5363955 : build_vcall_and_vbase_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10644                 :             : {
   10645                 :     5363955 :   tree b;
   10646                 :             : 
   10647                 :             :   /* If this is a derived class, we must first create entries
   10648                 :             :      corresponding to the primary base class.  */
   10649                 :     5363955 :   b = get_primary_binfo (binfo);
   10650                 :     5363955 :   if (b)
   10651                 :     2835188 :     build_vcall_and_vbase_vtbl_entries (b, vid);
   10652                 :             : 
   10653                 :             :   /* Add the vbase entries for this base.  */
   10654                 :     5363955 :   build_vbase_offset_vtbl_entries (binfo, vid);
   10655                 :             :   /* Add the vcall entries for this base.  */
   10656                 :     5363955 :   build_vcall_offset_vtbl_entries (binfo, vid);
   10657                 :     5363955 : }
   10658                 :             : 
   10659                 :             : /* Returns the initializers for the vbase offset entries in the vtable
   10660                 :             :    for BINFO (which is part of the class hierarchy dominated by T), in
   10661                 :             :    reverse order.  VBASE_OFFSET_INDEX gives the vtable index
   10662                 :             :    where the next vbase offset will go.  */
   10663                 :             : 
   10664                 :             : static void
   10665                 :     5363955 : build_vbase_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10666                 :             : {
   10667                 :     5363955 :   tree vbase;
   10668                 :     5363955 :   tree t;
   10669                 :     5363955 :   tree non_primary_binfo;
   10670                 :             : 
   10671                 :             :   /* If there are no virtual baseclasses, then there is nothing to
   10672                 :             :      do.  */
   10673                 :     5363955 :   if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
   10674                 :             :     return;
   10675                 :             : 
   10676                 :      939840 :   t = vid->derived;
   10677                 :             : 
   10678                 :             :   /* We might be a primary base class.  Go up the inheritance hierarchy
   10679                 :             :      until we find the most derived class of which we are a primary base:
   10680                 :             :      it is the offset of that which we need to use.  */
   10681                 :      939840 :   non_primary_binfo = binfo;
   10682                 :     1472660 :   while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
   10683                 :             :     {
   10684                 :      884141 :       tree b;
   10685                 :             : 
   10686                 :             :       /* If we have reached a virtual base, then it must be a primary
   10687                 :             :          base (possibly multi-level) of vid->binfo, or we wouldn't
   10688                 :             :          have called build_vcall_and_vbase_vtbl_entries for it.  But it
   10689                 :             :          might be a lost primary, so just skip down to vid->binfo.  */
   10690                 :      884141 :       if (BINFO_VIRTUAL_P (non_primary_binfo))
   10691                 :             :         {
   10692                 :      184550 :           non_primary_binfo = vid->binfo;
   10693                 :      184550 :           break;
   10694                 :             :         }
   10695                 :             : 
   10696                 :      699591 :       b = BINFO_INHERITANCE_CHAIN (non_primary_binfo);
   10697                 :      699591 :       if (get_primary_binfo (b) != non_primary_binfo)
   10698                 :             :         break;
   10699                 :             :       non_primary_binfo = b;
   10700                 :             :     }
   10701                 :             : 
   10702                 :             :   /* Go through the virtual bases, adding the offsets.  */
   10703                 :      939840 :   for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
   10704                 :     5665049 :        vbase;
   10705                 :     4725209 :        vbase = TREE_CHAIN (vbase))
   10706                 :             :     {
   10707                 :     4725209 :       tree b;
   10708                 :     4725209 :       tree delta;
   10709                 :             : 
   10710                 :     4725209 :       if (!BINFO_VIRTUAL_P (vbase))
   10711                 :     2202931 :         continue;
   10712                 :             : 
   10713                 :             :       /* Find the instance of this virtual base in the complete
   10714                 :             :          object.  */
   10715                 :     2522278 :       b = copied_binfo (vbase, binfo);
   10716                 :             : 
   10717                 :             :       /* If we've already got an offset for this virtual base, we
   10718                 :             :          don't need another one.  */
   10719                 :     2522278 :       if (BINFO_VTABLE_PATH_MARKED (b))
   10720                 :      312384 :         continue;
   10721                 :     2209894 :       BINFO_VTABLE_PATH_MARKED (b) = 1;
   10722                 :             : 
   10723                 :             :       /* Figure out where we can find this vbase offset.  */
   10724                 :     2209894 :       delta = size_binop (MULT_EXPR,
   10725                 :             :                           vid->index,
   10726                 :             :                           fold_convert (ssizetype,
   10727                 :             :                                    TYPE_SIZE_UNIT (vtable_entry_type)));
   10728                 :     2209894 :       if (vid->primary_vtbl_p)
   10729                 :      200557 :         BINFO_VPTR_FIELD (b) = delta;
   10730                 :             : 
   10731                 :     2209894 :       if (binfo != TYPE_BINFO (t))
   10732                 :             :         /* The vbase offset had better be the same.  */
   10733                 :     2151943 :         gcc_assert (tree_int_cst_equal (delta, BINFO_VPTR_FIELD (vbase)));
   10734                 :             : 
   10735                 :             :       /* The next vbase will come at a more negative offset.  */
   10736                 :     2209894 :       vid->index = size_binop (MINUS_EXPR, vid->index,
   10737                 :             :                                ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
   10738                 :             : 
   10739                 :             :       /* The initializer is the delta from BINFO to this virtual base.
   10740                 :             :          The vbase offsets go in reverse inheritance-graph order, and
   10741                 :             :          we are walking in inheritance graph order so these end up in
   10742                 :             :          the right order.  */
   10743                 :     2209894 :       delta = size_diffop_loc (input_location,
   10744                 :     2209894 :                            BINFO_OFFSET (b), BINFO_OFFSET (non_primary_binfo));
   10745                 :             : 
   10746                 :     6935103 :       CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE,
   10747                 :             :                               fold_build1_loc (input_location, NOP_EXPR,
   10748                 :             :                                                vtable_entry_type, delta));
   10749                 :             :     }
   10750                 :             : }
   10751                 :             : 
   10752                 :             : /* Adds the initializers for the vcall offset entries in the vtable
   10753                 :             :    for BINFO (which is part of the class hierarchy dominated by VID->DERIVED)
   10754                 :             :    to VID->INITS.  */
   10755                 :             : 
   10756                 :             : static void
   10757                 :     5363955 : build_vcall_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10758                 :             : {
   10759                 :             :   /* We only need these entries if this base is a virtual base.  We
   10760                 :             :      compute the indices -- but do not add to the vtable -- when
   10761                 :             :      building the main vtable for a class.  */
   10762                 :     5363955 :   if (binfo == TYPE_BINFO (vid->derived)
   10763                 :     9070195 :       || (BINFO_VIRTUAL_P (binfo)
   10764                 :             :           /* If BINFO is RTTI_BINFO, then (since BINFO does not
   10765                 :             :              correspond to VID->DERIVED), we are building a primary
   10766                 :             :              construction virtual table.  Since this is a primary
   10767                 :             :              virtual table, we do not need the vcall offsets for
   10768                 :             :              BINFO.  */
   10769                 :      606722 :           && binfo != vid->rtti_binfo))
   10770                 :             :     {
   10771                 :             :       /* We need a vcall offset for each of the virtual functions in this
   10772                 :             :          vtable.  For example:
   10773                 :             : 
   10774                 :             :            class A { virtual void f (); };
   10775                 :             :            class B1 : virtual public A { virtual void f (); };
   10776                 :             :            class B2 : virtual public A { virtual void f (); };
   10777                 :             :            class C: public B1, public B2 { virtual void f (); };
   10778                 :             : 
   10779                 :             :          A C object has a primary base of B1, which has a primary base of A.  A
   10780                 :             :          C also has a secondary base of B2, which no longer has a primary base
   10781                 :             :          of A.  So the B2-in-C construction vtable needs a secondary vtable for
   10782                 :             :          A, which will adjust the A* to a B2* to call f.  We have no way of
   10783                 :             :          knowing what (or even whether) this offset will be when we define B2,
   10784                 :             :          so we store this "vcall offset" in the A sub-vtable and look it up in
   10785                 :             :          a "virtual thunk" for B2::f.
   10786                 :             : 
   10787                 :             :          We need entries for all the functions in our primary vtable and
   10788                 :             :          in our non-virtual bases' secondary vtables.  */
   10789                 :     2251278 :       vid->vbase = binfo;
   10790                 :             :       /* If we are just computing the vcall indices -- but do not need
   10791                 :             :          the actual entries -- not that.  */
   10792                 :     2251278 :       if (!BINFO_VIRTUAL_P (binfo))
   10793                 :     1657715 :         vid->generate_vcall_entries = false;
   10794                 :             :       /* Now, walk through the non-virtual bases, adding vcall offsets.  */
   10795                 :     2251278 :       add_vcall_offset_vtbl_entries_r (binfo, vid);
   10796                 :             :     }
   10797                 :     5363955 : }
   10798                 :             : 
   10799                 :             : /* Build vcall offsets, starting with those for BINFO.  */
   10800                 :             : 
   10801                 :             : static void
   10802                 :     6106875 : add_vcall_offset_vtbl_entries_r (tree binfo, vtbl_init_data* vid)
   10803                 :             : {
   10804                 :     6106875 :   int i;
   10805                 :     6106875 :   tree primary_binfo;
   10806                 :     6106875 :   tree base_binfo;
   10807                 :             : 
   10808                 :             :   /* Don't walk into virtual bases -- except, of course, for the
   10809                 :             :      virtual base for which we are building vcall offsets.  Any
   10810                 :             :      primary virtual base will have already had its offsets generated
   10811                 :             :      through the recursion in build_vcall_and_vbase_vtbl_entries.  */
   10812                 :     6106875 :   if (BINFO_VIRTUAL_P (binfo) && vid->vbase != binfo)
   10813                 :     6106875 :     return;
   10814                 :             : 
   10815                 :             :   /* If BINFO has a primary base, process it first.  */
   10816                 :     5619358 :   primary_binfo = get_primary_binfo (binfo);
   10817                 :     5619358 :   if (primary_binfo)
   10818                 :     2785474 :     add_vcall_offset_vtbl_entries_r (primary_binfo, vid);
   10819                 :             : 
   10820                 :             :   /* Add BINFO itself to the list.  */
   10821                 :     5619358 :   add_vcall_offset_vtbl_entries_1 (binfo, vid);
   10822                 :             : 
   10823                 :             :   /* Scan the non-primary bases of BINFO.  */
   10824                 :    15094149 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
   10825                 :     3855433 :     if (base_binfo != primary_binfo)
   10826                 :     1070123 :       add_vcall_offset_vtbl_entries_r (base_binfo, vid);
   10827                 :             : }
   10828                 :             : 
   10829                 :             : /* Called from build_vcall_offset_vtbl_entries_r.  */
   10830                 :             : 
   10831                 :             : static void
   10832                 :     5619358 : add_vcall_offset_vtbl_entries_1 (tree binfo, vtbl_init_data* vid)
   10833                 :             : {
   10834                 :             :   /* Make entries for the rest of the virtuals.  */
   10835                 :     5619358 :   tree orig_fn;
   10836                 :             : 
   10837                 :             :   /* The ABI requires that the methods be processed in declaration
   10838                 :             :      order.  */
   10839                 :     5619358 :   for (orig_fn = TYPE_FIELDS (BINFO_TYPE (binfo));
   10840                 :   196156317 :        orig_fn;
   10841                 :   190536959 :        orig_fn = DECL_CHAIN (orig_fn))
   10842                 :   190536959 :     if (TREE_CODE (orig_fn) == FUNCTION_DECL && DECL_VINDEX (orig_fn))
   10843                 :    24151183 :       add_vcall_offset (orig_fn, binfo, vid);
   10844                 :     5619358 : }
   10845                 :             : 
   10846                 :             : /* Add a vcall offset entry for ORIG_FN to the vtable.  */
   10847                 :             : 
   10848                 :             : static void
   10849                 :    24151183 : add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
   10850                 :             : {
   10851                 :    24151183 :   size_t i;
   10852                 :    24151183 :   tree vcall_offset;
   10853                 :    24151183 :   tree derived_entry;
   10854                 :             : 
   10855                 :             :   /* If there is already an entry for a function with the same
   10856                 :             :      signature as FN, then we do not need a second vcall offset.
   10857                 :             :      Check the list of functions already present in the derived
   10858                 :             :      class vtable.  */
   10859                 :    66120181 :   FOR_EACH_VEC_SAFE_ELT (vid->fns, i, derived_entry)
   10860                 :             :     {
   10861                 :    57723997 :       if (same_signature_p (derived_entry, orig_fn)
   10862                 :             :           /* We only use one vcall offset for virtual destructors,
   10863                 :             :              even though there are two virtual table entries.  */
   10864                 :   109113047 :           || (DECL_DESTRUCTOR_P (derived_entry)
   10865                 :    38152026 :               && DECL_DESTRUCTOR_P (orig_fn)))
   10866                 :    24151183 :         return;
   10867                 :             :     }
   10868                 :             : 
   10869                 :             :   /* If we are building these vcall offsets as part of building
   10870                 :             :      the vtable for the most derived class, remember the vcall
   10871                 :             :      offset.  */
   10872                 :     8396184 :   if (vid->binfo == TYPE_BINFO (vid->derived))
   10873                 :             :     {
   10874                 :     7959760 :       tree_pair_s elt = {orig_fn, vid->index};
   10875                 :     7959760 :       vec_safe_push (CLASSTYPE_VCALL_INDICES (vid->derived), elt);
   10876                 :             :     }
   10877                 :             : 
   10878                 :             :   /* The next vcall offset will be found at a more negative
   10879                 :             :      offset.  */
   10880                 :     8396184 :   vid->index = size_binop (MINUS_EXPR, vid->index,
   10881                 :             :                            ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
   10882                 :             : 
   10883                 :             :   /* Keep track of this function.  */
   10884                 :     8396184 :   vec_safe_push (vid->fns, orig_fn);
   10885                 :             : 
   10886                 :     8396184 :   if (vid->generate_vcall_entries)
   10887                 :             :     {
   10888                 :      438516 :       tree base;
   10889                 :      438516 :       tree fn;
   10890                 :             : 
   10891                 :             :       /* Find the overriding function.  */
   10892                 :      438516 :       fn = find_final_overrider (vid->rtti_binfo, binfo, orig_fn);
   10893                 :      438516 :       if (fn == error_mark_node)
   10894                 :          27 :         vcall_offset = build_zero_cst (vtable_entry_type);
   10895                 :             :       else
   10896                 :             :         {
   10897                 :      438489 :           base = TREE_VALUE (fn);
   10898                 :             : 
   10899                 :             :           /* The vbase we're working on is a primary base of
   10900                 :             :              vid->binfo.  But it might be a lost primary, so its
   10901                 :             :              BINFO_OFFSET might be wrong, so we just use the
   10902                 :             :              BINFO_OFFSET from vid->binfo.  */
   10903                 :     1753956 :           vcall_offset = size_diffop_loc (input_location,
   10904                 :      438489 :                                       BINFO_OFFSET (base),
   10905                 :      438489 :                                       BINFO_OFFSET (vid->binfo));
   10906                 :      438489 :           vcall_offset = fold_build1_loc (input_location,
   10907                 :             :                                       NOP_EXPR, vtable_entry_type,
   10908                 :             :                                       vcall_offset);
   10909                 :             :         }
   10910                 :             :       /* Add the initializer to the vtable.  */
   10911                 :      438516 :       CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, vcall_offset);
   10912                 :             :     }
   10913                 :             : }
   10914                 :             : 
   10915                 :             : /* Return vtbl initializers for the RTTI entries corresponding to the
   10916                 :             :    BINFO's vtable.  The RTTI entries should indicate the object given
   10917                 :             :    by VID->rtti_binfo.  */
   10918                 :             : 
   10919                 :             : static void
   10920                 :     2528767 : build_rtti_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10921                 :             : {
   10922                 :     2528767 :   tree b;
   10923                 :     2528767 :   tree t;
   10924                 :     2528767 :   tree offset;
   10925                 :     2528767 :   tree decl;
   10926                 :     2528767 :   tree init;
   10927                 :             : 
   10928                 :     2528767 :   t = BINFO_TYPE (vid->rtti_binfo);
   10929                 :             : 
   10930                 :             :   /* To find the complete object, we will first convert to our most
   10931                 :             :      primary base, and then add the offset in the vtbl to that value.  */
   10932                 :     2528767 :   b = most_primary_binfo (binfo);
   10933                 :     2528767 :   offset = size_diffop_loc (input_location,
   10934                 :     2528767 :                         BINFO_OFFSET (vid->rtti_binfo), BINFO_OFFSET (b));
   10935                 :             : 
   10936                 :             :   /* The second entry is the address of the typeinfo object.  */
   10937                 :     2528767 :   if (flag_rtti)
   10938                 :     2525868 :     decl = build_address (get_tinfo_decl (t));
   10939                 :             :   else
   10940                 :        2899 :     decl = integer_zero_node;
   10941                 :             : 
   10942                 :             :   /* Convert the declaration to a type that can be stored in the
   10943                 :             :      vtable.  */
   10944                 :     2528767 :   init = build_nop (vfunc_ptr_type_node, decl);
   10945                 :     2528767 :   CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, init);
   10946                 :             : 
   10947                 :             :   /* Add the offset-to-top entry.  It comes earlier in the vtable than
   10948                 :             :      the typeinfo entry.  Convert the offset to look like a
   10949                 :             :      function pointer, so that we can put it in the vtable.  */
   10950                 :     2528767 :   init = build_nop (vfunc_ptr_type_node, offset);
   10951                 :     2528767 :   CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, init);
   10952                 :     2528767 : }
   10953                 :             : 
   10954                 :             : /* TRUE iff TYPE is uniquely derived from PARENT.  Ignores
   10955                 :             :    accessibility.  */
   10956                 :             : 
   10957                 :             : bool
   10958                 :        2855 : uniquely_derived_from_p (tree parent, tree type)
   10959                 :             : {
   10960                 :        2855 :   tree base = lookup_base (type, parent, ba_unique, NULL, tf_none);
   10961                 :        2855 :   return base && base != error_mark_node;
   10962                 :             : }
   10963                 :             : 
   10964                 :             : /* TRUE iff TYPE is publicly & uniquely derived from PARENT.  */
   10965                 :             : 
   10966                 :             : bool
   10967                 :        3678 : publicly_uniquely_derived_p (tree parent, tree type)
   10968                 :             : {
   10969                 :        3678 :   tree base = lookup_base (type, parent, ba_ignore_scope | ba_check,
   10970                 :             :                            NULL, tf_none);
   10971                 :        3678 :   return base && base != error_mark_node;
   10972                 :             : }
   10973                 :             : 
   10974                 :             : /* CTX1 and CTX2 are declaration contexts.  Return the innermost common
   10975                 :             :    class between them, if any.  */
   10976                 :             : 
   10977                 :             : tree
   10978                 :        2597 : common_enclosing_class (tree ctx1, tree ctx2)
   10979                 :             : {
   10980                 :        2597 :   if (!TYPE_P (ctx1) || !TYPE_P (ctx2))
   10981                 :             :     return NULL_TREE;
   10982                 :        2597 :   gcc_assert (ctx1 == TYPE_MAIN_VARIANT (ctx1)
   10983                 :             :               && ctx2 == TYPE_MAIN_VARIANT (ctx2));
   10984                 :        2597 :   if (ctx1 == ctx2)
   10985                 :             :     return ctx1;
   10986                 :         267 :   for (tree t = ctx1; TYPE_P (t); t = TYPE_CONTEXT (t))
   10987                 :         195 :     TYPE_MARKED_P (t) = true;
   10988                 :         129 :   tree found = NULL_TREE;
   10989                 :         129 :   for (tree t = ctx2; TYPE_P (t); t = TYPE_CONTEXT (t))
   10990                 :         129 :     if (TYPE_MARKED_P (t))
   10991                 :             :       {
   10992                 :             :         found = t;
   10993                 :             :         break;
   10994                 :             :       }
   10995                 :         267 :   for (tree t = ctx1; TYPE_P (t); t = TYPE_CONTEXT (t))
   10996                 :         195 :     TYPE_MARKED_P (t) = false;
   10997                 :             :   return found;
   10998                 :             : }
   10999                 :             : 
   11000                 :             : #include "gt-cp-class.h"
        

Generated by: LCOV version 2.1-beta

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