LCOV - code coverage report
Current view: top level - gcc/cp - class.cc (source / functions) Hit Total Coverage
Test: gcc.info Lines: 4064 4217 96.4 %
Date: 2023-07-19 08:18:47 Functions: 193 198 97.5 %

          Line data    Source code
       1             : /* Functions related to building -*- C++ -*- classes and their related objects.
       2             :    Copyright (C) 1987-2023 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 = false,
     145             :                              tree = NULL_TREE, 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             : 
     209             : /* Set CURRENT_ACCESS_SPECIFIER based on the protection of DECL.  */
     210             : 
     211             : void
     212   112063177 : set_current_access_from_decl (tree decl)
     213             : {
     214   112063177 :   if (TREE_PRIVATE (decl))
     215    10262526 :     current_access_specifier = access_private_node;
     216   101800651 :   else if (TREE_PROTECTED (decl))
     217     7680423 :     current_access_specifier = access_protected_node;
     218             :   else
     219    94120228 :     current_access_specifier = access_public_node;
     220   112063177 : }
     221             : 
     222             : /* Return a COND_EXPR that executes TRUE_STMT if this execution of the
     223             :    'structor is in charge of 'structing virtual bases, or FALSE_STMT
     224             :    otherwise.  */
     225             : 
     226             : tree
     227      138820 : build_if_in_charge (tree true_stmt, tree false_stmt)
     228             : {
     229      138820 :   gcc_assert (DECL_HAS_IN_CHARGE_PARM_P (current_function_decl));
     230      277640 :   tree cmp = build2 (NE_EXPR, boolean_type_node,
     231      138820 :                      current_in_charge_parm, integer_zero_node);
     232      138820 :   tree type = unlowered_expr_type (true_stmt);
     233      138820 :   if (VOID_TYPE_P (type))
     234        9828 :     type = unlowered_expr_type (false_stmt);
     235      138820 :   tree cond = build3 (COND_EXPR, type,
     236             :                       cmp, true_stmt, false_stmt);
     237      138820 :   return cond;
     238             : }
     239             : 
     240             : /* Convert to or from a base subobject.  EXPR is an expression of type
     241             :    `A' or `A*', an expression of type `B' or `B*' is returned.  To
     242             :    convert A to a base B, CODE is PLUS_EXPR and BINFO is the binfo for
     243             :    the B base instance within A.  To convert base A to derived B, CODE
     244             :    is MINUS_EXPR and BINFO is the binfo for the A instance within B.
     245             :    In this latter case, A must not be a morally virtual base of B.
     246             :    NONNULL is true if EXPR is known to be non-NULL (this is only
     247             :    needed when EXPR is of pointer type).  CV qualifiers are preserved
     248             :    from EXPR.  */
     249             : 
     250             : tree
     251    24357481 : build_base_path (enum tree_code code,
     252             :                  tree expr,
     253             :                  tree binfo,
     254             :                  int nonnull,
     255             :                  tsubst_flags_t complain)
     256             : {
     257    24357481 :   tree v_binfo = NULL_TREE;
     258    24357481 :   tree d_binfo = NULL_TREE;
     259    24357481 :   tree probe;
     260    24357481 :   tree offset;
     261    24357481 :   tree target_type;
     262    24357481 :   tree null_test = NULL;
     263    24357481 :   tree ptr_target_type;
     264    24357481 :   int fixed_type_p;
     265    24357481 :   int want_pointer = TYPE_PTR_P (TREE_TYPE (expr));
     266    24357481 :   bool has_empty = false;
     267    24357481 :   bool virtual_access;
     268    24357481 :   bool rvalue = false;
     269             : 
     270    24357481 :   if (expr == error_mark_node || binfo == error_mark_node || !binfo)
     271             :     return error_mark_node;
     272             : 
     273    53356278 :   for (probe = binfo; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
     274             :     {
     275    28998815 :       d_binfo = probe;
     276    28998815 :       if (is_empty_class (BINFO_TYPE (probe)))
     277     5216502 :         has_empty = true;
     278    28998815 :       if (!v_binfo && BINFO_VIRTUAL_P (probe))
     279             :         v_binfo = probe;
     280             :     }
     281             : 
     282    24357463 :   probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
     283    24357463 :   if (want_pointer)
     284    22410841 :     probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
     285    24357463 :   if (dependent_type_p (probe))
     286      206468 :     if (tree open = currently_open_class (probe))
     287    24357463 :       probe = open;
     288             : 
     289    24357463 :   if (code == PLUS_EXPR
     290    47597940 :       && !SAME_BINFO_TYPE_P (BINFO_TYPE (d_binfo), probe))
     291             :     {
     292             :       /* This can happen when adjust_result_of_qualified_name_lookup can't
     293             :          find a unique base binfo in a call to a member function.  We
     294             :          couldn't give the diagnostic then since we might have been calling
     295             :          a static member function, so we do it now.  In other cases, eg.
     296             :          during error recovery (c++/71979), we may not have a base at all.  */
     297           7 :       if (complain & tf_error)
     298             :         {
     299           7 :           tree base = lookup_base (probe, BINFO_TYPE (d_binfo),
     300             :                                    ba_unique, NULL, complain);
     301           7 :           gcc_assert (base == error_mark_node || !base);
     302             :         }
     303           7 :       return error_mark_node;
     304             :     }
     305             : 
     306    25474442 :   gcc_assert ((code == MINUS_EXPR
     307             :                && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), probe))
     308             :               || code == PLUS_EXPR);
     309             : 
     310    24357456 :   if (binfo == d_binfo)
     311             :     /* Nothing to do.  */
     312             :     return expr;
     313             : 
     314     4394077 :   if (code == MINUS_EXPR && v_binfo)
     315             :     {
     316          15 :       if (complain & tf_error)
     317             :         {
     318          11 :           if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (v_binfo)))
     319             :             {
     320          11 :               if (want_pointer)
     321          22 :                 error ("cannot convert from pointer to base class %qT to "
     322             :                        "pointer to derived class %qT because the base is "
     323          11 :                        "virtual", BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
     324             :               else
     325           0 :                 error ("cannot convert from base class %qT to derived "
     326             :                        "class %qT because the base is virtual",
     327           0 :                        BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
     328             :             }         
     329             :           else
     330             :             {
     331           0 :               if (want_pointer)
     332           0 :                 error ("cannot convert from pointer to base class %qT to "
     333             :                        "pointer to derived class %qT via virtual base %qT",
     334           0 :                        BINFO_TYPE (binfo), BINFO_TYPE (d_binfo),
     335           0 :                        BINFO_TYPE (v_binfo));
     336             :               else
     337           0 :                 error ("cannot convert from base class %qT to derived "
     338           0 :                        "class %qT via virtual base %qT", BINFO_TYPE (binfo),
     339           0 :                        BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo));
     340             :             }
     341             :         }
     342          15 :       return error_mark_node;
     343             :     }
     344             : 
     345     8788124 :   bool uneval = (cp_unevaluated_operand != 0
     346     4268989 :                  || processing_template_decl
     347     8418894 :                  || in_template_context);
     348             : 
     349             :   /* For a non-pointer simple base reference, express it as a COMPONENT_REF
     350             :      without taking its address (and so causing lambda capture, 91933).  */
     351     4394062 :   if (code == PLUS_EXPR && !v_binfo && !want_pointer && !has_empty && !uneval)
     352     1239963 :     return build_simple_base_path (expr, binfo);
     353             : 
     354     3154099 :   if (!want_pointer)
     355             :     {
     356      698594 :       rvalue = !lvalue_p (expr);
     357             :       /* This must happen before the call to save_expr.  */
     358      698594 :       expr = cp_build_addr_expr (expr, complain);
     359             :     }
     360             :   else
     361     2455505 :     expr = mark_rvalue_use (expr);
     362             : 
     363     3154099 :   offset = BINFO_OFFSET (binfo);
     364     3154099 :   fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
     365     6308198 :   target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo);
     366             :   /* TARGET_TYPE has been extracted from BINFO, and, is therefore always
     367             :      cv-unqualified.  Extract the cv-qualifiers from EXPR so that the
     368             :      expression returned matches the input.  */
     369     3154099 :   target_type = cp_build_qualified_type
     370     3154099 :     (target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr))));
     371     3154099 :   ptr_target_type = build_pointer_type (target_type);
     372             : 
     373             :   /* Do we need to look in the vtable for the real offset?  */
     374     3154099 :   virtual_access = (v_binfo && fixed_type_p <= 0);
     375             : 
     376             :   /* Don't bother with the calculations inside sizeof; they'll ICE if the
     377             :      source type is incomplete and the pointer value doesn't matter.  In a
     378             :      template (even in instantiate_non_dependent_expr), we don't have vtables
     379             :      set up properly yet, and the value doesn't matter there either; we're
     380             :      just interested in the result of overload resolution.  */
     381     3154099 :   if (uneval)
     382             :     {
     383      370638 :       expr = build_nop (ptr_target_type, expr);
     384      370638 :       goto indout;
     385             :     }
     386             : 
     387     2783461 :   if (!COMPLETE_TYPE_P (probe))
     388             :     {
     389           6 :       if (complain & tf_error)
     390          18 :         error ("cannot convert from %qT to base class %qT because %qT is "
     391           6 :                "incomplete", BINFO_TYPE (d_binfo), BINFO_TYPE (binfo),
     392           6 :                BINFO_TYPE (d_binfo));
     393           6 :       return error_mark_node;
     394             :     }
     395             : 
     396             :   /* If we're in an NSDMI, we don't have the full constructor context yet
     397             :      that we need for converting to a virtual base, so just build a stub
     398             :      CONVERT_EXPR and expand it later in bot_replace.  */
     399     2783455 :   if (virtual_access && fixed_type_p < 0
     400     2783455 :       && current_scope () != current_function_decl)
     401             :     {
     402          33 :       expr = build1 (CONVERT_EXPR, ptr_target_type, expr);
     403          33 :       CONVERT_EXPR_VBASE_PATH (expr) = true;
     404          33 :       goto indout;
     405             :     }
     406             : 
     407             :   /* Do we need to check for a null pointer?  */
     408     2783422 :   if (want_pointer && !nonnull)
     409             :     {
     410             :       /* If we know the conversion will not actually change the value
     411             :          of EXPR, then we can avoid testing the expression for NULL.
     412             :          We have to avoid generating a COMPONENT_REF for a base class
     413             :          field, because other parts of the compiler know that such
     414             :          expressions are always non-NULL.  */
     415       68211 :       if (!virtual_access && integer_zerop (offset))
     416       65947 :         return build_nop (ptr_target_type, expr);
     417        2264 :       null_test = error_mark_node;
     418             :     }
     419             : 
     420             :   /* Protect against multiple evaluation if necessary.  */
     421     2717475 :   if (TREE_SIDE_EFFECTS (expr) && (null_test || virtual_access))
     422         357 :     expr = save_expr (expr);
     423             : 
     424             :   /* Store EXPR and build the real null test just before returning.  */
     425     2717475 :   if (null_test)
     426        2264 :     null_test = expr;
     427             : 
     428             :   /* If this is a simple base reference, express it as a COMPONENT_REF.  */
     429     2717475 :   if (code == PLUS_EXPR && !virtual_access
     430             :       /* We don't build base fields for empty bases, and they aren't very
     431             :          interesting to the optimizers anyway.  */
     432     2646569 :       && !has_empty)
     433             :     {
     434     1436118 :       expr = cp_build_fold_indirect_ref (expr);
     435     1436118 :       expr = build_simple_base_path (expr, binfo);
     436     1436118 :       if (rvalue && lvalue_p (expr))
     437           0 :         expr = move (expr);
     438     1436118 :       if (want_pointer)
     439     1435253 :         expr = build_address (expr);
     440     1436118 :       target_type = TREE_TYPE (expr);
     441     1436118 :       goto out;
     442             :     }
     443             : 
     444     1281357 :   if (virtual_access)
     445             :     {
     446             :       /* Going via virtual base V_BINFO.  We need the static offset
     447             :          from V_BINFO to BINFO, and the dynamic offset from D_BINFO to
     448             :          V_BINFO.  That offset is an entry in D_BINFO's vtable.  */
     449       47406 :       tree v_offset;
     450             : 
     451       47406 :       if (fixed_type_p < 0 && in_base_initializer)
     452             :         {
     453             :           /* In a base member initializer, we cannot rely on the
     454             :              vtable being set up.  We have to indirect via the
     455             :              vtt_parm.  */
     456           8 :           tree t;
     457             : 
     458           8 :           t = TREE_TYPE (TYPE_VFIELD (current_class_type));
     459           8 :           t = build_pointer_type (t);
     460           8 :           v_offset = fold_convert (t, current_vtt_parm);
     461           8 :           v_offset = cp_build_fold_indirect_ref (v_offset);
     462           8 :         }
     463             :       else
     464             :         {
     465       47398 :           tree t = expr;
     466       47398 :           if (sanitize_flags_p (SANITIZE_VPTR)
     467       47398 :               && fixed_type_p == 0)
     468             :             {
     469          40 :               t = cp_ubsan_maybe_instrument_cast_to_vbase (input_location,
     470             :                                                            probe, expr);
     471          40 :               if (t == NULL_TREE)
     472       47358 :                 t = expr;
     473             :             }
     474       47398 :           v_offset = build_vfield_ref (cp_build_fold_indirect_ref (t),
     475       47398 :           TREE_TYPE (TREE_TYPE (expr)));
     476             :         }
     477             : 
     478       47406 :       if (v_offset == error_mark_node)
     479             :         return error_mark_node;
     480             : 
     481       47406 :       v_offset = fold_build_pointer_plus (v_offset, BINFO_VPTR_FIELD (v_binfo));
     482       47406 :       v_offset = build1 (NOP_EXPR,
     483             :                          build_pointer_type (ptrdiff_type_node),
     484             :                          v_offset);
     485       47406 :       v_offset = cp_build_fold_indirect_ref (v_offset);
     486       47406 :       TREE_CONSTANT (v_offset) = 1;
     487             : 
     488       94812 :       offset = convert_to_integer (ptrdiff_type_node,
     489             :                                    size_diffop_loc (input_location, offset,
     490       47406 :                                                 BINFO_OFFSET (v_binfo)));
     491             : 
     492       47406 :       if (!integer_zerop (offset))
     493         657 :         v_offset = build2 (code, ptrdiff_type_node, v_offset, offset);
     494             : 
     495       47406 :       if (fixed_type_p < 0)
     496             :         /* Negative fixed_type_p means this is a constructor or destructor;
     497             :            virtual base layout is fixed in in-charge [cd]tors, but not in
     498             :            base [cd]tors.  */
     499       37619 :         offset = build_if_in_charge
     500       37619 :           (convert_to_integer (ptrdiff_type_node, BINFO_OFFSET (binfo)),
     501             :            v_offset);
     502             :       else
     503             :         offset = v_offset;
     504             :     }
     505             : 
     506     1281357 :   if (want_pointer)
     507     1281357 :     target_type = ptr_target_type;
     508             : 
     509     1281357 :   if (!integer_zerop (offset))
     510             :     {
     511       49091 :       offset = fold_convert (sizetype, offset);
     512       49091 :       if (code == MINUS_EXPR)
     513         362 :         offset = fold_build1_loc (input_location, NEGATE_EXPR, sizetype, offset);
     514       49091 :       expr = fold_build_pointer_plus (expr, offset);
     515             :     }
     516             :   else
     517             :     null_test = NULL;
     518             : 
     519     1281357 :   expr = build1 (NOP_EXPR, ptr_target_type, expr);
     520             : 
     521     1652028 :  indout:
     522     1652028 :   if (!want_pointer)
     523             :     {
     524      697729 :       expr = cp_build_fold_indirect_ref (expr);
     525      697729 :       if (rvalue)
     526      164975 :         expr = move (expr);
     527             :     }
     528             : 
     529      954299 :  out:
     530     3088146 :   if (null_test)
     531             :     /* Wrap EXPR in a null test.  */
     532        2264 :     expr = build_if_nonnull (null_test, expr, complain);
     533             : 
     534             :   return expr;
     535             : }
     536             : 
     537             : /* Subroutine of build_base_path; EXPR and BINFO are as in that function.
     538             :    Perform a derived-to-base conversion by recursively building up a
     539             :    sequence of COMPONENT_REFs to the appropriate base fields.  */
     540             : 
     541             : static tree
     542     9483033 : build_simple_base_path (tree expr, tree binfo)
     543             : {
     544     9483033 :   tree type = BINFO_TYPE (binfo);
     545     9483033 :   tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
     546     9483033 :   tree field;
     547             : 
     548     9483033 :   if (d_binfo == NULL_TREE)
     549             :     {
     550     4689058 :       tree temp;
     551             : 
     552     4689058 :       gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type);
     553             : 
     554             :       /* Transform `(a, b).x' into `(*(a, &b)).x', `(a ? b : c).x'
     555             :          into `(*(a ?  &b : &c)).x', and so on.  A COND_EXPR is only
     556             :          an lvalue in the front end; only _DECLs and _REFs are lvalues
     557             :          in the back end.  */
     558     4689058 :       temp = unary_complex_lvalue (ADDR_EXPR, expr);
     559     4689058 :       if (temp)
     560           0 :         expr = cp_build_fold_indirect_ref (temp);
     561             : 
     562     4689058 :       return expr;
     563             :     }
     564             : 
     565             :   /* Recurse.  */
     566     4793975 :   expr = build_simple_base_path (expr, d_binfo);
     567             : 
     568     4793975 :   for (field = TYPE_FIELDS (BINFO_TYPE (d_binfo));
     569    21852504 :        field; field = DECL_CHAIN (field))
     570             :     /* Is this the base field created by build_base_field?  */
     571    21852504 :     if (TREE_CODE (field) == FIELD_DECL
     572     5735333 :         && DECL_FIELD_IS_BASE (field)
     573     5708080 :         && TREE_TYPE (field) == type
     574             :         /* If we're looking for a field in the most-derived class,
     575             :            also check the field offset; we can have two base fields
     576             :            of the same type if one is an indirect virtual base and one
     577             :            is a direct non-virtual base.  */
     578    26646630 :         && (BINFO_INHERITANCE_CHAIN (d_binfo)
     579     4689209 :             || tree_int_cst_equal (byte_position (field),
     580     4689209 :                                    BINFO_OFFSET (binfo))))
     581             :       {
     582             :         /* We don't use build_class_member_access_expr here, as that
     583             :            has unnecessary checks, and more importantly results in
     584             :            recursive calls to dfs_walk_once.  */
     585     4793975 :         int type_quals = cp_type_quals (TREE_TYPE (expr));
     586             : 
     587     4793975 :         expr = build3 (COMPONENT_REF,
     588             :                        cp_build_qualified_type (type, type_quals),
     589             :                        expr, field, NULL_TREE);
     590             :         /* Mark the expression const or volatile, as appropriate.
     591             :            Even though we've dealt with the type above, we still have
     592             :            to mark the expression itself.  */
     593     4793975 :         if (type_quals & TYPE_QUAL_CONST)
     594      502396 :           TREE_READONLY (expr) = 1;
     595     4793975 :         if (type_quals & TYPE_QUAL_VOLATILE)
     596       14733 :           TREE_THIS_VOLATILE (expr) = 1;
     597             : 
     598     4793975 :         return expr;
     599             :       }
     600             : 
     601             :   /* Didn't find the base field?!?  */
     602           0 :   gcc_unreachable ();
     603             : }
     604             : 
     605             : /* Convert OBJECT to the base TYPE.  OBJECT is an expression whose
     606             :    type is a class type or a pointer to a class type.  In the former
     607             :    case, TYPE is also a class type; in the latter it is another
     608             :    pointer type.  If CHECK_ACCESS is true, an error message is emitted
     609             :    if TYPE is inaccessible.  If OBJECT has pointer type, the value is
     610             :    assumed to be non-NULL.  */
     611             : 
     612             : tree
     613      804975 : convert_to_base (tree object, tree type, bool check_access, bool nonnull,
     614             :                  tsubst_flags_t complain)
     615             : {
     616      804975 :   tree binfo;
     617      804975 :   tree object_type;
     618             : 
     619      804975 :   if (TYPE_PTR_P (TREE_TYPE (object)))
     620             :     {
     621      113482 :       object_type = TREE_TYPE (TREE_TYPE (object));
     622      113482 :       type = TREE_TYPE (type);
     623             :     }
     624             :   else
     625      691493 :     object_type = TREE_TYPE (object);
     626             : 
     627      806947 :   binfo = lookup_base (object_type, type, check_access ? ba_check : ba_unique,
     628             :                        NULL, complain);
     629      804975 :   if (!binfo || binfo == error_mark_node)
     630         104 :     return error_mark_node;
     631             : 
     632      804871 :   return build_base_path (PLUS_EXPR, object, binfo, nonnull, complain);
     633             : }
     634             : 
     635             : /* EXPR is an expression with unqualified class type.  BASE is a base
     636             :    binfo of that class type.  Returns EXPR, converted to the BASE
     637             :    type.  This function assumes that EXPR is the most derived class;
     638             :    therefore virtual bases can be found at their static offsets.  */
     639             : 
     640             : tree
     641     1203145 : convert_to_base_statically (tree expr, tree base)
     642             : {
     643     1203145 :   tree expr_type;
     644             : 
     645     1203145 :   expr_type = TREE_TYPE (expr);
     646     1203145 :   if (!SAME_BINFO_TYPE_P (BINFO_TYPE (base), expr_type))
     647             :     {
     648             :       /* If this is a non-empty base, use a COMPONENT_REF.  */
     649     1203145 :       if (!is_empty_class (BINFO_TYPE (base)))
     650      861300 :         return build_simple_base_path (expr, base);
     651             : 
     652             :       /* We use fold_build2 and fold_convert below to simplify the trees
     653             :          provided to the optimizers.  It is not safe to call these functions
     654             :          when processing a template because they do not handle C++-specific
     655             :          trees.  */
     656      341845 :       gcc_assert (!processing_template_decl);
     657      341845 :       expr = cp_build_addr_expr (expr, tf_warning_or_error);
     658      341845 :       if (!integer_zerop (BINFO_OFFSET (base)))
     659         252 :         expr = fold_build_pointer_plus_loc (input_location,
     660         252 :                                             expr, BINFO_OFFSET (base));
     661      341845 :       expr = fold_convert (build_pointer_type (BINFO_TYPE (base)), expr);
     662      341845 :       expr = build_fold_indirect_ref_loc (input_location, expr);
     663             :     }
     664             : 
     665             :   return expr;
     666             : }
     667             : 
     668             : /* True IFF EXPR is a reference to an empty base class "subobject", as built in
     669             :    convert_to_base_statically.  We look for the result of the fold_convert
     670             :    call, a NOP_EXPR from one pointer type to another, where the target is an
     671             :    empty base of the original type.  */
     672             : 
     673             : bool
     674    13879298 : is_empty_base_ref (tree expr)
     675             : {
     676    13879298 :   if (INDIRECT_REF_P (expr))
     677    11193132 :     expr = TREE_OPERAND (expr, 0);
     678    13879298 :   if (TREE_CODE (expr) != NOP_EXPR)
     679             :     return false;
     680      556335 :   tree type = TREE_TYPE (expr);
     681      556335 :   if (!POINTER_TYPE_P (type))
     682             :     return false;
     683      556335 :   type = TREE_TYPE (type);
     684      556335 :   if (!is_empty_class (type))
     685             :     return false;
     686      328026 :   STRIP_NOPS (expr);
     687      328026 :   tree fromtype = TREE_TYPE (expr);
     688      328026 :   if (!POINTER_TYPE_P (fromtype))
     689             :     return false;
     690      328026 :   fromtype = TREE_TYPE (fromtype);
     691      322891 :   return (CLASS_TYPE_P (fromtype)
     692      322891 :           && !same_type_ignoring_top_level_qualifiers_p (fromtype, type)
     693      650518 :           && DERIVED_FROM_P (type, fromtype));
     694             : }
     695             : 
     696             : tree
     697     1038804 : build_vfield_ref (tree datum, tree type)
     698             : {
     699     1038804 :   tree vfield, vcontext;
     700             : 
     701     1038804 :   if (datum == error_mark_node
     702             :       /* Can happen in case of duplicate base types (c++/59082).  */
     703     1038804 :       || !TYPE_VFIELD (type))
     704             :     return error_mark_node;
     705             : 
     706             :   /* First, convert to the requested type.  */
     707     1038804 :   if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (datum), type))
     708           0 :     datum = convert_to_base (datum, type, /*check_access=*/false,
     709             :                              /*nonnull=*/true, tf_warning_or_error);
     710             : 
     711             :   /* Second, the requested type may not be the owner of its own vptr.
     712             :      If not, convert to the base class that owns it.  We cannot use
     713             :      convert_to_base here, because VCONTEXT may appear more than once
     714             :      in the inheritance hierarchy of TYPE, and thus direct conversion
     715             :      between the types may be ambiguous.  Following the path back up
     716             :      one step at a time via primary bases avoids the problem.  */
     717     1038804 :   vfield = TYPE_VFIELD (type);
     718     1038804 :   vcontext = DECL_CONTEXT (vfield);
     719     2190481 :   while (!same_type_ignoring_top_level_qualifiers_p (vcontext, type))
     720             :     {
     721     1151677 :       datum = build_simple_base_path (datum, CLASSTYPE_PRIMARY_BINFO (type));
     722     1151677 :       type = TREE_TYPE (datum);
     723             :     }
     724             : 
     725     1038804 :   return build3 (COMPONENT_REF, TREE_TYPE (vfield), datum, vfield, NULL_TREE);
     726             : }
     727             : 
     728             : /* Given an object INSTANCE, return an expression which yields the
     729             :    vtable element corresponding to INDEX.  There are many special
     730             :    cases for INSTANCE which we take care of here, mainly to avoid
     731             :    creating extra tree nodes when we don't have to.  */
     732             : 
     733             : tree
     734      344340 : build_vtbl_ref (tree instance, tree idx)
     735             : {
     736      344340 :   tree aref;
     737      344340 :   tree vtbl = NULL_TREE;
     738             : 
     739             :   /* Try to figure out what a reference refers to, and
     740             :      access its virtual function table directly.  */
     741             : 
     742      344340 :   int cdtorp = 0;
     743      344340 :   tree fixed_type = fixed_type_or_null (instance, NULL, &cdtorp);
     744             : 
     745      344340 :   tree basetype = non_reference (TREE_TYPE (instance));
     746             : 
     747      344340 :   if (fixed_type && !cdtorp)
     748             :     {
     749         131 :       tree binfo = lookup_base (fixed_type, basetype,
     750             :                                 ba_unique, NULL, tf_none);
     751         131 :       if (binfo && binfo != error_mark_node)
     752         111 :         vtbl = unshare_expr (BINFO_VTABLE (binfo));
     753             :     }
     754             : 
     755         111 :   if (!vtbl)
     756      344307 :     vtbl = build_vfield_ref (instance, basetype);
     757             : 
     758      344340 :   aref = build_array_ref (input_location, vtbl, idx);
     759      688647 :   TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
     760             : 
     761      344340 :   return aref;
     762             : }
     763             : 
     764             : /* Given a stable object pointer INSTANCE_PTR, return an expression which
     765             :    yields a function pointer corresponding to vtable element INDEX.  */
     766             : 
     767             : tree
     768      343500 : build_vfn_ref (tree instance_ptr, tree idx)
     769             : {
     770      343500 :   tree aref;
     771             : 
     772      343500 :   aref = build_vtbl_ref (cp_build_fold_indirect_ref (instance_ptr), idx);
     773             : 
     774             :   /* When using function descriptors, the address of the
     775             :      vtable entry is treated as a function pointer.  */
     776      343500 :   if (TARGET_VTABLE_USES_DESCRIPTORS)
     777             :     aref = build1 (NOP_EXPR, TREE_TYPE (aref),
     778             :                    cp_build_addr_expr (aref, tf_warning_or_error));
     779             : 
     780             :   /* Remember this as a method reference, for later devirtualization.  */
     781      343500 :   aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr,
     782      343500 :                  fold_convert (TREE_TYPE (instance_ptr), idx));
     783             : 
     784      343500 :   return aref;
     785             : }
     786             : 
     787             : /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
     788             :    for the given TYPE.  */
     789             : 
     790             : static tree
     791     1176829 : get_vtable_name (tree type)
     792             : {
     793           0 :   return mangle_vtbl_for_type (type);
     794             : }
     795             : 
     796             : /* DECL is an entity associated with TYPE, like a virtual table or an
     797             :    implicitly generated constructor.  Determine whether or not DECL
     798             :    should have external or internal linkage at the object file
     799             :    level.  This routine does not deal with COMDAT linkage and other
     800             :    similar complexities; it simply sets TREE_PUBLIC if it possible for
     801             :    entities in other translation units to contain copies of DECL, in
     802             :    the abstract.  */
     803             : 
     804             : void
     805    16889849 : set_linkage_according_to_type (tree /*type*/, tree decl)
     806             : {
     807    16889849 :   TREE_PUBLIC (decl) = 1;
     808    15384277 :   determine_visibility (decl);
     809    15384277 : }
     810             : 
     811             : /* Create a VAR_DECL for a primary or secondary vtable for CLASS_TYPE.
     812             :    (For a secondary vtable for B-in-D, CLASS_TYPE should be D, not B.)
     813             :    Use NAME for the name of the vtable, and VTABLE_TYPE for its type.  */
     814             : 
     815             : static tree
     816     1505572 : build_vtable (tree class_type, tree name, tree vtable_type)
     817             : {
     818     1505572 :   tree decl;
     819             : 
     820     1505572 :   decl = build_lang_decl (VAR_DECL, name, vtable_type);
     821             :   /* vtable names are already mangled; give them their DECL_ASSEMBLER_NAME
     822             :      now to avoid confusion in mangle_decl.  */
     823     1505572 :   SET_DECL_ASSEMBLER_NAME (decl, name);
     824     1505572 :   DECL_CONTEXT (decl) = class_type;
     825     1505572 :   DECL_ARTIFICIAL (decl) = 1;
     826     1505572 :   TREE_STATIC (decl) = 1;
     827     1505572 :   TREE_READONLY (decl) = 1;
     828     1505572 :   DECL_VIRTUAL_P (decl) = 1;
     829     1515449 :   SET_DECL_ALIGN (decl, TARGET_VTABLE_ENTRY_ALIGN);
     830     1505572 :   DECL_USER_ALIGN (decl) = true;
     831     1505572 :   DECL_VTABLE_OR_VTT_P (decl) = 1;
     832     1505572 :   set_linkage_according_to_type (class_type, decl);
     833             :   /* The vtable has not been defined -- yet.  */
     834     1505572 :   DECL_EXTERNAL (decl) = 1;
     835     1505572 :   DECL_NOT_REALLY_EXTERN (decl) = 1;
     836             : 
     837             :   /* Mark the VAR_DECL node representing the vtable itself as a
     838             :      "gratuitous" one, thereby forcing dwarfout.c to ignore it.  It
     839             :      is rather important that such things be ignored because any
     840             :      effort to actually generate DWARF for them will run into
     841             :      trouble when/if we encounter code like:
     842             : 
     843             :      #pragma interface
     844             :      struct S { virtual void member (); };
     845             : 
     846             :      because the artificial declaration of the vtable itself (as
     847             :      manufactured by the g++ front end) will say that the vtable is
     848             :      a static member of `S' but only *after* the debug output for
     849             :      the definition of `S' has already been output.  This causes
     850             :      grief because the DWARF entry for the definition of the vtable
     851             :      will try to refer back to an earlier *declaration* of the
     852             :      vtable as a static member of `S' and there won't be one.  We
     853             :      might be able to arrange to have the "vtable static member"
     854             :      attached to the member list for `S' before the debug info for
     855             :      `S' get written (which would solve the problem) but that would
     856             :      require more intrusive changes to the g++ front end.  */
     857     1505572 :   DECL_IGNORED_P (decl) = 1;
     858             : 
     859     1505572 :   return decl;
     860             : }
     861             : 
     862             : /* Get the VAR_DECL of the vtable for TYPE. TYPE need not be polymorphic,
     863             :    or even complete.  If this does not exist, create it.  If COMPLETE is
     864             :    nonzero, then complete the definition of it -- that will render it
     865             :    impossible to actually build the vtable, but is useful to get at those
     866             :    which are known to exist in the runtime.  */
     867             : 
     868             : tree
     869     5593338 : get_vtable_decl (tree type, int complete)
     870             : {
     871     5593338 :   tree decl;
     872             : 
     873     5593338 :   if (CLASSTYPE_VTABLES (type))
     874     4416509 :     return CLASSTYPE_VTABLES (type);
     875             : 
     876     1176829 :   decl = build_vtable (type, get_vtable_name (type), vtbl_type_node);
     877     1176829 :   CLASSTYPE_VTABLES (type) = decl;
     878             : 
     879     1176829 :   if (complete)
     880             :     {
     881       32063 :       DECL_EXTERNAL (decl) = 1;
     882       32063 :       cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
     883             :     }
     884             : 
     885             :   return decl;
     886             : }
     887             : 
     888             : /* Build the primary virtual function table for TYPE.  If BINFO is
     889             :    non-NULL, build the vtable starting with the initial approximation
     890             :    that it is the same as the one which is the head of the association
     891             :    list.  Returns a nonzero value if a new vtable is actually
     892             :    created.  */
     893             : 
     894             : static int
     895     4408451 : build_primary_vtable (tree binfo, tree type)
     896             : {
     897     4408451 :   tree decl;
     898     4408451 :   tree virtuals;
     899             : 
     900     4408451 :   decl = get_vtable_decl (type, /*complete=*/0);
     901             : 
     902     4408451 :   if (binfo)
     903             :     {
     904     4234647 :       if (BINFO_NEW_VTABLE_MARKED (binfo))
     905             :         /* We have already created a vtable for this base, so there's
     906             :            no need to do it again.  */
     907             :         return 0;
     908             : 
     909      970962 :       virtuals = copy_list (BINFO_VIRTUALS (binfo));
     910      970962 :       TREE_TYPE (decl) = TREE_TYPE (get_vtbl_decl_for_binfo (binfo));
     911      970962 :       DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (decl));
     912      970962 :       DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
     913             :     }
     914             :   else
     915             :     {
     916      173804 :       gcc_assert (TREE_TYPE (decl) == vtbl_type_node);
     917             :       virtuals = NULL_TREE;
     918             :     }
     919             : 
     920             :   /* Initialize the association list for this type, based
     921             :      on our first approximation.  */
     922     1144766 :   BINFO_VTABLE (TYPE_BINFO (type)) = decl;
     923     1144766 :   BINFO_VIRTUALS (TYPE_BINFO (type)) = virtuals;
     924     1144766 :   SET_BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (type));
     925             :   return 1;
     926             : }
     927             : 
     928             : /* Give BINFO a new virtual function table which is initialized
     929             :    with a skeleton-copy of its original initialization.  The only
     930             :    entry that changes is the `delta' entry, so we can really
     931             :    share a lot of structure.
     932             : 
     933             :    FOR_TYPE is the most derived type which caused this table to
     934             :    be needed.
     935             : 
     936             :    Returns nonzero if we haven't met BINFO before.
     937             : 
     938             :    The order in which vtables are built (by calling this function) for
     939             :    an object must remain the same, otherwise a binary incompatibility
     940             :    can result.  */
     941             : 
     942             : static int
     943      553445 : build_secondary_vtable (tree binfo)
     944             : {
     945      553445 :   if (BINFO_NEW_VTABLE_MARKED (binfo))
     946             :     /* We already created a vtable for this base.  There's no need to
     947             :        do it again.  */
     948             :     return 0;
     949             : 
     950             :   /* Remember that we've created a vtable for this BINFO, so that we
     951             :      don't try to do so again.  */
     952      194927 :   SET_BINFO_NEW_VTABLE_MARKED (binfo);
     953             : 
     954             :   /* Make fresh virtual list, so we can smash it later.  */
     955      194927 :   BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
     956             : 
     957             :   /* Secondary vtables are laid out as part of the same structure as
     958             :      the primary vtable.  */
     959      194927 :   BINFO_VTABLE (binfo) = NULL_TREE;
     960      194927 :   return 1;
     961             : }
     962             : 
     963             : /* Create a new vtable for BINFO which is the hierarchy dominated by
     964             :    T. Return nonzero if we actually created a new vtable.  */
     965             : 
     966             : static int
     967     4788092 : make_new_vtable (tree t, tree binfo)
     968             : {
     969     4788092 :   if (binfo == TYPE_BINFO (t))
     970             :     /* In this case, it is *type*'s vtable we are modifying.  We start
     971             :        with the approximation that its vtable is that of the
     972             :        immediate base class.  */
     973     4234647 :     return build_primary_vtable (binfo, t);
     974             :   else
     975             :     /* This is our very own copy of `basetype' to play with.  Later,
     976             :        we will fill in all the virtual functions that override the
     977             :        virtual functions in these base classes which are not defined
     978             :        by the current type.  */
     979      553445 :     return build_secondary_vtable (binfo);
     980             : }
     981             : 
     982             : /* Make *VIRTUALS, an entry on the BINFO_VIRTUALS list for BINFO
     983             :    (which is in the hierarchy dominated by T) list FNDECL as its
     984             :    BV_FN.  DELTA is the required constant adjustment from the `this'
     985             :    pointer where the vtable entry appears to the `this' required when
     986             :    the function is actually called.  */
     987             : 
     988             : static void
     989     4914397 : modify_vtable_entry (tree t,
     990             :                      tree binfo,
     991             :                      tree fndecl,
     992             :                      tree delta,
     993             :                      tree *virtuals)
     994             : {
     995     4914397 :   tree v;
     996             : 
     997     4914397 :   v = *virtuals;
     998             : 
     999     4914397 :   if (fndecl != BV_FN (v)
    1000     4914397 :       || !tree_int_cst_equal (delta, BV_DELTA (v)))
    1001             :     {
    1002             :       /* We need a new vtable for BINFO.  */
    1003     3622203 :       if (make_new_vtable (t, binfo))
    1004             :         {
    1005             :           /* If we really did make a new vtable, we also made a copy
    1006             :              of the BINFO_VIRTUALS list.  Now, we have to find the
    1007             :              corresponding entry in that list.  */
    1008           0 :           *virtuals = BINFO_VIRTUALS (binfo);
    1009           0 :           while (BV_FN (*virtuals) != BV_FN (v))
    1010           0 :             *virtuals = TREE_CHAIN (*virtuals);
    1011             :           v = *virtuals;
    1012             :         }
    1013             : 
    1014     3622203 :       BV_DELTA (v) = delta;
    1015     3622203 :       BV_VCALL_INDEX (v) = NULL_TREE;
    1016     3622203 :       BV_FN (v) = fndecl;
    1017             :     }
    1018     4914397 : }
    1019             : 
    1020             : 
    1021             : /* Add method METHOD to class TYPE.  If VIA_USING indicates whether
    1022             :    METHOD is being injected via a using_decl.  Returns true if the
    1023             :    method could be added to the method vec.  */
    1024             : 
    1025             : bool
    1026   184509649 : add_method (tree type, tree method, bool via_using)
    1027             : {
    1028   184509649 :   if (method == error_mark_node)
    1029             :     return false;
    1030             : 
    1031   184509649 :   gcc_assert (!DECL_EXTERN_C_P (method));
    1032             : 
    1033   184509649 :   tree *slot = find_member_slot (type, DECL_NAME (method));
    1034   184509649 :   tree current_fns = slot ? *slot : NULL_TREE;
    1035             : 
    1036             :   /* See below.  */
    1037   184509649 :   int losem = -1;
    1038             : 
    1039             :   /* Check to see if we've already got this method.  */
    1040   828277043 :   for (ovl_iterator iter (current_fns); iter; ++iter)
    1041             :     {
    1042   321885201 :       tree fn = *iter;
    1043             : 
    1044   321885201 :       if (TREE_CODE (fn) != TREE_CODE (method))
    1045    79421998 :         continue;
    1046             : 
    1047             :       /* Two using-declarations can coexist, we'll complain about ambiguity in
    1048             :          overload resolution.  */
    1049     2046776 :       if (via_using && iter.using_p ()
    1050             :           /* Except handle inherited constructors specially.  */
    1051   244727187 :           && ! DECL_CONSTRUCTOR_P (fn))
    1052             :         {
    1053      931768 :           if (fn == method)
    1054             :             /* Don't add the same one twice.  */
    1055        1504 :             return false;
    1056      931757 :           continue;
    1057             :         }
    1058             : 
    1059             :       /* [over.load] Member function declarations with the
    1060             :          same name and the same parameter types cannot be
    1061             :          overloaded if any of them is a static member
    1062             :          function declaration.
    1063             : 
    1064             :          [over.load] Member function declarations with the same name and
    1065             :          the same parameter-type-list as well as member function template
    1066             :          declarations with the same name, the same parameter-type-list, and
    1067             :          the same template parameter lists cannot be overloaded if any of
    1068             :          them, but not all, have a ref-qualifier.
    1069             : 
    1070             :          [namespace.udecl] When a using-declaration brings names
    1071             :          from a base class into a derived class scope, member
    1072             :          functions in the derived class override and/or hide member
    1073             :          functions with the same name and parameter types in a base
    1074             :          class (rather than conflicting).  */
    1075   241531435 :       tree fn_type = TREE_TYPE (fn);
    1076   241531435 :       tree method_type = TREE_TYPE (method);
    1077             : 
    1078             :       /* Compare the quals on the 'this' parm.  Don't compare
    1079             :          the whole types, as used functions are treated as
    1080             :          coming from the using class in overload resolution.  */
    1081   241531435 :       if (! DECL_STATIC_FUNCTION_P (fn)
    1082   239574937 :           && ! DECL_STATIC_FUNCTION_P (method)
    1083             :           /* Either both or neither need to be ref-qualified for
    1084             :              differing quals to allow overloading.  */
    1085   239566921 :           && (FUNCTION_REF_QUALIFIED (fn_type)
    1086   239566921 :               == FUNCTION_REF_QUALIFIED (method_type))
    1087   481088739 :           && (type_memfn_quals (fn_type) != type_memfn_quals (method_type)
    1088   229363036 :               || type_memfn_rqual (fn_type) != type_memfn_rqual (method_type)))
    1089    10269892 :           continue;
    1090             : 
    1091   231261543 :       tree real_fn = fn;
    1092   231261543 :       tree real_method = method;
    1093             : 
    1094             :       /* Templates and conversion ops must match return types.  */
    1095   462465046 :       if ((DECL_CONV_FN_P (fn) || TREE_CODE (fn) == TEMPLATE_DECL)
    1096   326402042 :           && !same_type_p (TREE_TYPE (fn_type), TREE_TYPE (method_type)))
    1097     2846725 :         continue;
    1098             :       
    1099             :       /* For templates, the template parameters must be identical.  */
    1100   228414818 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    1101             :         {
    1102   184703610 :           if (!comp_template_parms (DECL_TEMPLATE_PARMS (fn),
    1103    92351805 :                                     DECL_TEMPLATE_PARMS (method)))
    1104    76748069 :             continue;
    1105             : 
    1106    15603736 :           real_fn = DECL_TEMPLATE_RESULT (fn);
    1107    15603736 :           real_method = DECL_TEMPLATE_RESULT (method);
    1108             :         }
    1109             : 
    1110   151666749 :       tree parms1 = TYPE_ARG_TYPES (fn_type);
    1111   151666749 :       tree parms2 = TYPE_ARG_TYPES (method_type);
    1112   151666749 :       if (! DECL_STATIC_FUNCTION_P (real_fn))
    1113   150374259 :         parms1 = TREE_CHAIN (parms1);
    1114   151666749 :       if (! DECL_STATIC_FUNCTION_P (real_method))
    1115   150371167 :         parms2 = TREE_CHAIN (parms2);
    1116             : 
    1117             :       /* Bring back parameters omitted from an inherited ctor.  The
    1118             :          method and the function can have different omittedness.  */
    1119   151666749 :       if (ctor_omit_inherited_parms (real_fn))
    1120         729 :         parms1 = FUNCTION_FIRST_USER_PARMTYPE (DECL_CLONED_FUNCTION (real_fn));
    1121   151666749 :       if (ctor_omit_inherited_parms (real_method))
    1122         330 :         parms2 = (FUNCTION_FIRST_USER_PARMTYPE
    1123             :                   (DECL_CLONED_FUNCTION (real_method)));
    1124             : 
    1125   151666749 :       if (!compparms (parms1, parms2))
    1126   151630864 :         continue;
    1127             : 
    1128       35885 :       if (!equivalently_constrained (fn, method))
    1129             :         {
    1130       32449 :           if (processing_template_decl)
    1131             :             /* We can't check satisfaction in dependent context, wait until
    1132             :                the class is instantiated.  */
    1133       19180 :             continue;
    1134             : 
    1135       13269 :           special_function_kind sfk = special_memfn_p (method);
    1136             : 
    1137       24615 :           if (sfk == sfk_none
    1138        3868 :               || DECL_INHERITED_CTOR (fn)
    1139       15195 :               || TREE_CODE (fn) == TEMPLATE_DECL)
    1140             :             /* Member function templates and non-special member functions
    1141             :                coexist if they are not equivalently constrained.  A member
    1142             :                function is not hidden by an inherited constructor.  */
    1143       11346 :             continue;
    1144             : 
    1145             :           /* P0848: For special member functions, deleted, unsatisfied, or
    1146             :              less constrained overloads are ineligible.  We implement this
    1147             :              by removing them from CLASSTYPE_MEMBER_VEC.  Destructors don't
    1148             :              use the notion of eligibility, and the selected destructor can
    1149             :              be deleted, but removing unsatisfied or less constrained
    1150             :              overloads has the same effect as overload resolution.  */
    1151        1923 :           bool dtor = (sfk == sfk_destructor);
    1152        1923 :           if (losem == -1)
    1153        3626 :             losem = ((!dtor && DECL_DELETED_FN (method))
    1154        3626 :                      || !constraints_satisfied_p (method));
    1155        1711 :           bool losef = ((!dtor && DECL_DELETED_FN (fn))
    1156        2677 :                         || !constraints_satisfied_p (fn));
    1157        1923 :           int win;
    1158        1923 :           if (losem || losef)
    1159        1515 :             win = losem - losef;
    1160             :           else
    1161         408 :             win = more_constrained (fn, method);
    1162        1923 :           if (win > 0)
    1163             :             /* Leave FN in the method vec, discard METHOD.  */
    1164             :             return false;
    1165        1092 :           else if (win < 0)
    1166             :             {
    1167             :               /* Remove FN, add METHOD.  */
    1168         931 :               current_fns = iter.remove_node (current_fns);
    1169         931 :               continue;
    1170             :             }
    1171             :           else
    1172             :             /* Let them coexist for now.  */
    1173         161 :             continue;
    1174             :         }
    1175             : 
    1176             :       /* If these are versions of the same function, process and
    1177             :          move on.  */
    1178        3472 :       if (TREE_CODE (fn) == FUNCTION_DECL
    1179        3436 :           && maybe_version_functions (method, fn, true))
    1180          36 :         continue;
    1181             : 
    1182        6800 :       if (DECL_INHERITED_CTOR (method))
    1183             :         {
    1184        1158 :           if (!DECL_INHERITED_CTOR (fn))
    1185             :             /* Defer to the other function.  */
    1186             :             return false;
    1187             :             
    1188          75 :           tree basem = DECL_INHERITED_CTOR_BASE (method);
    1189         150 :           tree basef = DECL_INHERITED_CTOR_BASE (fn);
    1190          75 :           if (flag_new_inheriting_ctors)
    1191             :             {
    1192          72 :               if (basem == basef)
    1193             :                 {
    1194             :                   /* Inheriting the same constructor along different
    1195             :                      paths, combine them.  */
    1196          90 :                   SET_DECL_INHERITED_CTOR
    1197             :                     (fn, ovl_make (DECL_INHERITED_CTOR (method),
    1198             :                                    DECL_INHERITED_CTOR (fn)));
    1199             :                   /* And discard the new one.  */
    1200          30 :                   return false;
    1201             :                 }
    1202             :               else
    1203             :                 /* Inherited ctors can coexist until overload
    1204             :                    resolution.  */
    1205          42 :                 continue;
    1206             :             }
    1207             : 
    1208           3 :           error_at (DECL_SOURCE_LOCATION (method),
    1209             :                     "%q#D conflicts with version inherited from %qT",
    1210             :                     method, basef);
    1211           3 :           inform (DECL_SOURCE_LOCATION (fn),
    1212             :                   "version inherited from %qT declared here",
    1213             :                   basef);
    1214           3 :           return false;
    1215             :         }
    1216             : 
    1217        2821 :       if (via_using)
    1218             :         /* Defer to the local function.  */
    1219             :         return false;
    1220        2805 :       else if (iter.using_p ()
    1221        2805 :                ||  (flag_new_inheriting_ctors
    1222        3126 :                     && DECL_INHERITED_CTOR (fn)))
    1223             :         {
    1224             :           /* Remove the inherited function.  */
    1225        2696 :           current_fns = iter.remove_node (current_fns);
    1226        2696 :           continue;
    1227             :         }
    1228             :       else
    1229             :         {
    1230         109 :           error_at (DECL_SOURCE_LOCATION (method),
    1231             :                     "%q#D cannot be overloaded with %q#D", method, fn);
    1232         109 :           inform (DECL_SOURCE_LOCATION (fn),
    1233             :                   "previous declaration %q#D", fn);
    1234         109 :           return false;
    1235             :         }
    1236             :     }
    1237             : 
    1238   184508145 :   current_fns = ovl_insert (method, current_fns, via_using);
    1239             : 
    1240   343093995 :   if (!COMPLETE_TYPE_P (type) && !DECL_CONV_FN_P (method)
    1241   342068023 :       && !push_class_level_binding (DECL_NAME (method), current_fns))
    1242             :     return false;
    1243             : 
    1244   184508125 :   if (!slot)
    1245    84671898 :     slot = add_member_slot (type, DECL_NAME (method));
    1246             : 
    1247             :   /* Maintain TYPE_HAS_USER_CONSTRUCTOR, etc.  */
    1248   184508125 :   grok_special_member_properties (method);
    1249             : 
    1250   184508125 :   *slot = current_fns;
    1251             : 
    1252   184508125 :   return true;
    1253             : }
    1254             : 
    1255             : /* Subroutines of finish_struct.  */
    1256             : 
    1257             : /* Change the access of FDECL to ACCESS in T.  Return 1 if change was
    1258             :    legit, otherwise return 0.  */
    1259             : 
    1260             : static int
    1261     1695023 : alter_access (tree t, tree fdecl, tree access)
    1262             : {
    1263     1695023 :   tree elem;
    1264             : 
    1265     1695023 :   retrofit_lang_decl (fdecl);
    1266             : 
    1267     1695023 :   gcc_assert (!DECL_DISCRIMINATOR_P (fdecl));
    1268             : 
    1269     3389853 :   elem = purpose_member (t, DECL_ACCESS (fdecl));
    1270     1695023 :   if (elem)
    1271             :     {
    1272           0 :       if (TREE_VALUE (elem) != access)
    1273             :         {
    1274           0 :           if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
    1275           0 :             error ("conflicting access specifications for method"
    1276           0 :                    " %q+D, ignored", TREE_TYPE (fdecl));
    1277             :           else
    1278           0 :             error ("conflicting access specifications for field %qE, ignored",
    1279           0 :                    DECL_NAME (fdecl));
    1280             :         }
    1281             :       else
    1282             :         {
    1283             :           /* They're changing the access to the same thing they changed
    1284             :              it to before.  That's OK.  */
    1285             :           ;
    1286             :         }
    1287             :     }
    1288             :   else
    1289             :     {
    1290     1695023 :       perform_or_defer_access_check (TYPE_BINFO (t), fdecl, fdecl,
    1291             :                                      tf_warning_or_error);
    1292     3389853 :       DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
    1293     1695023 :       return 1;
    1294             :     }
    1295             :   return 0;
    1296             : }
    1297             : 
    1298             : /* Return the access node for DECL's access in its enclosing class.  */
    1299             : 
    1300             : tree
    1301      139855 : declared_access (tree decl)
    1302             : {
    1303      139855 :   return (TREE_PRIVATE (decl) ? access_private_node
    1304      132338 :           : TREE_PROTECTED (decl) ? access_protected_node
    1305      139855 :           : access_public_node);
    1306             : }
    1307             : 
    1308             : /* If DECL is a non-dependent using of non-ctor function members, push them
    1309             :    and return true, otherwise return false.  Called from
    1310             :    finish_member_declaration.  */
    1311             : 
    1312             : bool
    1313   105584779 : maybe_push_used_methods (tree decl)
    1314             : {
    1315   105584779 :   if (TREE_CODE (decl) != USING_DECL)
    1316             :     return false;
    1317     1509232 :   tree used = strip_using_decl (decl);
    1318     1509232 :   if (!used || !is_overloaded_fn (used))
    1319             :     return false;
    1320             : 
    1321             :   /* Add the functions to CLASSTYPE_MEMBER_VEC so that overload resolution
    1322             :      works within the class body.  */
    1323     4137432 :   for (tree f : ovl_range (used))
    1324             :     {
    1325     3221426 :       if (DECL_CONSTRUCTOR_P (f))
    1326             :         /* Inheriting constructors are handled separately.  */
    1327       31865 :         return false;
    1328             : 
    1329     1578848 :       bool added = add_method (current_class_type, f, true);
    1330             : 
    1331     1578848 :       if (added)
    1332     1578821 :         alter_access (current_class_type, f, current_access_specifier);
    1333             : 
    1334             :       /* If add_method returns false because f was already declared, look
    1335             :          for a duplicate using-declaration.  */
    1336             :       else
    1337          93 :         for (tree d = TYPE_FIELDS (current_class_type); d; d = DECL_CHAIN (d))
    1338          74 :           if (TREE_CODE (d) == USING_DECL
    1339          31 :               && DECL_NAME (d) == DECL_NAME (decl)
    1340          85 :               && same_type_p (USING_DECL_SCOPE (d), USING_DECL_SCOPE (decl)))
    1341             :             {
    1342           8 :               diagnose_name_conflict (decl, d);
    1343           8 :               break;
    1344             :             }
    1345             :     }
    1346      947871 :   return true;
    1347             : }
    1348             : 
    1349             : /* Process the USING_DECL, which is a member of T.  */
    1350             : 
    1351             : static void
    1352     1063968 : handle_using_decl (tree using_decl, tree t)
    1353             : {
    1354     1063968 :   tree decl = USING_DECL_DECLS (using_decl);
    1355             : 
    1356     1063968 :   gcc_assert (!processing_template_decl && decl);
    1357             : 
    1358     1063968 :   cp_emit_debug_info_for_using (decl, t);
    1359             : 
    1360     1063968 :   if (is_overloaded_fn (decl))
    1361             :     /* Handled in maybe_push_used_methods.  */
    1362     1063968 :     return;
    1363             : 
    1364      116234 :   tree name = DECL_NAME (using_decl);
    1365      116234 :   tree old_value = lookup_member (t, name, /*protect=*/0, /*want_type=*/false,
    1366             :                                   tf_warning_or_error);
    1367      116234 :   if (old_value)
    1368             :     {
    1369      116234 :       old_value = OVL_FIRST (old_value);
    1370             : 
    1371      116234 :       if (DECL_P (old_value) && DECL_CONTEXT (old_value) == t)
    1372             :         /* OK */;
    1373             :       else
    1374             :         old_value = NULL_TREE;
    1375             :     }
    1376             : 
    1377           0 :   if (! old_value)
    1378             :     ;
    1379           0 :   else if (is_overloaded_fn (old_value))
    1380             :     {
    1381           0 :       error_at (DECL_SOURCE_LOCATION (using_decl), "%qD invalid in %q#T "
    1382             :                 "because of local method %q#D with same name",
    1383             :                 using_decl, t, old_value);
    1384           0 :       inform (DECL_SOURCE_LOCATION (old_value),
    1385             :               "local method %q#D declared here", old_value);
    1386           0 :       return;
    1387             :     }
    1388           0 :   else if (!DECL_ARTIFICIAL (old_value))
    1389             :     {
    1390           0 :       error_at (DECL_SOURCE_LOCATION (using_decl), "%qD invalid in %q#T "
    1391             :                 "because of local member %q#D with same name",
    1392             :                 using_decl, t, old_value);
    1393           0 :       inform (DECL_SOURCE_LOCATION (old_value),
    1394             :               "local member %q#D declared here", old_value);
    1395           0 :       return;
    1396             :     }
    1397             : 
    1398      116234 :   iloc_sentinel ils (DECL_SOURCE_LOCATION (using_decl));
    1399      116234 :   tree access = declared_access (using_decl);
    1400             : 
    1401             :   /* Make type T see field decl FDECL with access ACCESS.  */
    1402      116234 :   if (USING_DECL_UNRELATED_P (using_decl))
    1403             :     {
    1404             :       /* C++20 using enum can import non-inherited enumerators into class
    1405             :          scope.  We implement that by making a copy of the CONST_DECL for which
    1406             :          CONST_DECL_USING_P is true.  */
    1407          32 :       gcc_assert (TREE_CODE (decl) == CONST_DECL);
    1408             : 
    1409          32 :       auto cas = make_temp_override (current_access_specifier, access);
    1410          32 :       tree copy = copy_decl (decl);
    1411          32 :       DECL_CONTEXT (copy) = t;
    1412          32 :       DECL_ARTIFICIAL (copy) = true;
    1413             :       /* We emitted debug info for the USING_DECL above; make sure we don't
    1414             :          also emit anything for this clone.  */
    1415          32 :       DECL_IGNORED_P (copy) = true;
    1416          32 :       DECL_SOURCE_LOCATION (copy) = DECL_SOURCE_LOCATION (using_decl);
    1417          32 :       finish_member_declaration (copy);
    1418          32 :       DECL_ABSTRACT_ORIGIN (copy) = decl;
    1419          32 :     }
    1420             :   else
    1421      116202 :     alter_access (t, decl, access);
    1422      116234 : }
    1423             : 
    1424             : /* Data structure for find_abi_tags_r, below.  */
    1425             : 
    1426             : struct abi_tag_data
    1427             : {
    1428             :   tree t;               // The type that we're checking for missing tags.
    1429             :   tree subob;           // The subobject of T that we're getting tags from.
    1430             :   tree tags; // error_mark_node for diagnostics, or a list of missing tags.
    1431             : };
    1432             : 
    1433             : /* Subroutine of find_abi_tags_r. Handle a single TAG found on the class TP
    1434             :    in the context of P.  TAG can be either an identifier (the DECL_NAME of
    1435             :    a tag NAMESPACE_DECL) or a STRING_CST (a tag attribute).  */
    1436             : 
    1437             : static void
    1438     8461732 : check_tag (tree tag, tree id, tree *tp, abi_tag_data *p)
    1439             : {
    1440     8461732 :   if (!IDENTIFIER_MARKED (id))
    1441             :     {
    1442     3577254 :       if (p->tags != error_mark_node)
    1443             :         {
    1444             :           /* We're collecting tags from template arguments or from
    1445             :              the type of a variable or function return type.  */
    1446     3577230 :           p->tags = tree_cons (NULL_TREE, tag, p->tags);
    1447             : 
    1448             :           /* Don't inherit this tag multiple times.  */
    1449     3577230 :           IDENTIFIER_MARKED (id) = true;
    1450             : 
    1451     3577230 :           if (TYPE_P (p->t))
    1452             :             {
    1453             :               /* Tags inherited from type template arguments are only used
    1454             :                  to avoid warnings.  */
    1455     3574547 :               ABI_TAG_IMPLICIT (p->tags) = true;
    1456     3574547 :               return;
    1457             :             }
    1458             :           /* For functions and variables we want to warn, too.  */
    1459             :         }
    1460             : 
    1461             :       /* Otherwise we're diagnosing missing tags.  */
    1462        2707 :       if (TREE_CODE (p->t) == FUNCTION_DECL)
    1463             :         {
    1464        2351 :           auto_diagnostic_group d;
    1465        2351 :           if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag "
    1466             :                        "that %qT (used in its return type) has",
    1467             :                        p->t, tag, *tp))
    1468           4 :             inform (location_of (*tp), "%qT declared here", *tp);
    1469        2351 :         }
    1470         356 :       else if (VAR_P (p->t))
    1471             :         {
    1472         332 :           auto_diagnostic_group d;
    1473         332 :           if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag "
    1474             :                        "that %qT (used in its type) has", p->t, tag, *tp))
    1475           4 :             inform (location_of (*tp), "%qT declared here", *tp);
    1476         332 :         }
    1477          24 :       else if (TYPE_P (p->subob))
    1478             :         {
    1479           8 :           auto_diagnostic_group d;
    1480           8 :           if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag "
    1481             :                        "that base %qT has", p->t, tag, p->subob))
    1482           8 :             inform (location_of (p->subob), "%qT declared here",
    1483             :                     p->subob);
    1484           8 :         }
    1485             :       else
    1486             :         {
    1487          16 :           auto_diagnostic_group d;
    1488          16 :           if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag "
    1489             :                        "that %qT (used in the type of %qD) has",
    1490             :                        p->t, tag, *tp, p->subob))
    1491             :             {
    1492          16 :               inform (location_of (p->subob), "%qD declared here",
    1493             :                       p->subob);
    1494          16 :               inform (location_of (*tp), "%qT declared here", *tp);
    1495             :             }
    1496          16 :         }
    1497             :     }
    1498             : }
    1499             : 
    1500             : /* Find all the ABI tags in the attribute list ATTR and either call
    1501             :    check_tag (if TP is non-null) or set IDENTIFIER_MARKED to val.  */
    1502             : 
    1503             : static void
    1504  1086469300 : mark_or_check_attr_tags (tree attr, tree *tp, abi_tag_data *p, bool val)
    1505             : {
    1506  1086469300 :   if (!attr)
    1507             :     return;
    1508   117817641 :   for (; (attr = lookup_attribute ("abi_tag", attr));
    1509    46986952 :        attr = TREE_CHAIN (attr))
    1510    93973928 :     for (tree list = TREE_VALUE (attr); list;
    1511    46986976 :          list = TREE_CHAIN (list))
    1512             :       {
    1513    46986976 :         tree tag = TREE_VALUE (list);
    1514    46986976 :         tree id = get_identifier (TREE_STRING_POINTER (tag));
    1515    46986976 :         if (tp)
    1516     8461732 :           check_tag (tag, id, tp, p);
    1517             :         else
    1518    38525244 :           IDENTIFIER_MARKED (id) = val;
    1519             :       }
    1520             : }
    1521             : 
    1522             : /* Find all the ABI tags on T and its enclosing scopes and either call
    1523             :    check_tag (if TP is non-null) or set IDENTIFIER_MARKED to val.  */
    1524             : 
    1525             : static void
    1526   420859715 : mark_or_check_tags (tree t, tree *tp, abi_tag_data *p, bool val)
    1527             : {
    1528  1507329015 :   while (t != global_namespace)
    1529             :     {
    1530  1086469300 :       tree attr;
    1531  1086469300 :       if (TYPE_P (t))
    1532             :         {
    1533   431591752 :           attr = TYPE_ATTRIBUTES (t);
    1534   431591752 :           t = CP_TYPE_CONTEXT (t);
    1535             :         }
    1536             :       else
    1537             :         {
    1538   654877548 :           attr = DECL_ATTRIBUTES (t);
    1539   654877548 :           t = CP_DECL_CONTEXT (t);
    1540             :         }
    1541  1086469300 :       mark_or_check_attr_tags (attr, tp, p, val);
    1542             :     }
    1543   420859715 : }
    1544             : 
    1545             : /* walk_tree callback for check_abi_tags: if the type at *TP involves any
    1546             :    types with ABI tags, add the corresponding identifiers to the VEC in
    1547             :    *DATA and set IDENTIFIER_MARKED.  */
    1548             : 
    1549             : static tree
    1550   328658758 : find_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1551             : {
    1552   328658758 :   if (TYPE_P (*tp) && *walk_subtrees == 1 && flag_abi_version != 14)
    1553             :     /* Tell cp_walk_subtrees to look though typedefs. [PR98481] */
    1554   253266294 :     *walk_subtrees = 2;
    1555             : 
    1556   328658758 :   if (!OVERLOAD_TYPE_P (*tp))
    1557             :     return NULL_TREE;
    1558             : 
    1559             :   /* walk_tree shouldn't be walking into any subtrees of a RECORD_TYPE
    1560             :      anyway, but let's make sure of it.  */
    1561    76718943 :   *walk_subtrees = false;
    1562             : 
    1563    76718943 :   abi_tag_data *p = static_cast<struct abi_tag_data*>(data);
    1564             : 
    1565    76718943 :   mark_or_check_tags (*tp, tp, p, false);
    1566             : 
    1567    76718943 :   return NULL_TREE;
    1568             : }
    1569             : 
    1570             : /* walk_tree callback for mark_abi_tags: if *TP is a class, set
    1571             :    IDENTIFIER_MARKED on its ABI tags.  */
    1572             : 
    1573             : static tree
    1574   344481344 : mark_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1575             : {
    1576   344481344 :   if (TYPE_P (*tp) && *walk_subtrees == 1 && flag_abi_version != 14)
    1577             :     /* Tell cp_walk_subtrees to look though typedefs.  */
    1578   343627378 :     *walk_subtrees = 2;
    1579             : 
    1580   344481344 :   if (!OVERLOAD_TYPE_P (*tp))
    1581             :     return NULL_TREE;
    1582             : 
    1583             :   /* walk_tree shouldn't be walking into any subtrees of a RECORD_TYPE
    1584             :      anyway, but let's make sure of it.  */
    1585    65242786 :   *walk_subtrees = false;
    1586             : 
    1587    65242786 :   bool *valp = static_cast<bool*>(data);
    1588             : 
    1589    65242786 :   mark_or_check_tags (*tp, NULL, NULL, *valp);
    1590             : 
    1591    65242786 :   return NULL_TREE;
    1592             : }
    1593             : 
    1594             : /* Set IDENTIFIER_MARKED on all the ABI tags on T and its enclosing
    1595             :    scopes.  */
    1596             : 
    1597             : static void
    1598   278897986 : mark_abi_tags (tree t, bool val)
    1599             : {
    1600   278897986 :   mark_or_check_tags (t, NULL, NULL, val);
    1601   278897986 :   if (DECL_P (t))
    1602             :     {
    1603   291452382 :       if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t)
    1604   236830182 :           && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))
    1605             :         {
    1606             :           /* Template arguments are part of the signature.  */
    1607     3737142 :           tree level = INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t));
    1608    10201906 :           for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1609             :             {
    1610     6464764 :               tree arg = TREE_VEC_ELT (level, j);
    1611     6464764 :               cp_walk_tree_without_duplicates (&arg, mark_abi_tags_r, &val);
    1612             :             }
    1613             :         }
    1614   146796022 :       if (TREE_CODE (t) == FUNCTION_DECL)
    1615             :         /* A function's parameter types are part of the signature, so
    1616             :            we don't need to inherit any tags that are also in them.  */
    1617   397908526 :         for (tree arg = FUNCTION_FIRST_USER_PARMTYPE (t); arg;
    1618   266450202 :              arg = TREE_CHAIN (arg))
    1619   266450202 :           cp_walk_tree_without_duplicates (&TREE_VALUE (arg),
    1620             :                                            mark_abi_tags_r, &val);
    1621             :     }
    1622   278897986 : }
    1623             : 
    1624             : /* Check that T has all the ABI tags that subobject SUBOB has, or
    1625             :    warn if not.  If T is a (variable or function) declaration, also
    1626             :    return any missing tags, and add them to T if JUST_CHECKING is false.  */
    1627             : 
    1628             : static tree
    1629    98070039 : check_abi_tags (tree t, tree subob, bool just_checking = false)
    1630             : {
    1631    98070039 :   bool inherit = DECL_P (t);
    1632             : 
    1633    98070039 :   if (!inherit && !warn_abi_tag)
    1634             :     return NULL_TREE;
    1635             : 
    1636    73595360 :   tree decl = TYPE_P (t) ? TYPE_NAME (t) : t;
    1637    73595360 :   if (!TREE_PUBLIC (decl))
    1638             :     /* No need to worry about things local to this TU.  */
    1639             :     return NULL_TREE;
    1640             : 
    1641    73398039 :   mark_abi_tags (t, true);
    1642             : 
    1643    73398039 :   tree subtype = TYPE_P (subob) ? subob : TREE_TYPE (subob);
    1644    73398039 :   struct abi_tag_data data = { t, subob, error_mark_node };
    1645    73398039 :   if (inherit)
    1646    73398011 :     data.tags = NULL_TREE;
    1647             : 
    1648    73398039 :   cp_walk_tree_without_duplicates (&subtype, find_abi_tags_r, &data);
    1649             : 
    1650    73398039 :   if (!(inherit && data.tags))
    1651             :     /* We don't need to do anything with data.tags.  */;
    1652        2671 :   else if (just_checking)
    1653         132 :     for (tree t = data.tags; t; t = TREE_CHAIN (t))
    1654             :       {
    1655          72 :         tree id = get_identifier (TREE_STRING_POINTER (TREE_VALUE (t)));
    1656          72 :         IDENTIFIER_MARKED (id) = false;
    1657             :       }
    1658             :   else
    1659             :     {
    1660        2611 :       tree attr = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (t));
    1661        2611 :       if (attr)
    1662           0 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1663             :       else
    1664        2611 :         DECL_ATTRIBUTES (t)
    1665        5222 :           = tree_cons (abi_tag_identifier, data.tags, DECL_ATTRIBUTES (t));
    1666             :     }
    1667             : 
    1668    73398039 :   mark_abi_tags (t, false);
    1669             : 
    1670    73398039 :   return data.tags;
    1671             : }
    1672             : 
    1673             : /* Check that DECL has all the ABI tags that are used in parts of its type
    1674             :    that are not reflected in its mangled name.  */
    1675             : 
    1676             : void
    1677    77936216 : check_abi_tags (tree decl)
    1678             : {
    1679    77936216 :   if (VAR_P (decl))
    1680     7742060 :     check_abi_tags (decl, TREE_TYPE (decl));
    1681    70194156 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1682    70191241 :            && !DECL_CONV_FN_P (decl)
    1683   139848442 :            && !mangle_return_type_p (decl))
    1684    65348453 :     check_abi_tags (decl, TREE_TYPE (TREE_TYPE (decl)));
    1685    77936216 : }
    1686             : 
    1687             : /* Return any ABI tags that are used in parts of the type of DECL
    1688             :    that are not reflected in its mangled name.  This function is only
    1689             :    used in backward-compatible mangling for ABI <11.  */
    1690             : 
    1691             : tree
    1692      564059 : missing_abi_tags (tree decl)
    1693             : {
    1694      564059 :   if (VAR_P (decl))
    1695       29019 :     return check_abi_tags (decl, TREE_TYPE (decl), true);
    1696      535040 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1697             :            /* Don't check DECL_CONV_FN_P here like we do in check_abi_tags, so
    1698             :               that we can use this function for setting need_abi_warning
    1699             :               regardless of the current flag_abi_version.  */
    1700      535040 :            && !mangle_return_type_p (decl))
    1701      475796 :     return check_abi_tags (decl, TREE_TYPE (TREE_TYPE (decl)), true);
    1702             :   else
    1703       59244 :     return NULL_TREE;
    1704             : }
    1705             : 
    1706             : void
    1707    70694544 : inherit_targ_abi_tags (tree t)
    1708             : {
    1709    66052312 :   if (!CLASS_TYPE_P (t)
    1710   136746847 :       || CLASSTYPE_TEMPLATE_INFO (t) == NULL_TREE)
    1711     4643590 :     return;
    1712             : 
    1713    66050954 :   mark_abi_tags (t, true);
    1714             : 
    1715    66050954 :   tree args = CLASSTYPE_TI_ARGS (t);
    1716    66050954 :   struct abi_tag_data data = { t, NULL_TREE, NULL_TREE };
    1717   396305948 :   for (int i = 0; i < TMPL_ARGS_DEPTH (args); ++i)
    1718             :     {
    1719   134792258 :       tree level = TMPL_ARGS_LEVEL (args, i+1);
    1720   189831287 :       for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1721             :         {
    1722   122435158 :           tree arg = TREE_VEC_ELT (level, j);
    1723   122435158 :           data.subob = arg;
    1724   122435158 :           cp_walk_tree_without_duplicates (&arg, find_abi_tags_r, &data);
    1725             :         }
    1726             :     }
    1727             : 
    1728             :   // If we found some tags on our template arguments, add them to our
    1729             :   // abi_tag attribute.
    1730    66050954 :   if (data.tags)
    1731             :     {
    1732     3574547 :       tree attr = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (t));
    1733     3574547 :       if (attr)
    1734           4 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1735             :       else
    1736     3574543 :         TYPE_ATTRIBUTES (t)
    1737     7149086 :           = tree_cons (abi_tag_identifier, data.tags, TYPE_ATTRIBUTES (t));
    1738             :     }
    1739             : 
    1740    66050954 :   mark_abi_tags (t, false);
    1741             : }
    1742             : 
    1743             : /* Return true, iff class T has a non-virtual destructor that is
    1744             :    accessible from outside the class heirarchy (i.e. is public, or
    1745             :    there's a suitable friend.  */
    1746             : 
    1747             : static bool
    1748         129 : accessible_nvdtor_p (tree t)
    1749             : {
    1750         129 :   tree dtor = CLASSTYPE_DESTRUCTOR (t);
    1751             : 
    1752             :   /* An implicitly declared destructor is always public.  And,
    1753             :      if it were virtual, we would have created it by now.  */
    1754         129 :   if (!dtor)
    1755             :     return true;
    1756             : 
    1757         102 :   if (DECL_VINDEX (dtor))
    1758             :     return false; /* Virtual */
    1759             :   
    1760          54 :   if (!TREE_PRIVATE (dtor) && !TREE_PROTECTED (dtor))
    1761             :     return true;  /* Public */
    1762             : 
    1763          38 :   if (CLASSTYPE_FRIEND_CLASSES (t)
    1764          38 :       || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
    1765          16 :     return true;   /* Has friends */
    1766             : 
    1767             :   return false;
    1768             : }
    1769             : 
    1770             : /* Run through the base classes of T, updating CANT_HAVE_CONST_CTOR_P,
    1771             :    and NO_CONST_ASN_REF_P.  Also set flag bits in T based on
    1772             :    properties of the bases.  */
    1773             : 
    1774             : static void
    1775    25156660 : check_bases (tree t,
    1776             :              int* cant_have_const_ctor_p,
    1777             :              int* no_const_asn_ref_p)
    1778             : {
    1779    25156660 :   int i;
    1780    25156660 :   bool seen_non_virtual_nearly_empty_base_p = 0;
    1781    25156660 :   int seen_tm_mask = 0;
    1782    25156660 :   tree base_binfo;
    1783    25156660 :   tree binfo;
    1784    25156660 :   tree field = NULL_TREE;
    1785             : 
    1786    25156660 :   if (!CLASSTYPE_NON_STD_LAYOUT (t))
    1787   116577216 :     for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    1788    95067750 :       if (TREE_CODE (field) == FIELD_DECL)
    1789             :         break;
    1790             : 
    1791    39504201 :   for (binfo = TYPE_BINFO (t), i = 0;
    1792    39504201 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    1793             :     {
    1794    14347541 :       tree basetype = TREE_TYPE (base_binfo);
    1795             : 
    1796    14347541 :       gcc_assert (COMPLETE_TYPE_P (basetype));
    1797             : 
    1798    14347541 :       if (CLASSTYPE_FINAL (basetype))
    1799          11 :         error ("cannot derive from %<final%> base %qT in derived type %qT",
    1800             :                basetype, t);
    1801             : 
    1802             :       /* If any base class is non-literal, so is the derived class.  */
    1803    14347541 :       if (!CLASSTYPE_LITERAL_P (basetype))
    1804     1610140 :         CLASSTYPE_LITERAL_P (t) = false;
    1805             : 
    1806             :       /* If the base class doesn't have copy constructors or
    1807             :          assignment operators that take const references, then the
    1808             :          derived class cannot have such a member automatically
    1809             :          generated.  */
    1810    14347541 :       if (TYPE_HAS_COPY_CTOR (basetype)
    1811    14347541 :           && ! TYPE_HAS_CONST_COPY_CTOR (basetype))
    1812          50 :         *cant_have_const_ctor_p = 1;
    1813    14347541 :       if (TYPE_HAS_COPY_ASSIGN (basetype)
    1814    14347541 :           && !TYPE_HAS_CONST_COPY_ASSIGN (basetype))
    1815          15 :         *no_const_asn_ref_p = 1;
    1816             : 
    1817    14347541 :       if (BINFO_VIRTUAL_P (base_binfo))
    1818             :         /* A virtual base does not effect nearly emptiness.  */
    1819             :         ;
    1820    14310571 :       else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
    1821             :         {
    1822      201409 :           if (seen_non_virtual_nearly_empty_base_p)
    1823             :             /* And if there is more than one nearly empty base, then the
    1824             :                derived class is not nearly empty either.  */
    1825        1239 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    1826             :           else
    1827             :             /* Remember we've seen one.  */
    1828             :             seen_non_virtual_nearly_empty_base_p = 1;
    1829             :         }
    1830    14109162 :       else if (!is_empty_class (basetype))
    1831             :         /* If the base class is not empty or nearly empty, then this
    1832             :            class cannot be nearly empty.  */
    1833     1264476 :         CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    1834             : 
    1835             :       /* A lot of properties from the bases also apply to the derived
    1836             :          class.  */
    1837    14347541 :       TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
    1838    43042623 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    1839    14347541 :         |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
    1840    14347541 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    1841    14347541 :         |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (basetype)
    1842    14347541 :             || !TYPE_HAS_COPY_ASSIGN (basetype));
    1843    28695082 :       TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (basetype)
    1844    14347541 :                                          || !TYPE_HAS_COPY_CTOR (basetype));
    1845    43042623 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
    1846    14347541 :         |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (basetype);
    1847    14347541 :       TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (basetype);
    1848    14347541 :       TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
    1849    43042623 :       CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
    1850    14347541 :         |= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
    1851    28695082 :       TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
    1852    14347541 :                                     || TYPE_HAS_COMPLEX_DFLT (basetype));
    1853    14347541 :       SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT
    1854             :         (t, CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
    1855             :          | CLASSTYPE_READONLY_FIELDS_NEED_INIT (basetype));
    1856    14347541 :       SET_CLASSTYPE_REF_FIELDS_NEED_INIT
    1857             :         (t, CLASSTYPE_REF_FIELDS_NEED_INIT (t)
    1858             :          | CLASSTYPE_REF_FIELDS_NEED_INIT (basetype));
    1859    14347541 :       if (TYPE_HAS_MUTABLE_P (basetype))
    1860      665852 :         CLASSTYPE_HAS_MUTABLE (t) = 1;
    1861             : 
    1862             :       /*  A standard-layout class is a class that:
    1863             :           ...
    1864             :           * has no non-standard-layout base classes,  */
    1865    14347541 :       CLASSTYPE_NON_STD_LAYOUT (t) |= CLASSTYPE_NON_STD_LAYOUT (basetype);
    1866    14347541 :       if (!CLASSTYPE_NON_STD_LAYOUT (t))
    1867             :         {
    1868    13205376 :           tree basefield;
    1869             :           /* ...has no base classes of the same type as the first non-static
    1870             :              data member...  */
    1871      513184 :           if (field && DECL_CONTEXT (field) == t
    1872    13686540 :               && (same_type_ignoring_top_level_qualifiers_p
    1873      481164 :                   (TREE_TYPE (field), basetype)))
    1874         132 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    1875             :           /* DR 1813:
    1876             :              ...has at most one base class subobject of any given type...  */
    1877    13205244 :           else if (CLASSTYPE_REPEATED_BASE_P (t))
    1878         395 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    1879             :           else
    1880             :             /* ...has all non-static data members and bit-fields in the class
    1881             :                and its base classes first declared in the same class.  */
    1882   170447126 :             for (basefield = TYPE_FIELDS (basetype); basefield;
    1883   157242277 :                  basefield = DECL_CHAIN (basefield))
    1884   157726889 :               if (TREE_CODE (basefield) == FIELD_DECL
    1885   158561897 :                   && !(DECL_FIELD_IS_BASE (basefield)
    1886      835008 :                        && is_empty_field (basefield)))
    1887             :                 {
    1888      484612 :                   if (field)
    1889       64677 :                     CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    1890             :                   else
    1891             :                     field = basefield;
    1892             :                   break;
    1893             :                 }
    1894             :         }
    1895             : 
    1896             :       /* Don't bother collecting tm attributes if transactional memory
    1897             :          support is not enabled.  */
    1898    14347541 :       if (flag_tm)
    1899             :         {
    1900        1375 :           tree tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (basetype));
    1901        1375 :           if (tm_attr)
    1902          20 :             seen_tm_mask |= tm_attr_to_mask (tm_attr);
    1903             :         }
    1904             : 
    1905    14347541 :       check_abi_tags (t, basetype);
    1906             :     }
    1907             : 
    1908             :   /* If one of the base classes had TM attributes, and the current class
    1909             :      doesn't define its own, then the current class inherits one.  */
    1910    25156660 :   if (seen_tm_mask && !find_tm_attribute (TYPE_ATTRIBUTES (t)))
    1911             :     {
    1912          16 :       tree tm_attr = tm_mask_to_attr (least_bit_hwi (seen_tm_mask));
    1913          16 :       TYPE_ATTRIBUTES (t) = tree_cons (tm_attr, NULL, TYPE_ATTRIBUTES (t));
    1914             :     }
    1915    25156660 : }
    1916             : 
    1917             : /* Determine all the primary bases within T.  Sets BINFO_PRIMARY_BASE_P for
    1918             :    those that are primaries.  Sets BINFO_LOST_PRIMARY_P for those
    1919             :    that have had a nearly-empty virtual primary base stolen by some
    1920             :    other base in the hierarchy.  Determines CLASSTYPE_PRIMARY_BASE for
    1921             :    T.  */
    1922             : 
    1923             : static void
    1924    25156660 : determine_primary_bases (tree t)
    1925             : {
    1926    25156660 :   unsigned i;
    1927    25156660 :   tree primary = NULL_TREE;
    1928    25156660 :   tree type_binfo = TYPE_BINFO (t);
    1929    25156660 :   tree base_binfo;
    1930             : 
    1931             :   /* Determine the primary bases of our bases.  */
    1932    42320562 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    1933    17163902 :        base_binfo = TREE_CHAIN (base_binfo))
    1934             :     {
    1935    17163902 :       tree primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (base_binfo));
    1936             : 
    1937             :       /* See if we're the non-virtual primary of our inheritance
    1938             :          chain.  */
    1939    17163902 :       if (!BINFO_VIRTUAL_P (base_binfo))
    1940             :         {
    1941    17012330 :           tree parent = BINFO_INHERITANCE_CHAIN (base_binfo);
    1942    17012330 :           tree parent_primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (parent));
    1943             : 
    1944    17012330 :           if (parent_primary
    1945    17012330 :               && SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
    1946             :                                     BINFO_TYPE (parent_primary)))
    1947             :             /* We are the primary binfo.  */
    1948      720063 :             BINFO_PRIMARY_P (base_binfo) = 1;
    1949             :         }
    1950             :       /* Determine if we have a virtual primary base, and mark it so.
    1951             :        */
    1952    17891519 :       if (primary && BINFO_VIRTUAL_P (primary))
    1953             :         {
    1954        7554 :           tree this_primary = copied_binfo (primary, base_binfo);
    1955             : 
    1956        7554 :           if (BINFO_PRIMARY_P (this_primary))
    1957             :             /* Someone already claimed this base.  */
    1958         782 :             BINFO_LOST_PRIMARY_P (base_binfo) = 1;
    1959             :           else
    1960             :             {
    1961        6772 :               tree delta;
    1962             : 
    1963        6772 :               BINFO_PRIMARY_P (this_primary) = 1;
    1964        6772 :               BINFO_INHERITANCE_CHAIN (this_primary) = base_binfo;
    1965             : 
    1966             :               /* A virtual binfo might have been copied from within
    1967             :                  another hierarchy. As we're about to use it as a
    1968             :                  primary base, make sure the offsets match.  */
    1969        6772 :               delta = size_diffop_loc (input_location,
    1970        6772 :                                    fold_convert (ssizetype,
    1971             :                                             BINFO_OFFSET (base_binfo)),
    1972        6772 :                                    fold_convert (ssizetype,
    1973             :                                             BINFO_OFFSET (this_primary)));
    1974             : 
    1975        6772 :               propagate_binfo_offsets (this_primary, delta);
    1976             :             }
    1977             :         }
    1978             :     }
    1979             : 
    1980             :   /* First look for a dynamic direct non-virtual base.  */
    1981    38413847 :   for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, base_binfo); i++)
    1982             :     {
    1983    14226245 :       tree basetype = BINFO_TYPE (base_binfo);
    1984             : 
    1985    14226245 :       if (TYPE_CONTAINS_VPTR_P (basetype) && !BINFO_VIRTUAL_P (base_binfo))
    1986             :         {
    1987      969058 :           primary = base_binfo;
    1988      969058 :           goto found;
    1989             :         }
    1990             :     }
    1991             : 
    1992             :   /* A "nearly-empty" virtual base class can be the primary base
    1993             :      class, if no non-virtual polymorphic base can be found.  Look for
    1994             :      a nearly-empty virtual dynamic base that is not already a primary
    1995             :      base of something in the hierarchy.  If there is no such base,
    1996             :      just pick the first nearly-empty virtual base.  */
    1997             : 
    1998    39149102 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    1999    14961500 :        base_binfo = TREE_CHAIN (base_binfo))
    2000    14963303 :     if (BINFO_VIRTUAL_P (base_binfo)
    2001    14963303 :         && CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (base_binfo)))
    2002             :       {
    2003        1968 :         if (!BINFO_PRIMARY_P (base_binfo))
    2004             :           {
    2005             :             /* Found one that is not primary.  */
    2006        1803 :             primary = base_binfo;
    2007        1803 :             goto found;
    2008             :           }
    2009         165 :         else if (!primary)
    2010             :           /* Remember the first candidate.  */
    2011    14961500 :           primary = base_binfo;
    2012             :       }
    2013             : 
    2014    24185799 :  found:
    2015             :   /* If we've got a primary base, use it.  */
    2016    25156660 :   if (primary)
    2017             :     {
    2018      970962 :       tree basetype = BINFO_TYPE (primary);
    2019             : 
    2020      970962 :       CLASSTYPE_PRIMARY_BINFO (t) = primary;
    2021      970962 :       if (BINFO_PRIMARY_P (primary))
    2022             :         /* We are stealing a primary base.  */
    2023         101 :         BINFO_LOST_PRIMARY_P (BINFO_INHERITANCE_CHAIN (primary)) = 1;
    2024      970962 :       BINFO_PRIMARY_P (primary) = 1;
    2025      970962 :       if (BINFO_VIRTUAL_P (primary))
    2026             :         {
    2027        1904 :           tree delta;
    2028             : 
    2029        1904 :           BINFO_INHERITANCE_CHAIN (primary) = type_binfo;
    2030             :           /* A virtual binfo might have been copied from within
    2031             :              another hierarchy. As we're about to use it as a primary
    2032             :              base, make sure the offsets match.  */
    2033        1904 :           delta = size_diffop_loc (input_location, ssize_int (0),
    2034        1904 :                                fold_convert (ssizetype, BINFO_OFFSET (primary)));
    2035             : 
    2036        1904 :           propagate_binfo_offsets (primary, delta);
    2037             :         }
    2038             : 
    2039      970962 :       primary = TYPE_BINFO (basetype);
    2040             : 
    2041      970962 :       TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
    2042      970962 :       BINFO_VTABLE (type_binfo) = BINFO_VTABLE (primary);
    2043      970962 :       BINFO_VIRTUALS (type_binfo) = BINFO_VIRTUALS (primary);
    2044             :     }
    2045    25156660 : }
    2046             : 
    2047             : /* Update the variant types of T.  */
    2048             : 
    2049             : void
    2050    84225762 : fixup_type_variants (tree type)
    2051             : {
    2052    84225762 :   if (!type)
    2053             :     return;
    2054             : 
    2055    84225762 :   for (tree variant = TYPE_NEXT_VARIANT (type);
    2056   167154458 :        variant;
    2057    82928696 :        variant = TYPE_NEXT_VARIANT (variant))
    2058             :     {
    2059             :       /* These fields are in the _TYPE part of the node, not in
    2060             :          the TYPE_LANG_SPECIFIC component, so they are not shared.  */
    2061    82928696 :       TYPE_HAS_USER_CONSTRUCTOR (variant) = TYPE_HAS_USER_CONSTRUCTOR (type);
    2062    82928696 :       TYPE_NEEDS_CONSTRUCTING (variant) = TYPE_NEEDS_CONSTRUCTING (type);
    2063   165857392 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variant)
    2064    82928696 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    2065             : 
    2066    82928696 :       TYPE_POLYMORPHIC_P (variant) = TYPE_POLYMORPHIC_P (type);
    2067    82928696 :       CLASSTYPE_FINAL (variant) = CLASSTYPE_FINAL (type);
    2068             : 
    2069    82928696 :       TYPE_BINFO (variant) = TYPE_BINFO (type);
    2070             : 
    2071             :       /* Copy whatever these are holding today.  */
    2072    82928696 :       TYPE_VFIELD (variant) = TYPE_VFIELD (type);
    2073    82928696 :       TYPE_FIELDS (variant) = TYPE_FIELDS (type);
    2074             : 
    2075    82928696 :       TYPE_SIZE (variant) = TYPE_SIZE (type);
    2076    82928696 :       TYPE_SIZE_UNIT (variant) = TYPE_SIZE_UNIT (type);
    2077             : 
    2078    82928696 :       if (!TYPE_USER_ALIGN (variant)
    2079     1791006 :           || TYPE_NAME (variant) == TYPE_NAME (type)
    2080    83838674 :           || TYPE_ALIGN_RAW (variant) < TYPE_ALIGN_RAW (type))
    2081             :         {
    2082    82018718 :           TYPE_ALIGN_RAW (variant) =  TYPE_ALIGN_RAW (type);
    2083    82018718 :           TYPE_USER_ALIGN (variant) = TYPE_USER_ALIGN (type);
    2084             :         }
    2085             : 
    2086    82928696 :       TYPE_PRECISION (variant) = TYPE_PRECISION (type);
    2087    82928696 :       TYPE_MODE_RAW (variant) = TYPE_MODE_RAW (type);
    2088    82928696 :       TYPE_EMPTY_P (variant) = TYPE_EMPTY_P (type);
    2089             :     }
    2090             : }
    2091             : 
    2092             : /* KLASS is a class that we're applying may_alias to after the body is
    2093             :    parsed.  Fixup any POINTER_TO and REFERENCE_TO types.  The
    2094             :    canonical type(s) will be implicitly updated.  */
    2095             : 
    2096             : static void
    2097       28309 : fixup_may_alias (tree klass)
    2098             : {
    2099       28309 :   tree t, v;
    2100             : 
    2101       42359 :   for (t = TYPE_POINTER_TO (klass); t; t = TYPE_NEXT_PTR_TO (t))
    2102       42130 :     for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    2103       28080 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    2104       28336 :   for (t = TYPE_REFERENCE_TO (klass); t; t = TYPE_NEXT_REF_TO (t))
    2105          54 :     for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    2106          27 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    2107       28309 : }
    2108             : 
    2109             : /* Early variant fixups: we apply attributes at the beginning of the class
    2110             :    definition, and we need to fix up any variants that have already been
    2111             :    made via elaborated-type-specifier so that check_qualified_type works.  */
    2112             : 
    2113             : void
    2114    54850479 : fixup_attribute_variants (tree t)
    2115             : {
    2116    54850479 :   tree variants;
    2117             : 
    2118    54850479 :   if (!t)
    2119             :     return;
    2120             : 
    2121    54850479 :   tree attrs = TYPE_ATTRIBUTES (t);
    2122    54850479 :   unsigned align = TYPE_ALIGN (t);
    2123    54850479 :   bool user_align = TYPE_USER_ALIGN (t);
    2124    54850479 :   bool may_alias = lookup_attribute ("may_alias", attrs);
    2125    54850479 :   bool packed = TYPE_PACKED (t);
    2126             : 
    2127    54850479 :   if (may_alias)
    2128       14179 :     fixup_may_alias (t);
    2129             : 
    2130    54850479 :   for (variants = TYPE_NEXT_VARIANT (t);
    2131    81501907 :        variants;
    2132    26651428 :        variants = TYPE_NEXT_VARIANT (variants))
    2133             :     {
    2134             :       /* These are the two fields that check_qualified_type looks at and
    2135             :          are affected by attributes.  */
    2136    26651428 :       TYPE_ATTRIBUTES (variants) = attrs;
    2137    26651428 :       unsigned valign = align;
    2138    26651428 :       if (TYPE_USER_ALIGN (variants))
    2139         766 :         valign = MAX (valign, TYPE_ALIGN (variants));
    2140             :       else
    2141    26650662 :         TYPE_USER_ALIGN (variants) = user_align;
    2142    26651428 :       SET_TYPE_ALIGN (variants, valign);
    2143    26651428 :       TYPE_PACKED (variants) = packed;
    2144    26651428 :       if (may_alias)
    2145       14130 :         fixup_may_alias (variants);
    2146             :     }
    2147             : }
    2148             : 
    2149             : /* Set memoizing fields and bits of T (and its variants) for later
    2150             :    use.  */
    2151             : 
    2152             : static void
    2153    25156660 : finish_struct_bits (tree t)
    2154             : {
    2155             :   /* Fix up variants (if any).  */
    2156    25156660 :   fixup_type_variants (t);
    2157             : 
    2158    25156660 :   if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) && TYPE_POLYMORPHIC_P (t))
    2159             :     /* For a class w/o baseclasses, 'finish_struct' has set
    2160             :        CLASSTYPE_PURE_VIRTUALS correctly (by definition).
    2161             :        Similarly for a class whose base classes do not have vtables.
    2162             :        When neither of these is true, we might have removed abstract
    2163             :        virtuals (by providing a definition), added some (by declaring
    2164             :        new ones), or redeclared ones from a base class.  We need to
    2165             :        recalculate what's really an abstract virtual at this point (by
    2166             :        looking in the vtables).  */
    2167     1023622 :     get_pure_virtuals (t);
    2168             : 
    2169             :   /* If this type has a copy constructor or a destructor, force its
    2170             :      mode to be BLKmode, and force its TREE_ADDRESSABLE bit to be
    2171             :      nonzero.  This will cause it to be passed by invisible reference
    2172             :      and prevent it from being returned in a register.  */
    2173    25156660 :   if (type_has_nontrivial_copy_init (t)
    2174    25156660 :       || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    2175             :     {
    2176     3026641 :       tree variants;
    2177     3026641 :       SET_DECL_MODE (TYPE_MAIN_DECL (t), BLKmode);
    2178    12801377 :       for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
    2179             :         {
    2180     9774736 :           SET_TYPE_MODE (variants, BLKmode);
    2181     9774736 :           TREE_ADDRESSABLE (variants) = 1;
    2182             :         }
    2183             :     }
    2184    25156660 : }
    2185             : 
    2186             : /* Issue warnings about T having private constructors, but no friends,
    2187             :    and so forth.
    2188             : 
    2189             :    HAS_NONPRIVATE_METHOD is nonzero if T has any non-private methods or
    2190             :    static members.  HAS_NONPRIVATE_STATIC_FN is nonzero if T has any
    2191             :    non-private static member functions.  */
    2192             : 
    2193             : static void
    2194    17932196 : maybe_warn_about_overly_private_class (tree t)
    2195             : {
    2196    17932196 :   int has_member_fn = 0;
    2197    17932196 :   int has_nonprivate_method = 0;
    2198    17932196 :   bool nonprivate_ctor = false;
    2199             : 
    2200    17932196 :   if (!warn_ctor_dtor_privacy
    2201             :       /* If the class has friends, those entities might create and
    2202             :          access instances, so we should not warn.  */
    2203          59 :       || (CLASSTYPE_FRIEND_CLASSES (t)
    2204          59 :           || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
    2205             :       /* We will have warned when the template was declared; there's
    2206             :          no need to warn on every instantiation.  */
    2207    17932255 :       || CLASSTYPE_TEMPLATE_INSTANTIATION (t))
    2208             :     /* There's no reason to even consider warning about this
    2209             :        class.  */
    2210             :     return;
    2211             : 
    2212             :   /* We only issue one warning, if more than one applies, because
    2213             :      otherwise, on code like:
    2214             : 
    2215             :      class A {
    2216             :        // Oops - forgot `public:'
    2217             :        A();
    2218             :        A(const A&);
    2219             :        ~A();
    2220             :      };
    2221             : 
    2222             :      we warn several times about essentially the same problem.  */
    2223             : 
    2224             :   /* Check to see if all (non-constructor, non-destructor) member
    2225             :      functions are private.  (Since there are no friends or
    2226             :      non-private statics, we can't ever call any of the private member
    2227             :      functions.)  */
    2228         265 :   for (tree fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    2229         206 :     if (TREE_CODE (fn) == USING_DECL
    2230          21 :         && DECL_NAME (fn) == ctor_identifier
    2231         209 :         && !TREE_PRIVATE (fn))
    2232             :       nonprivate_ctor = true;
    2233         203 :     else if (!DECL_DECLARES_FUNCTION_P (fn))
    2234             :       /* Not a function.  */;
    2235         118 :     else if (DECL_ARTIFICIAL (fn))
    2236             :       /* We're not interested in compiler-generated methods; they don't
    2237             :          provide any way to call private members.  */;
    2238         118 :     else if (!TREE_PRIVATE (fn))
    2239             :       {
    2240          54 :         if (DECL_STATIC_FUNCTION_P (fn))
    2241             :           /* A non-private static member function is just like a
    2242             :              friend; it can create and invoke private member
    2243             :              functions, and be accessed without a class
    2244             :              instance.  */
    2245             :           return;
    2246             : 
    2247             :         has_nonprivate_method = 1;
    2248             :         /* Keep searching for a static member function.  */
    2249             :       }
    2250         128 :     else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
    2251             :       has_member_fn = 1;
    2252             : 
    2253          59 :   if (!has_nonprivate_method && has_member_fn)
    2254             :     {
    2255             :       /* There are no non-private methods, and there's at least one
    2256             :          private member function that isn't a constructor or
    2257             :          destructor.  (If all the private members are
    2258             :          constructors/destructors we want to use the code below that
    2259             :          issues error messages specifically referring to
    2260             :          constructors/destructors.)  */
    2261          16 :       unsigned i;
    2262          16 :       tree binfo = TYPE_BINFO (t);
    2263             : 
    2264          16 :       for (i = 0; i != BINFO_N_BASE_BINFOS (binfo); i++)
    2265           0 :         if (BINFO_BASE_ACCESS (binfo, i) != access_private_node)
    2266             :           {
    2267             :             has_nonprivate_method = 1;
    2268             :             break;
    2269             :           }
    2270          16 :       if (!has_nonprivate_method)
    2271             :         {
    2272          16 :           warning (OPT_Wctor_dtor_privacy,
    2273             :                    "all member functions in class %qT are private", t);
    2274          16 :           return;
    2275             :         }
    2276             :     }
    2277             : 
    2278             :   /* Even if some of the member functions are non-private, the class
    2279             :      won't be useful for much if all the constructors or destructors
    2280             :      are private: such an object can never be created or destroyed.  */
    2281          43 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    2282           8 :     if (TREE_PRIVATE (dtor))
    2283             :       {
    2284           8 :         warning (OPT_Wctor_dtor_privacy,
    2285             :                  "%q#T only defines a private destructor and has no friends",
    2286             :                  t);
    2287           8 :         return;
    2288             :       }
    2289             : 
    2290             :   /* Warn about classes that have private constructors and no friends.  */
    2291          35 :   if (TYPE_HAS_USER_CONSTRUCTOR (t)
    2292             :       /* Implicitly generated constructors are always public.  */
    2293          35 :       && !CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    2294             :     {
    2295          24 :       tree copy_or_move = NULL_TREE;
    2296             : 
    2297             :       /* If a non-template class does not define a copy
    2298             :          constructor, one is defined for it, enabling it to avoid
    2299             :          this warning.  For a template class, this does not
    2300             :          happen, and so we would normally get a warning on:
    2301             : 
    2302             :            template <class T> class C { private: C(); };
    2303             : 
    2304             :          To avoid this asymmetry, we check TYPE_HAS_COPY_CTOR.  All
    2305             :          complete non-template or fully instantiated classes have this
    2306             :          flag set.  */
    2307          24 :       if (!TYPE_HAS_COPY_CTOR (t))
    2308             :         nonprivate_ctor = true;
    2309             :       else
    2310          82 :         for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    2311          32 :           if (TREE_PRIVATE (fn))
    2312          16 :             continue;
    2313          16 :           else if (copy_fn_p (fn) || move_fn_p (fn))
    2314             :             /* Ideally, we wouldn't count any constructor that takes
    2315             :                an argument of the class type as a parameter, because
    2316             :                such things cannot be used to construct an instance of
    2317             :                the class unless you already have one.  */
    2318             :             copy_or_move = fn;
    2319             :           else
    2320             :             {
    2321             :               nonprivate_ctor = true;
    2322             :               break;
    2323             :             }
    2324             : 
    2325          24 :       if (!nonprivate_ctor)
    2326             :         {
    2327          18 :           bool w = warning (OPT_Wctor_dtor_privacy,
    2328             :                             "%q#T only defines private constructors and has "
    2329             :                             "no friends", t);
    2330          18 :           if (w && copy_or_move)
    2331           6 :             inform (DECL_SOURCE_LOCATION (copy_or_move),
    2332             :                     "%q#D is public, but requires an existing %q#T object",
    2333             :                     copy_or_move, t);
    2334          18 :           return;
    2335             :         }
    2336             :     }
    2337             : }
    2338             : 
    2339             : /* Make BINFO's vtable have N entries, including RTTI entries,
    2340             :    vbase and vcall offsets, etc.  Set its type and call the back end
    2341             :    to lay it out.  */
    2342             : 
    2343             : static void
    2344     1144766 : layout_vtable_decl (tree binfo, int n)
    2345             : {
    2346     1144766 :   tree atype;
    2347     1144766 :   tree vtable;
    2348             : 
    2349     1144766 :   atype = build_array_of_n_type (vtable_entry_type, n);
    2350     1144766 :   layout_type (atype);
    2351             : 
    2352             :   /* We may have to grow the vtable.  */
    2353     1144766 :   vtable = get_vtbl_decl_for_binfo (binfo);
    2354     1144766 :   if (!same_type_p (TREE_TYPE (vtable), atype))
    2355             :     {
    2356      404627 :       TREE_TYPE (vtable) = atype;
    2357      404627 :       DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE;
    2358      404627 :       layout_decl (vtable, 0);
    2359             :     }
    2360     1144766 : }
    2361             : 
    2362             : /* True iff FNDECL and BASE_FNDECL (both non-static member functions)
    2363             :    have the same signature.  */
    2364             : 
    2365             : int
    2366    54112723 : same_signature_p (const_tree fndecl, const_tree base_fndecl)
    2367             : {
    2368             :   /* One destructor overrides another if they are the same kind of
    2369             :      destructor.  */
    2370    83523369 :   if (DECL_DESTRUCTOR_P (base_fndecl) && DECL_DESTRUCTOR_P (fndecl)
    2371    68728429 :       && special_function_p (base_fndecl) == special_function_p (fndecl))
    2372             :     return 1;
    2373             :   /* But a non-destructor never overrides a destructor, nor vice
    2374             :      versa, nor do different kinds of destructors override
    2375             :      one-another.  For example, a complete object destructor does not
    2376             :      override a deleting destructor.  */
    2377   131737970 :   if (DECL_DESTRUCTOR_P (base_fndecl) || DECL_DESTRUCTOR_P (fndecl))
    2378             :     return 0;
    2379             : 
    2380    32639956 :   if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl)
    2381    32639956 :       || (DECL_CONV_FN_P (fndecl)
    2382          40 :           && DECL_CONV_FN_P (base_fndecl)
    2383          16 :           && same_type_p (DECL_CONV_FN_TYPE (fndecl),
    2384             :                           DECL_CONV_FN_TYPE (base_fndecl))))
    2385             :     {
    2386    11029368 :       tree fntype = TREE_TYPE (fndecl);
    2387    11029368 :       tree base_fntype = TREE_TYPE (base_fndecl);
    2388    11029368 :       if (type_memfn_quals (fntype) == type_memfn_quals (base_fntype)
    2389    11029058 :           && type_memfn_rqual (fntype) == type_memfn_rqual (base_fntype)
    2390    22058423 :           && compparms (FUNCTION_FIRST_USER_PARMTYPE (fndecl),
    2391    11029055 :                         FUNCTION_FIRST_USER_PARMTYPE (base_fndecl)))
    2392             :         return 1;
    2393             :     }
    2394             :   return 0;
    2395             : }
    2396             : 
    2397             : /* Returns TRUE if DERIVED is a binfo containing the binfo BASE as a
    2398             :    subobject.  */
    2399             : 
    2400             : static bool
    2401      178824 : base_derived_from (tree derived, tree base)
    2402             : {
    2403      178824 :   tree probe;
    2404             : 
    2405      179192 :   for (probe = base; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
    2406             :     {
    2407      179052 :       if (probe == derived)
    2408             :         return true;
    2409        2068 :       else if (BINFO_VIRTUAL_P (probe))
    2410             :         /* If we meet a virtual base, we can't follow the inheritance
    2411             :            any more.  See if the complete type of DERIVED contains
    2412             :            such a virtual base.  */
    2413        1700 :         return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (derived))
    2414        1700 :                 != NULL_TREE);
    2415             :     }
    2416             :   return false;
    2417             : }
    2418             : 
    2419     5239201 : struct find_final_overrider_data {
    2420             :   /* The function for which we are trying to find a final overrider.  */
    2421             :   tree fn;
    2422             :   /* The base class in which the function was declared.  */
    2423             :   tree declaring_base;
    2424             :   /* The candidate overriders.  */
    2425             :   tree candidates;
    2426             :   /* Path to most derived.  */
    2427             :   auto_vec<tree> path;
    2428             : };
    2429             : 
    2430             : /* Add the overrider along the current path to FFOD->CANDIDATES.
    2431             :    Returns true if an overrider was found; false otherwise.  */
    2432             : 
    2433             : static bool
    2434     8787681 : dfs_find_final_overrider_1 (tree binfo,
    2435             :                             find_final_overrider_data *ffod,
    2436             :                             unsigned depth)
    2437             : {
    2438     8787681 :   tree method;
    2439             : 
    2440             :   /* If BINFO is not the most derived type, try a more derived class.
    2441             :      A definition there will overrider a definition here.  */
    2442     8787681 :   if (depth)
    2443             :     {
    2444     3370376 :       depth--;
    2445     3370376 :       if (dfs_find_final_overrider_1
    2446     3370376 :           (ffod->path[depth], ffod, depth))
    2447             :         return true;
    2448             :     }
    2449             : 
    2450     6821938 :   method = look_for_overrides_here (BINFO_TYPE (binfo), ffod->fn);
    2451     6821938 :   if (method)
    2452             :     {
    2453     5417305 :       tree *candidate = &ffod->candidates;
    2454             : 
    2455             :       /* Remove any candidates overridden by this new function.  */
    2456     5418001 :       while (*candidate)
    2457             :         {
    2458             :           /* If *CANDIDATE overrides METHOD, then METHOD
    2459             :              cannot override anything else on the list.  */
    2460      178128 :           if (base_derived_from (TREE_VALUE (*candidate), binfo))
    2461             :             return true;
    2462             :           /* If METHOD overrides *CANDIDATE, remove *CANDIDATE.  */
    2463         696 :           if (base_derived_from (binfo, TREE_VALUE (*candidate)))
    2464         624 :             *candidate = TREE_CHAIN (*candidate);
    2465             :           else
    2466          72 :             candidate = &TREE_CHAIN (*candidate);
    2467             :         }
    2468             : 
    2469             :       /* Add the new function.  */
    2470     5239873 :       ffod->candidates = tree_cons (method, binfo, ffod->candidates);
    2471     5239873 :       return true;
    2472             :     }
    2473             : 
    2474             :   return false;
    2475             : }
    2476             : 
    2477             : /* Called from find_final_overrider via dfs_walk.  */
    2478             : 
    2479             : static tree
    2480    20051452 : dfs_find_final_overrider_pre (tree binfo, void *data)
    2481             : {
    2482    20051452 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2483             : 
    2484    20051452 :   if (binfo == ffod->declaring_base)
    2485    10834610 :     dfs_find_final_overrider_1 (binfo, ffod, ffod->path.length ());
    2486    20051452 :   ffod->path.safe_push (binfo);
    2487             : 
    2488    20051452 :   return NULL_TREE;
    2489             : }
    2490             : 
    2491             : static tree
    2492    20051452 : dfs_find_final_overrider_post (tree /*binfo*/, void *data)
    2493             : {
    2494    20051452 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2495    20051452 :   ffod->path.pop ();
    2496             : 
    2497    20051452 :   return NULL_TREE;
    2498             : }
    2499             : 
    2500             : /* Returns a TREE_LIST whose TREE_PURPOSE is the final overrider for
    2501             :    FN and whose TREE_VALUE is the binfo for the base where the
    2502             :    overriding occurs.  BINFO (in the hierarchy dominated by the binfo
    2503             :    DERIVED) is the base object in which FN is declared.  */
    2504             : 
    2505             : static tree
    2506     5239201 : find_final_overrider (tree derived, tree binfo, tree fn)
    2507             : {
    2508     5239201 :   find_final_overrider_data ffod;
    2509             : 
    2510             :   /* Getting this right is a little tricky.  This is valid:
    2511             : 
    2512             :        struct S { virtual void f (); };
    2513             :        struct T { virtual void f (); };
    2514             :        struct U : public S, public T { };
    2515             : 
    2516             :      even though calling `f' in `U' is ambiguous.  But,
    2517             : 
    2518             :        struct R { virtual void f(); };
    2519             :        struct S : virtual public R { virtual void f (); };
    2520             :        struct T : virtual public R { virtual void f (); };
    2521             :        struct U : public S, public T { };
    2522             : 
    2523             :      is not -- there's no way to decide whether to put `S::f' or
    2524             :      `T::f' in the vtable for `R'.
    2525             : 
    2526             :      The solution is to look at all paths to BINFO.  If we find
    2527             :      different overriders along any two, then there is a problem.  */
    2528     5239201 :   if (DECL_THUNK_P (fn))
    2529           0 :     fn = THUNK_TARGET (fn);
    2530             : 
    2531             :   /* Determine the depth of the hierarchy.  */
    2532     5239201 :   ffod.fn = fn;
    2533     5239201 :   ffod.declaring_base = binfo;
    2534     5239201 :   ffod.candidates = NULL_TREE;
    2535     5239201 :   ffod.path.create (30);
    2536             : 
    2537     5239201 :   dfs_walk_all (derived, dfs_find_final_overrider_pre,
    2538             :                 dfs_find_final_overrider_post, &ffod);
    2539             : 
    2540             :   /* If there was no winner, issue an error message.  */
    2541     5239201 :   if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
    2542          48 :     return error_mark_node;
    2543             : 
    2544             :   return ffod.candidates;
    2545     5239201 : }
    2546             : 
    2547             : /* Return the index of the vcall offset for FN when TYPE is used as a
    2548             :    virtual base.  */
    2549             : 
    2550             : static tree
    2551      269506 : get_vcall_index (tree fn, tree type)
    2552             : {
    2553      269506 :   vec<tree_pair_s, va_gc> *indices = CLASSTYPE_VCALL_INDICES (type);
    2554      269506 :   tree_pair_p p;
    2555      269506 :   unsigned ix;
    2556             : 
    2557      277416 :   FOR_EACH_VEC_SAFE_ELT (indices, ix, p)
    2558      827872 :     if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (p->purpose))
    2559      284928 :         || same_signature_p (fn, p->purpose))
    2560      269506 :       return p->value;
    2561             : 
    2562             :   /* There should always be an appropriate index.  */
    2563           0 :   gcc_unreachable ();
    2564             : }
    2565             : 
    2566             : /* Given a DECL_VINDEX of a virtual function found in BINFO, return the final
    2567             :    overrider at that index in the vtable.  This should only be used when we
    2568             :    know that BINFO is correct for the dynamic type of the object.  */
    2569             : 
    2570             : tree
    2571         914 : lookup_vfn_in_binfo (tree idx, tree binfo)
    2572             : {
    2573         914 :   int ix = tree_to_shwi (idx);
    2574         914 :   if (TARGET_VTABLE_USES_DESCRIPTORS)
    2575             :     ix /= MAX (TARGET_VTABLE_USES_DESCRIPTORS, 1);
    2576        1106 :   while (BINFO_PRIMARY_P (binfo))
    2577             :     /* BINFO_VIRTUALS in a primary base isn't accurate, find the derived
    2578             :        class that actually owns the vtable.  */
    2579         192 :     binfo = BINFO_INHERITANCE_CHAIN (binfo);
    2580         914 :   tree virtuals = BINFO_VIRTUALS (binfo);
    2581         914 :   return TREE_VALUE (chain_index (ix, virtuals));
    2582             : }
    2583             : 
    2584             : /* Update an entry in the vtable for BINFO, which is in the hierarchy
    2585             :    dominated by T.  FN is the old function; VIRTUALS points to the
    2586             :    corresponding position in the new BINFO_VIRTUALS list.  IX is the index
    2587             :    of that entry in the list.  */
    2588             : 
    2589             : static void
    2590     4914409 : update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
    2591             :                             unsigned ix)
    2592             : {
    2593     4914409 :   tree b;
    2594     4914409 :   tree overrider;
    2595     4914409 :   tree delta;
    2596     4914409 :   tree virtual_base;
    2597     4914409 :   tree first_defn;
    2598     4914409 :   tree overrider_fn, overrider_target;
    2599     4914409 :   tree target_fn = DECL_THUNK_P (fn) ? THUNK_TARGET (fn) : fn;
    2600     4914409 :   tree over_return, base_return;
    2601     4914409 :   bool lost = false;
    2602             : 
    2603             :   /* Find the nearest primary base (possibly binfo itself) which defines
    2604             :      this function; this is the class the caller will convert to when
    2605             :      calling FN through BINFO.  */
    2606     6252724 :   for (b = binfo; ; b = get_primary_binfo (b))
    2607             :     {
    2608     6252724 :       gcc_assert (b);
    2609     6252724 :       if (look_for_overrides_here (BINFO_TYPE (b), target_fn))
    2610             :         break;
    2611             : 
    2612             :       /* The nearest definition is from a lost primary.  */
    2613     1338315 :       if (BINFO_LOST_PRIMARY_P (b))
    2614         488 :         lost = true;
    2615             :     }
    2616     4914409 :   first_defn = b;
    2617             : 
    2618             :   /* Find the final overrider.  */
    2619     4914409 :   overrider = find_final_overrider (TYPE_BINFO (t), b, target_fn);
    2620     4914409 :   if (overrider == error_mark_node)
    2621             :     {
    2622          12 :       error ("no unique final overrider for %qD in %qT", target_fn, t);
    2623          12 :       return;
    2624             :     }
    2625     4914397 :   overrider_target = overrider_fn = TREE_PURPOSE (overrider);
    2626             : 
    2627             :   /* Check for adjusting covariant return types.  */
    2628     4914397 :   over_return = TREE_TYPE (TREE_TYPE (overrider_target));
    2629     4914397 :   base_return = TREE_TYPE (TREE_TYPE (target_fn));
    2630             : 
    2631     4914397 :   if (INDIRECT_TYPE_P (over_return)
    2632      456904 :       && TREE_CODE (over_return) == TREE_CODE (base_return)
    2633      456892 :       && CLASS_TYPE_P (TREE_TYPE (over_return))
    2634       31185 :       && CLASS_TYPE_P (TREE_TYPE (base_return))
    2635             :       /* If the overrider is invalid, don't even try.  */
    2636     4945574 :       && !DECL_INVALID_OVERRIDER_P (overrider_target))
    2637             :     {
    2638             :       /* If FN is a covariant thunk, we must figure out the adjustment
    2639             :          to the final base FN was converting to. As OVERRIDER_TARGET might
    2640             :          also be converting to the return type of FN, we have to
    2641             :          combine the two conversions here.  */
    2642       31135 :       tree fixed_offset, virtual_offset;
    2643             : 
    2644       31135 :       over_return = TREE_TYPE (over_return);
    2645       31135 :       base_return = TREE_TYPE (base_return);
    2646             : 
    2647       31135 :       if (DECL_THUNK_P (fn))
    2648             :         {
    2649          80 :           gcc_assert (DECL_RESULT_THUNK_P (fn));
    2650          80 :           fixed_offset = ssize_int (THUNK_FIXED_OFFSET (fn));
    2651          80 :           virtual_offset = THUNK_VIRTUAL_OFFSET (fn);
    2652             :         }
    2653             :       else
    2654             :         fixed_offset = virtual_offset = NULL_TREE;
    2655             : 
    2656          80 :       if (virtual_offset)
    2657             :         /* Find the equivalent binfo within the return type of the
    2658             :            overriding function. We will want the vbase offset from
    2659             :            there.  */
    2660          72 :         virtual_offset = binfo_for_vbase (BINFO_TYPE (virtual_offset),
    2661             :                                           over_return);
    2662       31063 :       else if (!same_type_ignoring_top_level_qualifiers_p
    2663       31063 :                (over_return, base_return))
    2664             :         {
    2665             :           /* There was no existing virtual thunk (which takes
    2666             :              precedence).  So find the binfo of the base function's
    2667             :              return type within the overriding function's return type.
    2668             :              Fortunately we know the covariancy is valid (it
    2669             :              has already been checked), so we can just iterate along
    2670             :              the binfos, which have been chained in inheritance graph
    2671             :              order.  Of course it is lame that we have to repeat the
    2672             :              search here anyway -- we should really be caching pieces
    2673             :              of the vtable and avoiding this repeated work.  */
    2674         468 :           tree thunk_binfo = NULL_TREE;
    2675         468 :           tree base_binfo = TYPE_BINFO (base_return);
    2676             : 
    2677             :           /* Find the base binfo within the overriding function's
    2678             :              return type.  We will always find a thunk_binfo, except
    2679             :              when the covariancy is invalid (which we will have
    2680             :              already diagnosed).  */
    2681         468 :           if (base_binfo)
    2682        1224 :             for (thunk_binfo = TYPE_BINFO (over_return); thunk_binfo;
    2683         760 :                  thunk_binfo = TREE_CHAIN (thunk_binfo))
    2684        1224 :               if (SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo),
    2685             :                                      BINFO_TYPE (base_binfo)))
    2686             :                 break;
    2687         468 :           gcc_assert (thunk_binfo || errorcount);
    2688             : 
    2689             :           /* See if virtual inheritance is involved.  */
    2690         324 :           for (virtual_offset = thunk_binfo;
    2691         792 :                virtual_offset;
    2692         324 :                virtual_offset = BINFO_INHERITANCE_CHAIN (virtual_offset))
    2693         646 :             if (BINFO_VIRTUAL_P (virtual_offset))
    2694             :               break;
    2695             : 
    2696         468 :           if (virtual_offset
    2697         610 :               || (thunk_binfo && !BINFO_OFFSET_ZEROP (thunk_binfo)))
    2698             :             {
    2699         409 :               tree offset = fold_convert (ssizetype, BINFO_OFFSET (thunk_binfo));
    2700             : 
    2701         409 :               if (virtual_offset)
    2702             :                 {
    2703             :                   /* We convert via virtual base.  Adjust the fixed
    2704             :                      offset to be from there.  */
    2705         322 :                   offset = 
    2706         322 :                     size_diffop (offset,
    2707             :                                  fold_convert (ssizetype,
    2708             :                                           BINFO_OFFSET (virtual_offset)));
    2709             :                 }
    2710         409 :               if (fixed_offset)
    2711             :                 /* There was an existing fixed offset, this must be
    2712             :                    from the base just converted to, and the base the
    2713             :                    FN was thunking to.  */
    2714           8 :                 fixed_offset = size_binop (PLUS_EXPR, fixed_offset, offset);
    2715             :               else
    2716             :                 fixed_offset = offset;
    2717             :             }
    2718             :         }
    2719             : 
    2720       31135 :       if (fixed_offset || virtual_offset)
    2721             :         /* Replace the overriding function with a covariant thunk.  We
    2722             :            will emit the overriding function in its own slot as
    2723             :            well.  */
    2724         481 :         overrider_fn = make_thunk (overrider_target, /*this_adjusting=*/0,
    2725             :                                    fixed_offset, virtual_offset);
    2726             :     }
    2727             :   else
    2728     4883262 :     gcc_assert (DECL_INVALID_OVERRIDER_P (overrider_target) ||
    2729             :                 !DECL_THUNK_P (fn));
    2730             : 
    2731             :   /* If we need a covariant thunk, then we may need to adjust first_defn.
    2732             :      The ABI specifies that the thunks emitted with a function are
    2733             :      determined by which bases the function overrides, so we need to be
    2734             :      sure that we're using a thunk for some overridden base; even if we
    2735             :      know that the necessary this adjustment is zero, there may not be an
    2736             :      appropriate zero-this-adjustment thunk for us to use since thunks for
    2737             :      overriding virtual bases always use the vcall offset.
    2738             : 
    2739             :      Furthermore, just choosing any base that overrides this function isn't
    2740             :      quite right, as this slot won't be used for calls through a type that
    2741             :      puts a covariant thunk here.  Calling the function through such a type
    2742             :      will use a different slot, and that slot is the one that determines
    2743             :      the thunk emitted for that base.
    2744             : 
    2745             :      So, keep looking until we find the base that we're really overriding
    2746             :      in this slot: the nearest primary base that doesn't use a covariant
    2747             :      thunk in this slot.  */
    2748     4914397 :   if (overrider_target != overrider_fn)
    2749             :     {
    2750         481 :       if (BINFO_TYPE (b) == DECL_CONTEXT (overrider_target))
    2751             :         /* We already know that the overrider needs a covariant thunk.  */
    2752         166 :         b = get_primary_binfo (b);
    2753          40 :       for (; ; b = get_primary_binfo (b))
    2754             :         {
    2755         521 :           tree main_binfo = TYPE_BINFO (BINFO_TYPE (b));
    2756         521 :           tree bv = chain_index (ix, BINFO_VIRTUALS (main_binfo));
    2757         521 :           if (!DECL_THUNK_P (TREE_VALUE (bv)))
    2758             :             break;
    2759          40 :           if (BINFO_LOST_PRIMARY_P (b))
    2760           8 :             lost = true;
    2761          40 :         }
    2762             :       first_defn = b;
    2763             :     }
    2764             : 
    2765             :   /* Assume that we will produce a thunk that convert all the way to
    2766             :      the final overrider, and not to an intermediate virtual base.  */
    2767     4914397 :   virtual_base = NULL_TREE;
    2768             : 
    2769             :   /* See if we can convert to an intermediate virtual base first, and then
    2770             :      use the vcall offset located there to finish the conversion.  */
    2771     5061821 :   for (; b; b = BINFO_INHERITANCE_CHAIN (b))
    2772             :     {
    2773             :       /* If we find the final overrider, then we can stop
    2774             :          walking.  */
    2775     5061821 :       if (SAME_BINFO_TYPE_P (BINFO_TYPE (b),
    2776             :                              BINFO_TYPE (TREE_VALUE (overrider))))
    2777             :         break;
    2778             : 
    2779             :       /* If we find a virtual base, and we haven't yet found the
    2780             :          overrider, then there is a virtual base between the
    2781             :          declaring base (first_defn) and the final overrider.  */
    2782      416930 :       if (BINFO_VIRTUAL_P (b))
    2783             :         {
    2784             :           virtual_base = b;
    2785             :           break;
    2786             :         }
    2787             :     }
    2788             : 
    2789             :   /* Compute the constant adjustment to the `this' pointer.  The
    2790             :      `this' pointer, when this function is called, will point at BINFO
    2791             :      (or one of its primary bases, which are at the same offset).  */
    2792     4914397 :   if (virtual_base)
    2793             :     /* The `this' pointer needs to be adjusted from the declaration to
    2794             :        the nearest virtual base.  */
    2795      808518 :     delta = size_diffop_loc (input_location,
    2796      269506 :                          fold_convert (ssizetype, BINFO_OFFSET (virtual_base)),
    2797      269506 :                          fold_convert (ssizetype, BINFO_OFFSET (first_defn)));
    2798     4644891 :   else if (lost)
    2799             :     /* If the nearest definition is in a lost primary, we don't need an
    2800             :        entry in our vtable.  Except possibly in a constructor vtable,
    2801             :        if we happen to get our primary back.  In that case, the offset
    2802             :        will be zero, as it will be a primary base.  */
    2803         428 :     delta = size_zero_node;
    2804             :   else
    2805             :     /* The `this' pointer needs to be adjusted from pointing to
    2806             :        BINFO to pointing at the base where the final overrider
    2807             :        appears.  */
    2808    13933389 :     delta = size_diffop_loc (input_location,
    2809     4644463 :                          fold_convert (ssizetype,
    2810             :                                   BINFO_OFFSET (TREE_VALUE (overrider))),
    2811     4644463 :                          fold_convert (ssizetype, BINFO_OFFSET (binfo)));
    2812             : 
    2813     4914397 :   modify_vtable_entry (t, binfo, overrider_fn, delta, virtuals);
    2814             : 
    2815     4914397 :   if (virtual_base)
    2816      539012 :     BV_VCALL_INDEX (*virtuals)
    2817      539012 :       = get_vcall_index (overrider_target, BINFO_TYPE (virtual_base));
    2818             :   else
    2819     4644891 :     BV_VCALL_INDEX (*virtuals) = NULL_TREE;
    2820             : 
    2821     4914397 :   BV_LOST_PRIMARY (*virtuals) = lost;
    2822             : }
    2823             : 
    2824             : /* Called from modify_all_vtables via dfs_walk.  */
    2825             : 
    2826             : static tree
    2827    27438312 : dfs_modify_vtables (tree binfo, void* data)
    2828             : {
    2829    27438312 :   tree t = (tree) data;
    2830    27438312 :   tree virtuals;
    2831    27438312 :   tree old_virtuals;
    2832    27438312 :   unsigned ix;
    2833             : 
    2834    27438312 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
    2835             :     /* A base without a vtable needs no modification, and its bases
    2836             :        are uninteresting.  */
    2837             :     return dfs_skip_bases;
    2838             : 
    2839     3028814 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t)
    2840     3028814 :       && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    2841             :     /* Don't do the primary vtable, if it's new.  */
    2842             :     return NULL_TREE;
    2843             : 
    2844     2855010 :   if (BINFO_PRIMARY_P (binfo) && !BINFO_VIRTUAL_P (binfo))
    2845             :     /* There's no need to modify the vtable for a non-virtual primary
    2846             :        base; we're not going to use that vtable anyhow.  We do still
    2847             :        need to do this for virtual primary bases, as they could become
    2848             :        non-primary in a construction vtable.  */
    2849             :     return NULL_TREE;
    2850             : 
    2851     1165889 :   make_new_vtable (t, binfo);
    2852             : 
    2853             :   /* Now, go through each of the virtual functions in the virtual
    2854             :      function table for BINFO.  Find the final overrider, and update
    2855             :      the BINFO_VIRTUALS list appropriately.  */
    2856     1165889 :   for (ix = 0, virtuals = BINFO_VIRTUALS (binfo),
    2857     1165889 :          old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
    2858     6080298 :        virtuals;
    2859     4914409 :        ix++, virtuals = TREE_CHAIN (virtuals),
    2860     4914409 :          old_virtuals = TREE_CHAIN (old_virtuals))
    2861     4914409 :     update_vtable_entry_for_fn (t,
    2862             :                                 binfo,
    2863     4914409 :                                 BV_FN (old_virtuals),
    2864             :                                 &virtuals, ix);
    2865             : 
    2866             :   return NULL_TREE;
    2867             : }
    2868             : 
    2869             : /* Update all of the primary and secondary vtables for T.  Create new
    2870             :    vtables as required, and initialize their RTTI information.  Each
    2871             :    of the functions in VIRTUALS is declared in T and may override a
    2872             :    virtual function from a base class; find and modify the appropriate
    2873             :    entries to point to the overriding functions.  Returns a list, in
    2874             :    declaration order, of the virtual functions that are declared in T,
    2875             :    but do not appear in the primary base class vtable, and which
    2876             :    should therefore be appended to the end of the vtable for T.  */
    2877             : 
    2878             : static tree
    2879    25156660 : modify_all_vtables (tree t, tree virtuals)
    2880             : {
    2881    25156660 :   tree binfo = TYPE_BINFO (t);
    2882    25156660 :   tree *fnsp;
    2883             : 
    2884             :   /* Mangle the vtable name before entering dfs_walk (c++/51884).  */
    2885    25156660 :   if (TYPE_CONTAINS_VPTR_P (t))
    2886     1144766 :     get_vtable_decl (t, false);
    2887             : 
    2888             :   /* Update all of the vtables.  */
    2889    25156660 :   dfs_walk_once (binfo, dfs_modify_vtables, NULL, t);
    2890             : 
    2891             :   /* Add virtual functions not already in our primary vtable. These
    2892             :      will be both those introduced by this class, and those overridden
    2893             :      from secondary bases.  It does not include virtuals merely
    2894             :      inherited from secondary bases.  */
    2895    30469183 :   for (fnsp = &virtuals; *fnsp; )
    2896             :     {
    2897     5312523 :       tree fn = TREE_VALUE (*fnsp);
    2898             : 
    2899     5312523 :       if (!value_member (fn, BINFO_VIRTUALS (binfo))
    2900     8575987 :           || DECL_VINDEX (fn) == error_mark_node)
    2901             :         {
    2902             :           /* We don't need to adjust the `this' pointer when
    2903             :              calling this function.  */
    2904     2049059 :           BV_DELTA (*fnsp) = integer_zero_node;
    2905     2049059 :           BV_VCALL_INDEX (*fnsp) = NULL_TREE;
    2906             : 
    2907             :           /* This is a function not already in our vtable.  Keep it.  */
    2908     2049059 :           fnsp = &TREE_CHAIN (*fnsp);
    2909             :         }
    2910             :       else
    2911             :         /* We've already got an entry for this function.  Skip it.  */
    2912     3263464 :         *fnsp = TREE_CHAIN (*fnsp);
    2913             :     }
    2914             : 
    2915    25156660 :   return virtuals;
    2916             : }
    2917             : 
    2918             : /* Get the base virtual function declarations in T that have the
    2919             :    indicated NAME.  */
    2920             : 
    2921             : static void
    2922      174571 : get_basefndecls (tree name, tree t, vec<tree> *base_fndecls)
    2923             : {
    2924      174571 :   bool found_decls = false;
    2925             : 
    2926             :   /* Find virtual functions in T with the indicated NAME.  */
    2927      274609 :   for (tree method : ovl_range (get_class_binding (t, name)))
    2928             :     {
    2929       50019 :       if (TREE_CODE (method) == FUNCTION_DECL && DECL_VINDEX (method))
    2930             :         {
    2931        6054 :           base_fndecls->safe_push (method);
    2932        6054 :           found_decls = true;
    2933             :         }
    2934             :     }
    2935             : 
    2936      174571 :   if (found_decls)
    2937             :     return;
    2938             : 
    2939      168751 :   int n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t));
    2940      200202 :   for (int i = 0; i < n_baseclasses; i++)
    2941             :     {
    2942       31451 :       tree basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t), i));
    2943       31451 :       get_basefndecls (name, basetype, base_fndecls);
    2944             :     }
    2945             : }
    2946             : 
    2947             : /* If this method overrides a virtual method from a base, then mark
    2948             :    this member function as being virtual as well.  Do 'final' and
    2949             :    'override' checks too.  */
    2950             : 
    2951             : void
    2952    80132024 : check_for_override (tree decl, tree ctype)
    2953             : {
    2954    80132024 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    2955             :     /* In [temp.mem] we have:
    2956             : 
    2957             :          A specialization of a member function template does not
    2958             :          override a virtual function from a base class.  */
    2959             :     return;
    2960             : 
    2961             :   /* IDENTIFIER_VIRTUAL_P indicates whether the name has ever been
    2962             :      used for a vfunc.  That avoids the expensive look_for_overrides
    2963             :      call that when we know there's nothing to find.  As conversion
    2964             :      operators for the same type can have distinct identifiers, we
    2965             :      cannot optimize those in that way.  */
    2966    66608093 :   if ((IDENTIFIER_VIRTUAL_P (DECL_NAME (decl))
    2967    58849494 :        || DECL_CONV_FN_P (decl))
    2968     8329663 :       && look_for_overrides (ctype, decl)
    2969             :       /* Check staticness after we've checked if we 'override'.  */
    2970    68941314 :       && !DECL_STATIC_FUNCTION_P (decl))
    2971             :     {
    2972             :       /* Set DECL_VINDEX to a value that is neither an INTEGER_CST nor
    2973             :          the error_mark_node so that we know it is an overriding
    2974             :          function.  */
    2975     2333213 :       DECL_VINDEX (decl) = decl;
    2976             : 
    2977     2333213 :       if (warn_override
    2978           6 :           && !DECL_OVERRIDE_P (decl)
    2979           5 :           && !DECL_FINAL_P (decl)
    2980     2333217 :           && !DECL_DESTRUCTOR_P (decl))
    2981           3 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
    2982             :                     "%qD can be marked override", decl);
    2983             :     }
    2984    64274880 :   else if (DECL_OVERRIDE_P (decl))
    2985          12 :     error ("%q+#D marked %<override%>, but does not override", decl);
    2986             : 
    2987    66608093 :   if (DECL_VIRTUAL_P (decl))
    2988             :     {
    2989             :       /* Remember this identifier is virtual name.  */
    2990     4185385 :       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = true;
    2991             : 
    2992     4185385 :       if (!DECL_VINDEX (decl))
    2993             :         /* It's a new vfunc.  */
    2994     1852172 :         DECL_VINDEX (decl) = error_mark_node;
    2995             : 
    2996     4185385 :       if (DECL_DESTRUCTOR_P (decl))
    2997     1127134 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
    2998             :     }
    2999    62422708 :   else if (DECL_FINAL_P (decl))
    3000           3 :     error ("%q+#D marked %<final%>, but is not virtual", decl);
    3001             : }
    3002             : 
    3003             : /* Warn about hidden virtual functions that are not overridden in t.
    3004             :    We know that constructors and destructors don't apply.  */
    3005             : 
    3006             : static void
    3007      290223 : warn_hidden (tree t)
    3008             : {
    3009      290223 :   if (vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (t))
    3010     1573269 :     for (unsigned ix = member_vec->length (); ix--;)
    3011             :       {
    3012     1469022 :         tree fns = (*member_vec)[ix];
    3013             : 
    3014     1469022 :         if (!OVL_P (fns))
    3015      656118 :           continue;
    3016             : 
    3017      812904 :         tree name = OVL_NAME (fns);
    3018      812904 :         auto_vec<tree, 20> base_fndecls;
    3019      812904 :         tree base_binfo;
    3020      812904 :         tree binfo;
    3021      812904 :         unsigned j;
    3022             : 
    3023      812904 :         if (IDENTIFIER_CDTOR_P (name))
    3024      272410 :           continue;
    3025             : 
    3026             :         /* Iterate through all of the base classes looking for possibly
    3027             :            hidden functions.  */
    3028      683614 :         for (binfo = TYPE_BINFO (t), j = 0;
    3029      683614 :              BINFO_BASE_ITERATE (binfo, j, base_binfo); j++)
    3030             :           {
    3031      143120 :             tree basetype = BINFO_TYPE (base_binfo);
    3032      143120 :             get_basefndecls (name, basetype, &base_fndecls);
    3033             :           }
    3034             : 
    3035             :         /* If there are no functions to hide, continue.  */
    3036      540494 :         if (base_fndecls.is_empty ())
    3037      534678 :           continue;
    3038             : 
    3039             :         /* Remove any overridden functions.  */
    3040        5816 :         bool seen_non_override = false;
    3041       17992 :         for (tree fndecl : ovl_range (fns))
    3042             :           {
    3043        6088 :             bool any_override = false;
    3044        6088 :             if (TREE_CODE (fndecl) == FUNCTION_DECL
    3045        6088 :                 && DECL_VINDEX (fndecl))
    3046             :               {
    3047             :                 /* If the method from the base class has the same
    3048             :                    signature as the method from the derived class, it
    3049             :                    has been overridden.  Note that we can't move on
    3050             :                    after finding one match: fndecl might override
    3051             :                    multiple base fns.  */
    3052       12574 :                 for (size_t k = 0; k < base_fndecls.length (); k++)
    3053        6502 :                   if (base_fndecls[k]
    3054        6502 :                       && same_signature_p (fndecl, base_fndecls[k]))
    3055             :                     {
    3056        5986 :                       base_fndecls[k] = NULL_TREE;
    3057        5986 :                       any_override = true;
    3058             :                     }
    3059             :               }
    3060        6072 :             if (!any_override)
    3061             :               seen_non_override = true;
    3062             :           }
    3063             : 
    3064        5816 :         if (!seen_non_override && warn_overloaded_virtual == 1)
    3065             :           /* All the derived fns override base virtuals.  */
    3066        5694 :           return;
    3067             : 
    3068             :         /* Now give a warning for all base functions without overriders,
    3069             :            as they are hidden.  */
    3070         500 :         for (tree base_fndecl : base_fndecls)
    3071         134 :           if (base_fndecl)
    3072             :             {
    3073          30 :               auto_diagnostic_group d;
    3074             :               /* Here we know it is a hider, and no overrider exists.  */
    3075          30 :               if (warning_at (location_of (base_fndecl),
    3076             :                               OPT_Woverloaded_virtual_,
    3077             :                               "%qD was hidden", base_fndecl))
    3078          24 :                 inform (location_of (fns), "  by %qD", fns);
    3079          30 :             }
    3080     1469022 :       }
    3081             : }
    3082             : 
    3083             : /* Recursive helper for finish_struct_anon.  */
    3084             : 
    3085             : static void
    3086       96043 : finish_struct_anon_r (tree field)
    3087             : {
    3088      430371 :   for (tree elt = TYPE_FIELDS (TREE_TYPE (field)); elt; elt = DECL_CHAIN (elt))
    3089             :     {
    3090             :       /* We're generally only interested in entities the user
    3091             :          declared, but we also find nested classes by noticing
    3092             :          the TYPE_DECL that we create implicitly.  You're
    3093             :          allowed to put one anonymous union inside another,
    3094             :          though, so we explicitly tolerate that.  We use
    3095             :          TYPE_UNNAMED_P rather than ANON_AGGR_TYPE_P so that
    3096             :          we also allow unnamed types used for defining fields.  */
    3097      334328 :       if (DECL_ARTIFICIAL (elt)
    3098      334328 :           && (!DECL_IMPLICIT_TYPEDEF_P (elt)
    3099       43574 :               || TYPE_UNNAMED_P (TREE_TYPE (elt))))
    3100      110565 :         continue;
    3101             : 
    3102      223763 :       TREE_PRIVATE (elt) = TREE_PRIVATE (field);
    3103      223763 :       TREE_PROTECTED (elt) = TREE_PROTECTED (field);
    3104             : 
    3105             :       /* Recurse into the anonymous aggregates to correctly handle
    3106             :          access control (c++/24926):
    3107             : 
    3108             :          class A {
    3109             :            union {
    3110             :              union {
    3111             :                int i;
    3112             :              };
    3113             :            };
    3114             :          };
    3115             : 
    3116             :          int j=A().i;  */
    3117      223763 :       if (DECL_NAME (elt) == NULL_TREE
    3118      223763 :           && ANON_AGGR_TYPE_P (TREE_TYPE (elt)))
    3119       13855 :         finish_struct_anon_r (elt);
    3120             :     }
    3121       96043 : }
    3122             : 
    3123             : /* Fix up any anonymous union/struct members of T.  */
    3124             : 
    3125             : static void
    3126    25156660 : finish_struct_anon (tree t)
    3127             : {
    3128   173397327 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3129             :     {
    3130   148240667 :       if (TREE_STATIC (field))
    3131     6381882 :         continue;
    3132   141858785 :       if (TREE_CODE (field) != FIELD_DECL)
    3133   131953727 :         continue;
    3134             : 
    3135     9905058 :       if (DECL_NAME (field) == NULL_TREE
    3136     9905058 :           && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    3137       82188 :         finish_struct_anon_r (field);
    3138             :     }
    3139    25156660 : }
    3140             : 
    3141             : /* Add T to CLASSTYPE_DECL_LIST of current_class_type which
    3142             :    will be used later during class template instantiation.
    3143             :    When FRIEND_P is zero, T can be a static member data (VAR_DECL),
    3144             :    a non-static member data (FIELD_DECL), a member function
    3145             :    (FUNCTION_DECL), a nested type (RECORD_TYPE, ENUM_TYPE),
    3146             :    a typedef (TYPE_DECL) or a member class template (TEMPLATE_DECL)
    3147             :    When FRIEND_P is nonzero, T is either a friend class
    3148             :    (RECORD_TYPE, TEMPLATE_DECL) or a friend function
    3149             :    (FUNCTION_DECL, TEMPLATE_DECL).  */
    3150             : 
    3151             : void
    3152   243226974 : maybe_add_class_template_decl_list (tree type, tree t, int friend_p)
    3153             : {
    3154   243226974 :   if (CLASSTYPE_TEMPLATE_INFO (type)
    3155   243226974 :       && TREE_CODE (t) != CONST_DECL)
    3156             :     {
    3157   216329723 :       tree purpose = friend_p ? NULL_TREE : type;
    3158             : 
    3159   216329723 :       CLASSTYPE_DECL_LIST (type)
    3160   432659446 :         = tree_cons (purpose, t, CLASSTYPE_DECL_LIST (type));
    3161             :     }
    3162   243226974 : }
    3163             : 
    3164             : /* This function is called from declare_virt_assop_and_dtor via
    3165             :    dfs_walk_all.
    3166             : 
    3167             :    DATA is a type that direcly or indirectly inherits the base
    3168             :    represented by BINFO.  If BINFO contains a virtual assignment [copy
    3169             :    assignment or move assigment] operator or a virtual constructor,
    3170             :    declare that function in DATA if it hasn't been already declared.  */
    3171             : 
    3172             : static tree
    3173     2302997 : dfs_declare_virt_assop_and_dtor (tree binfo, void *data)
    3174             : {
    3175     2302997 :   tree bv, fn, t = (tree)data;
    3176     2302997 :   tree opname = assign_op_identifier;
    3177             : 
    3178     2302997 :   gcc_assert (t && CLASS_TYPE_P (t));
    3179     2302997 :   gcc_assert (binfo && TREE_CODE (binfo) == TREE_BINFO);
    3180             : 
    3181     2302997 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
    3182             :     /* A base without a vtable needs no modification, and its bases
    3183             :        are uninteresting.  */
    3184             :     return dfs_skip_bases;
    3185             : 
    3186     1931744 :   if (BINFO_PRIMARY_P (binfo))
    3187             :     /* If this is a primary base, then we have already looked at the
    3188             :        virtual functions of its vtable.  */
    3189             :     return NULL_TREE;
    3190             : 
    3191     7730245 :   for (bv = BINFO_VIRTUALS (binfo); bv; bv = TREE_CHAIN (bv))
    3192             :     {
    3193     5798501 :       fn = BV_FN (bv);
    3194             : 
    3195     5798501 :       if (DECL_NAME (fn) == opname)
    3196             :         {
    3197          28 :           if (CLASSTYPE_LAZY_COPY_ASSIGN (t))
    3198          28 :             lazily_declare_fn (sfk_copy_assignment, t);
    3199          28 :           if (CLASSTYPE_LAZY_MOVE_ASSIGN (t))
    3200          21 :             lazily_declare_fn (sfk_move_assignment, t);
    3201             :         }
    3202     5798473 :       else if (DECL_DESTRUCTOR_P (fn)
    3203     5798473 :                && CLASSTYPE_LAZY_DESTRUCTOR (t))
    3204      120036 :         lazily_declare_fn (sfk_destructor, t);
    3205             :     }
    3206             : 
    3207             :   return NULL_TREE;
    3208             : }
    3209             : 
    3210             : /* If the class type T has a direct or indirect base that contains a
    3211             :    virtual assignment operator or a virtual destructor, declare that
    3212             :    function in T if it hasn't been already declared.  */
    3213             : 
    3214             : static void
    3215    25156660 : declare_virt_assop_and_dtor (tree t)
    3216             : {
    3217    25156660 :   if (!(TYPE_POLYMORPHIC_P (t)
    3218     1142002 :         && (CLASSTYPE_LAZY_COPY_ASSIGN (t)
    3219      443705 :             || CLASSTYPE_LAZY_MOVE_ASSIGN (t)
    3220      443705 :             || CLASSTYPE_LAZY_DESTRUCTOR (t))))
    3221             :     return;
    3222             : 
    3223      735197 :   dfs_walk_all (TYPE_BINFO (t),
    3224             :                 dfs_declare_virt_assop_and_dtor,
    3225             :                 NULL, t);
    3226             : }
    3227             : 
    3228             : /* Declare the inheriting constructor for class T inherited from base
    3229             :    constructor CTOR with the parameter array PARMS of size NPARMS.  */
    3230             : 
    3231             : static void
    3232          90 : one_inheriting_sig (tree t, tree ctor, tree *parms, int nparms)
    3233             : {
    3234          90 :   gcc_assert (TYPE_MAIN_VARIANT (t) == t);
    3235             : 
    3236             :   /* We don't declare an inheriting ctor that would be a default,
    3237             :      copy or move ctor for derived or base.  */
    3238          90 :   if (nparms == 0)
    3239             :     return;
    3240          90 :   if (nparms == 1
    3241          87 :       && TYPE_REF_P (parms[0]))
    3242             :     {
    3243          54 :       tree parm = TYPE_MAIN_VARIANT (TREE_TYPE (parms[0]));
    3244          54 :       if (parm == t || parm == DECL_CONTEXT (ctor))
    3245             :         return;
    3246             :     }
    3247             : 
    3248          36 :   tree parmlist = void_list_node;
    3249          75 :   for (int i = nparms - 1; i >= 0; i--)
    3250          39 :     parmlist = tree_cons (NULL_TREE, parms[i], parmlist);
    3251          36 :   tree fn = implicitly_declare_fn (sfk_inheriting_constructor,
    3252             :                                    t, false, ctor, parmlist);
    3253             : 
    3254          36 :   if (add_method (t, fn, false))
    3255             :     {
    3256          27 :       DECL_CHAIN (fn) = TYPE_FIELDS (t);
    3257          27 :       TYPE_FIELDS (t) = fn;
    3258             :     }
    3259             : }
    3260             : 
    3261             : /* Declare all the inheriting constructors for class T inherited from base
    3262             :    constructor CTOR.  */
    3263             : 
    3264             : static void
    3265      156258 : one_inherited_ctor (tree ctor, tree t, tree using_decl)
    3266             : {
    3267      156258 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (ctor);
    3268             : 
    3269      156258 :   if (flag_new_inheriting_ctors)
    3270             :     {
    3271      156168 :       ctor = implicitly_declare_fn (sfk_inheriting_constructor,
    3272             :                                     t, /*const*/false, ctor, parms);
    3273      156168 :       add_method (t, ctor, using_decl != NULL_TREE);
    3274      156168 :       return;
    3275             :     }
    3276             : 
    3277          90 :   tree *new_parms = XALLOCAVEC (tree, list_length (parms));
    3278          90 :   int i = 0;
    3279         183 :   for (; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
    3280             :     {
    3281          93 :       if (TREE_PURPOSE (parms))
    3282           0 :         one_inheriting_sig (t, ctor, new_parms, i);
    3283          93 :       new_parms[i++] = TREE_VALUE (parms);
    3284             :     }
    3285          90 :   one_inheriting_sig (t, ctor, new_parms, i);
    3286          90 :   if (parms == NULL_TREE)
    3287             :     {
    3288           3 :       auto_diagnostic_group d;
    3289           3 :       if (warning (OPT_Winherited_variadic_ctor,
    3290             :                    "the ellipsis in %qD is not inherited", ctor))
    3291           3 :         inform (DECL_SOURCE_LOCATION (ctor), "%qD declared here", ctor);
    3292           3 :     }
    3293             : }
    3294             : 
    3295             : /* Create default constructors, assignment operators, and so forth for
    3296             :    the type indicated by T, if they are needed.  CANT_HAVE_CONST_CTOR,
    3297             :    and CANT_HAVE_CONST_ASSIGNMENT are nonzero if, for whatever reason,
    3298             :    the class cannot have a default constructor, copy constructor
    3299             :    taking a const reference argument, or an assignment operator taking
    3300             :    a const reference, respectively.  */
    3301             : 
    3302             : static void
    3303    25156660 : add_implicitly_declared_members (tree t, tree* access_decls,
    3304             :                                  int cant_have_const_cctor,
    3305             :                                  int cant_have_const_assignment)
    3306             : {
    3307             :   /* Destructor.  */
    3308    25156660 :   if (!CLASSTYPE_DESTRUCTOR (t))
    3309             :     /* In general, we create destructors lazily.  */
    3310    22711014 :     CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
    3311             : 
    3312    25156660 :   bool move_ok = false;
    3313    25069466 :   if (cxx_dialect >= cxx11 && CLASSTYPE_LAZY_DESTRUCTOR (t)
    3314    22638819 :       && !TYPE_HAS_COPY_CTOR (t) && !TYPE_HAS_COPY_ASSIGN (t)
    3315    47231427 :       && !classtype_has_move_assign_or_move_ctor_p (t, false))
    3316             :     move_ok = true;
    3317             : 
    3318             :   /* [class.ctor]
    3319             : 
    3320             :      If there is no user-declared constructor for a class, a default
    3321             :      constructor is implicitly declared.  */
    3322    25156660 :   if (! TYPE_HAS_USER_CONSTRUCTOR (t))
    3323             :     {
    3324    21216726 :       TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 1;
    3325    21216726 :       CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1;
    3326    21216726 :       if (cxx_dialect >= cxx11)
    3327    21150145 :         TYPE_HAS_CONSTEXPR_CTOR (t)
    3328             :           /* Don't force the declaration to get a hard answer; if the
    3329             :              definition would have made the class non-literal, it will still be
    3330             :              non-literal because of the base or member in question, and that
    3331             :              gives a better diagnostic.  */
    3332    42300290 :           = type_maybe_constexpr_default_constructor (t);
    3333             :     }
    3334             : 
    3335             :   /* [class.ctor]
    3336             : 
    3337             :      If a class definition does not explicitly declare a copy
    3338             :      constructor, one is declared implicitly.  */
    3339    25156660 :   if (! TYPE_HAS_COPY_CTOR (t))
    3340             :     {
    3341    23105804 :       TYPE_HAS_COPY_CTOR (t) = 1;
    3342    23105804 :       TYPE_HAS_CONST_COPY_CTOR (t) = !cant_have_const_cctor;
    3343    23105804 :       CLASSTYPE_LAZY_COPY_CTOR (t) = 1;
    3344    23105804 :       if (move_ok)
    3345    21921913 :         CLASSTYPE_LAZY_MOVE_CTOR (t) = 1;
    3346             :     }
    3347             : 
    3348             :   /* If there is no assignment operator, one will be created if and
    3349             :      when it is needed.  For now, just record whether or not the type
    3350             :      of the parameter to the assignment operator will be a const or
    3351             :      non-const reference.  */
    3352    25156660 :   if (!TYPE_HAS_COPY_ASSIGN (t))
    3353             :     {
    3354    23314758 :       TYPE_HAS_COPY_ASSIGN (t) = 1;
    3355    23314758 :       TYPE_HAS_CONST_COPY_ASSIGN (t) = !cant_have_const_assignment;
    3356    23314758 :       CLASSTYPE_LAZY_COPY_ASSIGN (t) = 1;
    3357    44949574 :       if (move_ok && !LAMBDA_TYPE_P (t))
    3358    21878907 :         CLASSTYPE_LAZY_MOVE_ASSIGN (t) = 1;
    3359             :     }
    3360             : 
    3361             :   /* We can't be lazy about declaring functions that might override
    3362             :      a virtual function from a base class.  */
    3363    25156660 :   declare_virt_assop_and_dtor (t);
    3364             : 
    3365             :   /* If the class definition does not explicitly declare an == operator
    3366             :      function, but declares a defaulted three-way comparison operator function,
    3367             :      an == operator function is declared implicitly.  */
    3368    25156660 :   if (!classtype_has_op (t, EQ_EXPR))
    3369    24629577 :     if (tree space = classtype_has_defaulted_op (t, SPACESHIP_EXPR))
    3370             :       {
    3371          55 :         tree eq = implicitly_declare_fn (sfk_comparison, t, false, space,
    3372             :                                          NULL_TREE);
    3373          55 :         bool is_friend = DECL_CONTEXT (space) != t;
    3374          55 :         if (is_friend)
    3375           7 :           do_friend (NULL_TREE, DECL_NAME (eq), eq,
    3376             :                      NO_SPECIAL, true);
    3377             :         else
    3378             :           {
    3379          48 :             add_method (t, eq, false);
    3380          48 :             DECL_CHAIN (eq) = TYPE_FIELDS (t);
    3381          48 :             TYPE_FIELDS (t) = eq;
    3382             :           }
    3383          55 :         maybe_add_class_template_decl_list (t, eq, is_friend);
    3384             :       }
    3385             : 
    3386    26251740 :   while (*access_decls)
    3387             :     {
    3388     1095080 :       tree using_decl = TREE_VALUE (*access_decls);
    3389     1095080 :       tree decl = USING_DECL_DECLS (using_decl);
    3390     1095080 :       if (DECL_NAME (using_decl) == ctor_identifier)
    3391             :         {
    3392             :           /* declare, then remove the decl */
    3393       31112 :           tree ctor_list = decl;
    3394       31112 :           location_t loc = input_location;
    3395       31112 :           input_location = DECL_SOURCE_LOCATION (using_decl);
    3396      343628 :           for (tree fn : ovl_range (ctor_list))
    3397      156258 :             one_inherited_ctor (fn, t, using_decl);
    3398       31112 :           *access_decls = TREE_CHAIN (*access_decls);
    3399       31112 :           input_location = loc;
    3400             :         }
    3401             :       else
    3402     1063968 :         access_decls = &TREE_CHAIN (*access_decls);
    3403             :     }
    3404    25156660 : }
    3405             : 
    3406             : /* Cache of enum_min_precision values.  */
    3407             : static GTY((deletable)) hash_map<tree, int> *enum_to_min_precision;
    3408             : 
    3409             : /* Return the minimum precision of a bit-field needed to store all
    3410             :    enumerators of ENUMERAL_TYPE TYPE.  */
    3411             : 
    3412             : static int
    3413       10311 : enum_min_precision (tree type)
    3414             : {
    3415       10311 :   type = TYPE_MAIN_VARIANT (type);
    3416             :   /* For unscoped enums without fixed underlying type and without mode
    3417             :      attribute we can just use precision of the underlying type.  */
    3418       10311 :   if (UNSCOPED_ENUM_P (type)
    3419        9987 :       && !ENUM_FIXED_UNDERLYING_TYPE_P (type)
    3420       20281 :       && !lookup_attribute ("mode", TYPE_ATTRIBUTES (type)))
    3421        9958 :     return TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type));
    3422             : 
    3423         353 :   if (enum_to_min_precision == NULL)
    3424          67 :     enum_to_min_precision = hash_map<tree, int>::create_ggc (37);
    3425             : 
    3426         353 :   bool existed;
    3427         353 :   int &prec = enum_to_min_precision->get_or_insert (type, &existed);
    3428         353 :   if (existed)
    3429         274 :     return prec;
    3430             : 
    3431          79 :   tree minnode, maxnode;
    3432          79 :   if (TYPE_VALUES (type))
    3433             :     {
    3434             :       minnode = maxnode = NULL_TREE;
    3435         351 :       for (tree values = TYPE_VALUES (type);
    3436         428 :            values; values = TREE_CHAIN (values))
    3437             :         {
    3438         351 :           tree decl = TREE_VALUE (values);
    3439         351 :           tree value = DECL_INITIAL (decl);
    3440         351 :           if (value == error_mark_node)
    3441           0 :             value = integer_zero_node;
    3442         351 :           if (!minnode)
    3443             :             minnode = maxnode = value;
    3444         274 :           else if (tree_int_cst_lt (maxnode, value))
    3445             :             maxnode = value;
    3446           0 :           else if (tree_int_cst_lt (value, minnode))
    3447           0 :             minnode = value;
    3448             :         }
    3449             :     }
    3450             :   else
    3451           2 :     minnode = maxnode = integer_zero_node;
    3452             : 
    3453          79 :   signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
    3454          79 :   int lowprec = tree_int_cst_min_precision (minnode, sgn);
    3455          79 :   int highprec = tree_int_cst_min_precision (maxnode, sgn);
    3456          79 :   prec = MAX (lowprec, highprec);
    3457          79 :   return prec;
    3458             : }
    3459             : 
    3460             : /* FIELD is a bit-field.  We are finishing the processing for its
    3461             :    enclosing type.  Issue any appropriate messages and set appropriate
    3462             :    flags.  Returns false if an error has been diagnosed.  */
    3463             : 
    3464             : static bool
    3465      245115 : check_bitfield_decl (tree field)
    3466             : {
    3467      245115 :   tree type = TREE_TYPE (field);
    3468      245115 :   tree w;
    3469             : 
    3470             :   /* Extract the declared width of the bitfield, which has been
    3471             :      temporarily stashed in DECL_BIT_FIELD_REPRESENTATIVE by grokbitfield.  */
    3472      245115 :   w = DECL_BIT_FIELD_REPRESENTATIVE (field);
    3473      245115 :   gcc_assert (w != NULL_TREE);
    3474             :   /* Remove the bit-field width indicator so that the rest of the
    3475             :      compiler does not treat that value as a qualifier.  */
    3476      245115 :   DECL_BIT_FIELD_REPRESENTATIVE (field) = NULL_TREE;
    3477             : 
    3478             :   /* Detect invalid bit-field type.  */
    3479      245115 :   if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    3480             :     {
    3481           4 :       error_at (DECL_SOURCE_LOCATION (field),
    3482             :                 "bit-field %q#D with non-integral type %qT", field, type);
    3483           4 :       w = error_mark_node;
    3484             :     }
    3485             :   else
    3486             :     {
    3487      245111 :       location_t loc = input_location;
    3488             :       /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs.  */
    3489      245111 :       STRIP_NOPS (w);
    3490             : 
    3491             :       /* detect invalid field size.  */
    3492      245111 :       input_location = DECL_SOURCE_LOCATION (field);
    3493      245111 :       w = cxx_constant_value (w);
    3494      245111 :       input_location = loc;
    3495             : 
    3496      245111 :       if (TREE_CODE (w) != INTEGER_CST)
    3497             :         {
    3498          19 :           error ("bit-field %q+D width not an integer constant", field);
    3499          19 :           w = error_mark_node;
    3500             :         }
    3501      245092 :       else if (tree_int_cst_sgn (w) < 0)
    3502             :         {
    3503           0 :           error ("negative width in bit-field %q+D", field);
    3504           0 :           w = error_mark_node;
    3505             :         }
    3506      245092 :       else if (integer_zerop (w) && DECL_NAME (field) != 0)
    3507             :         {
    3508          18 :           error ("zero width for bit-field %q+D", field);
    3509          18 :           w = error_mark_node;
    3510             :         }
    3511      245074 :       else if ((TREE_CODE (type) != ENUMERAL_TYPE
    3512      245074 :                 && TREE_CODE (type) != BOOLEAN_TYPE
    3513      233244 :                 && compare_tree_int (w, TYPE_PRECISION (type)) > 0)
    3514      245074 :                || ((TREE_CODE (type) == ENUMERAL_TYPE
    3515      244632 :                     || TREE_CODE (type) == BOOLEAN_TYPE)
    3516       11830 :                    && tree_int_cst_lt (TYPE_SIZE (type), w)))
    3517         784 :         warning_at (DECL_SOURCE_LOCATION (field), 0,
    3518             :                     "width of %qD exceeds its type", field);
    3519      244290 :       else if (TREE_CODE (type) == ENUMERAL_TYPE)
    3520             :         {
    3521       10311 :           int prec = enum_min_precision (type);
    3522       10311 :           if (compare_tree_int (w, prec) < 0)
    3523          54 :             warning_at (DECL_SOURCE_LOCATION (field), 0,
    3524             :                         "%qD is too small to hold all values of %q#T",
    3525             :                         field, type);
    3526             :         }
    3527             :     }
    3528             : 
    3529      245115 :   if (w != error_mark_node)
    3530             :     {
    3531      245074 :       DECL_SIZE (field) = fold_convert (bitsizetype, w);
    3532      245074 :       DECL_BIT_FIELD (field) = 1;
    3533      245074 :       return true;
    3534             :     }
    3535             :   else
    3536             :     {
    3537             :       /* Non-bit-fields are aligned for their type.  */
    3538          41 :       DECL_BIT_FIELD (field) = 0;
    3539          41 :       CLEAR_DECL_C_BIT_FIELD (field);
    3540          41 :       return false;
    3541             :     }
    3542             : }
    3543             : 
    3544             : /* FIELD is a non bit-field.  We are finishing the processing for its
    3545             :    enclosing type T.  Issue any appropriate messages and set appropriate
    3546             :    flags.  */
    3547             : 
    3548             : static bool
    3549    10127166 : check_field_decl (tree field,
    3550             :                   tree t,
    3551             :                   int* cant_have_const_ctor,
    3552             :                   int* no_const_asn_ref)
    3553             : {
    3554    10127166 :   tree type = strip_array_types (TREE_TYPE (field));
    3555    10127166 :   bool any_default_members = false;
    3556             : 
    3557             :   /* In C++98 an anonymous union cannot contain any fields which would change
    3558             :      the settings of CANT_HAVE_CONST_CTOR and friends.  */
    3559    10127166 :   if (ANON_UNION_TYPE_P (type) && cxx_dialect < cxx11)
    3560             :     ;
    3561             :   /* And, we don't set TYPE_HAS_CONST_COPY_CTOR, etc., for anonymous
    3562             :      structs.  So, we recurse through their fields here.  */
    3563    10126468 :   else if (ANON_AGGR_TYPE_P (type))
    3564             :     {
    3565      427476 :       for (tree fields = TYPE_FIELDS (type); fields;
    3566      332148 :            fields = DECL_CHAIN (fields))
    3567      332148 :         if (TREE_CODE (fields) == FIELD_DECL)
    3568      222314 :           any_default_members |= check_field_decl (fields, t,
    3569             :                                                    cant_have_const_ctor,
    3570             :                                                    no_const_asn_ref);
    3571             :     }
    3572             :   /* Check members with class type for constructors, destructors,
    3573             :      etc.  */
    3574    10031140 :   else if (CLASS_TYPE_P (type))
    3575             :     {
    3576             :       /* Never let anything with uninheritable virtuals
    3577             :          make it through without complaint.  */
    3578     1676608 :       abstract_virtuals_error (field, type);
    3579             : 
    3580     1676608 :       if (TREE_CODE (t) == UNION_TYPE && cxx_dialect < cxx11)
    3581             :         {
    3582        2245 :           static bool warned;
    3583        2245 :           int oldcount = errorcount;
    3584        2245 :           if (TYPE_NEEDS_CONSTRUCTING (type))
    3585           2 :             error ("member %q+#D with constructor not allowed in union",
    3586             :                    field);
    3587        2245 :           if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    3588           0 :             error ("member %q+#D with destructor not allowed in union", field);
    3589        2245 :           if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    3590           3 :             error ("member %q+#D with copy assignment operator not allowed in union",
    3591             :                    field);
    3592        2245 :           if (!warned && errorcount > oldcount)
    3593             :             {
    3594           4 :               inform (DECL_SOURCE_LOCATION (field), "unrestricted unions "
    3595             :                       "only available with %<-std=c++11%> or %<-std=gnu++11%>");
    3596           4 :               warned = true;
    3597             :             }
    3598             :         }
    3599             :       else
    3600             :         {
    3601     1674363 :           TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
    3602     5023089 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    3603     1674363 :             |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    3604     1674363 :           TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    3605     1674363 :             |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (type)
    3606     1674363 :                 || !TYPE_HAS_COPY_ASSIGN (type));
    3607     3348726 :           TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (type)
    3608     1674363 :                                              || !TYPE_HAS_COPY_CTOR (type));
    3609     1674363 :           TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (type);
    3610     1674363 :           TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (type);
    3611     3348726 :           TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type)
    3612     1674363 :                                         || TYPE_HAS_COMPLEX_DFLT (type));
    3613             :         }
    3614             : 
    3615     1676608 :       if (TYPE_HAS_COPY_CTOR (type)
    3616     1676608 :           && !TYPE_HAS_CONST_COPY_CTOR (type))
    3617         123 :         *cant_have_const_ctor = 1;
    3618             : 
    3619     1676608 :       if (TYPE_HAS_COPY_ASSIGN (type)
    3620     1676608 :           && !TYPE_HAS_CONST_COPY_ASSIGN (type))
    3621          47 :         *no_const_asn_ref = 1;
    3622             :     }
    3623             : 
    3624    10127166 :   check_abi_tags (t, field);
    3625             : 
    3626    10127166 :   if (DECL_INITIAL (field) != NULL_TREE)
    3627             :     /* `build_class_init_list' does not recognize
    3628             :        non-FIELD_DECLs.  */
    3629      377279 :     any_default_members = true;
    3630             : 
    3631    10127166 :   return any_default_members;
    3632             : }
    3633             : 
    3634             : /* Check the data members (both static and non-static), class-scoped
    3635             :    typedefs, etc., appearing in the declaration of T.  Issue
    3636             :    appropriate diagnostics.  Sets ACCESS_DECLS to a list (in
    3637             :    declaration order) of access declarations; each TREE_VALUE in this
    3638             :    list is a USING_DECL.
    3639             : 
    3640             :    In addition, set the following flags:
    3641             : 
    3642             :      EMPTY_P
    3643             :        The class is empty, i.e., contains no non-static data members.
    3644             : 
    3645             :      CANT_HAVE_CONST_CTOR_P
    3646             :        This class cannot have an implicitly generated copy constructor
    3647             :        taking a const reference.
    3648             : 
    3649             :      CANT_HAVE_CONST_ASN_REF
    3650             :        This class cannot have an implicitly generated assignment
    3651             :        operator taking a const reference.
    3652             : 
    3653             :    All of these flags should be initialized before calling this
    3654             :    function.   */
    3655             : 
    3656             : static void
    3657    25156660 : check_field_decls (tree t, tree *access_decls,
    3658             :                    int *cant_have_const_ctor_p,
    3659             :                    int *no_const_asn_ref_p)
    3660             : {
    3661    25156660 :   int cant_pack = 0;
    3662             : 
    3663             :   /* Assume there are no access declarations.  */
    3664    25156660 :   *access_decls = NULL_TREE;
    3665             :   /* Effective C has things to say about classes with pointer members.  */
    3666    25156660 :   tree pointer_member = NULL_TREE;
    3667             :   /* Default initialized members affect the whole class.  */
    3668    25156660 :   tree default_init_member = NULL_TREE;
    3669             :   /* Lack of any non-static data member of non-volatile literal
    3670             :      type affects a union.  */
    3671    25156660 :   bool found_nv_literal_p = false;
    3672             :   /* Standard layout requires all FIELDS have same access.  */
    3673    25156660 :   int field_access = -1;
    3674             : 
    3675   173397327 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3676             :     {
    3677   148240667 :       tree type = TREE_TYPE (field);
    3678             : 
    3679   148240667 :       switch (TREE_CODE (field))
    3680             :         {
    3681           0 :         default:
    3682           0 :           gcc_unreachable ();
    3683             : 
    3684     1095080 :         case USING_DECL:
    3685             :           /* Save the access declarations for our caller.  */
    3686     1095080 :           *access_decls = tree_cons (NULL_TREE, field, *access_decls);
    3687     1095080 :           break;
    3688             : 
    3689             :         case TYPE_DECL:
    3690             :         case TEMPLATE_DECL:
    3691             :           break;
    3692             : 
    3693             :         case FUNCTION_DECL:
    3694             :           /* FIXME: We should fold in the checking from check_methods.  */
    3695             :           break;
    3696             : 
    3697     1154771 :         case CONST_DECL:
    3698     1154771 :           DECL_NONLOCAL (field) = 1;
    3699     1154771 :           break;
    3700             :           
    3701     6339337 :         case VAR_DECL:
    3702     6339337 :           if (TREE_CODE (t) == UNION_TYPE
    3703          31 :               && cxx_dialect < cxx11)
    3704             :             {
    3705             :               /* [class.union]
    3706             : 
    3707             :                  (C++98) If a union contains a static data member,
    3708             :                  ... the program is ill-formed.  */
    3709           1 :               if (cxx_dialect < cxx11)
    3710           1 :                 error ("in C++98 %q+D may not be static because it is "
    3711             :                        "a member of a union", field);
    3712             :             }
    3713     6339337 :           goto data_member;
    3714             :           
    3715     9905058 :         case FIELD_DECL:
    3716     9905058 :           if (TREE_CODE (t) == UNION_TYPE)
    3717             :             {
    3718             :               /* [class.union]
    3719             : 
    3720             :                  If a union contains ... or a [non-static data] member
    3721             :                  of reference type, the program is ill-formed.  */
    3722      726170 :               if (TYPE_REF_P (type))
    3723          33 :                 error ("non-static data member %q+D in a union may not "
    3724             :                        "have reference type %qT", field, type);
    3725             :             }
    3726             : 
    3727     9178888 :         data_member:
    3728             :           /* Common VAR_DECL & FIELD_DECL processing.  */
    3729    16244395 :           DECL_CONTEXT (field) = t;
    3730    16244395 :           DECL_NONLOCAL (field) = 1;
    3731             : 
    3732             :           /* Template instantiation can cause this.  Perhaps this
    3733             :              should be a specific instantiation check?  */
    3734    16244395 :           if (TREE_CODE (type) == FUNCTION_TYPE)
    3735             :             {
    3736           8 :               error ("data member %q+D invalidly declared function type", field);
    3737           8 :               type = build_pointer_type (type);
    3738           8 :               TREE_TYPE (field) = type;
    3739             :             }
    3740    16244387 :           else if (TREE_CODE (type) == METHOD_TYPE)
    3741             :             {
    3742           0 :               error ("data member %q+D invalidly declared method type", field);
    3743           0 :               type = build_pointer_type (type);
    3744           0 :               TREE_TYPE (field) = type;
    3745             :             }
    3746             : 
    3747             :           break;
    3748             :         }
    3749             : 
    3750   148240667 :       if (TREE_CODE (field) != FIELD_DECL)
    3751   138335609 :         continue;
    3752             : 
    3753     9905058 :       if (type == error_mark_node)
    3754         206 :         continue;
    3755             : 
    3756             :       /* If it is not a union and at least one non-static data member is
    3757             :          non-literal, the whole class becomes non-literal.  Per Core/1453,
    3758             :          volatile non-static data members and base classes are also not allowed.
    3759             :          If it is a union, we might set CLASSTYPE_LITERAL_P after we've seen all
    3760             :          members.
    3761             :          Note: if the type is incomplete we will complain later on.  */
    3762     9904852 :       if (COMPLETE_TYPE_P (type))
    3763             :         {
    3764     9903531 :           if (!literal_type_p (type) || CP_TYPE_VOLATILE_P (type))
    3765      771462 :             CLASSTYPE_LITERAL_P (t) = false;
    3766             :           else
    3767             :             found_nv_literal_p = true;
    3768             :         }
    3769             : 
    3770     9904852 :       int this_field_access = (TREE_PROTECTED (field) ? 1
    3771     8757152 :                                : TREE_PRIVATE (field) ? 2 : 0);
    3772     9904852 :       if (field_access != this_field_access)
    3773             :         {
    3774             :           /* A standard-layout class is a class that:
    3775             : 
    3776             :              ... has the same access control (Clause 11) for all
    3777             :              non-static data members, */
    3778     3663310 :           if (field_access < 0)
    3779             :             field_access = this_field_access;
    3780             :           else
    3781       16266 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    3782             : 
    3783             :           /* Aggregates must be public.  */
    3784     3663310 :           if (this_field_access)
    3785     1737000 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    3786             :         }
    3787             : 
    3788             :       /* If this is of reference type, check if it needs an init.  */
    3789     9904852 :       if (TYPE_REF_P (type))
    3790             :         {
    3791      110772 :           CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    3792      110772 :           CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    3793      110772 :           if (DECL_INITIAL (field) == NULL_TREE)
    3794      110713 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    3795      110772 :           if (cxx_dialect < cxx11)
    3796             :             {
    3797             :               /* ARM $12.6.2: [A member initializer list] (or, for an
    3798             :                  aggregate, initialization by a brace-enclosed list) is the
    3799             :                  only way to initialize non-static const and reference
    3800             :                  members.  */
    3801         510 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    3802         510 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    3803             :             }
    3804             :         }
    3805             : 
    3806     9904852 :       type = strip_array_types (type);
    3807             : 
    3808     9904852 :       if (TYPE_PACKED (t))
    3809             :         {
    3810        1186 :           if (!layout_pod_type_p (type) && !TYPE_PACKED (type))
    3811             :             {
    3812          24 :               warning_at (DECL_SOURCE_LOCATION (field), 0,
    3813             :                           "ignoring packed attribute because of"
    3814             :                           " unpacked non-POD field %q#D", field);
    3815          24 :               cant_pack = 1;
    3816             :             }
    3817        1162 :           else if (DECL_C_BIT_FIELD (field)
    3818        1162 :                    || TYPE_ALIGN (TREE_TYPE (field)) > BITS_PER_UNIT)
    3819         912 :             DECL_PACKED (field) = 1;
    3820             :         }
    3821             : 
    3822     9904852 :       if (DECL_C_BIT_FIELD (field)
    3823     9904852 :           && integer_zerop (DECL_BIT_FIELD_REPRESENTATIVE (field)))
    3824             :         /* We don't treat zero-width bitfields as making a class
    3825             :            non-empty.  */
    3826             :         ;
    3827     9903771 :       else if (field_poverlapping_p (field)
    3828     9903771 :                && is_empty_class (TREE_TYPE (field)))
    3829             :         /* Empty data members also don't make a class non-empty.  */
    3830       24484 :         CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    3831             :       else
    3832             :         {
    3833             :           /* The class is non-empty.  */
    3834     9879287 :           CLASSTYPE_EMPTY_P (t) = 0;
    3835             :           /* The class is not even nearly empty.  */
    3836     9879287 :           CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    3837             :           /* If one of the data members contains an empty class, so
    3838             :              does T.  */
    3839     1725644 :           if (CLASS_TYPE_P (type)
    3840    11597150 :               && CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    3841      536479 :             CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    3842             :         }
    3843             : 
    3844             :       /* This is used by -Weffc++ (see below). Warn only for pointers
    3845             :          to members which might hold dynamic memory. So do not warn
    3846             :          for pointers to functions or pointers to members.  */
    3847     9904852 :       if (TYPE_PTR_P (type)
    3848     9904852 :           && !TYPE_PTRFN_P (type))
    3849             :         pointer_member = field;
    3850             : 
    3851     9904852 :       if (CLASS_TYPE_P (type))
    3852             :         {
    3853     1742347 :           if (CLASSTYPE_REF_FIELDS_NEED_INIT (type))
    3854        2563 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    3855     1742347 :           if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (type))
    3856       21671 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    3857             :         }
    3858             : 
    3859     9904852 :       if (DECL_MUTABLE_P (field) || TYPE_HAS_MUTABLE_P (type))
    3860      154907 :         CLASSTYPE_HAS_MUTABLE (t) = 1;
    3861             : 
    3862     9904852 :       if (DECL_MUTABLE_P (field))
    3863             :         {
    3864       96290 :           if (TYPE_REF_P (type))
    3865           4 :             error ("member %q+D cannot be declared as a %<mutable%> "
    3866             :                    "reference", field);
    3867       96286 :           else if (CP_TYPE_CONST_P (type))
    3868           4 :             error ("member %q+D cannot be declared both %<const%> "
    3869             :                    "and %<mutable%>", field);
    3870             :         }
    3871             : 
    3872     9904852 :       if (! layout_pod_type_p (type))
    3873             :         /* DR 148 now allows pointers to members (which are POD themselves),
    3874             :            to be allowed in POD structs.  */
    3875     1150094 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    3876             : 
    3877     9904852 :       if (field_poverlapping_p (field))
    3878             :         /* A potentially-overlapping non-static data member makes the class
    3879             :            non-layout-POD.  */
    3880       26856 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    3881             : 
    3882     9904852 :       if (!std_layout_type_p (type))
    3883      253015 :         CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    3884             : 
    3885     9904852 :       if (! zero_init_p (type))
    3886         153 :         CLASSTYPE_NON_ZERO_INIT_P (t) = 1;
    3887             : 
    3888             :       /* We set DECL_C_BIT_FIELD in grokbitfield.
    3889             :          If the type and width are valid, we'll also set DECL_BIT_FIELD.  */
    3890     9904852 :       if (DECL_C_BIT_FIELD (field))
    3891      245115 :         check_bitfield_decl (field);
    3892             : 
    3893     9904852 :       if (check_field_decl (field, t,
    3894             :                             cant_have_const_ctor_p, no_const_asn_ref_p))
    3895             :         {
    3896      377258 :           if (default_init_member
    3897      183813 :               && TREE_CODE (t) == UNION_TYPE)
    3898             :             {
    3899          12 :               error ("multiple fields in union %qT initialized", t);
    3900          12 :               inform (DECL_SOURCE_LOCATION (default_init_member),
    3901             :                       "initialized member %q+D declared here",
    3902             :                       default_init_member);
    3903             :             }
    3904             :           default_init_member = field;
    3905             :         }
    3906             : 
    3907             :       /* Now that we've removed bit-field widths from DECL_INITIAL,
    3908             :          anything left in DECL_INITIAL is an NSDMI that makes the class
    3909             :          non-aggregate in C++11, and non-layout-POD always.  */
    3910     9904852 :       if (DECL_INITIAL (field))
    3911             :         {
    3912      377089 :           if (cxx_dialect < cxx14)
    3913         675 :             CLASSTYPE_NON_AGGREGATE (t) = true;
    3914             :           else
    3915      376414 :             CLASSTYPE_NON_POD_AGGREGATE (t) = true;
    3916             :         }
    3917             : 
    3918     9904852 :       if (CP_TYPE_CONST_P (type))
    3919             :         {
    3920             :           /* If any field is const, the structure type is pseudo-const.  */
    3921      106226 :           C_TYPE_FIELDS_READONLY (t) = 1;
    3922      106226 :           if (DECL_INITIAL (field) == NULL_TREE)
    3923       72155 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    3924      106226 :           if (cxx_dialect < cxx11)
    3925             :             {
    3926             :               /* ARM $12.6.2: [A member initializer list] (or, for an
    3927             :                  aggregate, initialization by a brace-enclosed list) is the
    3928             :                  only way to initialize non-static const and reference
    3929             :                  members.  */
    3930         205 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    3931         205 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    3932             :             }
    3933             :         }
    3934             :       /* A field that is pseudo-const makes the structure likewise.  */
    3935     9798626 :       else if (CLASS_TYPE_P (type))
    3936             :         {
    3937     1707620 :           C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type);
    3938     1707620 :           SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t,
    3939             :             CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
    3940             :             | CLASSTYPE_READONLY_FIELDS_NEED_INIT (type));
    3941             :         }
    3942             : 
    3943             :       /* Core issue 80: A non-static data member is required to have a
    3944             :          different name from the class iff the class has a
    3945             :          user-declared constructor.  */
    3946     9904852 :       if (constructor_name_p (DECL_NAME (field), t)
    3947     9904852 :           && TYPE_HAS_USER_CONSTRUCTOR (t))
    3948          16 :         permerror (DECL_SOURCE_LOCATION (field),
    3949             :                    "field %q#D with same name as class", field);
    3950             :     }
    3951             : 
    3952             :   /* Per CWG 2096, a type is a literal type if it is a union, and at least
    3953             :      one of its non-static data members is of non-volatile literal type.  */
    3954    25156660 :   if (TREE_CODE (t) == UNION_TYPE && found_nv_literal_p)
    3955      298827 :     CLASSTYPE_LITERAL_P (t) = true;
    3956             : 
    3957             :   /* Effective C++ rule 11: if a class has dynamic memory held by pointers,
    3958             :      it should also define a copy constructor and an assignment operator to
    3959             :      implement the correct copy semantic (deep vs shallow, etc.). As it is
    3960             :      not feasible to check whether the constructors do allocate dynamic memory
    3961             :      and store it within members, we approximate the warning like this:
    3962             : 
    3963             :      -- Warn only if there are members which are pointers
    3964             :      -- Warn only if there is a non-trivial constructor (otherwise,
    3965             :         there cannot be memory allocated).
    3966             :      -- Warn only if there is a non-trivial destructor. We assume that the
    3967             :         user at least implemented the cleanup correctly, and a destructor
    3968             :         is needed to free dynamic memory.
    3969             : 
    3970             :      This seems enough for practical purposes.  */
    3971    25156660 :   if (warn_ecpp
    3972         184 :       && pointer_member
    3973          20 :       && TYPE_HAS_USER_CONSTRUCTOR (t)
    3974          20 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    3975    25156676 :       && !(TYPE_HAS_COPY_CTOR (t) && TYPE_HAS_COPY_ASSIGN (t)))
    3976             :     {
    3977          12 :       if (warning (OPT_Weffc__, "%q#T has pointer data members", t))
    3978             :         {
    3979          12 :           if (! TYPE_HAS_COPY_CTOR (t))
    3980             :             {
    3981           8 :               warning (OPT_Weffc__,
    3982             :                        "  but does not declare %<%T(const %T&)%>", t, t);
    3983           8 :               if (!TYPE_HAS_COPY_ASSIGN (t))
    3984           4 :                 warning (OPT_Weffc__, "  or %<operator=(const %T&)%>", t);
    3985             :             }
    3986           4 :           else if (! TYPE_HAS_COPY_ASSIGN (t))
    3987           4 :             warning (OPT_Weffc__,
    3988             :                      "  but does not declare %<operator=(const %T&)%>", t);
    3989          12 :           inform (DECL_SOURCE_LOCATION (pointer_member),
    3990             :                   "pointer member %q+D declared here", pointer_member);
    3991             :         }
    3992             :     }
    3993             : 
    3994             :   /* Non-static data member initializers make the default constructor
    3995             :      non-trivial.  */
    3996    25156660 :   if (default_init_member)
    3997             :     {
    3998      193445 :       TYPE_NEEDS_CONSTRUCTING (t) = true;
    3999      193445 :       TYPE_HAS_COMPLEX_DFLT (t) = true;
    4000             :     }
    4001             : 
    4002             :   /* If any of the fields couldn't be packed, unset TYPE_PACKED.  */
    4003    25156660 :   if (cant_pack)
    4004          16 :     TYPE_PACKED (t) = 0;
    4005             : 
    4006             :   /* Check anonymous struct/anonymous union fields.  */
    4007    25156660 :   finish_struct_anon (t);
    4008             : 
    4009             :   /* We've built up the list of access declarations in reverse order.
    4010             :      Fix that now.  */
    4011    25156660 :   *access_decls = nreverse (*access_decls);
    4012    25156660 : }
    4013             : 
    4014             : /* If TYPE is an empty class type, records its OFFSET in the table of
    4015             :    OFFSETS.  */
    4016             : 
    4017             : static int
    4018    17730215 : record_subobject_offset (tree type, tree offset, splay_tree offsets)
    4019             : {
    4020    17730215 :   splay_tree_node n;
    4021             : 
    4022    17730215 :   if (!is_empty_class (type))
    4023             :     return 0;
    4024             : 
    4025             :   /* Record the location of this empty object in OFFSETS.  */
    4026    16070219 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    4027    16070219 :   if (!n)
    4028    13419612 :     n = splay_tree_insert (offsets,
    4029             :                            (splay_tree_key) offset,
    4030             :                            (splay_tree_value) NULL_TREE);
    4031    32140438 :   n->value = ((splay_tree_value)
    4032    16070219 :               tree_cons (NULL_TREE,
    4033             :                          type,
    4034    16070219 :                          (tree) n->value));
    4035             : 
    4036    16070219 :   return 0;
    4037             : }
    4038             : 
    4039             : /* Returns nonzero if TYPE is an empty class type and there is
    4040             :    already an entry in OFFSETS for the same TYPE as the same OFFSET.  */
    4041             : 
    4042             : static int
    4043      571099 : check_subobject_offset (tree type, tree offset, splay_tree offsets)
    4044             : {
    4045      571099 :   splay_tree_node n;
    4046      571099 :   tree t;
    4047             : 
    4048      571099 :   if (!is_empty_class (type))
    4049             :     return 0;
    4050             : 
    4051             :   /* Record the location of this empty object in OFFSETS.  */
    4052      471542 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    4053      471542 :   if (!n)
    4054             :     return 0;
    4055             : 
    4056     4313879 :   for (t = (tree) n->value; t; t = TREE_CHAIN (t))
    4057     3844224 :     if (same_type_p (TREE_VALUE (t), type))
    4058             :       return 1;
    4059             : 
    4060             :   return 0;
    4061             : }
    4062             : 
    4063             : /* Walk through all the subobjects of TYPE (located at OFFSET).  Call
    4064             :    F for every subobject, passing it the type, offset, and table of
    4065             :    OFFSETS.  If VBASES_P is one, then virtual non-primary bases should
    4066             :    be traversed.
    4067             : 
    4068             :    If MAX_OFFSET is non-NULL, then subobjects with an offset greater
    4069             :    than MAX_OFFSET will not be walked.
    4070             : 
    4071             :    If F returns a nonzero value, the traversal ceases, and that value
    4072             :    is returned.  Otherwise, returns zero.  */
    4073             : 
    4074             : static int
    4075    31706534 : walk_subobject_offsets (tree type,
    4076             :                         subobject_offset_fn f,
    4077             :                         tree offset,
    4078             :                         splay_tree offsets,
    4079             :                         tree max_offset,
    4080             :                         int vbases_p)
    4081             : {
    4082    31706534 :   int r = 0;
    4083    31706534 :   tree type_binfo = NULL_TREE;
    4084             : 
    4085             :   /* If this OFFSET is bigger than the MAX_OFFSET, then we should
    4086             :      stop.  */
    4087    31706534 :   if (max_offset && tree_int_cst_lt (max_offset, offset))
    4088             :     return 0;
    4089             : 
    4090    24488777 :   if (type == error_mark_node)
    4091             :     return 0;
    4092             : 
    4093    24488777 :   if (!TYPE_P (type))
    4094             :     {
    4095     3993824 :       type_binfo = type;
    4096     3993824 :       type = BINFO_TYPE (type);
    4097             :     }
    4098             : 
    4099    24488777 :   if (CLASS_TYPE_P (type))
    4100             :     {
    4101    20502844 :       tree field;
    4102    20502844 :       tree binfo;
    4103    20502844 :       int i;
    4104             : 
    4105             :       /* Avoid recursing into objects that are not interesting.  */
    4106    20502844 :       if (!CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    4107             :         return 0;
    4108             : 
    4109             :       /* Record the location of TYPE.  */
    4110    18301833 :       r = (*f) (type, offset, offsets);
    4111    18301833 :       if (r)
    4112             :         return r;
    4113             : 
    4114             :       /* Iterate through the direct base classes of TYPE.  */
    4115    18300012 :       if (!type_binfo)
    4116    14880020 :         type_binfo = TYPE_BINFO (type);
    4117    22209638 :       for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, binfo); i++)
    4118             :         {
    4119     3910829 :           tree binfo_offset;
    4120             : 
    4121     3910829 :           if (BINFO_VIRTUAL_P (binfo))
    4122        1945 :             continue;
    4123             : 
    4124     3908884 :           tree orig_binfo;
    4125             :           /* We cannot rely on BINFO_OFFSET being set for the base
    4126             :              class yet, but the offsets for direct non-virtual
    4127             :              bases can be calculated by going back to the TYPE.  */
    4128     3908884 :           orig_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
    4129     3908884 :           binfo_offset = size_binop (PLUS_EXPR,
    4130             :                                      offset,
    4131             :                                      BINFO_OFFSET (orig_binfo));
    4132             : 
    4133     3908884 :           r = walk_subobject_offsets (binfo,
    4134             :                                       f,
    4135             :                                       binfo_offset,
    4136             :                                       offsets,
    4137             :                                       max_offset,
    4138             :                                       /*vbases_p=*/0);
    4139     3908884 :           if (r)
    4140        1203 :             return r;
    4141             :         }
    4142             : 
    4143    18298809 :       if (CLASSTYPE_VBASECLASSES (type))
    4144             :         {
    4145        1559 :           unsigned ix;
    4146        1559 :           vec<tree, va_gc> *vbases;
    4147             : 
    4148             :           /* Iterate through the virtual base classes of TYPE.  In G++
    4149             :              3.2, we included virtual bases in the direct base class
    4150             :              loop above, which results in incorrect results; the
    4151             :              correct offsets for virtual bases are only known when
    4152             :              working with the most derived type.  */
    4153        1559 :           if (vbases_p)
    4154          32 :             for (vbases = CLASSTYPE_VBASECLASSES (type), ix = 0;
    4155          32 :                  vec_safe_iterate (vbases, ix, &binfo); ix++)
    4156             :               {
    4157          16 :                 r = walk_subobject_offsets (binfo,
    4158             :                                             f,
    4159          16 :                                             size_binop (PLUS_EXPR,
    4160             :                                                         offset,
    4161             :                                                         BINFO_OFFSET (binfo)),
    4162             :                                             offsets,
    4163             :                                             max_offset,
    4164             :                                             /*vbases_p=*/0);
    4165          16 :                 if (r)
    4166           0 :                   return r;
    4167             :               }
    4168             :           else
    4169             :             {
    4170             :               /* We still have to walk the primary base, if it is
    4171             :                  virtual.  (If it is non-virtual, then it was walked
    4172             :                  above.)  */
    4173        1543 :               tree vbase = get_primary_binfo (type_binfo);
    4174             : 
    4175         512 :               if (vbase && BINFO_VIRTUAL_P (vbase)
    4176         303 :                   && BINFO_PRIMARY_P (vbase)
    4177        1846 :                   && BINFO_INHERITANCE_CHAIN (vbase) == type_binfo)
    4178             :                 {
    4179         260 :                   r = (walk_subobject_offsets
    4180         260 :                        (vbase, f, offset,
    4181             :                         offsets, max_offset, /*vbases_p=*/0));
    4182         260 :                   if (r)
    4183             :                     return r;
    4184             :                 }
    4185             :             }
    4186             :         }
    4187             : 
    4188             :       /* Iterate through the fields of TYPE.  */
    4189   331840669 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    4190   313542016 :         if (TREE_CODE (field) == FIELD_DECL
    4191     5881074 :             && TREE_TYPE (field) != error_mark_node
    4192   319423052 :             && !DECL_ARTIFICIAL (field))
    4193             :           {
    4194     1962178 :             tree field_offset;
    4195             : 
    4196     1962178 :             field_offset = byte_position (field);
    4197             : 
    4198     1962178 :             r = walk_subobject_offsets (TREE_TYPE (field),
    4199             :                                         f,
    4200             :                                         size_binop (PLUS_EXPR,
    4201             :                                                     offset,
    4202             :                                                     field_offset),
    4203             :                                         offsets,
    4204             :                                         max_offset,
    4205             :                                         /*vbases_p=*/1);
    4206     1962178 :             if (r)
    4207         156 :               return r;
    4208             :           }
    4209             :     }
    4210     3985933 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    4211             :     {
    4212      511326 :       tree element_type = strip_array_types (type);
    4213      511326 :       tree domain = TYPE_DOMAIN (type);
    4214      511326 :       tree index;
    4215             : 
    4216             :       /* Avoid recursing into objects that are not interesting.  */
    4217       19694 :       if (!CLASS_TYPE_P (element_type)
    4218       19682 :           || !CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type)
    4219        8843 :           || !domain
    4220      520146 :           || integer_minus_onep (TYPE_MAX_VALUE (domain)))
    4221      502732 :         return 0;
    4222             : 
    4223             :       /* Step through each of the elements in the array.  */
    4224        8594 :       for (index = size_zero_node;
    4225       18361 :            !tree_int_cst_lt (TYPE_MAX_VALUE (domain), index);
    4226        9767 :            index = size_binop (PLUS_EXPR, index, size_one_node))
    4227             :         {
    4228       17875 :           r = walk_subobject_offsets (TREE_TYPE (type),
    4229             :                                       f,
    4230             :                                       offset,
    4231             :                                       offsets,
    4232             :                                       max_offset,
    4233             :                                       /*vbases_p=*/1);
    4234       17875 :           if (r)
    4235           0 :             return r;
    4236       17875 :           offset = size_binop (PLUS_EXPR, offset,
    4237             :                                TYPE_SIZE_UNIT (TREE_TYPE (type)));
    4238             :           /* If this new OFFSET is bigger than the MAX_OFFSET, then
    4239             :              there's no point in iterating through the remaining
    4240             :              elements of the array.  */
    4241       17875 :           if (max_offset && tree_int_cst_lt (max_offset, offset))
    4242             :             break;
    4243             :         }
    4244             :     }
    4245             : 
    4246             :   return 0;
    4247             : }
    4248             : 
    4249             : /* Return true iff FIELD_DECL DECL is potentially overlapping.  */
    4250             : 
    4251             : static bool
    4252    39812447 : field_poverlapping_p (tree decl)
    4253             : {
    4254             :   /* Base fields are actually potentially overlapping, but C++ bases go through
    4255             :      a different code path based on binfos, and ObjC++ base fields are laid out
    4256             :      in objc-act, so we don't want layout_class_type to mess with them.  */
    4257    39812447 :   if (DECL_FIELD_IS_BASE (decl))
    4258             :     {
    4259           0 :       gcc_checking_assert (c_dialect_objc ());
    4260             :       return false;
    4261             :     }
    4262             : 
    4263    39812447 :   return lookup_attribute ("no_unique_address",
    4264    79624894 :                            DECL_ATTRIBUTES (decl));
    4265             : }
    4266             : 
    4267             : /* Return true iff DECL is an empty field, either for an empty base or a
    4268             :    [[no_unique_address]] data member.  */
    4269             : 
    4270             : bool
    4271    39030137 : is_empty_field (tree decl)
    4272             : {
    4273    39030137 :   if (!decl || TREE_CODE (decl) != FIELD_DECL)
    4274             :     return false;
    4275             : 
    4276    31783195 :   bool r = (is_empty_class (TREE_TYPE (decl))
    4277    31783195 :             && (DECL_FIELD_IS_BASE (decl)
    4278      160556 :                 || field_poverlapping_p (decl)));
    4279             : 
    4280             :   /* Empty fields should have size zero.  */
    4281     1499994 :   gcc_checking_assert (!r || integer_zerop (DECL_SIZE (decl)));
    4282             : 
    4283             :   return r;
    4284             : }
    4285             : 
    4286             : /* Record all of the empty subobjects of DECL_OR_BINFO.  */
    4287             : 
    4288             : static void
    4289    24360324 : record_subobject_offsets (tree decl_or_binfo,
    4290             :                           splay_tree offsets)
    4291             : {
    4292    24360324 :   tree type, offset;
    4293    24360324 :   bool overlapping, vbases_p;
    4294             : 
    4295    24360324 :   if (DECL_P (decl_or_binfo))
    4296             :     {
    4297     9904852 :       tree decl = decl_or_binfo;
    4298     9904852 :       type = TREE_TYPE (decl);
    4299     9904852 :       offset = byte_position (decl);
    4300     9904852 :       overlapping = field_poverlapping_p (decl);
    4301     9904852 :       vbases_p = true;
    4302             :     }
    4303             :   else
    4304             :     {
    4305    14455472 :       type = BINFO_TYPE (decl_or_binfo);
    4306    14455472 :       offset = BINFO_OFFSET (decl_or_binfo);
    4307    14455472 :       overlapping = true;
    4308    14455472 :       vbases_p = false;
    4309             :     }
    4310             : 
    4311    24360324 :   tree max_offset;
    4312             :   /* If recording subobjects for a non-static data member or a
    4313             :      non-empty base class, we do not need to record offsets beyond
    4314             :      the size of the biggest empty class.  Additional data members
    4315             :      will go at the end of the class.  Additional base classes will go
    4316             :      either at offset zero (if empty, in which case they cannot
    4317             :      overlap with offsets past the size of the biggest empty class) or
    4318             :      at the end of the class.
    4319             : 
    4320             :      However, if we are placing an empty base class, then we must record
    4321             :      all offsets, as either the empty class is at offset zero (where
    4322             :      other empty classes might later be placed) or at the end of the
    4323             :      class (where other objects might then be placed, so other empty
    4324             :      subobjects might later overlap).  */
    4325    24360324 :   if (!overlapping
    4326    24360324 :       || !is_empty_class (type))
    4327    11488640 :     max_offset = sizeof_biggest_empty_class;
    4328             :   else
    4329             :     max_offset = NULL_TREE;
    4330    24360324 :   walk_subobject_offsets (type, record_subobject_offset, offset,
    4331             :                           offsets, max_offset, vbases_p);
    4332    24360324 : }
    4333             : 
    4334             : /* Returns nonzero if any of the empty subobjects of TYPE (located at
    4335             :    OFFSET) conflict with entries in OFFSETS.  If VBASES_P is nonzero,
    4336             :    virtual bases of TYPE are examined.  */
    4337             : 
    4338             : static int
    4339    23636721 : layout_conflict_p (tree type,
    4340             :                    tree offset,
    4341             :                    splay_tree offsets,
    4342             :                    int vbases_p)
    4343             : {
    4344    23636721 :   splay_tree_node max_node;
    4345             : 
    4346             :   /* Get the node in OFFSETS that indicates the maximum offset where
    4347             :      an empty subobject is located.  */
    4348    23636721 :   max_node = splay_tree_max (offsets);
    4349             :   /* If there aren't any empty subobjects, then there's no point in
    4350             :      performing this check.  */
    4351    23636721 :   if (!max_node)
    4352             :     return 0;
    4353             : 
    4354     1456608 :   return walk_subobject_offsets (type, check_subobject_offset, offset,
    4355     1456608 :                                  offsets, (tree) (max_node->key),
    4356     1456608 :                                  vbases_p);
    4357             : }
    4358             : 
    4359             : /* DECL is a FIELD_DECL corresponding either to a base subobject of a
    4360             :    non-static data member of the type indicated by RLI.  BINFO is the
    4361             :    binfo corresponding to the base subobject, OFFSETS maps offsets to
    4362             :    types already located at those offsets.  This function determines
    4363             :    the position of the DECL.  */
    4364             : 
    4365             : static void
    4366    11489417 : layout_nonempty_base_or_field (record_layout_info rli,
    4367             :                                tree decl,
    4368             :                                tree binfo,
    4369             :                                splay_tree offsets)
    4370             : {
    4371    11489417 :   tree offset = NULL_TREE;
    4372    11489417 :   bool field_p;
    4373    11489417 :   tree type;
    4374             : 
    4375    11489417 :   if (binfo)
    4376             :     {
    4377             :       /* For the purposes of determining layout conflicts, we want to
    4378             :          use the class type of BINFO; TREE_TYPE (DECL) will be the
    4379             :          CLASSTYPE_AS_BASE version, which does not contain entries for
    4380             :          zero-sized bases.  */
    4381     1608272 :       type = TREE_TYPE (binfo);
    4382     1608272 :       field_p = false;
    4383             :     }
    4384             :   else
    4385             :     {
    4386     9881145 :       type = TREE_TYPE (decl);
    4387     9881145 :       field_p = true;
    4388             :     }
    4389             : 
    4390             :   /* Try to place the field.  It may take more than one try if we have
    4391             :      a hard time placing the field without putting two objects of the
    4392             :      same type at the same address.  */
    4393    11489699 :   while (1)
    4394             :     {
    4395    11489699 :       struct record_layout_info_s old_rli = *rli;
    4396             : 
    4397             :       /* Place this field.  */
    4398    11489699 :       place_field (rli, decl);
    4399    11489699 :       offset = byte_position (decl);
    4400             : 
    4401             :       /* We have to check to see whether or not there is already
    4402             :          something of the same type at the offset we're about to use.
    4403             :          For example, consider:
    4404             : 
    4405             :            struct S {};
    4406             :            struct T : public S { int i; };
    4407             :            struct U : public S, public T {};
    4408             : 
    4409             :          Here, we put S at offset zero in U.  Then, we can't put T at
    4410             :          offset zero -- its S component would be at the same address
    4411             :          as the S we already allocated.  So, we have to skip ahead.
    4412             :          Since all data members, including those whose type is an
    4413             :          empty class, have nonzero size, any overlap can happen only
    4414             :          with a direct or indirect base-class -- it can't happen with
    4415             :          a data member.  */
    4416             :       /* In a union, overlap is permitted; all members are placed at
    4417             :          offset zero.  */
    4418    11489699 :       if (TREE_CODE (rli->t) == UNION_TYPE)
    4419             :         break;
    4420    12373552 :       if (layout_conflict_p (field_p ? type : binfo, offset,
    4421             :                              offsets, field_p))
    4422             :         {
    4423             :           /* Strip off the size allocated to this field.  That puts us
    4424             :              at the first place we could have put the field with
    4425             :              proper alignment.  */
    4426         282 :           *rli = old_rli;
    4427             : 
    4428             :           /* Bump up by the alignment required for the type.  */
    4429         282 :           rli->bitpos
    4430         282 :             = size_binop (PLUS_EXPR, rli->bitpos,
    4431             :                           bitsize_int (binfo
    4432             :                                        ? CLASSTYPE_ALIGN (type)
    4433             :                                        : TYPE_ALIGN (type)));
    4434         282 :           normalize_rli (rli);
    4435             :         }
    4436    10764923 :       else if (TREE_CODE (type) == NULLPTR_TYPE
    4437       21542 :                && warn_abi && abi_version_crosses (9))
    4438             :         {
    4439             :           /* Before ABI v9, we were giving nullptr_t alignment of 1; if
    4440             :              the offset wasn't aligned like a pointer when we started to
    4441             :              layout this field, that affects its position.  */
    4442         138 :           tree pos = rli_size_unit_so_far (&old_rli);
    4443         138 :           if (int_cst_value (pos) % TYPE_ALIGN_UNIT (ptr_type_node) != 0)
    4444             :             {
    4445           3 :               if (abi_version_at_least (9))
    4446           3 :                 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wabi,
    4447             :                             "alignment of %qD increased in %<-fabi-version=9%> "
    4448             :                             "(GCC 5.2)", decl);
    4449             :               else
    4450           0 :                 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wabi, "alignment "
    4451             :                             "of %qD will increase in %<-fabi-version=9%>",
    4452             :                             decl);
    4453             :             }
    4454             :           break;
    4455             :         }
    4456             :       else
    4457             :         /* There was no conflict.  We're done laying out this field.  */
    4458             :         break;
    4459             :     }
    4460             : 
    4461             :   /* Now that we know where it will be placed, update its
    4462             :      BINFO_OFFSET.  */
    4463    13097689 :   if (binfo && CLASS_TYPE_P (BINFO_TYPE (binfo)))
    4464             :     /* Indirect virtual bases may have a nonzero BINFO_OFFSET at
    4465             :        this point because their BINFO_OFFSET is copied from another
    4466             :        hierarchy.  Therefore, we may not need to add the entire
    4467             :        OFFSET.  */
    4468     1608272 :     propagate_binfo_offsets (binfo,
    4469             :                              size_diffop_loc (input_location,
    4470             :                                           fold_convert (ssizetype, offset),
    4471     1608272 :                                           fold_convert (ssizetype,
    4472             :                                                    BINFO_OFFSET (binfo))));
    4473    11489417 : }
    4474             : 
    4475             : /* Returns true if TYPE is empty and OFFSET is nonzero.  */
    4476             : 
    4477             : static int
    4478         519 : empty_base_at_nonzero_offset_p (tree type,
    4479             :                                 tree offset,
    4480             :                                 splay_tree /*offsets*/)
    4481             : {
    4482         519 :   return is_empty_class (type) && !integer_zerop (offset);
    4483             : }
    4484             : 
    4485             : /* Layout the empty base BINFO.  EOC indicates the byte currently just
    4486             :    past the end of the class, and should be correctly aligned for a
    4487             :    class of the type indicated by BINFO; OFFSETS gives the offsets of
    4488             :    the empty bases allocated so far. T is the most derived
    4489             :    type.  Return nonzero iff we added it at the end.  */
    4490             : 
    4491             : static bool
    4492    12871684 : layout_empty_base_or_field (record_layout_info rli, tree binfo_or_decl,
    4493             :                             splay_tree offsets)
    4494             : {
    4495    12871684 :   tree alignment;
    4496    12871684 :   bool atend = false;
    4497    12871684 :   tree binfo = NULL_TREE;
    4498    12871684 :   tree decl = NULL_TREE;
    4499    12871684 :   tree type;
    4500    12871684 :   if (TREE_CODE (binfo_or_decl) == TREE_BINFO)
    4501             :     {
    4502    12847200 :       binfo = binfo_or_decl;
    4503    12847200 :       type = BINFO_TYPE (binfo);
    4504             :     }
    4505             :   else
    4506             :     {
    4507       24484 :       decl = binfo_or_decl;
    4508       24484 :       type = TREE_TYPE (decl);
    4509             :     }
    4510             : 
    4511             :   /* On some platforms (ARM), even empty classes will not be
    4512             :      byte-aligned.  */
    4513    12871684 :   tree eoc = round_up_loc (input_location,
    4514             :                            rli_size_unit_so_far (rli),
    4515    12871684 :                            CLASSTYPE_ALIGN_UNIT (type));
    4516             : 
    4517             :   /* This routine should only be used for empty classes.  */
    4518    12871684 :   gcc_assert (is_empty_class (type));
    4519             : 
    4520    12871684 :   if (decl && DECL_USER_ALIGN (decl))
    4521           1 :     alignment = size_int (DECL_ALIGN_UNIT (decl));
    4522             :   else
    4523    12871683 :     alignment = size_int (CLASSTYPE_ALIGN_UNIT (type));
    4524             : 
    4525             :   /* This is an empty base class.  We first try to put it at offset
    4526             :      zero.  */
    4527    12871684 :   tree offset = size_zero_node;
    4528    12871684 :   if (TREE_CODE (rli->t) != UNION_TYPE
    4529    12871684 :       && layout_conflict_p (type,
    4530             :                             offset,
    4531             :                             offsets,
    4532             :                             /*vbases_p=*/0))
    4533             :     {
    4534             :       /* That didn't work.  Now, we move forward from the next
    4535             :          available spot in the class.  */
    4536        1531 :       atend = true;
    4537             :       offset = eoc;
    4538        2213 :       while (1)
    4539             :         {
    4540        1531 :           if (!layout_conflict_p (type,
    4541             :                                   offset,
    4542             :                                   offsets,
    4543             :                                   /*vbases_p=*/0))
    4544             :             /* We finally found a spot where there's no overlap.  */
    4545             :             break;
    4546             : 
    4547             :           /* There's overlap here, too.  Bump along to the next spot.  */
    4548         682 :           offset = size_binop (PLUS_EXPR, offset, alignment);
    4549             :         }
    4550             :     }
    4551             : 
    4552    12871684 :   if (decl && DECL_USER_ALIGN (decl))
    4553             :     {
    4554           1 :       rli->record_align = MAX (rli->record_align, DECL_ALIGN (decl));
    4555           1 :       if (warn_packed)
    4556           0 :         rli->unpacked_align = MAX (rli->unpacked_align, DECL_ALIGN (decl));
    4557           1 :       TYPE_USER_ALIGN (rli->t) = 1;
    4558             :     }
    4559    12871683 :   else if (CLASSTYPE_USER_ALIGN (type))
    4560             :     {
    4561          17 :       rli->record_align = MAX (rli->record_align, CLASSTYPE_ALIGN (type));
    4562          17 :       if (warn_packed)
    4563           0 :         rli->unpacked_align = MAX (rli->unpacked_align, CLASSTYPE_ALIGN (type));
    4564          17 :       TYPE_USER_ALIGN (rli->t) = 1;
    4565             :     }
    4566             : 
    4567    12871684 :   if (binfo)
    4568             :     /* Adjust BINFO_OFFSET (binfo) to be exactly OFFSET.  */
    4569    25694400 :     propagate_binfo_offsets (binfo,
    4570    12847200 :                              size_diffop (offset, BINFO_OFFSET (binfo)));
    4571             :   else
    4572             :     {
    4573       24484 :       DECL_FIELD_OFFSET (decl) = offset;
    4574       24484 :       DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    4575       24484 :       SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    4576             :     }
    4577             : 
    4578    12871684 :   return atend;
    4579             : }
    4580             : 
    4581             : /* Build the FIELD_DECL for BASETYPE as a base of T, add it to the chain of
    4582             :    fields at NEXT_FIELD, and return it.  */
    4583             : 
    4584             : static tree
    4585    14330255 : build_base_field_1 (tree t, tree binfo, tree access, tree *&next_field)
    4586             : {
    4587             :   /* Create the FIELD_DECL.  */
    4588    14330255 :   tree basetype = BINFO_TYPE (binfo);
    4589    14330255 :   tree as_base = CLASSTYPE_AS_BASE (basetype);
    4590    14330255 :   gcc_assert (as_base);
    4591    14330255 :   tree decl = build_decl (input_location, FIELD_DECL, NULL_TREE, as_base);
    4592             : 
    4593    14330255 :   DECL_ARTIFICIAL (decl) = 1;
    4594    14330255 :   DECL_IGNORED_P (decl) = 1;
    4595    14330255 :   DECL_FIELD_CONTEXT (decl) = t;
    4596    14330255 :   if (is_empty_class (basetype))
    4597             :     /* CLASSTYPE_SIZE is one byte, but the field needs to have size zero.  */
    4598    12721983 :     DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = size_zero_node;
    4599             :   else
    4600             :     {
    4601     1608272 :       DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
    4602     1608272 :       DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
    4603             :     }
    4604    14330255 :   SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype));
    4605    14330255 :   DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
    4606    14330255 :   SET_DECL_MODE (decl, TYPE_MODE (basetype));
    4607    14330255 :   DECL_FIELD_IS_BASE (decl) = 1;
    4608             : 
    4609    14330255 :   if (access == access_private_node)
    4610      548287 :     TREE_PRIVATE (decl) = true;
    4611    13781968 :   else if (access == access_protected_node)
    4612       45057 :     TREE_PROTECTED (decl) = true;
    4613             : 
    4614             :   /* Add the new FIELD_DECL to the list of fields for T.  */
    4615    14330255 :   DECL_CHAIN (decl) = *next_field;
    4616    14330255 :   *next_field = decl;
    4617    14330255 :   next_field = &DECL_CHAIN (decl);
    4618             : 
    4619    14330255 :   return decl;
    4620             : }
    4621             : 
    4622             : /* Layout the base given by BINFO in the class indicated by RLI.
    4623             :    *BASE_ALIGN is a running maximum of the alignments of
    4624             :    any base class.  OFFSETS gives the location of empty base
    4625             :    subobjects.  T is the most derived type.  Return nonzero if the new
    4626             :    object cannot be nearly-empty.  A new FIELD_DECL is inserted at
    4627             :    *NEXT_FIELD, unless BINFO is for an empty base class.
    4628             : 
    4629             :    Returns the location at which the next field should be inserted.  */
    4630             : 
    4631             : static tree *
    4632    14455472 : build_base_field (record_layout_info rli, tree binfo, tree access,
    4633             :                   splay_tree offsets, tree *next_field)
    4634             : {
    4635    14455472 :   tree t = rli->t;
    4636    14455472 :   tree basetype = BINFO_TYPE (binfo);
    4637             : 
    4638    14455472 :   if (!COMPLETE_TYPE_P (basetype))
    4639             :     /* This error is now reported in xref_tag, thus giving better
    4640             :        location information.  */
    4641           0 :     return next_field;
    4642             : 
    4643             :   /* Place the base class.  */
    4644    14455472 :   if (!is_empty_class (basetype))
    4645             :     {
    4646     1608272 :       tree decl;
    4647             : 
    4648             :       /* The containing class is non-empty because it has a non-empty
    4649             :          base class.  */
    4650     1608272 :       CLASSTYPE_EMPTY_P (t) = 0;
    4651             : 
    4652             :       /* Create the FIELD_DECL.  */
    4653     1608272 :       decl = build_base_field_1 (t, binfo, access, next_field);
    4654             : 
    4655             :       /* Try to place the field.  It may take more than one try if we
    4656             :          have a hard time placing the field without putting two
    4657             :          objects of the same type at the same address.  */
    4658     1608272 :       layout_nonempty_base_or_field (rli, decl, binfo, offsets);
    4659             :     }
    4660             :   else
    4661             :     {
    4662    12847200 :       bool atend = layout_empty_base_or_field (rli, binfo, offsets);
    4663             :       /* A nearly-empty class "has no proper base class that is empty,
    4664             :          not morally virtual, and at an offset other than zero."  */
    4665    12847200 :       if (!BINFO_VIRTUAL_P (binfo) && CLASSTYPE_NEARLY_EMPTY_P (t))
    4666             :         {
    4667         505 :           if (atend)
    4668         116 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4669             :           /* The check above (used in G++ 3.2) is insufficient because
    4670             :              an empty class placed at offset zero might itself have an
    4671             :              empty base at a nonzero offset.  */
    4672         389 :           else if (walk_subobject_offsets (basetype,
    4673             :                                            empty_base_at_nonzero_offset_p,
    4674             :                                            size_zero_node,
    4675             :                                            /*offsets=*/NULL,
    4676             :                                            /*max_offset=*/NULL_TREE,
    4677             :                                            /*vbases_p=*/true))
    4678           8 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4679             :         }
    4680             : 
    4681             :       /* We used to not create a FIELD_DECL for empty base classes because of
    4682             :          back end issues with overlapping FIELD_DECLs, but that doesn't seem to
    4683             :          be a problem anymore.  We need them to handle initialization of C++17
    4684             :          aggregate bases.  */
    4685    25570797 :       if (cxx_dialect >= cxx17 && !BINFO_VIRTUAL_P (binfo))
    4686             :         {
    4687    12721983 :           tree decl = build_base_field_1 (t, binfo, access, next_field);
    4688    12721983 :           DECL_FIELD_OFFSET (decl) = BINFO_OFFSET (binfo);
    4689    12721983 :           DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    4690    12721983 :           SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    4691    12721983 :           SET_DECL_FIELD_ABI_IGNORED (decl, 1);
    4692             :         }
    4693             : 
    4694             :       /* An empty virtual base causes a class to be non-empty
    4695             :          -- but in that case we do not need to clear CLASSTYPE_EMPTY_P
    4696             :          here because that was already done when the virtual table
    4697             :          pointer was created.  */
    4698             :     }
    4699             : 
    4700             :   /* Record the offsets of BINFO and its base subobjects.  */
    4701    14455472 :   record_subobject_offsets (binfo, offsets);
    4702             : 
    4703    14455472 :   return next_field;
    4704             : }
    4705             : 
    4706             : /* Layout all of the non-virtual base classes.  Record empty
    4707             :    subobjects in OFFSETS.  T is the most derived type.  Return nonzero
    4708             :    if the type cannot be nearly empty.  The fields created
    4709             :    corresponding to the base classes will be inserted at
    4710             :    *NEXT_FIELD.  */
    4711             : 
    4712             : static void
    4713    25156660 : build_base_fields (record_layout_info rli,
    4714             :                    splay_tree offsets, tree *next_field)
    4715             : {
    4716             :   /* Chain to hold all the new FIELD_DECLs which stand in for base class
    4717             :      subobjects.  */
    4718    25156660 :   tree t = rli->t;
    4719    25156660 :   tree binfo = TYPE_BINFO (t);
    4720    25156660 :   int n_baseclasses = BINFO_N_BASE_BINFOS (binfo);
    4721             : 
    4722             :   /* The primary base class is always allocated first.  */
    4723    25156660 :   const tree primary_binfo = CLASSTYPE_PRIMARY_BINFO (t);
    4724    25156660 :   if (primary_binfo)
    4725             :     {
    4726             :       /* We need to walk BINFO_BASE_BINFO to find the access of the primary
    4727             :          base, if it is direct.  Indirect base fields are private.  */
    4728      970962 :       tree primary_access = access_private_node;
    4729      971996 :       for (int i = 0; i < n_baseclasses; ++i)
    4730             :         {
    4731      971911 :           tree base_binfo = BINFO_BASE_BINFO (binfo, i);
    4732      971911 :           if (base_binfo == primary_binfo)
    4733             :             {
    4734      970877 :               primary_access = BINFO_BASE_ACCESS (binfo, i);
    4735      970877 :               break;
    4736             :             }
    4737             :         }
    4738      970962 :       next_field = build_base_field (rli, primary_binfo,
    4739             :                                      primary_access,
    4740             :                                      offsets, next_field);
    4741             :     }
    4742             : 
    4743             :   /* Now allocate the rest of the bases.  */
    4744    39504201 :   for (int i = 0; i < n_baseclasses; ++i)
    4745             :     {
    4746    14347541 :       tree base_binfo = BINFO_BASE_BINFO (binfo, i);
    4747             : 
    4748             :       /* The primary base was already allocated above, so we don't
    4749             :          need to allocate it again here.  */
    4750    14347541 :       if (base_binfo == primary_binfo)
    4751      970877 :        continue;
    4752             : 
    4753             :       /* Virtual bases are added at the end (a primary virtual base
    4754             :          will have already been added).  */
    4755    13376664 :       if (BINFO_VIRTUAL_P (base_binfo))
    4756       35151 :         continue;
    4757             : 
    4758    13341513 :       next_field = build_base_field (rli, base_binfo,
    4759    13341513 :                                      BINFO_BASE_ACCESS (binfo, i),
    4760             :                                      offsets, next_field);
    4761             :     }
    4762    25156660 : }
    4763             : 
    4764             : /* Go through the TYPE_FIELDS of T issuing any appropriate
    4765             :    diagnostics, figuring out which methods override which other
    4766             :    methods, and so forth.  */
    4767             : 
    4768             : static void
    4769    25156660 : check_methods (tree t)
    4770             : {
    4771   173397327 :   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    4772   148240667 :     if (DECL_DECLARES_FUNCTION_P (x))
    4773             :       {
    4774    75741128 :         check_for_override (x, t);
    4775             : 
    4776    75741128 :         if (DECL_PURE_VIRTUAL_P (x)
    4777    75741128 :             && (TREE_CODE (x) != FUNCTION_DECL || ! DECL_VINDEX (x)))
    4778           4 :           error ("initializer specified for non-virtual method %q+D", x);
    4779             :         /* The name of the field is the original field name
    4780             :            Save this in auxiliary field for later overloading.  */
    4781    75741128 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_VINDEX (x))
    4782             :           {
    4783     4065345 :             TYPE_POLYMORPHIC_P (t) = 1;
    4784     4065345 :             if (DECL_PURE_VIRTUAL_P (x))
    4785      423017 :               vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    4786             :           }
    4787             : 
    4788    75741128 :         if (!DECL_VIRTUAL_P (x)
    4789   147416911 :             && lookup_attribute ("transaction_safe_dynamic",
    4790    71675783 :                                  DECL_ATTRIBUTES (x)))
    4791           2 :           error_at (DECL_SOURCE_LOCATION (x),
    4792             :                     "%<transaction_safe_dynamic%> may only be specified for "
    4793             :                     "a virtual function");
    4794             :       }
    4795             : 
    4796             :   /* Check whether the eligible special member functions (P0848) are
    4797             :      user-provided.  add_method arranged that the CLASSTYPE_MEMBER_VEC only
    4798             :      has the eligible ones, unless none are eligible; TYPE_FIELDS also contains
    4799             :      ineligible overloads, which is why this needs to be separate from the loop
    4800             :      above.  */
    4801             : 
    4802    25156660 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    4803             :     {
    4804     2445646 :       if (TREE_CODE (dtor) == OVERLOAD)
    4805             :         {
    4806             :           /* P0848: At the end of the definition of a class, overload
    4807             :              resolution is performed among the prospective destructors declared
    4808             :              in that class with an empty argument list to select the destructor
    4809             :              for the class, also known as the selected destructor. The program
    4810             :              is ill-formed if overload resolution fails. */
    4811           2 :           int viable = 0;
    4812          10 :           for (tree fn : ovl_range (dtor))
    4813           4 :             if (constraints_satisfied_p (fn))
    4814           2 :               ++viable;
    4815           2 :           gcc_checking_assert (viable != 1);
    4816             : 
    4817           2 :           auto_diagnostic_group d;
    4818           2 :           if (viable == 0)
    4819           1 :             error_at (location_of (t), "no viable destructor for %qT", t);
    4820             :           else
    4821           1 :             error_at (location_of (t), "destructor for %qT is ambiguous", t);
    4822           2 :           print_candidates (dtor);
    4823             : 
    4824             :           /* Arbitrarily prune the overload set to a single function for
    4825             :              sake of error recovery.  */
    4826           2 :           tree *slot = find_member_slot (t, dtor_identifier);
    4827           2 :           *slot = get_first_fn (dtor);
    4828           2 :         }
    4829     2445644 :       else if (user_provided_p (dtor))
    4830     1904930 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = true;
    4831             :     }
    4832             : 
    4833    57007956 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    4834             :     {
    4835    15925648 :       if (!user_provided_p (fn))
    4836             :         /* Might be trivial.  */;
    4837    13073282 :       else if (TREE_CODE (fn) == TEMPLATE_DECL)
    4838             :         /* Templates are never special members.  */;
    4839     8339363 :       else if (copy_fn_p (fn)
    4840     8339363 :                && constraints_satisfied_p (fn))
    4841      637613 :         TYPE_HAS_COMPLEX_COPY_CTOR (t) = true;
    4842     7701750 :       else if (move_fn_p (fn)
    4843     7701750 :                && constraints_satisfied_p (fn))
    4844      588260 :         TYPE_HAS_COMPLEX_MOVE_CTOR (t) = true;
    4845             :     }
    4846             : 
    4847    34205950 :   for (tree fn : ovl_range (get_class_binding_direct (t, assign_op_identifier)))
    4848             :     {
    4849     4524645 :       if (!user_provided_p (fn))
    4850             :         /* Might be trivial.  */;
    4851     2463046 :       else if (TREE_CODE (fn) == TEMPLATE_DECL)
    4852             :         /* Templates are never special members.  */;
    4853     1841493 :       else if (copy_fn_p (fn)
    4854     1841493 :                && constraints_satisfied_p (fn))
    4855      416840 :         TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = true;
    4856     1424653 :       else if (move_fn_p (fn)
    4857     1424653 :                && constraints_satisfied_p (fn))
    4858      558957 :         TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = true;
    4859             :     }
    4860    25156660 : }
    4861             : 
    4862             : /* FN is constructor, destructor or operator function.  Clone the
    4863             :    declaration to create a NAME'd variant.  NEED_VTT_PARM_P and
    4864             :    OMIT_INHERITED_PARMS_P are relevant if it's a cdtor.  */
    4865             : 
    4866             : static tree
    4867    65307386 : copy_fndecl_with_name (tree fn, tree name, tree_code code,
    4868             :                        bool need_vtt_parm_p, bool omit_inherited_parms_p)
    4869             : {
    4870             :   /* Copy the function.  */
    4871    65307386 :   tree clone = copy_decl (fn);
    4872             :   /* Reset the function name.  */
    4873    65307386 :   DECL_NAME (clone) = name;
    4874             : 
    4875    65307386 :   if (flag_concepts)
    4876             :     /* Clone constraints.  */
    4877     3280740 :     if (tree ci = get_constraints (fn))
    4878      103585 :       set_constraints (clone, copy_node (ci));
    4879             : 
    4880    65307386 :   SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
    4881             :   /* There's no pending inline data for this function.  */
    4882    65307386 :   DECL_PENDING_INLINE_INFO (clone) = NULL;
    4883    65307386 :   DECL_PENDING_INLINE_P (clone) = 0;
    4884             : 
    4885    65307386 :   if (name == base_dtor_identifier)
    4886             :     {
    4887             :       /* The base-class destructor is not virtual.  */
    4888     5344833 :       DECL_VIRTUAL_P (clone) = 0;
    4889     5344833 :       DECL_VINDEX (clone) = NULL_TREE;
    4890             :     }
    4891    59962553 :   else if (code != ERROR_MARK)
    4892             :     {
    4893             :       /* Set the operator code.  */
    4894          55 :       const ovl_op_info_t *ovl_op = OVL_OP_INFO (false, code);
    4895          55 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (clone) = ovl_op->ovl_op_code;
    4896             : 
    4897             :       /* The operator could be virtual.  */
    4898          55 :       if (DECL_VIRTUAL_P (clone))
    4899           4 :         IDENTIFIER_VIRTUAL_P (name) = true;
    4900             :    }
    4901             : 
    4902    65307386 :   if (omit_inherited_parms_p)
    4903         120 :     gcc_assert (DECL_HAS_IN_CHARGE_PARM_P (clone));
    4904             : 
    4905             :   /* If there was an in-charge parameter, drop it from the function
    4906             :      type.  */
    4907    65307386 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    4908             :     {
    4909    13096727 :       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
    4910    13096727 :       tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
    4911             :       /* Skip the `this' parameter.  */
    4912    13096727 :       parmtypes = TREE_CHAIN (parmtypes);
    4913             :       /* Skip the in-charge parameter.  */
    4914    13096727 :       parmtypes = TREE_CHAIN (parmtypes);
    4915             :       /* And the VTT parm, in a complete [cd]tor.  */
    4916    13096727 :       if (DECL_HAS_VTT_PARM_P (fn) && !need_vtt_parm_p)
    4917      908351 :         parmtypes = TREE_CHAIN (parmtypes);
    4918    13096727 :       if (omit_inherited_parms_p)
    4919             :         {
    4920             :           /* If we're omitting inherited parms, that just leaves the VTT.  */
    4921         120 :           gcc_assert (need_vtt_parm_p);
    4922         120 :           parmtypes = tree_cons (NULL_TREE, vtt_parm_type, void_list_node);
    4923             :         }
    4924    13096727 :       TREE_TYPE (clone)
    4925    13096727 :         = build_method_type_directly (basetype,
    4926    13096727 :                                       TREE_TYPE (TREE_TYPE (clone)),
    4927             :                                       parmtypes);
    4928    13096727 :       TREE_TYPE (clone)
    4929    13096727 :         = cp_build_type_attribute_variant (TREE_TYPE (clone),
    4930    13096727 :                                            TYPE_ATTRIBUTES (TREE_TYPE (fn)));
    4931    13096727 :       TREE_TYPE (clone)
    4932    26193454 :         = cxx_copy_lang_qualifiers (TREE_TYPE (clone), TREE_TYPE (fn));
    4933             :     }
    4934             : 
    4935             :   /* Copy the function parameters.  */
    4936    65307386 :   DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
    4937             : 
    4938             :   /* Remove the in-charge parameter.  */
    4939    65307386 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    4940             :     {
    4941    13096727 :       DECL_CHAIN (DECL_ARGUMENTS (clone))
    4942    13096727 :         = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    4943    13096727 :       DECL_HAS_IN_CHARGE_PARM_P (clone) = 0;
    4944             :     }
    4945             : 
    4946             :   /* And the VTT parm, in a complete [cd]tor.  */
    4947    65307386 :   if (DECL_HAS_VTT_PARM_P (fn))
    4948             :     {
    4949     1683448 :       if (need_vtt_parm_p)
    4950      775097 :         DECL_HAS_VTT_PARM_P (clone) = 1;
    4951             :       else
    4952             :         {
    4953     1816702 :           DECL_CHAIN (DECL_ARGUMENTS (clone))
    4954      908351 :             = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    4955      908351 :           DECL_HAS_VTT_PARM_P (clone) = 0;
    4956             :         }
    4957             :     }
    4958             : 
    4959             :   /* A base constructor inheriting from a virtual base doesn't get the
    4960             :      arguments.  */
    4961    65307386 :   if (omit_inherited_parms_p)
    4962         120 :     DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone))) = NULL_TREE;
    4963             : 
    4964   203868193 :   for (tree parms = DECL_ARGUMENTS (clone); parms; parms = DECL_CHAIN (parms))
    4965             :     {
    4966   138560807 :       DECL_CONTEXT (parms) = clone;
    4967   138560807 :       cxx_dup_lang_specific_decl (parms);
    4968             :     }
    4969             : 
    4970             :   /* Create the RTL for this function.  */
    4971    65307386 :   SET_DECL_RTL (clone, NULL);
    4972             : 
    4973             :   /* Regardless of the current scope, this is a member function, so
    4974             :      not at namespace scope.  */
    4975    65307386 :   rest_of_decl_compilation (clone, /*top_level=*/0, at_eof);
    4976             : 
    4977    65307386 :   return clone;
    4978             : }
    4979             : 
    4980             : /* FN is an operator function, create a variant for CODE.  */
    4981             : 
    4982             : tree
    4983          55 : copy_operator_fn (tree fn, tree_code code)
    4984             : {
    4985          55 :   return copy_fndecl_with_name (fn, ovl_op_identifier (code),
    4986          55 :                                 code, false, false);
    4987             : }
    4988             : 
    4989             : /* FN is a constructor or destructor.  Clone the declaration to create
    4990             :    a specialized in-charge or not-in-charge version, as indicated by
    4991             :    NAME.  */
    4992             : 
    4993             : static tree
    4994    74905447 : build_clone (tree fn, tree name, bool need_vtt_parm_p,
    4995             :              bool omit_inherited_parms_p)
    4996             : {
    4997    74905447 :   tree clone;
    4998             : 
    4999             :   /* If this is a template, do the rest on the DECL_TEMPLATE_RESULT.  */
    5000    74905447 :   if (TREE_CODE (fn) == TEMPLATE_DECL)
    5001             :     {
    5002     9598116 :       clone = copy_decl (fn);
    5003     9598116 :       DECL_NAME (clone) = name;
    5004             : 
    5005     9598116 :       tree result = build_clone (DECL_TEMPLATE_RESULT (clone), name,
    5006             :                                  need_vtt_parm_p, omit_inherited_parms_p);
    5007     9598116 :       DECL_TEMPLATE_RESULT (clone) = result;
    5008             : 
    5009     9598116 :       DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
    5010     9598116 :       DECL_TI_TEMPLATE (result) = clone;
    5011             : 
    5012     9598116 :       TREE_TYPE (clone) = TREE_TYPE (result);
    5013             :     }
    5014             :   else
    5015             :     {
    5016    65307331 :       clone = copy_fndecl_with_name (fn, name, ERROR_MARK,
    5017             :                                      need_vtt_parm_p, omit_inherited_parms_p);
    5018    65307331 :       DECL_CLONED_FUNCTION (clone) = fn;
    5019             :     }
    5020             : 
    5021             :   /* Remember where this function came from.  */
    5022    74905447 :   DECL_ABSTRACT_ORIGIN (clone) = fn;
    5023             : 
    5024             :   /* Make it easy to find the CLONE given the FN.  Note the
    5025             :      template_result of a template will be chained this way too.  */
    5026    74905447 :   DECL_CHAIN (clone) = DECL_CHAIN (fn);
    5027    74905447 :   DECL_CHAIN (fn) = clone;
    5028             : 
    5029    74905447 :   return clone;
    5030             : }
    5031             : 
    5032             : /* Build the clones of FN, return the number of clones built.  These
    5033             :    will be inserted onto DECL_CHAIN of FN.  */
    5034             : 
    5035             : void
    5036    32089305 : build_cdtor_clones (tree fn, bool needs_vtt_p, bool base_omits_inherited_p,
    5037             :                     bool update_methods)
    5038             : {
    5039    32089305 :   unsigned count = 0;
    5040             : 
    5041    32089305 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
    5042             :     {
    5043             :       /* For each constructor, we need two variants: an in-charge version
    5044             :          and a not-in-charge version.  */
    5045    26744472 :       build_clone (fn, complete_ctor_identifier, false, false);
    5046    26744472 :       build_clone (fn, base_ctor_identifier, needs_vtt_p,
    5047             :                    base_omits_inherited_p);
    5048    26744472 :       count += 2;
    5049             :     }
    5050             :   else
    5051             :     {
    5052     5344833 :       gcc_assert (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn));
    5053             : 
    5054             :       /* For each destructor, we need three variants: an in-charge
    5055             :          version, a not-in-charge version, and an in-charge deleting
    5056             :          version.  We clone the deleting version first because that
    5057             :          means it will go second on the TYPE_FIELDS list -- and that
    5058             :          corresponds to the correct layout order in the virtual
    5059             :          function table.
    5060             : 
    5061             :          For a non-virtual destructor, we do not build a deleting
    5062             :          destructor.  */
    5063     5344833 :       if (DECL_VIRTUAL_P (fn))
    5064             :         {
    5065     1128721 :           build_clone (fn, deleting_dtor_identifier, false, false);
    5066     1128721 :           count++;
    5067             :         }
    5068     5344833 :       build_clone (fn, complete_dtor_identifier, false, false);
    5069     5344833 :       build_clone (fn, base_dtor_identifier, needs_vtt_p, false);
    5070     5344833 :       count += 2;
    5071             :     }
    5072             : 
    5073             :   /* The original is now an abstract function that is never
    5074             :      emitted.  */
    5075    32089305 :   DECL_ABSTRACT_P (fn) = true;
    5076             : 
    5077    32089305 :   if (update_methods)
    5078    81491521 :     for (tree clone = fn; count--;)
    5079             :       {
    5080    54703392 :         clone = DECL_CHAIN (clone);
    5081    54703392 :         add_method (DECL_CONTEXT (clone), clone, false);
    5082             :       }
    5083    32089305 : }
    5084             : 
    5085             : /* Produce declarations for all appropriate clones of FN.  If
    5086             :    UPDATE_METHODS is true, the clones are added to the
    5087             :    CLASSTYPE_MEMBER_VEC.  */
    5088             : 
    5089             : void
    5090    32229210 : clone_cdtor (tree fn, bool update_methods)
    5091             : {
    5092             :   /* Avoid inappropriate cloning.  */
    5093    32229210 :   if (DECL_CHAIN (fn)
    5094    32229210 :       && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn)))
    5095             :     return;
    5096             : 
    5097             :   /* Base cdtors need a vtt parm if there are virtual bases.  */
    5098    32051174 :   bool vtt = CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn));
    5099             : 
    5100             :   /* Base ctor omits inherited parms it needs a vttparm and inherited
    5101             :      from a virtual nase ctor.  */
    5102    32051174 :   bool base_omits_inherited = (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
    5103    32051174 :                                && base_ctor_omit_inherited_parms (fn));
    5104             : 
    5105    32051174 :   build_cdtor_clones (fn, vtt, base_omits_inherited, update_methods);
    5106             : }
    5107             : 
    5108             : /* DECL is an in charge constructor, which is being defined. This will
    5109             :    have had an in class declaration, from whence clones were
    5110             :    declared. An out-of-class definition can specify additional default
    5111             :    arguments. As it is the clones that are involved in overload
    5112             :    resolution, we must propagate the information from the DECL to its
    5113             :    clones.  */
    5114             : 
    5115             : void
    5116    11911272 : adjust_clone_args (tree decl)
    5117             : {
    5118    11911272 :   tree clone;
    5119             : 
    5120    18880298 :   for (clone = DECL_CHAIN (decl); clone && DECL_CLONED_FUNCTION_P (clone);
    5121     6969026 :        clone = DECL_CHAIN (clone))
    5122             :     {
    5123     6969026 :       tree orig_clone_parms = TYPE_ARG_TYPES (TREE_TYPE (clone));
    5124     6969026 :       tree orig_decl_parms = TYPE_ARG_TYPES (TREE_TYPE (decl));
    5125     6969026 :       tree decl_parms, clone_parms;
    5126             : 
    5127             :       /* Skip the 'this' parameter.  */
    5128     6969026 :       orig_clone_parms = TREE_CHAIN (orig_clone_parms);
    5129     6969026 :       orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5130             : 
    5131     6969026 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl))
    5132       14648 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5133     6969026 :       if (DECL_HAS_VTT_PARM_P (decl))
    5134       14648 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5135             : 
    5136     6969026 :       clone_parms = orig_clone_parms;
    5137     6969026 :       if (DECL_HAS_VTT_PARM_P (clone))
    5138        7324 :         clone_parms = TREE_CHAIN (clone_parms);
    5139             : 
    5140    13806602 :       for (decl_parms = orig_decl_parms; decl_parms;
    5141     6837576 :            decl_parms = TREE_CHAIN (decl_parms),
    5142     6837576 :              clone_parms = TREE_CHAIN (clone_parms))
    5143             :         {
    5144    13805032 :           if (clone_parms == void_list_node)
    5145             :             {
    5146     6967424 :               gcc_assert (decl_parms == clone_parms
    5147             :                           || ctor_omit_inherited_parms (clone));
    5148             :               break;
    5149             :             }
    5150             : 
    5151     6837608 :           gcc_checking_assert (same_type_p (TREE_VALUE (decl_parms),
    5152             :                                             TREE_VALUE (clone_parms)));
    5153             : 
    5154     7452304 :           if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms))
    5155             :             {
    5156             :               /* A default parameter has been added. Adjust the
    5157             :                  clone's parameters.  */
    5158          32 :               clone_parms = orig_decl_parms;
    5159             : 
    5160          32 :               if (DECL_HAS_VTT_PARM_P (clone))
    5161             :                 {
    5162           4 :                   clone_parms = tree_cons (TREE_PURPOSE (orig_clone_parms),
    5163           4 :                                            TREE_VALUE (orig_clone_parms),
    5164             :                                            clone_parms);
    5165           4 :                   TREE_TYPE (clone_parms) = TREE_TYPE (orig_clone_parms);
    5166             :                 }
    5167             : 
    5168          32 :               tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
    5169          32 :               tree type
    5170          32 :                 = build_method_type_directly (basetype,
    5171          32 :                                               TREE_TYPE (TREE_TYPE (clone)),
    5172             :                                               clone_parms);
    5173          32 :               if (tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (clone)))
    5174           0 :                 type = cp_build_type_attribute_variant (type, attrs);
    5175          32 :               type = cxx_copy_lang_qualifiers (type, TREE_TYPE (clone));
    5176          32 :               TREE_TYPE (clone) = type;
    5177             : 
    5178          32 :               clone_parms = NULL_TREE;
    5179          32 :               break;
    5180             :             }
    5181             :         }
    5182     6969026 :       gcc_assert (!clone_parms || clone_parms == void_list_node);
    5183             :     }
    5184    11911272 : }
    5185             : 
    5186             : /* For each of the constructors and destructors in T, create an
    5187             :    in-charge and not-in-charge variant.  */
    5188             : 
    5189             : static void
    5190    25156660 : clone_constructors_and_destructors (tree t)
    5191             : {
    5192             :   /* We do not need to propagate the usingness to the clone, at this
    5193             :      point that is not needed.  */
    5194    57319290 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5195    16081315 :     clone_cdtor (fn, /*update_methods=*/true);
    5196             : 
    5197    25156660 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    5198     2565682 :     clone_cdtor (dtor, /*update_methods=*/true);
    5199    25156660 : }
    5200             : 
    5201             : /* Deduce noexcept for a destructor DTOR.  */
    5202             : 
    5203             : void
    5204     2491313 : deduce_noexcept_on_destructor (tree dtor)
    5205             : {
    5206     2491313 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (dtor)))
    5207     1565820 :     TREE_TYPE (dtor) = build_exception_variant (TREE_TYPE (dtor),
    5208             :                                                 noexcept_deferred_spec);
    5209     2491313 : }
    5210             : 
    5211             : /* Subroutine of set_one_vmethod_tm_attributes.  Search base classes
    5212             :    of TYPE for virtual functions which FNDECL overrides.  Return a
    5213             :    mask of the tm attributes found therein.  */
    5214             : 
    5215             : static int
    5216         986 : look_for_tm_attr_overrides (tree type, tree fndecl)
    5217             : {
    5218         986 :   tree binfo = TYPE_BINFO (type);
    5219         986 :   tree base_binfo;
    5220         986 :   int ix, found = 0;
    5221             : 
    5222        1648 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ++ix)
    5223             :     {
    5224         662 :       tree o, basetype = BINFO_TYPE (base_binfo);
    5225             : 
    5226         662 :       if (!TYPE_POLYMORPHIC_P (basetype))
    5227          48 :         continue;
    5228             : 
    5229         614 :       o = look_for_overrides_here (basetype, fndecl);
    5230         614 :       if (o)
    5231             :         {
    5232         444 :           if (lookup_attribute ("transaction_safe_dynamic",
    5233         444 :                                 DECL_ATTRIBUTES (o)))
    5234             :             /* transaction_safe_dynamic is not inherited.  */;
    5235             :           else
    5236         341 :             found |= tm_attr_to_mask (find_tm_attribute
    5237         341 :                                       (TYPE_ATTRIBUTES (TREE_TYPE (o))));
    5238             :         }
    5239             :       else
    5240         170 :         found |= look_for_tm_attr_overrides (basetype, fndecl);
    5241             :     }
    5242             : 
    5243         986 :   return found;
    5244             : }
    5245             : 
    5246             : /* Subroutine of set_method_tm_attributes.  Handle the checks and
    5247             :    inheritance for one virtual method FNDECL.  */
    5248             : 
    5249             : static void
    5250         816 : set_one_vmethod_tm_attributes (tree type, tree fndecl)
    5251             : {
    5252         816 :   tree tm_attr;
    5253         816 :   int found, have;
    5254             : 
    5255         816 :   found = look_for_tm_attr_overrides (type, fndecl);
    5256             : 
    5257             :   /* If FNDECL doesn't actually override anything (i.e. T is the
    5258             :      class that first declares FNDECL virtual), then we're done.  */
    5259         816 :   if (found == 0)
    5260             :     return;
    5261             : 
    5262          59 :   tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (TREE_TYPE (fndecl)));
    5263          59 :   have = tm_attr_to_mask (tm_attr);
    5264             : 
    5265             :   /* Intel STM Language Extension 3.0, Section 4.2 table 4:
    5266             :      tm_pure must match exactly, otherwise no weakening of
    5267             :      tm_safe > tm_callable > nothing.  */
    5268             :   /* ??? The tm_pure attribute didn't make the transition to the
    5269             :      multivendor language spec.  */
    5270          59 :   if (have == TM_ATTR_PURE)
    5271             :     {
    5272           0 :       if (found != TM_ATTR_PURE)
    5273             :         {
    5274           0 :           found &= -found;
    5275           0 :           goto err_override;
    5276             :         }
    5277             :     }
    5278             :   /* If the overridden function is tm_pure, then FNDECL must be.  */
    5279          59 :   else if (found == TM_ATTR_PURE && tm_attr)
    5280           8 :     goto err_override;
    5281             :   /* Look for base class combinations that cannot be satisfied.  */
    5282          51 :   else if (found != TM_ATTR_PURE && (found & TM_ATTR_PURE))
    5283             :     {
    5284           0 :       found &= ~TM_ATTR_PURE;
    5285           0 :       found &= -found;
    5286           0 :       error_at (DECL_SOURCE_LOCATION (fndecl),
    5287             :                 "method overrides both %<transaction_pure%> and %qE methods",
    5288             :                 tm_mask_to_attr (found));
    5289             :     }
    5290             :   /* If FNDECL did not declare an attribute, then inherit the most
    5291             :      restrictive one.  */
    5292          51 :   else if (tm_attr == NULL)
    5293             :     {
    5294          18 :       apply_tm_attr (fndecl, tm_mask_to_attr (least_bit_hwi (found)));
    5295             :     }
    5296             :   /* Otherwise validate that we're not weaker than a function
    5297             :      that is being overridden.  */
    5298             :   else
    5299             :     {
    5300          33 :       found &= -found;
    5301          33 :       if (found <= TM_ATTR_CALLABLE && have > found)
    5302          12 :         goto err_override;
    5303             :     }
    5304             :   return;
    5305             : 
    5306          20 :  err_override:
    5307          20 :   error_at (DECL_SOURCE_LOCATION (fndecl),
    5308             :             "method declared %qE overriding %qE method",
    5309             :             tm_attr, tm_mask_to_attr (found));
    5310             : }
    5311             : 
    5312             : /* For each of the methods in T, propagate a class-level tm attribute.  */
    5313             : 
    5314             : static void
    5315    25156660 : set_method_tm_attributes (tree t)
    5316             : {
    5317    25156660 :   tree class_tm_attr, fndecl;
    5318             : 
    5319             :   /* Don't bother collecting tm attributes if transactional memory
    5320             :      support is not enabled.  */
    5321    25156660 :   if (!flag_tm)
    5322             :     return;
    5323             : 
    5324             :   /* Process virtual methods first, as they inherit directly from the
    5325             :      base virtual function and also require validation of new attributes.  */
    5326        4074 :   if (TYPE_CONTAINS_VPTR_P (t))
    5327             :     {
    5328         228 :       tree vchain;
    5329        1044 :       for (vchain = BINFO_VIRTUALS (TYPE_BINFO (t)); vchain;
    5330         816 :            vchain = TREE_CHAIN (vchain))
    5331             :         {
    5332         816 :           fndecl = BV_FN (vchain);
    5333         816 :           if (DECL_THUNK_P (fndecl))
    5334           4 :             fndecl = THUNK_TARGET (fndecl);
    5335         816 :           set_one_vmethod_tm_attributes (t, fndecl);
    5336             :         }
    5337             :     }
    5338             : 
    5339             :   /* If the class doesn't have an attribute, nothing more to do.  */
    5340        4074 :   class_tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (t));
    5341        4074 :   if (class_tm_attr == NULL)
    5342             :     return;
    5343             : 
    5344             :   /* Any method that does not yet have a tm attribute inherits
    5345             :      the one from the class.  */
    5346         142 :   for (fndecl = TYPE_FIELDS (t); fndecl; fndecl = DECL_CHAIN (fndecl))
    5347          58 :     if (DECL_DECLARES_FUNCTION_P (fndecl)
    5348         106 :         && !find_tm_attribute (TYPE_ATTRIBUTES (TREE_TYPE (fndecl))))
    5349          28 :       apply_tm_attr (fndecl, class_tm_attr);
    5350             : }
    5351             : 
    5352             : /* Returns true if FN is a default constructor.  */
    5353             : 
    5354             : bool
    5355     5815744 : default_ctor_p (const_tree fn)
    5356             : {
    5357     5815744 :   return (DECL_CONSTRUCTOR_P (fn)
    5358     5815744 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
    5359             : }
    5360             : 
    5361             : /* Returns true iff class T has a user-provided constructor that can be called
    5362             :    with more than zero arguments.  */
    5363             : 
    5364             : bool
    5365          63 : type_has_user_nondefault_constructor (tree t)
    5366             : {
    5367          63 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5368             :     return false;
    5369             : 
    5370         107 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5371             :     {
    5372          44 :       if (user_provided_p (fn)
    5373          44 :           && (TREE_CODE (fn) == TEMPLATE_DECL
    5374          23 :               || (skip_artificial_parms_for (fn, DECL_ARGUMENTS (fn))
    5375             :                   != NULL_TREE)))
    5376           4 :         return true;
    5377             :     }
    5378             : 
    5379          23 :   return false;
    5380             : }
    5381             : 
    5382             : /* Returns the defaulted constructor if T has one. Otherwise, returns
    5383             :    NULL_TREE.  */
    5384             : 
    5385             : tree
    5386          59 : in_class_defaulted_default_constructor (tree t)
    5387             : {
    5388          59 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5389             :     return NULL_TREE;
    5390             : 
    5391          81 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5392             :     {
    5393          52 :       tree fn = *iter;
    5394             : 
    5395         104 :       if (DECL_DEFAULTED_IN_CLASS_P (fn)
    5396          78 :           && default_ctor_p (fn))
    5397          23 :         return fn;
    5398             :     }
    5399             : 
    5400           0 :   return NULL_TREE;
    5401             : }
    5402             : 
    5403             : /* Returns true iff FN is a user-provided function, i.e. user-declared
    5404             :    and not defaulted at its first declaration.  */
    5405             : 
    5406             : bool
    5407    60288959 : user_provided_p (tree fn)
    5408             : {
    5409    60288959 :   fn = STRIP_TEMPLATE (fn);
    5410    60288959 :   return (!DECL_ARTIFICIAL (fn)
    5411    60288959 :           && !(DECL_INITIALIZED_IN_CLASS_P (fn)
    5412    49953679 :                && (DECL_DEFAULTED_FN (fn) || DECL_DELETED_FN (fn))));
    5413             : }
    5414             : 
    5415             : /* Returns true iff class T has a user-provided constructor.  */
    5416             : 
    5417             : bool
    5418    25156814 : type_has_user_provided_constructor (tree t)
    5419             : {
    5420    25156814 :   if (!CLASS_TYPE_P (t))
    5421             :     return false;
    5422             : 
    5423    25156754 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5424             :     return false;
    5425             : 
    5426     5697465 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5427     4549583 :     if (user_provided_p (*iter))
    5428     3670820 :       return true;
    5429             : 
    5430      269119 :   return false;
    5431             : }
    5432             : 
    5433             : /* Returns true iff class T has a user-provided or explicit constructor.  */
    5434             : 
    5435             : bool
    5436    32085561 : type_has_user_provided_or_explicit_constructor (tree t)
    5437             : {
    5438    32085561 :   if (!CLASS_TYPE_P (t))
    5439             :     return false;
    5440             : 
    5441    32085561 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5442             :     return false;
    5443             : 
    5444     7470941 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5445             :     {
    5446     5934123 :       tree fn = *iter;
    5447     5934123 :       if (user_provided_p (fn) || DECL_NONCONVERTING_P (fn))
    5448     4707281 :         return true;
    5449             :     }
    5450             : 
    5451      309976 :   return false;
    5452             : }
    5453             : 
    5454             : /* Returns true iff class T has a non-user-provided (i.e. implicitly
    5455             :    declared or explicitly defaulted in the class body) default
    5456             :    constructor.  */
    5457             : 
    5458             : bool
    5459     2116390 : type_has_non_user_provided_default_constructor (tree t)
    5460             : {
    5461     2116390 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t))
    5462             :     return false;
    5463     2116363 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5464             :     return true;
    5465             : 
    5466    15708822 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5467             :     {
    5468     7672627 :       tree fn = *iter;
    5469     7672627 :       if (TREE_CODE (fn) == FUNCTION_DECL
    5470     5314441 :           && default_ctor_p (fn)
    5471     9744271 :           && !user_provided_p (fn))
    5472      876053 :         return true;
    5473             :     }
    5474             : 
    5475     1239621 :   return false;
    5476             : }
    5477             : 
    5478             : /* TYPE is being used as a virtual base, and has a non-trivial move
    5479             :    assignment.  Return true if this is due to there being a user-provided
    5480             :    move assignment in TYPE or one of its subobjects; if there isn't, then
    5481             :    multiple move assignment can't cause any harm.  */
    5482             : 
    5483             : bool
    5484          21 : vbase_has_user_provided_move_assign (tree type)
    5485             : {
    5486             :   /* Does the type itself have a user-provided move assignment operator?  */
    5487          21 :   if (!CLASSTYPE_LAZY_MOVE_ASSIGN (type))
    5488          30 :     for (ovl_iterator iter (get_class_binding_direct
    5489          21 :                             (type, assign_op_identifier));
    5490          51 :          iter; ++iter)
    5491          42 :       if (user_provided_p (*iter) && move_fn_p (*iter))
    5492          12 :         return true;
    5493             : 
    5494             :   /* Do any of its bases?  */
    5495           9 :   tree binfo = TYPE_BINFO (type);
    5496           9 :   tree base_binfo;
    5497          12 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    5498           6 :     if (vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo)))
    5499             :       return true;
    5500             : 
    5501             :   /* Or non-static data members?  */
    5502          27 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    5503             :     {
    5504          21 :       if (TREE_CODE (field) == FIELD_DECL
    5505           3 :           && CLASS_TYPE_P (TREE_TYPE (field))
    5506          21 :           && vbase_has_user_provided_move_assign (TREE_TYPE (field)))
    5507             :         return true;
    5508             :     }
    5509             : 
    5510             :   /* Seems not.  */
    5511             :   return false;
    5512             : }
    5513             : 
    5514             : /* If default-initialization leaves part of TYPE uninitialized, returns
    5515             :    a DECL for the field or TYPE itself (DR 253).  */
    5516             : 
    5517             : tree
    5518      571286 : default_init_uninitialized_part (tree type)
    5519             : {
    5520      571286 :   tree t, r, binfo;
    5521      571286 :   int i;
    5522             : 
    5523      571286 :   type = strip_array_types (type);
    5524      571286 :   if (!CLASS_TYPE_P (type))
    5525             :     return type;
    5526      445821 :   if (!type_has_non_user_provided_default_constructor (type))
    5527             :     return NULL_TREE;
    5528      309862 :   for (binfo = TYPE_BINFO (type), i = 0;
    5529      309862 :        BINFO_BASE_ITERATE (binfo, i, t); ++i)
    5530             :     {
    5531        2268 :       r = default_init_uninitialized_part (BINFO_TYPE (t));
    5532        2268 :       if (r)
    5533           3 :         return r;
    5534             :     }
    5535      310584 :   for (t = next_aggregate_field (TYPE_FIELDS (type)); t;
    5536        2990 :        t = next_aggregate_field (DECL_CHAIN (t)))
    5537      104100 :     if (!DECL_INITIAL (t) && !DECL_ARTIFICIAL (t))
    5538             :       {
    5539      101179 :         r = default_init_uninitialized_part (TREE_TYPE (t));
    5540      101179 :         if (r)
    5541      202214 :           return DECL_P (r) ? r : t;
    5542             :       }
    5543             : 
    5544             :   return NULL_TREE;
    5545             : }
    5546             : 
    5547             : /* Returns true iff for class T, a trivial synthesized default constructor
    5548             :    would be constexpr.  */
    5549             : 
    5550             : bool
    5551    22578121 : trivial_default_constructor_is_constexpr (tree t)
    5552             : {
    5553             :   /* A defaulted trivial default constructor is constexpr
    5554             :      if there is nothing to initialize.  */
    5555    22578121 :   gcc_assert (!TYPE_HAS_COMPLEX_DFLT (t));
    5556             :   /* A class with a vptr doesn't have a trivial default ctor.
    5557             :      In C++20, a class can have transient uninitialized members, e.g.:
    5558             : 
    5559             :        struct S { int i; constexpr S() = default; };
    5560             : 
    5561             :      should work.  */
    5562    22578121 :   return (cxx_dialect >= cxx20
    5563    22578121 :           || is_really_empty_class (t, /*ignore_vptr*/true));
    5564             : }
    5565             : 
    5566             : /* Returns true iff class T has a constexpr default constructor.  */
    5567             : 
    5568             : bool
    5569    20983989 : type_has_constexpr_default_constructor (tree t)
    5570             : {
    5571    20983989 :   tree fns;
    5572             : 
    5573    20983989 :   if (!CLASS_TYPE_P (t))
    5574             :     {
    5575             :       /* The caller should have stripped an enclosing array.  */
    5576         201 :       gcc_assert (TREE_CODE (t) != ARRAY_TYPE);
    5577             :       return false;
    5578             :     }
    5579    20983788 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5580             :     {
    5581    20982189 :       if (!TYPE_HAS_COMPLEX_DFLT (t))
    5582    20982129 :         return trivial_default_constructor_is_constexpr (t);
    5583             :       /* Non-trivial, we need to check subobject constructors.  */
    5584          60 :       lazily_declare_fn (sfk_constructor, t);
    5585             :     }
    5586        1659 :   fns = locate_ctor (t);
    5587        1659 :   return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
    5588             : }
    5589             : 
    5590             : /* Returns true iff class T has a constexpr default constructor or has an
    5591             :    implicitly declared default constructor that we can't tell if it's constexpr
    5592             :    without forcing a lazy declaration (which might cause undesired
    5593             :    instantiations).  */
    5594             : 
    5595             : static bool
    5596    21150145 : type_maybe_constexpr_default_constructor (tree t)
    5597             : {
    5598    21150145 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DEFAULT_CTOR (t)
    5599    42300290 :       && TYPE_HAS_COMPLEX_DFLT (t))
    5600             :     /* Assume it's constexpr.  */
    5601             :     return true;
    5602    20982129 :   return type_has_constexpr_default_constructor (t);
    5603             : }
    5604             : 
    5605             : /* Returns true iff class T has a constexpr destructor.  */
    5606             : 
    5607             : bool
    5608         109 : type_has_constexpr_destructor (tree t)
    5609             : {
    5610         109 :   tree fns;
    5611             : 
    5612         109 :   if (CLASSTYPE_LAZY_DESTRUCTOR (t))
    5613             :     /* Non-trivial, we need to check subobject destructors.  */
    5614           4 :     lazily_declare_fn (sfk_destructor, t);
    5615         109 :   fns = CLASSTYPE_DESTRUCTOR (t);
    5616         109 :   return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
    5617             : }
    5618             : 
    5619             : /* Returns true iff class T has a constexpr destructor or has an
    5620             :    implicitly declared destructor that we can't tell if it's constexpr
    5621             :    without forcing a lazy declaration (which might cause undesired
    5622             :    instantiations).  */
    5623             : 
    5624             : static bool
    5625    23206842 : type_maybe_constexpr_destructor (tree t)
    5626             : {
    5627             :   /* Until C++20, only trivial destruction is constexpr.  */
    5628    23206842 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (t))
    5629             :     return true;
    5630      676823 :   if (cxx_dialect < cxx20)
    5631             :     return false;
    5632       48465 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DESTRUCTOR (t))
    5633             :     /* Assume it's constexpr.  */
    5634             :     return true;
    5635       43139 :   tree fn = CLASSTYPE_DESTRUCTOR (t);
    5636       43139 :   return (fn && maybe_constexpr_fn (fn));
    5637             : }
    5638             : 
    5639             : /* Returns true iff class TYPE has a virtual destructor.  */
    5640             : 
    5641             : bool
    5642     2193153 : type_has_virtual_destructor (tree type)
    5643             : {
    5644     2193153 :   tree dtor;
    5645             : 
    5646     2193153 :   if (!NON_UNION_CLASS_TYPE_P (type))
    5647             :     return false;
    5648             : 
    5649     2193006 :   gcc_assert (COMPLETE_TYPE_P (type));
    5650     2193006 :   dtor = CLASSTYPE_DESTRUCTOR (type);
    5651     2193006 :   return (dtor && DECL_VIRTUAL_P (dtor));
    5652             : }
    5653             : 
    5654             : /* Returns true iff T, a class, has a move-assignment or
    5655             :    move-constructor.  Does not lazily declare either.
    5656             :    If USER_P is false, any move function will do.  If it is true, the
    5657             :    move function must be user-declared.
    5658             : 
    5659             :    Note that user-declared here is different from "user-provided",
    5660             :    which doesn't include functions that are defaulted in the
    5661             :    class.  */
    5662             : 
    5663             : bool
    5664    25654520 : classtype_has_move_assign_or_move_ctor_p (tree t, bool user_p)
    5665             : {
    5666    25654520 :   gcc_assert (user_p
    5667             :               || (!CLASSTYPE_LAZY_MOVE_CTOR (t)
    5668             :                   && !CLASSTYPE_LAZY_MOVE_ASSIGN (t)));
    5669             : 
    5670    25654520 :   if (!CLASSTYPE_LAZY_MOVE_CTOR (t))
    5671    32952549 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5672     5353136 :       if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter))
    5673      620584 :         return true;
    5674             : 
    5675    25033936 :   if (!CLASSTYPE_LAZY_MOVE_ASSIGN (t))
    5676      725956 :     for (ovl_iterator iter (get_class_binding_direct
    5677    22996730 :                             (t, assign_op_identifier));
    5678    23722686 :          iter; ++iter)
    5679      702331 :       if ((!user_p || !DECL_ARTIFICIAL (*iter))
    5680      154704 :           && DECL_CONTEXT (*iter) == t
    5681      879631 :           && move_fn_p (*iter))
    5682        1401 :         return true;
    5683             :   
    5684             :   return false;
    5685             : }
    5686             : 
    5687             : /* True iff T has a move constructor that is not deleted.  */
    5688             : 
    5689             : bool
    5690           6 : classtype_has_non_deleted_move_ctor (tree t)
    5691             : {
    5692           6 :   if (CLASSTYPE_LAZY_MOVE_CTOR (t))
    5693           0 :     lazily_declare_fn (sfk_move_constructor, t);
    5694           6 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5695           6 :     if (move_fn_p (*iter) && !DECL_DELETED_FN (*iter))
    5696           6 :       return true;
    5697           0 :   return false;
    5698             : }
    5699             : 
    5700             : /* If T, a class, has a user-provided copy constructor, copy assignment
    5701             :    operator, or destructor, returns that function.  Otherwise, null.  */
    5702             : 
    5703             : tree
    5704     2828368 : classtype_has_depr_implicit_copy (tree t)
    5705             : {
    5706     2828368 :   if (!CLASSTYPE_LAZY_COPY_CTOR (t))
    5707     9576990 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5708             :       {
    5709     3696226 :         tree fn = *iter;
    5710     3696226 :         if (user_provided_p (fn) && copy_fn_p (fn))
    5711      132322 :           return fn;
    5712             :       }
    5713             : 
    5714     2696046 :   if (!CLASSTYPE_LAZY_COPY_ASSIGN (t))
    5715      637812 :     for (ovl_iterator iter (get_class_binding_direct
    5716      866777 :                             (t, assign_op_identifier));
    5717     1504589 :          iter; ++iter)
    5718             :       {
    5719      638207 :         tree fn = *iter;
    5720      638207 :         if (DECL_CONTEXT (fn) == t
    5721      638207 :             && user_provided_p (fn) && copy_fn_p (fn))
    5722         395 :           return fn;
    5723             :       }
    5724             : 
    5725     2695651 :   if (!CLASSTYPE_LAZY_DESTRUCTOR (t))
    5726             :     {
    5727      812782 :       tree fn = CLASSTYPE_DESTRUCTOR (t);
    5728      812782 :       if (user_provided_p (fn))
    5729             :         return fn;
    5730             :     }
    5731             : 
    5732             :   return NULL_TREE;
    5733             : }
    5734             : 
    5735             : /* True iff T has a member or friend declaration of operator OP.  */
    5736             : 
    5737             : bool
    5738    25156660 : classtype_has_op (tree t, tree_code op)
    5739             : {
    5740    25156660 :   tree name = ovl_op_identifier (op);
    5741    25156660 :   if (get_class_binding (t, name))
    5742             :     return true;
    5743    26060534 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    5744     1430957 :     if (FRIEND_NAME (f) == name)
    5745             :       return true;
    5746             :   return false;
    5747             : }
    5748             : 
    5749             : 
    5750             : /* If T has a defaulted member or friend declaration of OP, return it.  */
    5751             : 
    5752             : tree
    5753    24629577 : classtype_has_defaulted_op (tree t, tree_code op)
    5754             : {
    5755    24629577 :   tree name = ovl_op_identifier (op);
    5756    24629603 :   for (ovl_iterator oi (get_class_binding (t, name)); oi; ++oi)
    5757             :     {
    5758          61 :       tree fn = *oi;
    5759          61 :       if (DECL_DEFAULTED_FN (fn))
    5760          48 :         return fn;
    5761             :     }
    5762    24981277 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    5763      351755 :     if (FRIEND_NAME (f) == name)
    5764          78 :       for (tree l = FRIEND_DECLS (f); l; l = TREE_CHAIN (l))
    5765             :         {
    5766          45 :           tree fn = TREE_VALUE (l);
    5767          45 :           if (DECL_DEFAULTED_FN (fn))
    5768           7 :             return fn;
    5769             :         }
    5770             :   return NULL_TREE;
    5771             : }
    5772             : 
    5773             : /* Nonzero if we need to build up a constructor call when initializing an
    5774             :    object of this class, either because it has a user-declared constructor
    5775             :    or because it doesn't have a default constructor (so we need to give an
    5776             :    error if no initializer is provided).  Use TYPE_NEEDS_CONSTRUCTING when
    5777             :    what you care about is whether or not an object can be produced by a
    5778             :    constructor (e.g. so we don't set TREE_READONLY on const variables of
    5779             :    such type); use this function when what you care about is whether or not
    5780             :    to try to call a constructor to create an object.  The latter case is
    5781             :    the former plus some cases of constructors that cannot be called.  */
    5782             : 
    5783             : bool
    5784    27944759 : type_build_ctor_call (tree t)
    5785             : {
    5786    27944759 :   tree inner;
    5787    27944759 :   if (TYPE_NEEDS_CONSTRUCTING (t))
    5788             :     return true;
    5789    25183302 :   inner = strip_array_types (t);
    5790    25183302 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner))
    5791             :     return false;
    5792     1916703 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (inner))
    5793             :     return true;
    5794     1674739 :   if (cxx_dialect < cxx11)
    5795             :     return false;
    5796             :   /* A user-declared constructor might be private, and a constructor might
    5797             :      be trivial but deleted.  */
    5798     6528823 :   for (ovl_iterator iter (get_class_binding (inner, complete_ctor_identifier));
    5799     6528823 :        iter; ++iter)
    5800             :     {
    5801     4994022 :       tree fn = *iter;
    5802     4994022 :       if (!DECL_ARTIFICIAL (fn)
    5803             :           || TREE_DEPRECATED (fn)
    5804     4888148 :           || TREE_UNAVAILABLE (fn)
    5805     9879669 :           || DECL_DELETED_FN (fn))
    5806      131987 :         return true;
    5807             :     }
    5808     1534801 :   return false;
    5809             : }
    5810             : 
    5811             : /* Like type_build_ctor_call, but for destructors.  */
    5812             : 
    5813             : bool
    5814    52991658 : type_build_dtor_call (tree t)
    5815             : {
    5816    52991658 :   tree inner;
    5817    52991658 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    5818             :     return true;
    5819    36761200 :   inner = strip_array_types (t);
    5820    13113073 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner)
    5821    49797435 :       || !COMPLETE_TYPE_P (inner))
    5822             :     return false;
    5823    13036211 :   if (cxx_dialect < cxx11)
    5824             :     return false;
    5825             :   /* A user-declared destructor might be private, and a destructor might
    5826             :      be trivial but deleted.  */
    5827    22854779 :   for (ovl_iterator iter (get_class_binding (inner, complete_dtor_identifier));
    5828    22854779 :        iter; ++iter)
    5829             :     {
    5830    12767510 :       tree fn = *iter;
    5831    12767510 :       if (!DECL_ARTIFICIAL (fn)
    5832             :           || TREE_DEPRECATED (fn)
    5833     9847936 :           || TREE_UNAVAILABLE (fn)
    5834    22615446 :           || DECL_DELETED_FN (fn))
    5835     2919574 :         return true;
    5836             :     }
    5837    10087269 :   return false;
    5838             : }
    5839             : 
    5840             : /* Returns TRUE iff we need a cookie when dynamically allocating an
    5841             :    array whose elements have the indicated class TYPE.  */
    5842             : 
    5843             : static bool
    5844    25156660 : type_requires_array_cookie (tree type)
    5845             : {
    5846    25156660 :   tree fns;
    5847    25156660 :   bool has_two_argument_delete_p = false;
    5848             : 
    5849    25156660 :   gcc_assert (CLASS_TYPE_P (type));
    5850             : 
    5851             :   /* If there's a non-trivial destructor, we need a cookie.  In order
    5852             :      to iterate through the array calling the destructor for each
    5853             :      element, we'll have to know how many elements there are.  */
    5854    25156660 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    5855             :     return true;
    5856             : 
    5857             :   /* If the usual deallocation function is a two-argument whose second
    5858             :      argument is of type `size_t', then we have to pass the size of
    5859             :      the array to the deallocation function, so we will need to store
    5860             :      a cookie.  */
    5861    22761532 :   fns = lookup_fnfields (TYPE_BINFO (type),
    5862             :                          ovl_op_identifier (false, VEC_DELETE_EXPR),
    5863             :                          /*protect=*/0, tf_warning_or_error);
    5864             :   /* If there are no `operator []' members, or the lookup is
    5865             :      ambiguous, then we don't need a cookie.  */
    5866    22761532 :   if (!fns || fns == error_mark_node)
    5867             :     return false;
    5868             :   /* Loop through all of the functions.  */
    5869         430 :   for (lkp_iterator iter (BASELINK_FUNCTIONS (fns)); iter; ++iter)
    5870             :     {
    5871         279 :       tree fn = *iter;
    5872             : 
    5873             :       /* See if this function is a one-argument delete function.  If
    5874             :          it is, then it will be the usual deallocation function.  */
    5875         279 :       tree second_parm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)));
    5876         279 :       if (second_parm == void_list_node)
    5877         119 :         return false;
    5878             :       /* Do not consider this function if its second argument is an
    5879             :          ellipsis.  */
    5880         160 :       if (!second_parm)
    5881           4 :         continue;
    5882             :       /* Otherwise, if we have a two-argument function and the second
    5883             :          argument is `size_t', it will be the usual deallocation
    5884             :          function -- unless there is one-argument function, too.  */
    5885         156 :       if (TREE_CHAIN (second_parm) == void_list_node
    5886         156 :           && same_type_p (TREE_VALUE (second_parm), size_type_node))
    5887             :         has_two_argument_delete_p = true;
    5888             :     }
    5889             : 
    5890          16 :   return has_two_argument_delete_p;
    5891             : }
    5892             : 
    5893             : /* Finish computing the `literal type' property of class type T.
    5894             : 
    5895             :    At this point, we have already processed base classes and
    5896             :    non-static data members.  We need to check whether the copy
    5897             :    constructor is trivial, the destructor is trivial, and there
    5898             :    is a trivial default constructor or at least one constexpr
    5899             :    constructor other than the copy constructor.  */
    5900             : 
    5901             : static void
    5902    25156660 : finalize_literal_type_property (tree t)
    5903             : {
    5904    25156660 :   tree fn;
    5905             : 
    5906    25156660 :   if (cxx_dialect < cxx11)
    5907       87194 :     CLASSTYPE_LITERAL_P (t) = false;
    5908    25069466 :   else if (CLASSTYPE_LITERAL_P (t)
    5909    25069466 :            && !type_maybe_constexpr_destructor (t))
    5910      655901 :     CLASSTYPE_LITERAL_P (t) = false;
    5911    46671501 :   else if (CLASSTYPE_LITERAL_P (t) && LAMBDA_TYPE_P (t))
    5912       42849 :     CLASSTYPE_LITERAL_P (t) = (cxx_dialect >= cxx17);
    5913    46878801 :   else if (CLASSTYPE_LITERAL_P (t) && !TYPE_HAS_TRIVIAL_DFLT (t)
    5914     1074557 :            && CLASSTYPE_NON_AGGREGATE (t)
    5915    25423415 :            && !TYPE_HAS_CONSTEXPR_CTOR (t))
    5916      406773 :     CLASSTYPE_LITERAL_P (t) = false;
    5917             : 
    5918             :   /* C++14 DR 1684 removed this restriction.  */
    5919    25156660 :   if (cxx_dialect < cxx14
    5920    25255673 :       && !CLASSTYPE_LITERAL_P (t) && !LAMBDA_TYPE_P (t))
    5921     1065960 :     for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    5922      961077 :       if (TREE_CODE (fn) == FUNCTION_DECL
    5923      472526 :           && DECL_DECLARED_CONSTEXPR_P (fn)
    5924        2451 :           && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
    5925      963183 :           && !DECL_CONSTRUCTOR_P (fn))
    5926             :         {
    5927         566 :           DECL_DECLARED_CONSTEXPR_P (fn) = false;
    5928         566 :           if (!DECL_GENERATED_P (fn))
    5929             :             {
    5930           0 :               auto_diagnostic_group d;
    5931           0 :               if (pedwarn (DECL_SOURCE_LOCATION (fn), OPT_Wpedantic,
    5932             :                              "enclosing class of %<constexpr%> non-static "
    5933             :                              "member function %q+#D is not a literal type", fn))
    5934           0 :                 explain_non_literal_class (t);
    5935           0 :             }
    5936             :         }
    5937    25156660 : }
    5938             : 
    5939             : /* T is a non-literal type used in a context which requires a constant
    5940             :    expression.  Explain why it isn't literal.  */
    5941             : 
    5942             : void
    5943         115 : explain_non_literal_class (tree t)
    5944             : {
    5945         115 :   static hash_set<tree> *diagnosed;
    5946             : 
    5947         115 :   if (!CLASS_TYPE_P (t))
    5948          44 :     return;
    5949         115 :   t = TYPE_MAIN_VARIANT (t);
    5950             : 
    5951         115 :   if (diagnosed == NULL)
    5952          59 :     diagnosed = new hash_set<tree>;
    5953         115 :   if (diagnosed->add (t))
    5954             :     /* Already explained.  */
    5955             :     return;
    5956             : 
    5957          86 :   auto_diagnostic_group d;
    5958          86 :   inform (UNKNOWN_LOCATION, "%q+T is not literal because:", t);
    5959         112 :   if (cxx_dialect < cxx17 && LAMBDA_TYPE_P (t))
    5960           1 :     inform (UNKNOWN_LOCATION,
    5961             :             "  %qT is a closure type, which is only literal in "
    5962             :             "C++17 and later", t);
    5963          85 :   else if (cxx_dialect < cxx20 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    5964           8 :     inform (UNKNOWN_LOCATION, "  %q+T has a non-trivial destructor", t);
    5965          77 :   else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    5966          77 :            && !type_maybe_constexpr_destructor (t))
    5967           7 :     inform (UNKNOWN_LOCATION, "  %q+T does not have %<constexpr%> destructor",
    5968             :             t);
    5969          70 :   else if (CLASSTYPE_NON_AGGREGATE (t)
    5970          60 :            && !TYPE_HAS_TRIVIAL_DFLT (t)
    5971         117 :            && !LAMBDA_TYPE_P (t)
    5972         130 :            && !TYPE_HAS_CONSTEXPR_CTOR (t))
    5973             :     {
    5974          37 :       inform (UNKNOWN_LOCATION,
    5975             :               "  %q+T is not an aggregate, does not have a trivial "
    5976             :               "default constructor, and has no %<constexpr%> constructor that "
    5977             :               "is not a copy or move constructor", t);
    5978          37 :       if (type_has_non_user_provided_default_constructor (t))
    5979             :         /* Note that we can't simply call locate_ctor because when the
    5980             :            constructor is deleted it just returns NULL_TREE.  */
    5981           0 :         for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5982             :           {
    5983           0 :             tree fn = *iter;
    5984           0 :             tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
    5985             : 
    5986           0 :             parms = skip_artificial_parms_for (fn, parms);
    5987             : 
    5988           0 :             if (sufficient_parms_p (parms))
    5989             :               {
    5990           0 :                 if (DECL_DELETED_FN (fn))
    5991           0 :                   maybe_explain_implicit_delete (fn);
    5992             :                 else
    5993           0 :                   explain_invalid_constexpr_fn (fn);
    5994             :                 break;
    5995             :               }
    5996             :         }
    5997             :     }
    5998             :   else
    5999             :     {
    6000          33 :       tree binfo, base_binfo, field; int i;
    6001          33 :       for (binfo = TYPE_BINFO (t), i = 0;
    6002          33 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    6003             :         {
    6004          15 :           tree basetype = TREE_TYPE (base_binfo);
    6005          15 :           if (!CLASSTYPE_LITERAL_P (basetype))
    6006             :             {
    6007          15 :               inform (UNKNOWN_LOCATION,
    6008             :                       "  base class %qT of %q+T is non-literal",
    6009             :                       basetype, t);
    6010          15 :               explain_non_literal_class (basetype);
    6011          15 :               return;
    6012             :             }
    6013             :         }
    6014         138 :       for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
    6015             :         {
    6016         120 :           tree ftype;
    6017         120 :           if (TREE_CODE (field) != FIELD_DECL)
    6018         102 :             continue;
    6019          18 :           ftype = TREE_TYPE (field);
    6020          18 :           if (!literal_type_p (ftype))
    6021             :             {
    6022           6 :               inform (DECL_SOURCE_LOCATION (field),
    6023             :                       "  non-static data member %qD has non-literal type",
    6024             :                       field);
    6025           6 :               if (CLASS_TYPE_P (ftype))
    6026           6 :                 explain_non_literal_class (ftype);
    6027             :             }
    6028          18 :           if (CP_TYPE_VOLATILE_P (ftype))
    6029          12 :             inform (DECL_SOURCE_LOCATION (field),
    6030             :                     "  non-static data member %qD has volatile type", field);
    6031             :         }
    6032             :     }
    6033          86 : }
    6034             : 
    6035             : /* Check the validity of the bases and members declared in T.  Add any
    6036             :    implicitly-generated functions (like copy-constructors and
    6037             :    assignment operators).  Compute various flag bits (like
    6038             :    CLASSTYPE_NON_LAYOUT_POD_T) for T.  This routine works purely at the C++
    6039             :    level: i.e., independently of the ABI in use.  */
    6040             : 
    6041             : static void
    6042    25156660 : check_bases_and_members (tree t)
    6043             : {
    6044             :   /* Nonzero if the implicitly generated copy constructor should take
    6045             :      a non-const reference argument.  */
    6046    25156660 :   int cant_have_const_ctor;
    6047             :   /* Nonzero if the implicitly generated assignment operator
    6048             :      should take a non-const reference argument.  */
    6049    25156660 :   int no_const_asn_ref;
    6050    25156660 :   tree access_decls;
    6051    25156660 :   bool saved_complex_asn_ref;
    6052    25156660 :   bool saved_nontrivial_dtor;
    6053    25156660 :   tree fn;
    6054             : 
    6055             :   /* By default, we use const reference arguments and generate default
    6056             :      constructors.  */
    6057    25156660 :   cant_have_const_ctor = 0;
    6058    25156660 :   no_const_asn_ref = 0;
    6059             : 
    6060             :   /* Check all the base-classes and set FMEM members to point to arrays
    6061             :      of potential interest.  */
    6062    25156660 :   check_bases (t, &cant_have_const_ctor, &no_const_asn_ref);
    6063             : 
    6064             :   /* Deduce noexcept on destructor.  This needs to happen after we've set
    6065             :      triviality flags appropriately for our bases, and before checking
    6066             :      overriden virtual functions via check_methods.  */
    6067    25156660 :   if (cxx_dialect >= cxx11)
    6068    25069466 :     if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    6069     7291945 :       for (tree fn : ovl_range (dtor))
    6070     2430649 :         deduce_noexcept_on_destructor (fn);
    6071             : 
    6072             :   /* Check all the method declarations.  */
    6073    25156660 :   check_methods (t);
    6074             : 
    6075             :   /* Save the initial values of these flags which only indicate whether
    6076             :      or not the class has user-provided functions.  As we analyze the
    6077             :      bases and members we can set these flags for other reasons.  */
    6078    25156660 :   saved_complex_asn_ref = TYPE_HAS_COMPLEX_COPY_ASSIGN (t);
    6079    25156660 :   saved_nontrivial_dtor = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
    6080             : 
    6081             :   /* Check all the data member declarations.  We cannot call
    6082             :      check_field_decls until we have called check_bases check_methods,
    6083             :      as check_field_decls depends on TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    6084             :      being set appropriately.  */
    6085    25156660 :   check_field_decls (t, &access_decls,
    6086             :                      &cant_have_const_ctor,
    6087             :                      &no_const_asn_ref);
    6088             : 
    6089             :   /* A nearly-empty class has to be vptr-containing; a nearly empty
    6090             :      class contains just a vptr.  */
    6091    25156660 :   if (!TYPE_CONTAINS_VPTR_P (t))
    6092    24011894 :     CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    6093             : 
    6094             :   /* Do some bookkeeping that will guide the generation of implicitly
    6095             :      declared member functions.  */
    6096    26301426 :   TYPE_HAS_COMPLEX_COPY_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
    6097    26301426 :   TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
    6098             :   /* We need to call a constructor for this class if it has a
    6099             :      user-provided constructor, or if the default constructor is going
    6100             :      to initialize the vptr.  (This is not an if-and-only-if;
    6101             :      TYPE_NEEDS_CONSTRUCTING is set elsewhere if bases or members
    6102             :      themselves need constructing.)  */
    6103    25156660 :   TYPE_NEEDS_CONSTRUCTING (t)
    6104    25156660 :     |= (type_has_user_provided_constructor (t) || TYPE_CONTAINS_VPTR_P (t));
    6105             :   /* [dcl.init.aggr]
    6106             : 
    6107             :      An aggregate is an array or a class with no user-provided
    6108             :      constructors ... and no virtual functions.  
    6109             : 
    6110             :      Again, other conditions for being an aggregate are checked
    6111             :      elsewhere.  */
    6112    25156660 :   CLASSTYPE_NON_AGGREGATE (t)
    6113    50313320 :     |= ((cxx_dialect < cxx20
    6114    25156660 :          ? type_has_user_provided_or_explicit_constructor (t)
    6115     1835720 :          : TYPE_HAS_USER_CONSTRUCTOR (t))
    6116    25156660 :         || TYPE_POLYMORPHIC_P (t));
    6117             :   /* This is the C++98/03 definition of POD; it changed in C++0x, but we
    6118             :      retain the old definition internally for ABI reasons.  */
    6119    25156660 :   CLASSTYPE_NON_LAYOUT_POD_P (t)
    6120    25156660 :     |= (CLASSTYPE_NON_AGGREGATE (t)
    6121    25156660 :         || saved_nontrivial_dtor || saved_complex_asn_ref);
    6122    26301426 :   CLASSTYPE_NON_STD_LAYOUT (t) |= TYPE_CONTAINS_VPTR_P (t);
    6123    26301426 :   TYPE_HAS_COMPLEX_COPY_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    6124    26301426 :   TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    6125    26301426 :   TYPE_HAS_COMPLEX_DFLT (t) |= TYPE_CONTAINS_VPTR_P (t);
    6126             : 
    6127             :   /* Is this class non-layout-POD because it wasn't an aggregate in C++98?  */
    6128    25156660 :   if (CLASSTYPE_NON_POD_AGGREGATE (t))
    6129             :     {
    6130      192853 :       if (CLASSTYPE_NON_LAYOUT_POD_P (t))
    6131             :         /* It's non-POD for another reason.  */
    6132      183060 :         CLASSTYPE_NON_POD_AGGREGATE (t) = false;
    6133        9793 :       else if (abi_version_at_least (17))
    6134        9790 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = true;
    6135             :     }
    6136             : 
    6137             :   /* If the only explicitly declared default constructor is user-provided,
    6138             :      set TYPE_HAS_COMPLEX_DFLT.  */
    6139    25156660 :   if (!TYPE_HAS_COMPLEX_DFLT (t)
    6140    22801104 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (t)
    6141    26637694 :       && !type_has_non_user_provided_default_constructor (t))
    6142      977684 :     TYPE_HAS_COMPLEX_DFLT (t) = true;
    6143             : 
    6144             :   /* Warn if a public base of a polymorphic type has an accessible
    6145             :      non-virtual destructor.  It is only now that we know the class is
    6146             :      polymorphic.  Although a polymorphic base will have a already
    6147             :      been diagnosed during its definition, we warn on use too.  */
    6148    25156660 :   if (TYPE_POLYMORPHIC_P (t) && warn_nonvdtor)
    6149             :     {
    6150         110 :       tree binfo = TYPE_BINFO (t);
    6151         110 :       vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
    6152         110 :       tree base_binfo;
    6153         110 :       unsigned i;
    6154             :       
    6155         149 :       for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    6156             :         {
    6157          39 :           tree basetype = TREE_TYPE (base_binfo);
    6158             : 
    6159          39 :           if ((*accesses)[i] == access_public_node
    6160          23 :               && (TYPE_POLYMORPHIC_P (basetype) || warn_ecpp)
    6161          58 :               && accessible_nvdtor_p (basetype))
    6162          12 :             warning (OPT_Wnon_virtual_dtor,
    6163             :                      "base class %q#T has accessible non-virtual destructor",
    6164             :                      basetype);
    6165             :         }
    6166             :     }
    6167             :   
    6168             :   /* If the class has no user-declared constructor, but does have
    6169             :      non-static const or reference data members that can never be
    6170             :      initialized, issue a warning.  */
    6171    25156660 :   if (warn_uninitialized
    6172             :       /* Classes with user-declared constructors are presumed to
    6173             :          initialize these members.  */
    6174      295225 :       && !TYPE_HAS_USER_CONSTRUCTOR (t)
    6175             :       /* Aggregates can be initialized with brace-enclosed
    6176             :          initializers.  */
    6177    25397364 :       && CLASSTYPE_NON_AGGREGATE (t))
    6178             :     {
    6179       36566 :       tree field;
    6180             : 
    6181      228851 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6182             :         {
    6183      192285 :           tree type;
    6184             : 
    6185      362922 :           if (TREE_CODE (field) != FIELD_DECL
    6186      192285 :               || DECL_INITIAL (field) != NULL_TREE)
    6187      170637 :             continue;
    6188             : 
    6189       21648 :           type = TREE_TYPE (field);
    6190       21648 :           if (TYPE_REF_P (type))
    6191           7 :             warning_at (DECL_SOURCE_LOCATION (field),
    6192             :                         OPT_Wuninitialized, "non-static reference %q#D "
    6193             :                         "in class without a constructor", field);
    6194       21641 :           else if (CP_TYPE_CONST_P (type)
    6195       21641 :                    && (!CLASS_TYPE_P (type)
    6196           4 :                        || !TYPE_HAS_DEFAULT_CONSTRUCTOR (type)))
    6197          11 :             warning_at (DECL_SOURCE_LOCATION (field),
    6198             :                         OPT_Wuninitialized, "non-static const member %q#D "
    6199             :                         "in class without a constructor", field);
    6200             :         }
    6201             :     }
    6202             : 
    6203             :   /* Synthesize any needed methods.  */
    6204    25156660 :   add_implicitly_declared_members (t, &access_decls,
    6205             :                                    cant_have_const_ctor,
    6206             :                                    no_const_asn_ref);
    6207             : 
    6208             :   /* Check defaulted declarations here so we have cant_have_const_ctor
    6209             :      and don't need to worry about clones.  */
    6210   173877595 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6211    86023479 :     if (DECL_DECLARES_FUNCTION_P (fn)
    6212    76221396 :         && !DECL_ARTIFICIAL (fn)
    6213   224422866 :         && DECL_DEFAULTED_IN_CLASS_P (fn))
    6214             :       {
    6215             :         /* ...except handle comparisons later, in finish_struct_1.  */
    6216     3387722 :         if (special_function_p (fn) == sfk_comparison)
    6217        3241 :           continue;
    6218             : 
    6219     3384481 :         int copy = copy_fn_p (fn);
    6220     3384481 :         if (copy > 0)
    6221             :           {
    6222     1254700 :             bool imp_const_p
    6223     2509400 :               = (DECL_CONSTRUCTOR_P (fn) ? !cant_have_const_ctor
    6224      578243 :                  : !no_const_asn_ref);
    6225     1254700 :             bool fn_const_p = (copy == 2);
    6226             : 
    6227     1254700 :             if (fn_const_p && !imp_const_p)
    6228             :               /* If the function is defaulted outside the class, we just
    6229             :                  give the synthesis error.  Core Issue #1331 says this is
    6230             :                  no longer ill-formed, it is defined as deleted instead.  */
    6231          18 :               DECL_DELETED_FN (fn) = true;
    6232             :           }
    6233     3384481 :         defaulted_late_check (fn);
    6234             :       }
    6235             : 
    6236    50012371 :   if (LAMBDA_TYPE_P (t))
    6237             :     /* "This class type is not an aggregate."  */
    6238       43012 :     CLASSTYPE_NON_AGGREGATE (t) = 1;
    6239             : 
    6240             :   /* Compute the 'literal type' property before we
    6241             :      do anything with non-static member functions.  */
    6242    25156660 :   finalize_literal_type_property (t);
    6243             : 
    6244             :   /* Create the in-charge and not-in-charge variants of constructors
    6245             :      and destructors.  */
    6246    25156660 :   clone_constructors_and_destructors (t);
    6247             : 
    6248             :   /* Process the using-declarations.  */
    6249    51377288 :   for (; access_decls; access_decls = TREE_CHAIN (access_decls))
    6250     1063968 :     handle_using_decl (TREE_VALUE (access_decls), t);
    6251             : 
    6252             :   /* Figure out whether or not we will need a cookie when dynamically
    6253             :      allocating an array of this type.  */
    6254    25156660 :   LANG_TYPE_CLASS_CHECK (t)->vec_new_uses_cookie
    6255    25156660 :     = type_requires_array_cookie (t);
    6256    25156660 : }
    6257             : 
    6258             : /* If T needs a pointer to its virtual function table, set TYPE_VFIELD
    6259             :    accordingly.  If a new vfield was created (because T doesn't have a
    6260             :    primary base class), then the newly created field is returned.  It
    6261             :    is not added to the TYPE_FIELDS list; it is the caller's
    6262             :    responsibility to do that.  Accumulate declared virtual functions
    6263             :    on VIRTUALS_P.  */
    6264             : 
    6265             : static tree
    6266    25156660 : create_vtable_ptr (tree t, tree* virtuals_p)
    6267             : {
    6268    25156660 :   tree fn;
    6269             : 
    6270             :   /* Collect the virtual functions declared in T.  */
    6271   211627367 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6272   186470707 :     if (TREE_CODE (fn) == FUNCTION_DECL
    6273    90917054 :         && DECL_VINDEX (fn) && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)
    6274   191783230 :         && TREE_CODE (DECL_VINDEX (fn)) != INTEGER_CST)
    6275             :       {
    6276     5312523 :         tree new_virtual = make_node (TREE_LIST);
    6277             : 
    6278     5312523 :         BV_FN (new_virtual) = fn;
    6279     5312523 :         BV_DELTA (new_virtual) = integer_zero_node;
    6280     5312523 :         BV_VCALL_INDEX (new_virtual) = NULL_TREE;
    6281             : 
    6282     5312523 :         TREE_CHAIN (new_virtual) = *virtuals_p;
    6283     5312523 :         *virtuals_p = new_virtual;
    6284             :       }
    6285             : 
    6286             :   /* If we couldn't find an appropriate base class, create a new field
    6287             :      here.  Even if there weren't any new virtual functions, we might need a
    6288             :      new virtual function table if we're supposed to include vptrs in
    6289             :      all classes that need them.  */
    6290    25156660 :   if (!TYPE_VFIELD (t) && (*virtuals_p || TYPE_CONTAINS_VPTR_P (t)))
    6291             :     {
    6292             :       /* We build this decl with vtbl_ptr_type_node, which is a
    6293             :          `vtable_entry_type*'.  It might seem more precise to use
    6294             :          `vtable_entry_type (*)[N]' where N is the number of virtual
    6295             :          functions.  However, that would require the vtable pointer in
    6296             :          base classes to have a different type than the vtable pointer
    6297             :          in derived classes.  We could make that happen, but that
    6298             :          still wouldn't solve all the problems.  In particular, the
    6299             :          type-based alias analysis code would decide that assignments
    6300             :          to the base class vtable pointer can't alias assignments to
    6301             :          the derived class vtable pointer, since they have different
    6302             :          types.  Thus, in a derived class destructor, where the base
    6303             :          class constructor was inlined, we could generate bad code for
    6304             :          setting up the vtable pointer.
    6305             : 
    6306             :          Therefore, we use one type for all vtable pointers.  We still
    6307             :          use a type-correct type; it's just doesn't indicate the array
    6308             :          bounds.  That's better than using `void*' or some such; it's
    6309             :          cleaner, and it let's the alias analysis code know that these
    6310             :          stores cannot alias stores to void*!  */
    6311      173804 :       tree field;
    6312             : 
    6313      173804 :       field = build_decl (input_location, 
    6314             :                           FIELD_DECL, get_vfield_name (t), vtbl_ptr_type_node);
    6315      173804 :       DECL_VIRTUAL_P (field) = 1;
    6316      173804 :       DECL_ARTIFICIAL (field) = 1;
    6317      173804 :       DECL_FIELD_CONTEXT (field) = t;
    6318      173804 :       DECL_FCONTEXT (field) = t;
    6319      173804 :       if (TYPE_PACKED (t))
    6320           4 :         DECL_PACKED (field) = 1;
    6321             : 
    6322      173804 :       TYPE_VFIELD (t) = field;
    6323             : 
    6324             :       /* This class is non-empty.  */
    6325      173804 :       CLASSTYPE_EMPTY_P (t) = 0;
    6326             : 
    6327      173804 :       return field;
    6328             :     }
    6329             : 
    6330             :   return NULL_TREE;
    6331             : }
    6332             : 
    6333             : /* Add OFFSET to all base types of BINFO which is a base in the
    6334             :    hierarchy dominated by T.
    6335             : 
    6336             :    OFFSET, which is a type offset, is number of bytes.  */
    6337             : 
    6338             : static void
    6339    17173648 : propagate_binfo_offsets (tree binfo, tree offset)
    6340             : {
    6341    17173648 :   int i;
    6342    17173648 :   tree primary_binfo;
    6343    17173648 :   tree base_binfo;
    6344             : 
    6345             :   /* Update BINFO's offset.  */
    6346    17173648 :   BINFO_OFFSET (binfo)
    6347    17173648 :     = fold_convert (sizetype,
    6348             :                size_binop (PLUS_EXPR,
    6349             :                            fold_convert (ssizetype, BINFO_OFFSET (binfo)),
    6350             :                            offset));
    6351             : 
    6352             :   /* Find the primary base class.  */
    6353    17173648 :   primary_binfo = get_primary_binfo (binfo);
    6354             : 
    6355    17902434 :   if (primary_binfo && BINFO_INHERITANCE_CHAIN (primary_binfo) == binfo)
    6356      727571 :     propagate_binfo_offsets (primary_binfo, offset);
    6357             : 
    6358             :   /* Scan all of the bases, pushing the BINFO_OFFSET adjust
    6359             :      downwards.  */
    6360    20052280 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6361             :     {
    6362             :       /* Don't do the primary base twice.  */
    6363     3607324 :       if (base_binfo == primary_binfo)
    6364      728692 :         continue;
    6365             : 
    6366     2149940 :       if (BINFO_VIRTUAL_P (base_binfo))
    6367      168011 :         continue;
    6368             : 
    6369     1981929 :       propagate_binfo_offsets (base_binfo, offset);
    6370             :     }
    6371    17173648 : }
    6372             : 
    6373             : /* Set BINFO_OFFSET for all of the virtual bases for RLI->T.  Update
    6374             :    TYPE_ALIGN and TYPE_SIZE for T.  OFFSETS gives the location of
    6375             :    empty subobjects of T.  */
    6376             : 
    6377             : static void
    6378    25156660 : layout_virtual_bases (record_layout_info rli, splay_tree offsets)
    6379             : {
    6380    25156660 :   tree vbase;
    6381    25156660 :   tree t = rli->t;
    6382    25156660 :   tree *next_field;
    6383             : 
    6384    25156660 :   if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) == 0)
    6385             :     return;
    6386             : 
    6387             :   /* Find the last field.  The artificial fields created for virtual
    6388             :      bases will go after the last extant field to date.  */
    6389    13903101 :   next_field = &TYPE_FIELDS (t);
    6390   107990336 :   while (*next_field)
    6391    94087235 :     next_field = &DECL_CHAIN (*next_field);
    6392             : 
    6393             :   /* Go through the virtual bases, allocating space for each virtual
    6394             :      base that is not already a primary base class.  These are
    6395             :      allocated in inheritance graph order.  */
    6396    44970104 :   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
    6397             :     {
    6398    31067003 :       if (!BINFO_VIRTUAL_P (vbase))
    6399    30915431 :         continue;
    6400             : 
    6401      151572 :       if (!BINFO_PRIMARY_P (vbase))
    6402             :         {
    6403             :           /* This virtual base is not a primary base of any class in the
    6404             :              hierarchy, so we have to add space for it.  */
    6405      142997 :           next_field = build_base_field (rli, vbase,
    6406             :                                          access_private_node,
    6407             :                                          offsets, next_field);
    6408             :         }
    6409             :     }
    6410             : }
    6411             : 
    6412             : /* Returns the offset of the byte just past the end of the base class
    6413             :    BINFO.  */
    6414             : 
    6415             : static tree
    6416    28776796 : end_of_base (tree binfo)
    6417             : {
    6418    28776796 :   tree size;
    6419             : 
    6420    28776796 :   if (!CLASSTYPE_AS_BASE (BINFO_TYPE (binfo)))
    6421           0 :     size = TYPE_SIZE_UNIT (char_type_node);
    6422    28776796 :   else if (is_empty_class (BINFO_TYPE (binfo)))
    6423             :     /* An empty class has zero CLASSTYPE_SIZE_UNIT, but we need to
    6424             :        allocate some space for it. It cannot have virtual bases, so
    6425             :        TYPE_SIZE_UNIT is fine.  */
    6426    25692028 :     size = TYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6427             :   else
    6428     3084768 :     size = CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6429             : 
    6430    28776796 :   return size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), size);
    6431             : }
    6432             : 
    6433             : /* Returns one of three variations of the ending offset of T.  If MODE is
    6434             :    eoc_nvsize, the result is the ABI "nvsize" (i.e. sizeof before allocating
    6435             :    vbases).  If MODE is eoc_vsize, the result is the sizeof after allocating
    6436             :    vbases but before rounding, which is not named in the ABI.  If MODE is
    6437             :    eoc_nv_or_dsize, the result is the greater of "nvsize" and "dsize" (the size
    6438             :    of the actual data in the class, kinda), as used for allocation of
    6439             :    potentially-overlapping fields.  */
    6440             : 
    6441             : enum eoc_mode { eoc_nvsize, eoc_vsize, eoc_nv_or_dsize };
    6442             : static tree
    6443    49219871 : end_of_class (tree t, eoc_mode mode)
    6444             : {
    6445    49219871 :   tree result = size_zero_node;
    6446    49219871 :   vec<tree, va_gc> *vbases;
    6447    49219871 :   tree binfo;
    6448    49219871 :   tree base_binfo;
    6449    49219871 :   tree offset;
    6450    49219871 :   int i;
    6451             : 
    6452    49219871 :   for (binfo = TYPE_BINFO (t), i = 0;
    6453    77915404 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6454             :     {
    6455    28695533 :       if (BINFO_VIRTUAL_P (base_binfo)
    6456    28695533 :           && (!BINFO_PRIMARY_P (base_binfo)
    6457        3940 :               || BINFO_INHERITANCE_CHAIN (base_binfo) != TYPE_BINFO (t)))
    6458       70309 :         continue;
    6459             : 
    6460    28625224 :       offset = end_of_base (base_binfo);
    6461    28625224 :       if (tree_int_cst_lt (result, offset))
    6462    28695533 :         result = offset;
    6463             :     }
    6464             : 
    6465   445177818 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6466   395957947 :     if (TREE_CODE (field) == FIELD_DECL
    6467   395957947 :         && !DECL_FIELD_IS_BASE (field))
    6468             :       {
    6469    15698377 :         tree size = DECL_SIZE_UNIT (field);
    6470    15698377 :         if (!size)
    6471             :           /* DECL_SIZE_UNIT can be null for a flexible array.  */
    6472        1904 :           continue;
    6473             : 
    6474    15696473 :         if (is_empty_field (field))
    6475             :           /* For empty fields DECL_SIZE_UNIT is 0, but we want the
    6476             :              size of the type (usually 1) for computing nvsize.  */
    6477       49029 :           size = TYPE_SIZE_UNIT (TREE_TYPE (field));
    6478             : 
    6479    15696473 :         if (DECL_BIT_FIELD_TYPE (field))
    6480             :           {
    6481      257561 :             offset = size_binop (PLUS_EXPR, bit_position (field),
    6482             :                                  DECL_SIZE (field));
    6483      257561 :             offset = size_binop (CEIL_DIV_EXPR, offset, bitsize_unit_node);
    6484      257561 :             offset = fold_convert (sizetype, offset);
    6485             :           }
    6486             :         else
    6487    15438912 :           offset = size_binop (PLUS_EXPR, byte_position (field), size);
    6488    15696473 :         if (tree_int_cst_lt (result, offset))
    6489   395957947 :           result = offset;
    6490             :       }
    6491             : 
    6492    49219871 :   if (mode != eoc_nvsize)
    6493    25309984 :     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    6494    25309984 :          vec_safe_iterate (vbases, i, &base_binfo); i++)
    6495             :       {
    6496      151579 :         if (mode == eoc_nv_or_dsize)
    6497             :           /* For dsize, don't count trailing empty bases.  */
    6498           7 :           offset = size_binop (PLUS_EXPR, BINFO_OFFSET (base_binfo),
    6499             :                                CLASSTYPE_SIZE_UNIT (BINFO_TYPE (base_binfo)));
    6500             :         else
    6501      151572 :           offset = end_of_base (base_binfo);
    6502      151579 :         if (tree_int_cst_lt (result, offset))
    6503      140366 :           result = offset;
    6504             :       }
    6505             : 
    6506    49219871 :   return result;
    6507             : }
    6508             : 
    6509             : /* Warn as appropriate about the change in whether we pack into the tail
    6510             :    padding of FIELD, a base field which has a C++14 aggregate type with default
    6511             :    member initializers.  */
    6512             : 
    6513             : static void
    6514   200834283 : check_non_pod_aggregate (tree field)
    6515             : {
    6516   200834283 :   if (!abi_version_crosses (17) || cxx_dialect < cxx14)
    6517             :     return;
    6518      545508 :   if (TREE_CODE (field) != FIELD_DECL
    6519      545508 :       || (!DECL_FIELD_IS_BASE (field)
    6520       33564 :           && !field_poverlapping_p (field)))
    6521      505582 :     return;
    6522       39926 :   tree next = DECL_CHAIN (field);
    6523      167785 :   while (next && TREE_CODE (next) != FIELD_DECL) next = DECL_CHAIN (next);
    6524       39926 :   if (!next)
    6525             :     return;
    6526        2944 :   tree type = TREE_TYPE (field);
    6527        2944 :   if (TYPE_IDENTIFIER (type) == as_base_identifier)
    6528        1334 :     type = TYPE_CONTEXT (type);
    6529        2944 :   if (!CLASS_TYPE_P (type) || !CLASSTYPE_NON_POD_AGGREGATE (type))
    6530             :     return;
    6531          18 :   tree size = end_of_class (type, (DECL_FIELD_IS_BASE (field)
    6532             :                                    ? eoc_nvsize : eoc_nv_or_dsize));
    6533          16 :   tree rounded = round_up_loc (input_location, size, DECL_ALIGN_UNIT (next));
    6534          16 :   if (tree_int_cst_lt (rounded, TYPE_SIZE_UNIT (type)))
    6535             :     {
    6536          16 :       location_t loc = DECL_SOURCE_LOCATION (next);
    6537          16 :       if (DECL_FIELD_IS_BASE (next))
    6538           8 :         warning_at (loc, OPT_Wabi,"offset of %qT base class for "
    6539             :                     "%<-std=c++14%> and up changes in "
    6540           8 :                     "%<-fabi-version=17%> (GCC 12)", TREE_TYPE (next));
    6541             :       else
    6542           8 :         warning_at (loc, OPT_Wabi, "offset of %qD for "
    6543             :                     "%<-std=c++14%> and up changes in "
    6544             :                     "%<-fabi-version=17%> (GCC 12)", next);
    6545             :     }
    6546             : }
    6547             : 
    6548             : /* Warn about bases of T that are inaccessible because they are
    6549             :    ambiguous.  For example:
    6550             : 
    6551             :      struct S {};
    6552             :      struct T : public S {};
    6553             :      struct U : public S, public T {};
    6554             : 
    6555             :    Here, `(S*) new U' is not allowed because there are two `S'
    6556             :    subobjects of U.  */
    6557             : 
    6558             : static void
    6559    25156660 : maybe_warn_about_inaccessible_bases (tree t)
    6560             : {
    6561    25156660 :   int i;
    6562    25156660 :   vec<tree, va_gc> *vbases;
    6563    25156660 :   tree basetype;
    6564    25156660 :   tree binfo;
    6565    25156660 :   tree base_binfo;
    6566             : 
    6567             :   /* If not checking for warning then return early.  */
    6568    25156660 :   if (!warn_inaccessible_base)
    6569    25156660 :     return;
    6570             : 
    6571             :   /* If there are no repeated bases, nothing can be ambiguous.  */
    6572    25156526 :   if (!CLASSTYPE_REPEATED_BASE_P (t))
    6573             :     return;
    6574             : 
    6575             :   /* Check direct bases.  */
    6576        4373 :   for (binfo = TYPE_BINFO (t), i = 0;
    6577        4373 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6578             :     {
    6579        3178 :       basetype = BINFO_TYPE (base_binfo);
    6580             : 
    6581        3178 :       if (!uniquely_derived_from_p (basetype, t))
    6582         963 :         warning (OPT_Winaccessible_base, "direct base %qT inaccessible "
    6583             :                  "in %qT due to ambiguity", basetype, t);
    6584             :     }
    6585             : 
    6586             :   /* Check for ambiguous virtual bases.  */
    6587        1195 :   if (extra_warnings)
    6588           8 :     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    6589           8 :          vec_safe_iterate (vbases, i, &binfo); i++)
    6590             :       {
    6591           4 :         basetype = BINFO_TYPE (binfo);
    6592             : 
    6593           4 :         if (!uniquely_derived_from_p (basetype, t))
    6594           4 :           warning (OPT_Winaccessible_base, "virtual base %qT inaccessible in "
    6595             :                    "%qT due to ambiguity", basetype, t);
    6596             :       }
    6597             : }
    6598             : 
    6599             : /* Compare two INTEGER_CSTs K1 and K2.  */
    6600             : 
    6601             : static int
    6602     6303886 : splay_tree_compare_integer_csts (splay_tree_key k1, splay_tree_key k2)
    6603             : {
    6604     6303886 :   return tree_int_cst_compare ((tree) k1, (tree) k2);
    6605             : }
    6606             : 
    6607             : /* Increase the size indicated in RLI to account for empty classes
    6608             :    that are "off the end" of the class.  */
    6609             : 
    6610             : static void
    6611    25156660 : include_empty_classes (record_layout_info rli)
    6612             : {
    6613    25156660 :   tree eoc;
    6614    25156660 :   tree rli_size;
    6615             : 
    6616             :   /* It might be the case that we grew the class to allocate a
    6617             :      zero-sized base class.  That won't be reflected in RLI, yet,
    6618             :      because we are willing to overlay multiple bases at the same
    6619             :      offset.  However, now we need to make sure that RLI is big enough
    6620             :      to reflect the entire class.  */
    6621    25156660 :   eoc = end_of_class (rli->t, eoc_vsize);
    6622    25156660 :   rli_size = rli_size_unit_so_far (rli);
    6623    25156660 :   if (TREE_CODE (rli_size) == INTEGER_CST
    6624    25156660 :       && tree_int_cst_lt (rli_size, eoc))
    6625             :     {
    6626             :       /* The size should have been rounded to a whole byte.  */
    6627    12212484 :       gcc_assert (tree_int_cst_equal
    6628             :                   (rli->bitpos, round_down (rli->bitpos, BITS_PER_UNIT)));
    6629    12212484 :       rli->bitpos
    6630    12212484 :         = size_binop (PLUS_EXPR,
    6631             :                       rli->bitpos,
    6632             :                       size_binop (MULT_EXPR,
    6633             :                                   fold_convert (bitsizetype,
    6634             :                                            size_binop (MINUS_EXPR,
    6635             :                                                        eoc, rli_size)),
    6636             :                                   bitsize_int (BITS_PER_UNIT)));
    6637    12212484 :       normalize_rli (rli);
    6638             :     }
    6639    25156660 : }
    6640             : 
    6641             : /* Calculate the TYPE_SIZE, TYPE_ALIGN, etc for T.  Calculate
    6642             :    BINFO_OFFSETs for all of the base-classes.  Position the vtable
    6643             :    pointer.  Accumulate declared virtual functions on VIRTUALS_P.  */
    6644             : 
    6645             : static void
    6646    25156660 : layout_class_type (tree t, tree *virtuals_p)
    6647             : {
    6648    25156660 :   tree non_static_data_members;
    6649    25156660 :   tree field;
    6650    25156660 :   tree vptr;
    6651    25156660 :   record_layout_info rli;
    6652             :   /* Maps offsets (represented as INTEGER_CSTs) to a TREE_LIST of
    6653             :      types that appear at that offset.  */
    6654    25156660 :   splay_tree empty_base_offsets;
    6655             :   /* True if the last field laid out was a bit-field.  */
    6656    25156660 :   bool last_field_was_bitfield = false;
    6657             :   /* The location at which the next field should be inserted.  */
    6658    25156660 :   tree *next_field;
    6659             : 
    6660             :   /* Keep track of the first non-static data member.  */
    6661    25156660 :   non_static_data_members = TYPE_FIELDS (t);
    6662             : 
    6663             :   /* Start laying out the record.  */
    6664    25156660 :   rli = start_record_layout (t);
    6665             : 
    6666             :   /* Mark all the primary bases in the hierarchy.  */
    6667    25156660 :   determine_primary_bases (t);
    6668             : 
    6669             :   /* Create a pointer to our virtual function table.  */
    6670    25156660 :   vptr = create_vtable_ptr (t, virtuals_p);
    6671             : 
    6672             :   /* The vptr is always the first thing in the class.  */
    6673    25156660 :   if (vptr)
    6674             :     {
    6675      173804 :       DECL_CHAIN (vptr) = TYPE_FIELDS (t);
    6676      173804 :       TYPE_FIELDS (t) = vptr;
    6677      173804 :       next_field = &DECL_CHAIN (vptr);
    6678      173804 :       place_field (rli, vptr);
    6679             :     }
    6680             :   else
    6681    24982856 :     next_field = &TYPE_FIELDS (t);
    6682             : 
    6683             :   /* Build FIELD_DECLs for all of the non-virtual base-types.  */
    6684    25156660 :   empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
    6685             :                                        NULL, NULL);
    6686    25156660 :   build_base_fields (rli, empty_base_offsets, next_field);
    6687             : 
    6688             :   /* Layout the non-static data members.  */
    6689   211627367 :   for (field = non_static_data_members; field; field = DECL_CHAIN (field))
    6690             :     {
    6691   186470707 :       tree type;
    6692   186470707 :       tree padding;
    6693             : 
    6694             :       /* We still pass things that aren't non-static data members to
    6695             :          the back end, in case it wants to do something with them.  */
    6696   186470707 :       if (TREE_CODE (field) != FIELD_DECL)
    6697             :         {
    6698   176565649 :           place_field (rli, field);
    6699             :           /* If the static data member has incomplete type, keep track
    6700             :              of it so that it can be completed later.  (The handling
    6701             :              of pending statics in finish_record_layout is
    6702             :              insufficient; consider:
    6703             : 
    6704             :                struct S1;
    6705             :                struct S2 { static S1 s1; };
    6706             : 
    6707             :              At this point, finish_record_layout will be called, but
    6708             :              S1 is still incomplete.)  */
    6709   176565649 :           if (VAR_P (field))
    6710             :             {
    6711     6339337 :               maybe_register_incomplete_var (field);
    6712             :               /* The visibility of static data members is determined
    6713             :                  at their point of declaration, not their point of
    6714             :                  definition.  */
    6715     6339337 :               determine_visibility (field);
    6716             :             }
    6717   176565649 :           continue;
    6718             :         }
    6719             : 
    6720     9905058 :       type = TREE_TYPE (field);
    6721     9905058 :       if (type == error_mark_node)
    6722         206 :         continue;
    6723             : 
    6724     9904852 :       padding = NULL_TREE;
    6725             : 
    6726     9904852 :       bool might_overlap = field_poverlapping_p (field);
    6727             : 
    6728       26856 :       if (might_overlap && CLASS_TYPE_P (type)
    6729     9931117 :           && (CLASSTYPE_NON_LAYOUT_POD_P (type) || CLASSTYPE_EMPTY_P (type)))
    6730             :         {
    6731             :           /* if D is a potentially-overlapping data member, update sizeof(C) to
    6732             :              max (sizeof(C), offset(D)+max (nvsize(D), dsize(D))).  */
    6733       26227 :           if (CLASSTYPE_EMPTY_P (type))
    6734       24484 :             DECL_SIZE (field) = DECL_SIZE_UNIT (field) = size_zero_node;
    6735             :           else
    6736             :             {
    6737        1743 :               tree size = end_of_class (type, eoc_nv_or_dsize);
    6738        1743 :               DECL_SIZE_UNIT (field) = size;
    6739        1743 :               DECL_SIZE (field) = bit_from_pos (size, bitsize_zero_node);
    6740             :             }
    6741             :         }
    6742             : 
    6743             :       /* If this field is a bit-field whose width is greater than its
    6744             :          type, then there are some special rules for allocating
    6745             :          it.  */
    6746     9904852 :       if (DECL_C_BIT_FIELD (field)
    6747     9904852 :           && tree_int_cst_lt (TYPE_SIZE (type), DECL_SIZE (field)))
    6748             :         {
    6749         784 :           bool was_unnamed_p = false;
    6750             :           /* We must allocate the bits as if suitably aligned for the
    6751             :              longest integer type that fits in this many bits.  Then,
    6752             :              we are supposed to use the left over bits as additional
    6753             :              padding.  */
    6754             : 
    6755             :           /* Do not pick a type bigger than MAX_FIXED_MODE_SIZE.  */
    6756        1568 :           tree limit = size_int (MAX_FIXED_MODE_SIZE);
    6757         784 :           if (tree_int_cst_lt (DECL_SIZE (field), limit))
    6758         757 :             limit = DECL_SIZE (field);
    6759             : 
    6760         784 :           tree integer_type = integer_types[itk_char];
    6761        6770 :           for (unsigned itk = itk_char; itk != itk_none; itk++)
    6762        6743 :             if (tree next = integer_types[itk])
    6763             :               {
    6764        6581 :                 if (tree_int_cst_lt (limit, TYPE_SIZE (next)))
    6765             :                   /* Too big, so our current guess is what we want.  */
    6766             :                   break;
    6767             :                 /* Not bigger than limit, ok  */
    6768             :                 integer_type = next;
    6769             :               }
    6770             : 
    6771             :           /* Figure out how much additional padding is required.  */
    6772         784 :           if (TREE_CODE (t) == UNION_TYPE)
    6773             :             /* In a union, the padding field must have the full width
    6774             :                of the bit-field; all fields start at offset zero.  */
    6775          79 :             padding = DECL_SIZE (field);
    6776             :           else
    6777         705 :             padding = size_binop (MINUS_EXPR, DECL_SIZE (field),
    6778             :                                   TYPE_SIZE (integer_type));
    6779             : 
    6780         784 :           if (integer_zerop (padding))
    6781           7 :             padding = NULL_TREE;
    6782             : 
    6783             :           /* An unnamed bitfield does not normally affect the
    6784             :              alignment of the containing class on a target where
    6785             :              PCC_BITFIELD_TYPE_MATTERS.  But, the C++ ABI does not
    6786             :              make any exceptions for unnamed bitfields when the
    6787             :              bitfields are longer than their types.  Therefore, we
    6788             :              temporarily give the field a name.  */
    6789         784 :           if (PCC_BITFIELD_TYPE_MATTERS && !DECL_NAME (field))
    6790             :             {
    6791           0 :               was_unnamed_p = true;
    6792           0 :               DECL_NAME (field) = make_anon_name ();
    6793             :             }
    6794             : 
    6795         784 :           DECL_SIZE (field) = TYPE_SIZE (integer_type);
    6796         784 :           SET_DECL_ALIGN (field, TYPE_ALIGN (integer_type));
    6797         784 :           DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type);
    6798         784 :           layout_nonempty_base_or_field (rli, field, NULL_TREE,
    6799             :                                          empty_base_offsets);
    6800         784 :           if (was_unnamed_p)
    6801           0 :             DECL_NAME (field) = NULL_TREE;
    6802             :           /* Now that layout has been performed, set the size of the
    6803             :              field to the size of its declared type; the rest of the
    6804             :              field is effectively invisible.  */
    6805         784 :           DECL_SIZE (field) = TYPE_SIZE (type);
    6806             :           /* We must also reset the DECL_MODE of the field.  */
    6807         784 :           SET_DECL_MODE (field, TYPE_MODE (type));
    6808             :         }
    6809     9904068 :       else if (might_overlap && is_empty_class (type))
    6810             :         {
    6811       24484 :           SET_DECL_FIELD_ABI_IGNORED (field, 1);
    6812       24484 :           layout_empty_base_or_field (rli, field, empty_base_offsets);
    6813             :         }
    6814             :       else
    6815     9879584 :         layout_nonempty_base_or_field (rli, field, NULL_TREE,
    6816             :                                        empty_base_offsets);
    6817             : 
    6818             :       /* Remember the location of any empty classes in FIELD.  */
    6819     9904852 :       record_subobject_offsets (field, empty_base_offsets);
    6820             : 
    6821             :       /* If a bit-field does not immediately follow another bit-field,
    6822             :          and yet it starts in the middle of a byte, we have failed to
    6823             :          comply with the ABI.  */
    6824     9904852 :       if (warn_abi
    6825       95652 :           && DECL_C_BIT_FIELD (field)
    6826             :           /* The TREE_NO_WARNING flag gets set by Objective-C when
    6827             :              laying out an Objective-C class.  The ObjC ABI differs
    6828             :              from the C++ ABI, and so we do not want a warning
    6829             :              here.  */
    6830        3724 :           && !warning_suppressed_p (field, OPT_Wabi)
    6831        3724 :           && !last_field_was_bitfield
    6832     9905224 :           && !integer_zerop (size_binop (TRUNC_MOD_EXPR,
    6833             :                                          DECL_FIELD_BIT_OFFSET (field),
    6834             :                                          bitsize_unit_node)))
    6835           0 :         warning_at (DECL_SOURCE_LOCATION (field), OPT_Wabi,
    6836             :                     "offset of %qD is not ABI-compliant and may "
    6837             :                     "change in a future version of GCC", field);
    6838             : 
    6839             :       /* The middle end uses the type of expressions to determine the
    6840             :          possible range of expression values.  In order to optimize
    6841             :          "x.i > 7" to "false" for a 2-bit bitfield "i", the middle end
    6842             :          must be made aware of the width of "i", via its type.
    6843             : 
    6844             :          Because C++ does not have integer types of arbitrary width,
    6845             :          we must (for the purposes of the front end) convert from the
    6846             :          type assigned here to the declared type of the bitfield
    6847             :          whenever a bitfield expression is used as an rvalue.
    6848             :          Similarly, when assigning a value to a bitfield, the value
    6849             :          must be converted to the type given the bitfield here.  */
    6850     9904852 :       if (DECL_C_BIT_FIELD (field))
    6851             :         {
    6852      245074 :           unsigned HOST_WIDE_INT width;
    6853      245074 :           tree ftype = TREE_TYPE (field);
    6854      245074 :           width = tree_to_uhwi (DECL_SIZE (field));
    6855      245074 :           if (width != TYPE_PRECISION (ftype))
    6856             :             {
    6857      139207 :               TREE_TYPE (field)
    6858      278414 :                 = c_build_bitfield_integer_type (width,
    6859      139207 :                                                  TYPE_UNSIGNED (ftype));
    6860      139207 :               TREE_TYPE (field)
    6861      278414 :                 = cp_build_qualified_type (TREE_TYPE (field),
    6862             :                                            cp_type_quals (ftype));
    6863             :             }
    6864             :         }
    6865             : 
    6866             :       /* If we needed additional padding after this field, add it
    6867             :          now.  */
    6868     9904852 :       if (padding)
    6869             :         {
    6870         777 :           tree padding_field;
    6871             : 
    6872         777 :           padding_field = build_decl (input_location,
    6873             :                                       FIELD_DECL,
    6874             :                                       NULL_TREE,
    6875             :                                       char_type_node);
    6876         777 :           DECL_BIT_FIELD (padding_field) = 1;
    6877         777 :           DECL_SIZE (padding_field) = padding;
    6878         777 :           DECL_CONTEXT (padding_field) = t;
    6879         777 :           DECL_ARTIFICIAL (padding_field) = 1;
    6880         777 :           DECL_IGNORED_P (padding_field) = 1;
    6881         777 :           DECL_PADDING_P (padding_field) = 1;
    6882         777 :           layout_nonempty_base_or_field (rli, padding_field,
    6883             :                                          NULL_TREE,
    6884             :                                          empty_base_offsets);
    6885             :         }
    6886             : 
    6887     9904852 :       last_field_was_bitfield = DECL_C_BIT_FIELD (field);
    6888             :     }
    6889             : 
    6890    25156660 :   if (!integer_zerop (rli->bitpos))
    6891             :     {
    6892             :       /* Make sure that we are on a byte boundary so that the size of
    6893             :          the class without virtual bases will always be a round number
    6894             :          of bytes.  */
    6895     2855554 :       rli->bitpos = round_up_loc (input_location, rli->bitpos, BITS_PER_UNIT);
    6896     2855554 :       normalize_rli (rli);
    6897             :     }
    6898             : 
    6899             :   /* We used to remove zero width bitfields at this point since PR42217,
    6900             :      while the C FE never did that.  That caused ABI differences on various
    6901             :      targets.  Set the DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD flag on them
    6902             :      instead, so that the backends can emit -Wpsabi warnings in the cases
    6903             :      where the ABI changed.  */
    6904   225990943 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6905             :     {
    6906   200834283 :       if (TREE_CODE (field) == FIELD_DECL
    6907    24268634 :           && DECL_C_BIT_FIELD (field)
    6908             :           /* We should not be confused by the fact that grokbitfield
    6909             :              temporarily sets the width of the bit field into
    6910             :              DECL_BIT_FIELD_REPRESENTATIVE (field).
    6911             :              check_bitfield_decl eventually sets DECL_SIZE (field)
    6912             :              to that width.  */
    6913   201079357 :           && (DECL_SIZE (field) == NULL_TREE
    6914      245074 :               || integer_zerop (DECL_SIZE (field))))
    6915        1081 :         SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field, 1);
    6916   200834283 :       check_non_pod_aggregate (field);
    6917             :     }
    6918             : 
    6919    25156660 :   if (CLASSTYPE_NON_LAYOUT_POD_P (t) || CLASSTYPE_EMPTY_P (t))
    6920             :     {
    6921             :       /* T needs a different layout as a base (eliding virtual bases
    6922             :          or whatever).  Create that version.  */
    6923    24061452 :       tree base_t = make_node (TREE_CODE (t));
    6924    24061452 :       tree base_d = create_implicit_typedef (as_base_identifier, base_t);
    6925             : 
    6926    24061452 :       TYPE_CONTEXT (base_t) = t;
    6927    24061452 :       DECL_CONTEXT (base_d) = t;
    6928             : 
    6929    24061452 :       set_instantiating_module (base_d);
    6930             : 
    6931             :       /* If the ABI version is not at least two, and the last
    6932             :          field was a bit-field, RLI may not be on a byte
    6933             :          boundary.  In particular, rli_size_unit_so_far might
    6934             :          indicate the last complete byte, while rli_size_so_far
    6935             :          indicates the total number of bits used.  Therefore,
    6936             :          rli_size_so_far, rather than rli_size_unit_so_far, is
    6937             :          used to compute TYPE_SIZE_UNIT.  */
    6938             : 
    6939             :       /* Set the size and alignment for the new type.  */
    6940    24061452 :       tree eoc = end_of_class (t, eoc_nvsize);
    6941    24061452 :       TYPE_SIZE_UNIT (base_t)
    6942    24061452 :         = size_binop (MAX_EXPR,
    6943             :                       fold_convert (sizetype,
    6944             :                                size_binop (CEIL_DIV_EXPR,
    6945             :                                            rli_size_so_far (rli),
    6946             :                                            bitsize_int (BITS_PER_UNIT))),
    6947             :                       eoc);
    6948    24061452 :       TYPE_SIZE (base_t)
    6949    24061452 :         = size_binop (MAX_EXPR,
    6950             :                       rli_size_so_far (rli),
    6951             :                       size_binop (MULT_EXPR,
    6952             :                                   fold_convert (bitsizetype, eoc),
    6953             :                                   bitsize_int (BITS_PER_UNIT)));
    6954    24061452 :       SET_TYPE_ALIGN (base_t, rli->record_align);
    6955    24061452 :       TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t);
    6956    24061452 :       TYPE_TYPELESS_STORAGE (base_t) = TYPE_TYPELESS_STORAGE (t);
    6957    24061452 :       TYPE_CXX_ODR_P (base_t) = TYPE_CXX_ODR_P (t);
    6958             : 
    6959             :       /* Copy the non-static data members of T. This will include its
    6960             :          direct non-virtual bases & vtable.  */
    6961    24061452 :       next_field = &TYPE_FIELDS (base_t);
    6962   218996469 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6963   194935017 :         if (TREE_CODE (field) == FIELD_DECL)
    6964             :           {
    6965    19807713 :             *next_field = copy_node (field);
    6966             :             /* Zap any NSDMI, it's not needed and might be a deferred
    6967             :                parse.  */
    6968    19807713 :             DECL_INITIAL (*next_field) = NULL_TREE;
    6969    19807713 :             DECL_CONTEXT (*next_field) = base_t;
    6970    19807713 :             next_field = &DECL_CHAIN (*next_field);
    6971             :           }
    6972    24061452 :       *next_field = NULL_TREE;
    6973             : 
    6974             :       /* We use the base type for trivial assignments, and hence it
    6975             :          needs a mode.  */
    6976    24061452 :       compute_record_mode (base_t);
    6977             : 
    6978             :       /* Record the base version of the type.  */
    6979    24061452 :       CLASSTYPE_AS_BASE (t) = base_t;
    6980             :     }
    6981             :   else
    6982     1095208 :     CLASSTYPE_AS_BASE (t) = t;
    6983             : 
    6984             :   /* Every empty class contains an empty class.  */
    6985    25156660 :   if (CLASSTYPE_EMPTY_P (t))
    6986    20527457 :     CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    6987             : 
    6988             :   /* Set the TYPE_DECL for this type to contain the right
    6989             :      value for DECL_OFFSET, so that we can use it as part
    6990             :      of a COMPONENT_REF for multiple inheritance.  */
    6991    25156660 :   layout_decl (TYPE_MAIN_DECL (t), 0);
    6992             : 
    6993             :   /* Now fix up any virtual base class types that we left lying
    6994             :      around.  We must get these done before we try to lay out the
    6995             :      virtual function table.  As a side-effect, this will remove the
    6996             :      base subobject fields.  */
    6997    25156660 :   layout_virtual_bases (rli, empty_base_offsets);
    6998             : 
    6999             :   /* Make sure that empty classes are reflected in RLI at this
    7000             :      point.  */
    7001    25156660 :   include_empty_classes (rli);
    7002             : 
    7003             :   /* Make sure not to create any structures with zero size.  */
    7004    25156660 :   if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
    7005     8315230 :     place_field (rli,
    7006             :                  build_decl (input_location,
    7007             :                              FIELD_DECL, NULL_TREE, char_type_node));
    7008             : 
    7009             :   /* If this is a non-POD, declaring it packed makes a difference to how it
    7010             :      can be used as a field; don't let finalize_record_size undo it.  */
    7011    25156660 :   if (TYPE_PACKED (t) && !layout_pod_type_p (t))
    7012          79 :     rli->packed_maybe_necessary = true;
    7013             : 
    7014             :   /* Let the back end lay out the type.  */
    7015    25156660 :   finish_record_layout (rli, /*free_p=*/true);
    7016             : 
    7017             :   /* If we didn't end up needing an as-base type, don't use it.  */
    7018    25156660 :   if (CLASSTYPE_AS_BASE (t) != t
    7019             :       /* If T's CLASSTYPE_AS_BASE is TYPE_USER_ALIGN, but T is not,
    7020             :          replacing the as-base type would change CLASSTYPE_USER_ALIGN,
    7021             :          causing us to lose the user-specified alignment as in PR94050.  */
    7022    24061452 :       && TYPE_USER_ALIGN (t) == TYPE_USER_ALIGN (CLASSTYPE_AS_BASE (t))
    7023    49218098 :       && tree_int_cst_equal (TYPE_SIZE (t),
    7024    24061438 :                              TYPE_SIZE (CLASSTYPE_AS_BASE (t))))
    7025    15169268 :     CLASSTYPE_AS_BASE (t) = t;
    7026             : 
    7027    25156660 :   if (TYPE_SIZE_UNIT (t)
    7028    25156660 :       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
    7029    25156660 :       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
    7030    50313308 :       && !valid_constant_size_p (TYPE_SIZE_UNIT (t)))
    7031           0 :     error ("size of type %qT is too large (%qE bytes)", t, TYPE_SIZE_UNIT (t));
    7032             : 
    7033             :   /* Warn about bases that can't be talked about due to ambiguity.  */
    7034    25156660 :   maybe_warn_about_inaccessible_bases (t);
    7035             : 
    7036             :   /* Now that we're done with layout, give the base fields the real types.  */
    7037   226131426 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7038   200974766 :     if (DECL_ARTIFICIAL (field) && IS_FAKE_BASE_TYPE (TREE_TYPE (field)))
    7039    12555628 :       TREE_TYPE (field) = TYPE_CONTEXT (TREE_TYPE (field));
    7040             : 
    7041             :   /* Clean up.  */
    7042    25156660 :   splay_tree_delete (empty_base_offsets);
    7043             : 
    7044    25156660 :   if (CLASSTYPE_EMPTY_P (t)
    7045    45684117 :       && tree_int_cst_lt (sizeof_biggest_empty_class,
    7046    20527457 :                           TYPE_SIZE_UNIT (t)))
    7047       49308 :     sizeof_biggest_empty_class = TYPE_SIZE_UNIT (t);
    7048    25156660 : }
    7049             : 
    7050             : /* Determine the "key method" for the class type indicated by TYPE,
    7051             :    and set CLASSTYPE_KEY_METHOD accordingly.  */
    7052             : 
    7053             : void
    7054     1144766 : determine_key_method (tree type)
    7055             : {
    7056     1144766 :   tree method;
    7057             : 
    7058     1144766 :   if (processing_template_decl
    7059     1144766 :       || CLASSTYPE_TEMPLATE_INSTANTIATION (type)
    7060     1662857 :       || CLASSTYPE_INTERFACE_KNOWN (type))
    7061             :     return;
    7062             : 
    7063             :   /* The key method is the first non-pure virtual function that is not
    7064             :      inline at the point of class definition.  On some targets the
    7065             :      key function may not be inline; those targets should not call
    7066             :      this function until the end of the translation unit.  */
    7067     5239966 :   for (method = TYPE_FIELDS (type); method; method = DECL_CHAIN (method))
    7068     5129047 :     if (TREE_CODE (method) == FUNCTION_DECL
    7069     4197016 :         && DECL_VINDEX (method) != NULL_TREE
    7070      820545 :         && ! DECL_DECLARED_INLINE_P (method)
    7071     5555402 :         && ! DECL_PURE_VIRTUAL_P (method))
    7072             :       {
    7073      407137 :         CLASSTYPE_KEY_METHOD (type) = method;
    7074      407137 :         break;
    7075             :       }
    7076             : 
    7077             :   return;
    7078             : }
    7079             : 
    7080             : /* Helper of find_flexarrays.  Return true when FLD refers to a non-static
    7081             :    class data member of non-zero size, otherwise false.  */
    7082             : 
    7083             : static inline bool
    7084    22913023 : field_nonempty_p (const_tree fld)
    7085             : {
    7086    22913023 :   if (TREE_CODE (fld) == ERROR_MARK)
    7087             :     return false;
    7088             : 
    7089    22913023 :   tree type = TREE_TYPE (fld);
    7090    22913023 :   if (TREE_CODE (fld) == FIELD_DECL
    7091    22913023 :       && TREE_CODE (type) != ERROR_MARK
    7092    45826046 :       && (DECL_NAME (fld) || RECORD_OR_UNION_TYPE_P (type)))
    7093             :     {
    7094    22811729 :       return TYPE_SIZE (type)
    7095    22811729 :         && (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
    7096    22810085 :             || !tree_int_cst_equal (size_zero_node, TYPE_SIZE (type)));
    7097             :     }
    7098             : 
    7099             :   return false;
    7100             : }
    7101             : 
    7102             : /* Used by find_flexarrays and related functions.  */
    7103             : 
    7104             : struct flexmems_t
    7105             : {
    7106             :   /* The first flexible array member or non-zero array member found
    7107             :      in the order of layout.  */
    7108             :   tree array;
    7109             :   /* First non-static non-empty data member in the class or its bases.  */
    7110             :   tree first;
    7111             :   /* The first non-static non-empty data member following either
    7112             :      the flexible array member, if found, or the zero-length array member
    7113             :      otherwise.  AFTER[1] refers to the first such data member of a union
    7114             :      of which the struct containing the flexible array member or zero-length
    7115             :      array is a member, or NULL when no such union exists.  This element is
    7116             :      only used during searching, not for diagnosing problems.  AFTER[0]
    7117             :      refers to the first such data member that is not a member of such
    7118             :      a union.  */
    7119             :   tree after[2];
    7120             : 
    7121             :   /* Refers to a struct (not union) in which the struct of which the flexible
    7122             :      array is member is defined.  Used to diagnose strictly (according to C)
    7123             :      invalid uses of the latter structs.  */
    7124             :   tree enclosing;
    7125             : };
    7126             : 
    7127             : /* Find either the first flexible array member or the first zero-length
    7128             :    array, in that order of preference, among members of class T (but not
    7129             :    its base classes), and set members of FMEM accordingly.
    7130             :    BASE_P is true if T is a base class of another class.
    7131             :    PUN is set to the outermost union in which the flexible array member
    7132             :    (or zero-length array) is defined if one such union exists, otherwise
    7133             :    to NULL.
    7134             :    Similarly, PSTR is set to a data member of the outermost struct of
    7135             :    which the flexible array is a member if one such struct exists,
    7136             :    otherwise to NULL.  */
    7137             : 
    7138             : static void
    7139    46687002 : find_flexarrays (tree t, flexmems_t *fmem, bool base_p,
    7140             :                  tree pun /* = NULL_TREE */,
    7141             :                  tree pstr /* = NULL_TREE */)
    7142             : {
    7143             :   /* Set the "pointer" to the outermost enclosing union if not set
    7144             :      yet and maintain it for the remainder of the recursion.   */
    7145    46687002 :   if (!pun && TREE_CODE (t) == UNION_TYPE)
    7146      980372 :     pun = t;
    7147             : 
    7148   650314578 :   for (tree fld = TYPE_FIELDS (t); fld; fld = DECL_CHAIN (fld))
    7149             :     {
    7150   603628281 :       if (fld == error_mark_node)
    7151             :         return;
    7152             : 
    7153             :       /* Is FLD a typedef for an anonymous struct?  */
    7154             : 
    7155             :       /* FIXME: Note that typedefs (as well as arrays) need to be fully
    7156             :          handled elsewhere so that errors like the following are detected
    7157             :          as well:
    7158             :            typedef struct { int i, a[], j; } S;   // bug c++/72753
    7159             :            S s [2];                               // bug c++/68489
    7160             :       */
    7161   604411365 :       if (TREE_CODE (fld) == TYPE_DECL
    7162   119431232 :           && DECL_IMPLICIT_TYPEDEF_P (fld)
    7163     5982211 :           && CLASS_TYPE_P (TREE_TYPE (fld))
    7164   607819806 :           && IDENTIFIER_ANON_P (DECL_NAME (fld)))
    7165             :         {
    7166             :           /* Check the nested unnamed type referenced via a typedef
    7167             :              independently of FMEM (since it's not a data member of
    7168             :              the enclosing class).  */
    7169      783084 :           check_flexarrays (TREE_TYPE (fld));
    7170      783084 :           continue;
    7171             :         }
    7172             : 
    7173             :       /* Skip anything that's GCC-generated or not a (non-static) data
    7174             :          member.  */
    7175   602845197 :       if (DECL_ARTIFICIAL (fld) || TREE_CODE (fld) != FIELD_DECL)
    7176   579142348 :         continue;
    7177             : 
    7178             :       /* Type of the member.  */
    7179    23702849 :       tree fldtype = TREE_TYPE (fld);
    7180    23702849 :       if (fldtype == error_mark_node)
    7181             :         return;
    7182             : 
    7183             :       /* Determine the type of the array element or object referenced
    7184             :          by the member so that it can be checked for flexible array
    7185             :          members if it hasn't been yet.  */
    7186             :       tree eltype = fldtype;
    7187    32442053 :       while (TREE_CODE (eltype) == ARRAY_TYPE
    7188    32442053 :              || INDIRECT_TYPE_P (eltype))
    7189     8739421 :         eltype = TREE_TYPE (eltype);
    7190             : 
    7191    23702632 :       if (RECORD_OR_UNION_TYPE_P (eltype))
    7192             :         {
    7193     8049471 :           if (fmem->array && !fmem->after[bool (pun)])
    7194             :             {
    7195             :               /* Once the member after the flexible array has been found
    7196             :                  we're done.  */
    7197         488 :               fmem->after[bool (pun)] = fld;
    7198         488 :               break;
    7199             :             }
    7200             : 
    7201    11512449 :           if (eltype == fldtype || TYPE_UNNAMED_P (eltype))
    7202             :             {
    7203             :               /* Descend into the non-static member struct or union and try
    7204             :                  to find a flexible array member or zero-length array among
    7205             :                  its members.  This is only necessary for anonymous types
    7206             :                  and types in whose context the current type T has not been
    7207             :                  defined (the latter must not be checked again because they
    7208             :                  are already in the process of being checked by one of the
    7209             :                  recursive calls).  */
    7210             : 
    7211     4581366 :               tree first = fmem->first;
    7212     4581366 :               tree array = fmem->array;
    7213             : 
    7214             :               /* If this member isn't anonymous and a prior non-flexible array
    7215             :                  member has been seen in one of the enclosing structs, clear
    7216             :                  the FIRST member since it doesn't contribute to the flexible
    7217             :                  array struct's members.  */
    7218     4581366 :               if (first && !array && !ANON_AGGR_TYPE_P (eltype))
    7219     2307034 :                 fmem->first = NULL_TREE;
    7220             : 
    7221     7278729 :               find_flexarrays (eltype, fmem, false, pun,
    7222     2697363 :                                !pstr && TREE_CODE (t) == RECORD_TYPE ? fld : pstr);
    7223             : 
    7224     4581366 :               if (fmem->array != array)
    7225        1262 :                 continue;
    7226             : 
    7227     4580104 :               if (first && !array && !ANON_AGGR_TYPE_P (eltype))
    7228             :                 {
    7229             :                   /* Restore the FIRST member reset above if no flexible
    7230             :                      array member has been found in this member's struct.  */
    7231     2306633 :                   fmem->first = first;
    7232             :                 }
    7233             : 
    7234             :               /* If the member struct contains the first flexible array
    7235             :                  member, or if this member is a base class, continue to
    7236             :                  the next member and avoid setting the FMEM->NEXT pointer
    7237             :                  to point to it.  */
    7238     4580104 :               if (base_p)
    7239      787859 :                 continue;
    7240             :             }
    7241             :         }
    7242             : 
    7243    22913023 :       if (field_nonempty_p (fld))
    7244             :         {
    7245             :           /* Remember the first non-static data member.  */
    7246    22807280 :           if (!fmem->first)
    7247     6341886 :             fmem->first = fld;
    7248             : 
    7249             :           /* Remember the first non-static data member after the flexible
    7250             :              array member, if one has been found, or the zero-length array
    7251             :              if it has been found.  */
    7252    22807280 :           if (fmem->array && !fmem->after[bool (pun)])
    7253        1581 :             fmem->after[bool (pun)] = fld;
    7254             :         }
    7255             : 
    7256             :       /* Skip non-arrays.  */
    7257    22913023 :       if (TREE_CODE (fldtype) != ARRAY_TYPE)
    7258    21024602 :         continue;
    7259             : 
    7260             :       /* Determine the upper bound of the array if it has one.  */
    7261     1888421 :       if (TYPE_DOMAIN (fldtype))
    7262             :         {
    7263     1886777 :           if (fmem->array)
    7264             :             {
    7265             :               /* Make a record of the zero-length array if either one
    7266             :                  such field or a flexible array member has been seen to
    7267             :                  handle the pathological and unlikely case of multiple
    7268             :                  such members.  */
    7269        1049 :               if (!fmem->after[bool (pun)])
    7270          79 :                 fmem->after[bool (pun)] = fld;
    7271             :             }
    7272     1885728 :           else if (integer_all_onesp (TYPE_MAX_VALUE (TYPE_DOMAIN (fldtype))))
    7273             :             {
    7274             :               /* Remember the first zero-length array unless a flexible array
    7275             :                  member has already been seen.  */
    7276        2486 :               fmem->array = fld;
    7277        2486 :               fmem->enclosing = pstr;
    7278             :             }
    7279             :         }
    7280             :       else
    7281             :         {
    7282             :           /* Flexible array members have no upper bound.  */
    7283        1644 :           if (fmem->array)
    7284             :             {
    7285         124 :               if (TYPE_DOMAIN (TREE_TYPE (fmem->array)))
    7286             :                 {
    7287             :                   /* Replace the zero-length array if it's been stored and
    7288             :                      reset the after pointer.  */
    7289          38 :                   fmem->after[bool (pun)] = NULL_TREE;
    7290          38 :                   fmem->array = fld;
    7291          38 :                   fmem->enclosing = pstr;
    7292             :                 }
    7293          86 :               else if (!fmem->after[bool (pun)])
    7294             :                 /* Make a record of another flexible array member.  */
    7295          20 :                 fmem->after[bool (pun)] = fld;
    7296             :             }
    7297             :           else
    7298             :             {
    7299        1520 :               fmem->array = fld;
    7300        1520 :               fmem->enclosing = pstr;
    7301             :             }
    7302             :         }
    7303             :     }
    7304             : }
    7305             : 
    7306             : /* Diagnose a strictly (by the C standard) invalid use of a struct with
    7307             :    a flexible array member (or the zero-length array extension).  */
    7308             : 
    7309             : static void
    7310        2097 : diagnose_invalid_flexarray (const flexmems_t *fmem)
    7311             : {
    7312        2097 :   if (fmem->array && fmem->enclosing)
    7313             :     {
    7314         636 :       auto_diagnostic_group d;
    7315         636 :       if (pedwarn (location_of (fmem->enclosing), OPT_Wpedantic,
    7316         636 :                      TYPE_DOMAIN (TREE_TYPE (fmem->array))
    7317             :                      ? G_("invalid use of %q#T with a zero-size array "
    7318             :                           "in %q#D")
    7319             :                      : G_("invalid use of %q#T with a flexible array member "
    7320             :                           "in %q#T"),
    7321         636 :                      DECL_CONTEXT (fmem->array),
    7322         636 :                      DECL_CONTEXT (fmem->enclosing)))
    7323          88 :         inform (DECL_SOURCE_LOCATION (fmem->array),
    7324          88 :                   "array member %q#D declared here", fmem->array);
    7325         636 :     }
    7326        2097 : }
    7327             : 
    7328             : /* Issue diagnostics for invalid flexible array members or zero-length
    7329             :    arrays that are not the last elements of the containing class or its
    7330             :    base classes or that are its sole members.  */
    7331             : 
    7332             : static void
    7333    24928935 : diagnose_flexarrays (tree t, const flexmems_t *fmem)
    7334             : {
    7335    24928935 :   if (!fmem->array)
    7336             :     return;
    7337             : 
    7338        4006 :   if (fmem->first && !fmem->after[0])
    7339             :     {
    7340        1806 :       diagnose_invalid_flexarray (fmem);
    7341        1806 :       return;
    7342             :     }
    7343             : 
    7344             :   /* Has a diagnostic been issued?  */
    7345        2200 :   bool diagd = false;
    7346             : 
    7347        2200 :   const char *msg = 0;
    7348             : 
    7349        2200 :   if (TYPE_DOMAIN (TREE_TYPE (fmem->array)))
    7350             :     {
    7351        1679 :       if (fmem->after[0])
    7352             :         msg = G_("zero-size array member %qD not at end of %q#T");
    7353         295 :       else if (!fmem->first)
    7354             :         msg = G_("zero-size array member %qD in an otherwise empty %q#T");
    7355             : 
    7356             :       if (msg)
    7357             :         {
    7358        1679 :           location_t loc = DECL_SOURCE_LOCATION (fmem->array);
    7359             : 
    7360        1679 :           auto_diagnostic_group d;
    7361        1679 :           if (pedwarn (loc, OPT_Wpedantic, msg, fmem->array, t))
    7362             :             {
    7363         192 :               inform (location_of (t), "in the definition of %q#T", t);
    7364         192 :               diagd = true;
    7365             :             }
    7366        1679 :         }
    7367             :     }
    7368             :   else
    7369             :     {
    7370         521 :       if (fmem->after[0])
    7371             :         msg = G_("flexible array member %qD not at end of %q#T");
    7372         241 :       else if (!fmem->first)
    7373             :         msg = G_("flexible array member %qD in an otherwise empty %q#T");
    7374             : 
    7375             :       if (msg)
    7376             :         {
    7377         521 :           location_t loc = DECL_SOURCE_LOCATION (fmem->array);
    7378         521 :           diagd = true;
    7379             : 
    7380         521 :           auto_diagnostic_group d;
    7381         521 :           error_at (loc, msg, fmem->array, t);
    7382             : 
    7383             :           /* In the unlikely event that the member following the flexible
    7384             :              array member is declared in a different class, or the member
    7385             :              overlaps another member of a common union, point to it.
    7386             :              Otherwise it should be obvious.  */
    7387         521 :           if (fmem->after[0]
    7388         521 :               && ((DECL_CONTEXT (fmem->after[0])
    7389         280 :                    != DECL_CONTEXT (fmem->array))))
    7390             :             {
    7391         136 :               inform (DECL_SOURCE_LOCATION (fmem->after[0]),
    7392             :                       "next member %q#D declared here",
    7393             :                       fmem->after[0]);
    7394         136 :               inform (location_of (t), "in the definition of %q#T", t);
    7395             :             }
    7396         521 :         }
    7397             :     }
    7398             : 
    7399        2200 :   if (!diagd && fmem->array && fmem->enclosing)
    7400         291 :     diagnose_invalid_flexarray (fmem);
    7401             : }
    7402             : 
    7403             : 
    7404             : /* Recursively check to make sure that any flexible array or zero-length
    7405             :    array members of class T or its bases are valid (i.e., not the sole
    7406             :    non-static data member of T and, if one exists, that it is the last
    7407             :    non-static data member of T and its base classes.  FMEM is expected
    7408             :    to be initially null and is used internally by recursive calls to
    7409             :    the function.  Issue the appropriate diagnostics for the array member
    7410             :    that fails the checks.  */
    7411             : 
    7412             : static void
    7413    43116457 : check_flexarrays (tree t, flexmems_t *fmem /* = NULL */,
    7414             :                   bool base_p /* = false */)
    7415             : {
    7416             :   /* Initialize the result of a search for flexible array and zero-length
    7417             :      array members.  Avoid doing any work if the most interesting FMEM data
    7418             :      have already been populated.  */
    7419    86232914 :   flexmems_t flexmems = flexmems_t ();
    7420    43116457 :   if (!fmem)
    7421             :     fmem = &flexmems;
    7422    17176713 :   else if (fmem->array && fmem->first && fmem->after[0])
    7423          12 :     return;
    7424             : 
    7425    43116445 :   tree fam = fmem->array;
    7426             : 
    7427             :   /* Recursively check the primary base class first.  */
    7428    43116445 :   if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    7429             :     {
    7430     1700180 :       tree basetype = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (t));
    7431     1700180 :       check_flexarrays (basetype, fmem, true);
    7432             :     }
    7433             : 
    7434             :   /* Recursively check the base classes.  */
    7435    43116445 :   int nbases = TYPE_BINFO (t) ? BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) : 0;
    7436    60344927 :   for (int i = 0; i < nbases; ++i)
    7437             :     {
    7438    17228482 :       tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (t), i);
    7439             : 
    7440             :       /* The primary base class was already checked above.  */
    7441    17228482 :       if (base_binfo == CLASSTYPE_PRIMARY_BINFO (t))
    7442     1700001 :         continue;
    7443             : 
    7444             :       /* Virtual base classes are at the end.  */
    7445    15528481 :       if (BINFO_VIRTUAL_P (base_binfo))
    7446      203524 :         continue;
    7447             : 
    7448             :       /* Check the base class.  */
    7449    15324957 :       check_flexarrays (BINFO_TYPE (base_binfo), fmem, /*base_p=*/true);
    7450             :     }
    7451             : 
    7452    43116445 :   if (fmem == &flexmems)
    7453             :     {
    7454             :       /* Check virtual base classes only once per derived class.
    7455             :          I.e., this check is not performed recursively for base
    7456             :          classes.  */
    7457    25939744 :       int i;
    7458    25939744 :       tree base_binfo;
    7459    25939744 :       vec<tree, va_gc> *vbases;
    7460    26091320 :       for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    7461    26091320 :            vec_safe_iterate (vbases, i, &base_binfo); i++)
    7462             :         {
    7463             :           /* Check the virtual base class.  */
    7464      151576 :           tree basetype = TREE_TYPE (base_binfo);
    7465             : 
    7466      151576 :           check_flexarrays (basetype, fmem, /*base_p=*/true);
    7467             :         }
    7468             :     }
    7469             : 
    7470             :   /* Is the type unnamed (and therefore a member of it potentially
    7471             :      an anonymous struct or union)?  */
    7472    87574578 :   bool maybe_anon_p = TYPE_UNNAMED_P (t);
    7473     1298391 :   if (tree ctx = maybe_anon_p ? TYPE_CONTEXT (t) : NULL_TREE)
    7474     1298391 :     maybe_anon_p = RECORD_OR_UNION_TYPE_P (ctx);
    7475             : 
    7476             :   /* Search the members of the current (possibly derived) class, skipping
    7477             :      unnamed structs and unions since those could be anonymous.  */
    7478    43116445 :   if (fmem != &flexmems || !maybe_anon_p)
    7479    59282567 :     find_flexarrays (t, fmem, base_p || fam != fmem->array);
    7480             : 
    7481    43116445 :   if (fmem == &flexmems && !maybe_anon_p)
    7482             :     {
    7483             :       /* Issue diagnostics for invalid flexible and zero-length array
    7484             :          members found in base classes or among the members of the current
    7485             :          class.  Ignore anonymous structs and unions whose members are
    7486             :          considered to be members of the enclosing class and thus will
    7487             :          be diagnosed when checking it.  */
    7488    24928935 :       diagnose_flexarrays (t, fmem);
    7489             :     }
    7490             : }
    7491             : 
    7492             : /* Perform processing required when the definition of T (a class type)
    7493             :    is complete.  Diagnose invalid definitions of flexible array members
    7494             :    and zero-size arrays.  */
    7495             : 
    7496             : void
    7497    25156660 : finish_struct_1 (tree t)
    7498             : {
    7499    25156660 :   tree x;
    7500             :   /* A TREE_LIST.  The TREE_VALUE of each node is a FUNCTION_DECL.  */
    7501    25156660 :   tree virtuals = NULL_TREE;
    7502             : 
    7503    25156660 :   if (COMPLETE_TYPE_P (t))
    7504             :     {
    7505           0 :       gcc_assert (MAYBE_CLASS_TYPE_P (t));
    7506           0 :       error ("redefinition of %q#T", t);
    7507           0 :       popclass ();
    7508           0 :       return;
    7509             :     }
    7510             : 
    7511             :   /* If this type was previously laid out as a forward reference,
    7512             :      make sure we lay it out again.  */
    7513    25156660 :   TYPE_SIZE (t) = NULL_TREE;
    7514    25156660 :   CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
    7515             : 
    7516             :   /* Make assumptions about the class; we'll reset the flags if
    7517             :      necessary.  */
    7518    25156660 :   CLASSTYPE_EMPTY_P (t) = 1;
    7519    25156660 :   CLASSTYPE_NEARLY_EMPTY_P (t) = 1;
    7520    25156660 :   CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 0;
    7521    25156660 :   CLASSTYPE_LITERAL_P (t) = true;
    7522             : 
    7523             :   /* Do end-of-class semantic processing: checking the validity of the
    7524             :      bases and members and add implicitly generated methods.  */
    7525    25156660 :   check_bases_and_members (t);
    7526             : 
    7527             :   /* Find the key method.  */
    7528    25156660 :   if (TYPE_CONTAINS_VPTR_P (t))
    7529             :     {
    7530             :       /* The Itanium C++ ABI permits the key method to be chosen when
    7531             :          the class is defined -- even though the key method so
    7532             :          selected may later turn out to be an inline function.  On
    7533             :          some systems (such as ARM Symbian OS) the key method cannot
    7534             :          be determined until the end of the translation unit.  On such
    7535             :          systems, we leave CLASSTYPE_KEY_METHOD set to NULL, which
    7536             :          will cause the class to be added to KEYED_CLASSES.  Then, in
    7537             :          finish_file we will determine the key method.  */
    7538     1144766 :       if (targetm.cxx.key_method_may_be_inline ())
    7539     1144766 :         determine_key_method (t);
    7540             : 
    7541             :       /* If a polymorphic class has no key method, we may emit the vtable
    7542             :          in every translation unit where the class definition appears.  If
    7543             :          we're devirtualizing, we can look into the vtable even if we
    7544             :          aren't emitting it.  */
    7545     1144766 :       if (!CLASSTYPE_KEY_METHOD (t))
    7546      737629 :         vec_safe_push (keyed_classes, t);
    7547             :     }
    7548             : 
    7549             :   /* Layout the class itself.  */
    7550    25156660 :   layout_class_type (t, &virtuals);
    7551             :   /* COMPLETE_TYPE_P is now true.  */
    7552             : 
    7553    25156660 :   set_class_bindings (t);
    7554             : 
    7555             :   /* With the layout complete, check for flexible array members and
    7556             :      zero-length arrays that might overlap other members in the final
    7557             :      layout.  */
    7558    25156660 :   check_flexarrays (t);
    7559             : 
    7560    25156660 :   virtuals = modify_all_vtables (t, nreverse (virtuals));
    7561             : 
    7562             :   /* If necessary, create the primary vtable for this class.  */
    7563    25156660 :   if (virtuals || TYPE_CONTAINS_VPTR_P (t))
    7564             :     {
    7565             :       /* We must enter these virtuals into the table.  */
    7566     1144766 :       if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    7567      173804 :         build_primary_vtable (NULL_TREE, t);
    7568      970962 :       else if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
    7569             :         /* Here we know enough to change the type of our virtual
    7570             :            function table, but we will wait until later this function.  */
    7571           0 :         build_primary_vtable (CLASSTYPE_PRIMARY_BINFO (t), t);
    7572             : 
    7573             :       /* If we're warning about ABI tags, check the types of the new
    7574             :          virtual functions.  */
    7575     1144766 :       if (warn_abi_tag)
    7576           8 :         for (tree v = virtuals; v; v = TREE_CHAIN (v))
    7577           4 :           check_abi_tags (t, TREE_VALUE (v));
    7578             :     }
    7579             : 
    7580    25156660 :   if (TYPE_CONTAINS_VPTR_P (t))
    7581             :     {
    7582     1144766 :       int vindex;
    7583     1144766 :       tree fn;
    7584             : 
    7585     1144766 :       if (BINFO_VTABLE (TYPE_BINFO (t)))
    7586     1144766 :         gcc_assert (DECL_VIRTUAL_P (BINFO_VTABLE (TYPE_BINFO (t))));
    7587     1144766 :       if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    7588      173804 :         gcc_assert (BINFO_VIRTUALS (TYPE_BINFO (t)) == NULL_TREE);
    7589             : 
    7590             :       /* Add entries for virtual functions introduced by this class.  */
    7591     1144766 :       BINFO_VIRTUALS (TYPE_BINFO (t))
    7592     1144766 :         = chainon (BINFO_VIRTUALS (TYPE_BINFO (t)), virtuals);
    7593             : 
    7594             :       /* Set DECL_VINDEX for all functions declared in this class.  */
    7595     1144766 :       for (vindex = 0, fn = BINFO_VIRTUALS (TYPE_BINFO (t));
    7596     7742693 :            fn;
    7597     6597927 :            fn = TREE_CHAIN (fn),
    7598     6597927 :              vindex += (TARGET_VTABLE_USES_DESCRIPTORS
    7599             :                         ? TARGET_VTABLE_USES_DESCRIPTORS : 1))
    7600             :         {
    7601     6597927 :           tree fndecl = BV_FN (fn);
    7602             : 
    7603     6597927 :           if (DECL_THUNK_P (fndecl))
    7604             :             /* A thunk. We should never be calling this entry directly
    7605             :                from this vtable -- we'd use the entry for the non
    7606             :                thunk base function.  */
    7607         158 :             DECL_VINDEX (fndecl) = NULL_TREE;
    7608     6597769 :           else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
    7609     5312523 :             DECL_VINDEX (fndecl) = build_int_cst (NULL_TREE, vindex);
    7610             :         }
    7611             :     }
    7612             : 
    7613    25156660 :   finish_struct_bits (t);
    7614             : 
    7615    25156660 :   set_method_tm_attributes (t);
    7616    25156660 :   if (flag_openmp || flag_openmp_simd)
    7617       23141 :     finish_omp_declare_simd_methods (t);
    7618             : 
    7619             :   /* Clear DECL_IN_AGGR_P for all member functions.  Complete the rtl
    7620             :      for any static member objects of the type we're working on.  */
    7621   226131426 :   for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    7622   200974766 :     if (DECL_DECLARES_FUNCTION_P (x))
    7623             :       {
    7624             :         /* Synthesize constexpr defaulted comparisons.  */
    7625   113971136 :         if (!DECL_ARTIFICIAL (x)
    7626   113451617 :             && DECL_DEFAULTED_IN_CLASS_P (x)
    7627   122577788 :             && special_function_p (x) == sfk_comparison)
    7628        3241 :           defaulted_late_check (x);
    7629   113971136 :         DECL_IN_AGGR_P (x) = false;
    7630             :       }
    7631    87003630 :     else if (VAR_P (x) && TREE_STATIC (x)
    7632     6339337 :              && TREE_TYPE (x) != error_mark_node
    7633    93342917 :              && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t))
    7634       16949 :       SET_DECL_MODE (x, TYPE_MODE (t));
    7635             : 
    7636             :   /* Complain if one of the field types requires lower visibility.  */
    7637    25156660 :   constrain_class_visibility (t);
    7638             : 
    7639             :   /* Make the rtl for any new vtables we have created, and unmark
    7640             :      the base types we marked.  */
    7641    25156660 :   finish_vtbls (t);
    7642             : 
    7643             :   /* Build the VTT for T.  */
    7644    25156660 :   build_vtt (t);
    7645             : 
    7646    25156660 :   if (warn_nonvdtor
    7647         194 :       && TYPE_POLYMORPHIC_P (t) && accessible_nvdtor_p (t)
    7648    25156707 :       && !CLASSTYPE_FINAL (t))
    7649          44 :     warning (OPT_Wnon_virtual_dtor,
    7650             :              "%q#T has virtual functions and accessible"
    7651             :              " non-virtual destructor", t);
    7652             : 
    7653    25156660 :   complete_vars (t);
    7654             : 
    7655    25156660 :   if (warn_overloaded_virtual)
    7656      290223 :     warn_hidden (t);
    7657             : 
    7658             :   /* Class layout, assignment of virtual table slots, etc., is now
    7659             :      complete.  Give the back end a chance to tweak the visibility of
    7660             :      the class or perform any other required target modifications.  */
    7661    25156660 :   targetm.cxx.adjust_class_at_definition (t);
    7662             : 
    7663    25156660 :   maybe_suppress_debug_info (t);
    7664             : 
    7665    25156660 :   if (flag_vtable_verify)
    7666          16 :     vtv_save_class_info (t);
    7667             : 
    7668    25156660 :   dump_class_hierarchy (t);
    7669             : 
    7670             :   /* Finish debugging output for this type.  */
    7671    25156660 :   rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
    7672             : 
    7673    25156660 :   if (TYPE_TRANSPARENT_AGGR (t))
    7674             :     {
    7675         180 :       tree field = first_field (t);
    7676         180 :       if (field == NULL_TREE || error_operand_p (field))
    7677             :         {
    7678          12 :           error ("type transparent %q#T does not have any fields", t);
    7679          12 :           TYPE_TRANSPARENT_AGGR (t) = 0;
    7680             :         }
    7681         168 :       else if (DECL_ARTIFICIAL (field))
    7682             :         {
    7683           4 :           if (DECL_FIELD_IS_BASE (field))
    7684           4 :             error ("type transparent class %qT has base classes", t);
    7685             :           else
    7686             :             {
    7687           0 :               gcc_checking_assert (DECL_VIRTUAL_P (field));
    7688           0 :               error ("type transparent class %qT has virtual functions", t);
    7689             :             }
    7690           4 :           TYPE_TRANSPARENT_AGGR (t) = 0;
    7691             :         }
    7692         164 :       else if (TYPE_MODE (t) != DECL_MODE (field))
    7693             :         {
    7694           4 :           error ("type transparent %q#T cannot be made transparent because "
    7695             :                  "the type of the first field has a different ABI from the "
    7696             :                  "class overall", t);
    7697           4 :           TYPE_TRANSPARENT_AGGR (t) = 0;
    7698             :         }
    7699             :     }
    7700             : }
    7701             : 
    7702             : /* When T was built up, the member declarations were added in reverse
    7703             :    order.  Rearrange them to declaration order.  */
    7704             : 
    7705             : void
    7706    37164175 : unreverse_member_declarations (tree t)
    7707             : {
    7708    37164175 :   tree next;
    7709    37164175 :   tree prev;
    7710    37164175 :   tree x;
    7711             : 
    7712             :   /* The following lists are all in reverse order.  Put them in
    7713             :      declaration order now.  */
    7714    37164175 :   CLASSTYPE_DECL_LIST (t) = nreverse (CLASSTYPE_DECL_LIST (t));
    7715             : 
    7716             :   /* For the TYPE_FIELDS, only the non TYPE_DECLs are in reverse
    7717             :      order, so we can't just use nreverse.  Due to stat_hack
    7718             :      chicanery in finish_member_declaration.  */
    7719    37164175 :   prev = NULL_TREE;
    7720    37164175 :   for (x = TYPE_FIELDS (t);
    7721   184878860 :        x && TREE_CODE (x) != TYPE_DECL;
    7722   147714685 :        x = next)
    7723             :     {
    7724   147714685 :       next = DECL_CHAIN (x);
    7725   147714685 :       DECL_CHAIN (x) = prev;
    7726   147714685 :       prev = x;
    7727             :     }
    7728             : 
    7729    37164175 :   if (prev)
    7730             :     {
    7731    14443099 :       DECL_CHAIN (TYPE_FIELDS (t)) = x;
    7732    14443099 :       TYPE_FIELDS (t) = prev;
    7733             :     }
    7734    37164175 : }
    7735             : 
    7736             : tree
    7737    17932196 : finish_struct (tree t, tree attributes)
    7738             : {
    7739    17932196 :   location_t saved_loc = input_location;
    7740             : 
    7741             :   /* Now that we've got all the field declarations, reverse everything
    7742             :      as necessary.  */
    7743    17932196 :   unreverse_member_declarations (t);
    7744             : 
    7745    17932196 :   cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
    7746    17932196 :   fixup_attribute_variants (t);
    7747             : 
    7748             :   /* Nadger the current location so that diagnostics point to the start of
    7749             :      the struct, not the end.  */
    7750    17932196 :   input_location = DECL_SOURCE_LOCATION (TYPE_NAME (t));
    7751             : 
    7752    17932196 :   if (processing_template_decl)
    7753             :     {
    7754    12007515 :       tree x;
    7755             : 
    7756    88225481 :       for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    7757    76217966 :         if (DECL_DECLARES_FUNCTION_P (x))
    7758             :           {
    7759    42533286 :             DECL_IN_AGGR_P (x) = false;
    7760    42533286 :             if (DECL_VIRTUAL_P (x))
    7761     1282996 :               CLASSTYPE_NON_AGGREGATE (t) = true;
    7762             :           }
    7763    33684680 :         else if (TREE_CODE (x) == FIELD_DECL)
    7764             :           {
    7765     5358172 :             if (TREE_PROTECTED (x) || TREE_PRIVATE (x))
    7766     3013307 :               CLASSTYPE_NON_AGGREGATE (t) = true;
    7767             :           }
    7768             : 
    7769             :       /* Also add a USING_DECL for operator=.  We know there'll be (at
    7770             :          least) one, but we don't know the signature(s).  We want name
    7771             :          lookup not to fail or recurse into bases.  This isn't added
    7772             :          to the template decl list so we drop this at instantiation
    7773             :          time.  */
    7774    12007515 :       tree ass_op = build_lang_decl (USING_DECL, assign_op_identifier,
    7775             :                                      NULL_TREE);
    7776    12007515 :       DECL_CONTEXT (ass_op) = t;
    7777    12007515 :       USING_DECL_SCOPE (ass_op) = t;
    7778    12007515 :       DECL_DEPENDENT_P (ass_op) = true;
    7779    12007515 :       DECL_ARTIFICIAL (ass_op) = true;
    7780    12007515 :       DECL_CHAIN (ass_op) = TYPE_FIELDS (t);
    7781    12007515 :       TYPE_FIELDS (t) = ass_op;
    7782             : 
    7783    12007515 :       TYPE_SIZE (t) = bitsize_zero_node;
    7784    12007515 :       TYPE_SIZE_UNIT (t) = size_zero_node;
    7785             :       /* COMPLETE_TYPE_P is now true.  */
    7786             : 
    7787    12007515 :       set_class_bindings (t);
    7788             : 
    7789             :       /* We need to emit an error message if this type was used as a parameter
    7790             :          and it is an abstract type, even if it is a template. We construct
    7791             :          a simple CLASSTYPE_PURE_VIRTUALS list without taking bases into
    7792             :          account and we call complete_vars with this type, which will check
    7793             :          the PARM_DECLS. Note that while the type is being defined,
    7794             :          CLASSTYPE_PURE_VIRTUALS contains the list of the inline friends
    7795             :          (see CLASSTYPE_INLINE_FRIENDS) so we need to clear it.  */
    7796    12007515 :       CLASSTYPE_PURE_VIRTUALS (t) = NULL;
    7797   100232996 :       for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    7798    88225481 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_PURE_VIRTUAL_P (x))
    7799      183805 :           vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    7800    12007515 :       complete_vars (t);
    7801             : 
    7802             :       /* Remember current #pragma pack value.  */
    7803    12007515 :       TYPE_PRECISION (t) = maximum_field_alignment;
    7804             : 
    7805    12007515 :       if (cxx_dialect < cxx20)
    7806             :         {
    7807    10900309 :           if (!CLASSTYPE_NON_AGGREGATE (t)
    7808    10900309 :               && type_has_user_provided_or_explicit_constructor (t))
    7809     1135836 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    7810             :         }
    7811     1107206 :       else if (TYPE_HAS_USER_CONSTRUCTOR (t))
    7812      133831 :         CLASSTYPE_NON_AGGREGATE (t) = 1;
    7813             : 
    7814             :       /* Fix up any variants we've already built.  */
    7815    12007515 :       fixup_type_variants (t);
    7816             :     }
    7817             :   else
    7818     5924681 :     finish_struct_1 (t);
    7819             :   /* COMPLETE_TYPE_P is now true.  */
    7820             : 
    7821    17932196 :   maybe_warn_about_overly_private_class (t);
    7822             :   
    7823    17932196 :   if (is_std_init_list (t))
    7824             :     {
    7825             :       /* People keep complaining that the compiler crashes on an invalid
    7826             :          definition of initializer_list, so I guess we should explicitly
    7827             :          reject it.  What the compiler internals care about is that it's a
    7828             :          template and has a pointer field followed by size_type field.  */
    7829       10759 :       bool ok = false;
    7830       10759 :       if (processing_template_decl)
    7831             :         {
    7832       10759 :           tree f = next_aggregate_field (TYPE_FIELDS (t));
    7833       10759 :           if (f && TYPE_PTR_P (TREE_TYPE (f)))
    7834             :             {
    7835       10756 :               f = next_aggregate_field (DECL_CHAIN (f));
    7836       10756 :               if (f && same_type_p (TREE_TYPE (f), size_type_node))
    7837             :                 ok = true;
    7838             :             }
    7839             :         }
    7840             :       /* It also cannot be a union.  */
    7841       10759 :       ok &= NON_UNION_CLASS_TYPE_P (t);
    7842       10759 :       if (!ok)
    7843           9 :         fatal_error (input_location, "definition of %qD does not match "
    7844           9 :                      "%<#include <initializer_list>%>", TYPE_NAME (t));
    7845             :     }
    7846             : 
    7847    17932187 :   input_location = saved_loc;
    7848             : 
    7849    17932187 :   TYPE_BEING_DEFINED (t) = 0;
    7850             : 
    7851    17932187 :   if (current_class_type)
    7852    17932187 :     popclass ();
    7853             :   else
    7854           0 :     error ("trying to finish struct, but kicked out due to previous parse errors");
    7855             : 
    7856    17932187 :   if (flag_openmp)
    7857      141923 :     for (tree decl = TYPE_FIELDS (t); decl; decl = DECL_CHAIN (decl))
    7858      117176 :       if (TREE_CODE (decl) == FUNCTION_DECL
    7859      117176 :           && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl))
    7860       27146 :         if (tree attr = lookup_attribute ("omp declare variant base",
    7861       27146 :                                           DECL_ATTRIBUTES (decl)))
    7862         118 :           omp_declare_variant_finalize (decl, attr);
    7863             : 
    7864    12007506 :   if (processing_template_decl && at_function_scope_p ()
    7865             :       /* Lambdas are defined by the LAMBDA_EXPR.  */
    7866    18556294 :       && !LAMBDA_TYPE_P (t))
    7867      106970 :     add_stmt (build_min (TAG_DEFN, t));
    7868             : 
    7869    17932187 :   return t;
    7870             : }
    7871             : 
    7872             : /* Hash table to avoid endless recursion when handling references.  */
    7873             : static hash_table<nofree_ptr_hash<tree_node> > *fixed_type_or_null_ref_ht;
    7874             : 
    7875             : /* Return the dynamic type of INSTANCE, if known.
    7876             :    Used to determine whether the virtual function table is needed
    7877             :    or not.
    7878             : 
    7879             :    *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
    7880             :    of our knowledge of its type.  *NONNULL should be initialized
    7881             :    before this function is called.  */
    7882             : 
    7883             : static tree
    7884     6596495 : fixed_type_or_null (tree instance, int *nonnull, int *cdtorp)
    7885             : {
    7886             : #define RECUR(T) fixed_type_or_null((T), nonnull, cdtorp)
    7887             : 
    7888     6596495 :   switch (TREE_CODE (instance))
    7889             :     {
    7890      376231 :     case INDIRECT_REF:
    7891      376231 :       if (INDIRECT_TYPE_P (TREE_TYPE (instance)))
    7892             :         return NULL_TREE;
    7893             :       else
    7894      344751 :         return RECUR (TREE_OPERAND (instance, 0));
    7895             : 
    7896      186340 :     case CALL_EXPR:
    7897             :       /* This is a call to a constructor, hence it's never zero.  */
    7898      186340 :       if (CALL_EXPR_FN (instance)
    7899      186340 :           && TREE_HAS_CONSTRUCTOR (instance))
    7900             :         {
    7901           0 :           if (nonnull)
    7902           0 :             *nonnull = 1;
    7903           0 :           return TREE_TYPE (instance);
    7904             :         }
    7905             :       return NULL_TREE;
    7906             : 
    7907       57648 :     case SAVE_EXPR:
    7908             :       /* This is a call to a constructor, hence it's never zero.  */
    7909       57648 :       if (TREE_HAS_CONSTRUCTOR (instance))
    7910             :         {
    7911           0 :           if (nonnull)
    7912           0 :             *nonnull = 1;
    7913           0 :           return TREE_TYPE (instance);
    7914             :         }
    7915       57648 :       return RECUR (TREE_OPERAND (instance, 0));
    7916             : 
    7917         255 :     case POINTER_PLUS_EXPR:
    7918         255 :     case PLUS_EXPR:
    7919         255 :     case MINUS_EXPR:
    7920         255 :       if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
    7921          32 :         return RECUR (TREE_OPERAND (instance, 0));
    7922         223 :       if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
    7923             :         /* Propagate nonnull.  */
    7924           0 :         return RECUR (TREE_OPERAND (instance, 0));
    7925             : 
    7926             :       return NULL_TREE;
    7927             : 
    7928     1546799 :     CASE_CONVERT:
    7929     1546799 :       return RECUR (TREE_OPERAND (instance, 0));
    7930             : 
    7931      604646 :     case ADDR_EXPR:
    7932      604646 :       instance = TREE_OPERAND (instance, 0);
    7933      604646 :       if (nonnull)
    7934             :         {
    7935             :           /* Just because we see an ADDR_EXPR doesn't mean we're dealing
    7936             :              with a real object -- given &p->f, p can still be null.  */
    7937      603212 :           tree t = get_base_address (instance);
    7938             :           /* ??? Probably should check DECL_WEAK here.  */
    7939      603212 :           if (t && DECL_P (t))
    7940       28708 :             *nonnull = 1;
    7941             :         }
    7942      604646 :       return RECUR (instance);
    7943             : 
    7944      370499 :     case COMPONENT_REF:
    7945             :       /* If this component is really a base class reference, then the field
    7946             :          itself isn't definitive.  */
    7947      370499 :       if (DECL_FIELD_IS_BASE (TREE_OPERAND (instance, 1)))
    7948        1043 :         return RECUR (TREE_OPERAND (instance, 0));
    7949      369456 :       return RECUR (TREE_OPERAND (instance, 1));
    7950             : 
    7951      432650 :     case VAR_DECL:
    7952      432650 :     case FIELD_DECL:
    7953      432650 :       if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
    7954      432654 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
    7955             :         {
    7956           4 :           if (nonnull)
    7957           4 :             *nonnull = 1;
    7958           4 :           return TREE_TYPE (TREE_TYPE (instance));
    7959             :         }
    7960             :       /* fall through.  */
    7961     3311340 :     case TARGET_EXPR:
    7962     3311340 :     case PARM_DECL:
    7963     3311340 :     case RESULT_DECL:
    7964     3915743 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (instance)))
    7965             :         {
    7966      604403 :           if (nonnull)
    7967      603073 :             *nonnull = 1;
    7968      604403 :           return TREE_TYPE (instance);
    7969             :         }
    7970     2706937 :       else if (instance == current_class_ptr)
    7971             :         {
    7972     2293458 :           if (nonnull)
    7973     1780040 :             *nonnull = 1;
    7974             : 
    7975             :           /* if we're in a ctor or dtor, we know our type.  If
    7976             :              current_class_ptr is set but we aren't in a function, we're in
    7977             :              an NSDMI (and therefore a constructor).  */
    7978     2293458 :           if (current_scope () != current_function_decl
    7979     2293458 :               || (DECL_LANG_SPECIFIC (current_function_decl)
    7980     4586776 :                   && (DECL_CONSTRUCTOR_P (current_function_decl)
    7981      863240 :                       || DECL_DESTRUCTOR_P (current_function_decl))))
    7982             :             {
    7983     1464632 :               if (cdtorp)
    7984     1464632 :                 *cdtorp = 1;
    7985     1464632 :               return TREE_TYPE (TREE_TYPE (instance));
    7986             :             }
    7987             :         }
    7988      413479 :       else if (TYPE_REF_P (TREE_TYPE (instance)))
    7989             :         {
    7990             :           /* We only need one hash table because it is always left empty.  */
    7991      350358 :           if (!fixed_type_or_null_ref_ht)
    7992        9927 :             fixed_type_or_null_ref_ht
    7993        9927 :               = new hash_table<nofree_ptr_hash<tree_node> > (37);
    7994             : 
    7995             :           /* Reference variables should be references to objects.  */
    7996      350358 :           if (nonnull)
    7997      348772 :             *nonnull = 1;
    7998             : 
    7999             :           /* Enter the INSTANCE in a table to prevent recursion; a
    8000             :              variable's initializer may refer to the variable
    8001             :              itself.  */
    8002      350358 :           if (VAR_P (instance)
    8003       11866 :               && DECL_INITIAL (instance)
    8004        1599 :               && !type_dependent_expression_p_push (DECL_INITIAL (instance))
    8005      351957 :               && !fixed_type_or_null_ref_ht->find (instance))
    8006             :             {
    8007        1535 :               tree type;
    8008        1535 :               tree_node **slot;
    8009             : 
    8010        1535 :               slot = fixed_type_or_null_ref_ht->find_slot (instance, INSERT);
    8011        1535 :               *slot = instance;
    8012        1535 :               type = RECUR (DECL_INITIAL (instance));
    8013        1535 :               fixed_type_or_null_ref_ht->remove_elt (instance);
    8014             : 
    8015        1535 :               return type;
    8016             :             }
    8017             :         }
    8018             :       return NULL_TREE;
    8019             : 
    8020       51030 :     case VIEW_CONVERT_EXPR:
    8021       51030 :       if (location_wrapper_p (instance))
    8022       51030 :         return RECUR (TREE_OPERAND (instance, 0));
    8023             :       else
    8024             :         /* TODO: Recursion may be correct for some non-location-wrapper
    8025             :            uses of VIEW_CONVERT_EXPR.  */
    8026             :         return NULL_TREE;
    8027             : 
    8028             :     default:
    8029             :       return NULL_TREE;
    8030             :     }
    8031             : #undef RECUR
    8032             : }
    8033             : 
    8034             : /* Return nonzero if the dynamic type of INSTANCE is known, and
    8035             :    equivalent to the static type.  We also handle the case where
    8036             :    INSTANCE is really a pointer. Return negative if this is a
    8037             :    ctor/dtor. There the dynamic type is known, but this might not be
    8038             :    the most derived base of the original object, and hence virtual
    8039             :    bases may not be laid out according to this type.
    8040             : 
    8041             :    Used to determine whether the virtual function table is needed
    8042             :    or not.
    8043             : 
    8044             :    *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
    8045             :    of our knowledge of its type.  *NONNULL should be initialized
    8046             :    before this function is called.  */
    8047             : 
    8048             : int
    8049     3520792 : resolves_to_fixed_type_p (tree instance, int* nonnull)
    8050             : {
    8051     3520792 :   tree t = TREE_TYPE (instance);
    8052     3520792 :   int cdtorp = 0;
    8053     3520792 :   tree fixed;
    8054             : 
    8055             :   /* processing_template_decl can be false in a template if we're in
    8056             :      instantiate_non_dependent_expr, but we still want to suppress
    8057             :      this check.  */
    8058     3520792 :   if (in_template_context)
    8059             :     {
    8060             :       /* In a template we only care about the type of the result.  */
    8061      245577 :       if (nonnull)
    8062      245572 :         *nonnull = true;
    8063      245577 :       return true;
    8064             :     }
    8065             : 
    8066     3275215 :   fixed = fixed_type_or_null (instance, nonnull, &cdtorp);
    8067     3275215 :   if (INDIRECT_TYPE_P (t))
    8068     3274801 :     t = TREE_TYPE (t);
    8069     3275215 :   if (CLASS_TYPE_P (t) && CLASSTYPE_FINAL (t))
    8070             :     return 1;
    8071     3238653 :   if (fixed == NULL_TREE)
    8072             :     return 0;
    8073     2047481 :   if (!same_type_ignoring_top_level_qualifiers_p (t, fixed))
    8074             :     return 0;
    8075     2047123 :   return cdtorp ? -1 : 1;
    8076             : }
    8077             : 
    8078             : 
    8079             : void
    8080       89260 : init_class_processing (void)
    8081             : {
    8082       89260 :   current_class_depth = 0;
    8083       89260 :   current_class_stack_size = 10;
    8084       89260 :   current_class_stack
    8085       89260 :     = XNEWVEC (struct class_stack_node, current_class_stack_size);
    8086       89260 :   sizeof_biggest_empty_class = size_zero_node;
    8087             : 
    8088       89260 :   ridpointers[(int) RID_PUBLIC] = access_public_node;
    8089       89260 :   ridpointers[(int) RID_PRIVATE] = access_private_node;
    8090       89260 :   ridpointers[(int) RID_PROTECTED] = access_protected_node;
    8091       89260 : }
    8092             : 
    8093             : /* Restore the cached PREVIOUS_CLASS_LEVEL.  */
    8094             : 
    8095             : static void
    8096   122097163 : restore_class_cache (void)
    8097             : {
    8098   122097163 :   tree type;
    8099             : 
    8100             :   /* We are re-entering the same class we just left, so we don't
    8101             :      have to search the whole inheritance matrix to find all the
    8102             :      decls to bind again.  Instead, we install the cached
    8103             :      class_shadowed list and walk through it binding names.  */
    8104   122097163 :   push_binding_level (previous_class_level);
    8105   122097163 :   class_binding_level = previous_class_level;
    8106             :   /* Restore IDENTIFIER_TYPE_VALUE.  */
    8107   122097163 :   for (type = class_binding_level->type_shadowed;
    8108   667131490 :        type;
    8109   545034327 :        type = TREE_CHAIN (type))
    8110   545034327 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (type), TREE_TYPE (type));
    8111   122097163 : }
    8112             : 
    8113             : /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE as
    8114             :    appropriate for TYPE.
    8115             : 
    8116             :    So that we may avoid calls to lookup_name, we cache the _TYPE
    8117             :    nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
    8118             : 
    8119             :    For multiple inheritance, we perform a two-pass depth-first search
    8120             :    of the type lattice.  */
    8121             : 
    8122             : void
    8123   235272242 : pushclass (tree type)
    8124             : {
    8125   235272242 :   class_stack_node_t csn;
    8126             : 
    8127   235272242 :   type = TYPE_MAIN_VARIANT (type);
    8128             : 
    8129             :   /* Make sure there is enough room for the new entry on the stack.  */
    8130   235272242 :   if (current_class_depth + 1 >= current_class_stack_size)
    8131             :     {
    8132        7803 :       current_class_stack_size *= 2;
    8133        7803 :       current_class_stack
    8134        7803 :         = XRESIZEVEC (struct class_stack_node, current_class_stack,
    8135             :                       current_class_stack_size);
    8136             :     }
    8137             : 
    8138             :   /* Insert a new entry on the class stack.  */
    8139   235272242 :   csn = current_class_stack + current_class_depth;
    8140   235272242 :   csn->name = current_class_name;
    8141   235272242 :   csn->type = current_class_type;
    8142   235272242 :   csn->access = current_access_specifier;
    8143   235272242 :   csn->names_used = 0;
    8144   235272242 :   csn->hidden = 0;
    8145   235272242 :   current_class_depth++;
    8146             : 
    8147             :   /* Now set up the new type.  */
    8148   235272242 :   current_class_name = TYPE_NAME (type);
    8149   235272242 :   if (TREE_CODE (current_class_name) == TYPE_DECL)
    8150   235272242 :     current_class_name = DECL_NAME (current_class_name);
    8151   235272242 :   current_class_type = type;
    8152             : 
    8153             :   /* By default, things in classes are private, while things in
    8154             :      structures or unions are public.  */
    8155   235272242 :   current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
    8156   235272242 :                               ? access_private_node
    8157             :                               : access_public_node);
    8158             : 
    8159   235272242 :   if (previous_class_level
    8160   171493897 :       && type != previous_class_level->this_entity
    8161    46299743 :       && current_class_depth == 1)
    8162             :     {
    8163             :       /* Forcibly remove any old class remnants.  */
    8164    19021565 :       invalidate_class_lookup_cache ();
    8165             :     }
    8166             : 
    8167   235272242 :   if (!previous_class_level
    8168   152472332 :       || type != previous_class_level->this_entity
    8169   125194154 :       || current_class_depth > 1)
    8170   113175079 :     pushlevel_class ();
    8171             :   else
    8172   122097163 :     restore_class_cache ();
    8173   235272242 : }
    8174             : 
    8175             : /* Get out of the current class scope. If we were in a class scope
    8176             :    previously, that is the one popped to.  */
    8177             : 
    8178             : void
    8179   235250560 : popclass (void)
    8180             : {
    8181   235250560 :   poplevel_class ();
    8182             : 
    8183   235250557 :   current_class_depth--;
    8184   235250557 :   current_class_name = current_class_stack[current_class_depth].name;
    8185   235250557 :   current_class_type = current_class_stack[current_class_depth].type;
    8186   235250557 :   current_access_specifier = current_class_stack[current_class_depth].access;
    8187   235250557 :   if (current_class_stack[current_class_depth].names_used)
    8188     9731754 :     splay_tree_delete (current_class_stack[current_class_depth].names_used);
    8189   235250557 : }
    8190             : 
    8191             : /* Mark the top of the class stack as hidden.  */
    8192             : 
    8193             : void
    8194   174665668 : push_class_stack (void)
    8195             : {
    8196   174665668 :   if (current_class_depth)
    8197    97666370 :     ++current_class_stack[current_class_depth - 1].hidden;
    8198   174665668 : }
    8199             : 
    8200             : /* Mark the top of the class stack as un-hidden.  */
    8201             : 
    8202             : void
    8203   174548401 : pop_class_stack (void)
    8204             : {
    8205   174548401 :   if (current_class_depth)
    8206    97648322 :     --current_class_stack[current_class_depth - 1].hidden;
    8207   174548401 : }
    8208             : 
    8209             : /* If the class type currently being defined is either T or
    8210             :    a nested type of T, returns the type from the current_class_stack,
    8211             :    which might be equivalent to but not equal to T in case of
    8212             :    constrained partial specializations.  */
    8213             : 
    8214             : tree
    8215  2677513517 : currently_open_class (tree t)
    8216             : {
    8217  2677513517 :   int i;
    8218             : 
    8219  2677513517 :   if (!CLASS_TYPE_P (t))
    8220             :     return NULL_TREE;
    8221             : 
    8222  2595460731 :   t = TYPE_MAIN_VARIANT (t);
    8223             : 
    8224             :   /* We start looking from 1 because entry 0 is from global scope,
    8225             :      and has no type.  */
    8226  3052081812 :   for (i = current_class_depth; i > 0; --i)
    8227             :     {
    8228  2579190381 :       tree c;
    8229  2579190381 :       if (i == current_class_depth)
    8230  2384502482 :         c = current_class_type;
    8231             :       else
    8232             :         {
    8233   194687899 :           if (current_class_stack[i].hidden)
    8234             :             break;
    8235   157782589 :           c = current_class_stack[i].type;
    8236             :         }
    8237  2542285071 :       if (!c)
    8238    92815457 :         continue;
    8239  2449469614 :       if (same_type_p (c, t))
    8240  2085663990 :         return c;
    8241             :     }
    8242             :   return NULL_TREE;
    8243             : }
    8244             : 
    8245             : /* If either current_class_type or one of its enclosing classes are derived
    8246             :    from T, return the appropriate type.  Used to determine how we found
    8247             :    something via unqualified lookup.  */
    8248             : 
    8249             : tree
    8250    79253204 : currently_open_derived_class (tree t)
    8251             : {
    8252    79253204 :   int i;
    8253             : 
    8254             :   /* The bases of a dependent type are unknown.  */
    8255    79253204 :   if (dependent_type_p (t))
    8256             :     return NULL_TREE;
    8257             : 
    8258    76690289 :   if (!current_class_type)
    8259             :     return NULL_TREE;
    8260             : 
    8261    76629101 :   if (DERIVED_FROM_P (t, current_class_type))
    8262    74773982 :     return current_class_type;
    8263             : 
    8264     1892872 :   for (i = current_class_depth - 1; i > 0; --i)
    8265             :     {
    8266     1825508 :       if (current_class_stack[i].hidden)
    8267             :         break;
    8268     1825508 :       if (DERIVED_FROM_P (t, current_class_stack[i].type))
    8269     1787755 :         return current_class_stack[i].type;
    8270             :     }
    8271             : 
    8272             :   return NULL_TREE;
    8273             : }
    8274             : 
    8275             : /* Return the outermost enclosing class type that is still open, or
    8276             :    NULL_TREE.  */
    8277             : 
    8278             : tree
    8279          13 : outermost_open_class (void)
    8280             : {
    8281          13 :   if (!current_class_type)
    8282             :     return NULL_TREE;
    8283          13 :   tree r = NULL_TREE;
    8284          13 :   if (TYPE_BEING_DEFINED (current_class_type))
    8285          13 :     r = current_class_type;
    8286          13 :   for (int i = current_class_depth - 1; i > 0; --i)
    8287             :     {
    8288           0 :       if (current_class_stack[i].hidden)
    8289             :         break;
    8290           0 :       tree t = current_class_stack[i].type;
    8291           0 :       if (!TYPE_BEING_DEFINED (t))
    8292             :         break;
    8293           0 :       r = t;
    8294             :     }
    8295             :   return r;
    8296             : }
    8297             : 
    8298             : /* Returns the innermost class type which is not a lambda closure type.  */
    8299             : 
    8300             : tree
    8301   706548662 : current_nonlambda_class_type (void)
    8302             : {
    8303   706548662 :   tree type = current_class_type;
    8304  1257541351 :   while (type && LAMBDA_TYPE_P (type))
    8305      584145 :     type = decl_type_context (TYPE_NAME (type));
    8306   706548662 :   return type;
    8307             : }
    8308             : 
    8309             : /* When entering a class scope, all enclosing class scopes' names with
    8310             :    static meaning (static variables, static functions, types and
    8311             :    enumerators) have to be visible.  This recursive function calls
    8312             :    pushclass for all enclosing class contexts until global or a local
    8313             :    scope is reached.  TYPE is the enclosed class.  */
    8314             : 
    8315             : void
    8316   374163827 : push_nested_class (tree type)
    8317             : {
    8318             :   /* A namespace might be passed in error cases, like A::B:C.  */
    8319   374163827 :   if (type == NULL_TREE
    8320   374163827 :       || !CLASS_TYPE_P (type))
    8321             :     return;
    8322             : 
    8323   191788103 :   push_nested_class (DECL_CONTEXT (TYPE_MAIN_DECL (type)));
    8324             : 
    8325   191788103 :   pushclass (type);
    8326             : }
    8327             : 
    8328             : /* Undoes a push_nested_class call.  */
    8329             : 
    8330             : void
    8331   182357660 : pop_nested_class (void)
    8332             : {
    8333   191766439 :   tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
    8334             : 
    8335   191766439 :   popclass ();
    8336   191766439 :   if (context && CLASS_TYPE_P (context))
    8337             :     pop_nested_class ();
    8338   182357660 : }
    8339             : 
    8340             : /* Returns the number of extern "LANG" blocks we are nested within.  */
    8341             : 
    8342             : int
    8343        2453 : current_lang_depth (void)
    8344             : {
    8345        2453 :   return vec_safe_length (current_lang_base);
    8346             : }
    8347             : 
    8348             : /* Set global variables CURRENT_LANG_NAME to appropriate value
    8349             :    so that behavior of name-mangling machinery is correct.  */
    8350             : 
    8351             : void
    8352      855027 : push_lang_context (tree name)
    8353             : {
    8354      855027 :   vec_safe_push (current_lang_base, current_lang_name);
    8355             : 
    8356      855027 :   if (name == lang_name_cplusplus)
    8357      432480 :     current_lang_name = name;
    8358      422547 :   else if (name == lang_name_c)
    8359      422547 :     current_lang_name = name;
    8360             :   else
    8361           0 :     error ("language string %<\"%E\"%> not recognized", name);
    8362      855027 : }
    8363             : 
    8364             : /* Get out of the current language scope.  */
    8365             : 
    8366             : void
    8367      855027 : pop_lang_context (void)
    8368             : {
    8369      855027 :   current_lang_name = current_lang_base->pop ();
    8370      855027 : }
    8371             : 
    8372             : /* Type instantiation routines.  */
    8373             : 
    8374             : /* Given an OVERLOAD and a TARGET_TYPE, return the function that
    8375             :    matches the TARGET_TYPE.  If there is no satisfactory match, return
    8376             :    error_mark_node, and issue an error & warning messages under
    8377             :    control of FLAGS.  Permit pointers to member function if FLAGS
    8378             :    permits.  If TEMPLATE_ONLY, the name of the overloaded function was
    8379             :    a template-id, and EXPLICIT_TARGS are the explicitly provided
    8380             :    template arguments.  
    8381             : 
    8382             :    If OVERLOAD is for one or more member functions, then ACCESS_PATH
    8383             :    is the base path used to reference those member functions.  If
    8384             :    the address is resolved to a member function, access checks will be
    8385             :    performed and errors issued if appropriate.  */
    8386             : 
    8387             : static tree
    8388      123062 : resolve_address_of_overloaded_function (tree target_type,
    8389             :                                         tree overload,
    8390             :                                         tsubst_flags_t complain,
    8391             :                                         bool template_only,
    8392             :                                         tree explicit_targs,
    8393             :                                         tree access_path)
    8394             : {
    8395             :   /* Here's what the standard says:
    8396             : 
    8397             :        [over.over]
    8398             : 
    8399             :        If the name is a function template, template argument deduction
    8400             :        is done, and if the argument deduction succeeds, the deduced
    8401             :        arguments are used to generate a single template function, which
    8402             :        is added to the set of overloaded functions considered.
    8403             : 
    8404             :        Non-member functions and static member functions match targets of
    8405             :        type "pointer-to-function" or "reference-to-function."  Nonstatic
    8406             :        member functions match targets of type "pointer-to-member
    8407             :        function;" the function type of the pointer to member is used to
    8408             :        select the member function from the set of overloaded member
    8409             :        functions.  If a non-static member function is selected, the
    8410             :        reference to the overloaded function name is required to have the
    8411             :        form of a pointer to member as described in 5.3.1.
    8412             : 
    8413             :        If more than one function is selected, any template functions in
    8414             :        the set are eliminated if the set also contains a non-template
    8415             :        function, and any given template function is eliminated if the
    8416             :        set contains a second template function that is more specialized
    8417             :        than the first according to the partial ordering rules 14.5.5.2.
    8418             :        After such eliminations, if any, there shall remain exactly one
    8419             :        selected function.  */
    8420             : 
    8421      123062 :   int is_ptrmem = 0;
    8422             :   /* We store the matches in a TREE_LIST rooted here.  The functions
    8423             :      are the TREE_PURPOSE, not the TREE_VALUE, in this list, for easy
    8424             :      interoperability with most_specialized_instantiation.  */
    8425      123062 :   tree matches = NULL_TREE;
    8426      123062 :   tree fn;
    8427      123062 :   tree target_fn_type;
    8428             : 
    8429             :   /* By the time we get here, we should be seeing only real
    8430             :      pointer-to-member types, not the internal POINTER_TYPE to
    8431             :      METHOD_TYPE representation.  */
    8432      123062 :   gcc_assert (!TYPE_PTR_P (target_type)
    8433             :               || TREE_CODE (TREE_TYPE (target_type)) != METHOD_TYPE);
    8434             : 
    8435      123062 :   gcc_assert (is_overloaded_fn (overload));
    8436             : 
    8437             :   /* Check that the TARGET_TYPE is reasonable.  */
    8438       25102 :   if (TYPE_PTRFN_P (target_type)
    8439      123066 :       || TYPE_REFFN_P (target_type))
    8440             :     /* This is OK.  */;
    8441       97961 :   else if (TYPE_PTRMEMFUNC_P (target_type))
    8442             :     /* This is OK, too.  */
    8443             :     is_ptrmem = 1;
    8444       96647 :   else if (TREE_CODE (target_type) == FUNCTION_TYPE)
    8445             :     /* This is OK, too.  This comes from a conversion to reference
    8446             :        type.  */
    8447       96593 :     target_type = build_reference_type (target_type);
    8448             :   else
    8449             :     {
    8450          54 :       if (complain & tf_error)
    8451          42 :         error ("cannot resolve overloaded function %qD based on"
    8452             :                " conversion to type %qT",
    8453          42 :                OVL_NAME (overload), target_type);
    8454          54 :       return error_mark_node;
    8455             :     }
    8456             : 
    8457             :   /* Non-member functions and static member functions match targets of type
    8458             :      "pointer-to-function" or "reference-to-function."  Nonstatic member
    8459             :      functions match targets of type "pointer-to-member-function;" the
    8460             :      function type of the pointer to member is used to select the member
    8461             :      function from the set of overloaded member functions.
    8462             : 
    8463             :      So figure out the FUNCTION_TYPE that we want to match against.  */
    8464      123008 :   target_fn_type = static_fn_type (target_type);
    8465             : 
    8466             :   /* If we can find a non-template function that matches, we can just
    8467             :      use it.  There's no point in generating template instantiations
    8468             :      if we're just going to throw them out anyhow.  But, of course, we
    8469             :      can only do this when we don't *need* a template function.  */
    8470      123008 :   if (!template_only)
    8471      901361 :     for (lkp_iterator iter (overload); iter; ++iter)
    8472             :       {
    8473      686927 :         tree fn = *iter;
    8474             : 
    8475      686927 :         if (TREE_CODE (fn) == TEMPLATE_DECL)
    8476             :           /* We're not looking for templates just yet.  */
    8477        9315 :           continue;
    8478             : 
    8479      677612 :         if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE) != is_ptrmem)
    8480             :           /* We're looking for a non-static member, and this isn't
    8481             :              one, or vice versa.  */
    8482         716 :           continue;
    8483             : 
    8484             :         /* Constraints must be satisfied. This is done before
    8485             :            return type deduction since that instantiates the
    8486             :            function. */
    8487      676896 :         if (!constraints_satisfied_p (fn))
    8488           3 :           continue;
    8489             : 
    8490      676893 :         if (undeduced_auto_decl (fn))
    8491             :           {
    8492             :             /* Force instantiation to do return type deduction.  */
    8493          16 :             maybe_instantiate_decl (fn);
    8494          16 :             require_deduced_type (fn);
    8495             :           }
    8496             : 
    8497             :         /* In C++17 we need the noexcept-qualifier to compare types.  */
    8498      676893 :         if (flag_noexcept_type
    8499      676893 :             && !maybe_instantiate_noexcept (fn, complain))
    8500           0 :           continue;
    8501             : 
    8502             :         /* See if there's a match.  */
    8503      676893 :         tree fntype = static_fn_type (fn);
    8504      676893 :         if (same_type_p (target_fn_type, fntype)
    8505      676893 :             || fnptr_conv_p (target_fn_type, fntype))
    8506       98739 :           matches = tree_cons (fn, NULL_TREE, matches);
    8507             :       }
    8508             : 
    8509             :   /* Now, if we've already got a match (or matches), there's no need
    8510             :      to proceed to the template functions.  But, if we don't have a
    8511             :      match we need to look at them, too.  */
    8512      107217 :   if (!matches)
    8513             :     {
    8514       25017 :       tree target_arg_types;
    8515       25017 :       tree target_ret_type;
    8516       25017 :       tree *args;
    8517       25017 :       unsigned int nargs, ia;
    8518       25017 :       tree arg;
    8519             : 
    8520       25017 :       target_arg_types = TYPE_ARG_TYPES (target_fn_type);
    8521       25017 :       target_ret_type = TREE_TYPE (target_fn_type);
    8522             : 
    8523       25017 :       nargs = list_length (target_arg_types);
    8524       25017 :       args = XALLOCAVEC (tree, nargs);
    8525       25017 :       for (arg = target_arg_types, ia = 0;
    8526       75711 :            arg != NULL_TREE;
    8527       50694 :            arg = TREE_CHAIN (arg), ++ia)
    8528       50694 :         args[ia] = TREE_VALUE (arg);
    8529       25017 :       nargs = ia;
    8530             : 
    8531       77588 :       for (lkp_iterator iter (overload); iter; ++iter)
    8532             :         {
    8533       27554 :           tree fn = *iter;
    8534       27554 :           tree instantiation;
    8535       27554 :           tree targs;
    8536             : 
    8537       27554 :           if (TREE_CODE (fn) != TEMPLATE_DECL)
    8538             :             /* We're only looking for templates.  */
    8539        2700 :             continue;
    8540             : 
    8541       24854 :           if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
    8542             :               != is_ptrmem)
    8543             :             /* We're not looking for a non-static member, and this is
    8544             :                one, or vice versa.  */
    8545          12 :             continue;
    8546             : 
    8547       24842 :           tree ret = target_ret_type;
    8548             : 
    8549             :           /* If the template has a deduced return type, don't expose it to
    8550             :              template argument deduction.  */
    8551       24842 :           if (undeduced_auto_decl (fn))
    8552          29 :             ret = NULL_TREE;
    8553             : 
    8554             :           /* Try to do argument deduction.  */
    8555       24842 :           targs = make_tree_vec (DECL_NTPARMS (fn));
    8556       24842 :           instantiation = fn_type_unification (fn, explicit_targs, targs, args,
    8557             :                                                nargs, ret,
    8558             :                                               DEDUCE_EXACT, LOOKUP_NORMAL,
    8559             :                                                NULL, false, false);
    8560       24842 :           if (instantiation == error_mark_node)
    8561             :             /* Instantiation failed.  */
    8562        4301 :             continue;
    8563             : 
    8564             :           /* Constraints must be satisfied. This is done before
    8565             :              return type deduction since that instantiates the
    8566             :              function. */
    8567       20541 :           if (flag_concepts && !constraints_satisfied_p (instantiation))
    8568           0 :             continue;
    8569             : 
    8570             :           /* And now force instantiation to do return type deduction.  */
    8571       20541 :           if (undeduced_auto_decl (instantiation))
    8572             :             {
    8573           6 :               ++function_depth;
    8574           6 :               instantiate_decl (instantiation, /*defer*/false, /*class*/false);
    8575           6 :               --function_depth;
    8576             : 
    8577           6 :               require_deduced_type (instantiation);
    8578             :             }
    8579             : 
    8580             :           /* In C++17 we need the noexcept-qualifier to compare types.  */
    8581       20541 :           if (flag_noexcept_type)
    8582       19340 :             maybe_instantiate_noexcept (instantiation, complain);
    8583             : 
    8584             :           /* See if there's a match.  */
    8585       20541 :           tree fntype = static_fn_type (instantiation);
    8586       20541 :           if (same_type_p (target_fn_type, fntype)
    8587       20541 :               || fnptr_conv_p (target_fn_type, fntype))
    8588       20527 :             matches = tree_cons (instantiation, fn, matches);
    8589             :         }
    8590             : 
    8591             :       /* Now, remove all but the most specialized of the matches.  */
    8592       25017 :       if (matches)
    8593             :         {
    8594       20442 :           tree match = most_specialized_instantiation (matches);
    8595             : 
    8596       20442 :           if (match != error_mark_node)
    8597       20434 :             matches = tree_cons (TREE_PURPOSE (match),
    8598             :                                  NULL_TREE,
    8599             :                                  NULL_TREE);
    8600             :         }
    8601             :     }
    8602             : 
    8603             :   /* Now we should have exactly one function in MATCHES.  */
    8604       20442 :   if (matches == NULL_TREE)
    8605             :     {
    8606             :       /* There were *no* matches.  */
    8607        4575 :       if (complain & tf_error)
    8608             :         {
    8609          94 :           error ("no matches converting function %qD to type %q#T",
    8610          94 :                  OVL_NAME (overload), target_type);
    8611             : 
    8612          94 :           print_candidates (overload);
    8613             :         }
    8614        4575 :       return error_mark_node;
    8615             :     }
    8616      118433 :   else if (TREE_CHAIN (matches))
    8617             :     {
    8618             :       /* There were too many matches.  First check if they're all
    8619             :          the same function.  */
    8620         180 :       tree match = NULL_TREE;
    8621             : 
    8622         180 :       fn = TREE_PURPOSE (matches);
    8623             : 
    8624             :       /* For multi-versioned functions, more than one match is just fine and
    8625             :          decls_match will return false as they are different.  */
    8626         928 :       for (match = TREE_CHAIN (matches); match; match = TREE_CHAIN (match))
    8627         756 :         if (!decls_match (fn, TREE_PURPOSE (match))
    8628        1492 :             && !targetm.target_option.function_versions
    8629         736 :                (fn, TREE_PURPOSE (match)))
    8630             :           break;
    8631             : 
    8632         180 :       if (match)
    8633             :         {
    8634           8 :           if (complain & tf_error)
    8635             :             {
    8636           4 :               error ("converting overloaded function %qD to type %q#T is ambiguous",
    8637           4 :                      OVL_NAME (overload), target_type);
    8638             : 
    8639             :               /* Since print_candidates expects the functions in the
    8640             :                  TREE_VALUE slot, we flip them here.  */
    8641          16 :               for (match = matches; match; match = TREE_CHAIN (match))
    8642           8 :                 TREE_VALUE (match) = TREE_PURPOSE (match);
    8643             : 
    8644           4 :               print_candidates (matches);
    8645             :             }
    8646             : 
    8647           8 :           return error_mark_node;
    8648             :         }
    8649             :     }
    8650             : 
    8651             :   /* Good, exactly one match.  Now, convert it to the correct type.  */
    8652      118425 :   fn = TREE_PURPOSE (matches);
    8653             : 
    8654      118425 :   if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
    8655      118425 :       && !(complain & tf_ptrmem_ok) && !flag_ms_extensions)
    8656             :     {
    8657         148 :       static int explained;
    8658             : 
    8659         148 :       if (!(complain & tf_error))
    8660         108 :         return error_mark_node;
    8661             : 
    8662          40 :       auto_diagnostic_group d;
    8663          40 :       if (permerror (input_location, "assuming pointer to member %qD", fn)
    8664          40 :           && !explained)
    8665             :         {
    8666          24 :           inform (input_location, "(a pointer to member can only be "
    8667             :                   "formed with %<&%E%>)", fn);
    8668          24 :           explained = 1;
    8669             :         }
    8670          40 :     }
    8671             : 
    8672             :   /* If a pointer to a function that is multi-versioned is requested, the
    8673             :      pointer to the dispatcher function is returned instead.  This works
    8674             :      well because indirectly calling the function will dispatch the right
    8675             :      function version at run-time.  */
    8676      118317 :   if (DECL_FUNCTION_VERSIONED (fn))
    8677             :     {
    8678         152 :       fn = get_function_version_dispatcher (fn);
    8679         152 :       if (fn == NULL)
    8680           8 :         return error_mark_node;
    8681             :       /* Mark all the versions corresponding to the dispatcher as used.  */
    8682         144 :       if (!(complain & tf_conv))
    8683          48 :         mark_versions_used (fn);
    8684             :     }
    8685             : 
    8686             :   /* If we're doing overload resolution purely for the purpose of
    8687             :      determining conversion sequences, we should not consider the
    8688             :      function used.  If this conversion sequence is selected, the
    8689             :      function will be marked as used at this point.  */
    8690      118309 :   if (!(complain & tf_conv))
    8691             :     {
    8692             :       /* Make =delete work with SFINAE.  */
    8693      106719 :       if (DECL_DELETED_FN (fn) && !(complain & tf_error))
    8694           0 :         return error_mark_node;
    8695      106719 :       if (!mark_used (fn, complain) && !(complain & tf_error))
    8696           0 :         return error_mark_node;
    8697             :     }
    8698             : 
    8699             :   /* We could not check access to member functions when this
    8700             :      expression was originally created since we did not know at that
    8701             :      time to which function the expression referred.  */
    8702      118309 :   if (DECL_FUNCTION_MEMBER_P (fn))
    8703             :     {
    8704        2629 :       gcc_assert (access_path);
    8705        2629 :       perform_or_defer_access_check (access_path, fn, fn, complain);
    8706             :     }
    8707             : 
    8708      118309 :   if (TYPE_PTRFN_P (target_type) || TYPE_PTRMEMFUNC_P (target_type))
    8709       22307 :     return cp_build_addr_expr (fn, complain);
    8710             :   else
    8711             :     {
    8712             :       /* The target must be a REFERENCE_TYPE.  Above, cp_build_unary_op
    8713             :          will mark the function as addressed, but here we must do it
    8714             :          explicitly.  */
    8715       96002 :       cxx_mark_addressable (fn);
    8716             : 
    8717       96002 :       return fn;
    8718             :     }
    8719             : }
    8720             : 
    8721             : /* This function will instantiate the type of the expression given in
    8722             :    RHS to match the type of LHSTYPE.  If errors exist, then return
    8723             :    error_mark_node. COMPLAIN is a bit mask.  If TF_ERROR is set, then
    8724             :    we complain on errors.  If we are not complaining, never modify rhs,
    8725             :    as overload resolution wants to try many possible instantiations, in
    8726             :    the hope that at least one will work.
    8727             : 
    8728             :    For non-recursive calls, LHSTYPE should be a function, pointer to
    8729             :    function, or a pointer to member function.  */
    8730             : 
    8731             : tree
    8732      125094 : instantiate_type (tree lhstype, tree rhs, tsubst_flags_t complain)
    8733             : {
    8734      129601 :   tsubst_flags_t complain_in = complain;
    8735      129601 :   tree access_path = NULL_TREE;
    8736             : 
    8737      129601 :   complain &= ~tf_ptrmem_ok;
    8738             : 
    8739      129601 :   STRIP_ANY_LOCATION_WRAPPER (rhs);
    8740             : 
    8741      129601 :   if (lhstype == unknown_type_node)
    8742             :     {
    8743           0 :       if (complain & tf_error)
    8744           0 :         error ("not enough type information");
    8745           0 :       return error_mark_node;
    8746             :     }
    8747             : 
    8748      129601 :   if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
    8749             :     {
    8750        1457 :       tree fntype = non_reference (lhstype);
    8751        1457 :       if (same_type_p (fntype, TREE_TYPE (rhs)))
    8752             :         return rhs;
    8753         293 :       if (fnptr_conv_p (fntype, TREE_TYPE (rhs)))
    8754             :         return rhs;
    8755         291 :       if (flag_ms_extensions
    8756          20 :           && TYPE_PTRMEMFUNC_P (fntype)
    8757         311 :           && !TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs)))
    8758             :         /* Microsoft allows `A::f' to be resolved to a
    8759             :            pointer-to-member.  */
    8760             :         ;
    8761             :       else
    8762             :         {
    8763         271 :           if (complain & tf_error)
    8764          53 :             error ("cannot convert %qE from type %qT to type %qT",
    8765          53 :                    rhs, TREE_TYPE (rhs), fntype);
    8766         271 :           return error_mark_node;
    8767             :         }
    8768             :     }
    8769             : 
    8770             :   /* If we instantiate a template, and it is a A ?: C expression
    8771             :      with omitted B, look through the SAVE_EXPR.  */
    8772      128164 :   if (TREE_CODE (rhs) == SAVE_EXPR)
    8773          12 :     rhs = TREE_OPERAND (rhs, 0);
    8774             : 
    8775      128164 :   if (BASELINK_P (rhs))
    8776             :     {
    8777        2860 :       access_path = BASELINK_ACCESS_BINFO (rhs);
    8778        2860 :       rhs = BASELINK_FUNCTIONS (rhs);
    8779             :     }
    8780             : 
    8781             :   /* If we are in a template, and have a NON_DEPENDENT_EXPR, we cannot
    8782             :      deduce any type information.  */
    8783      128164 :   if (TREE_CODE (rhs) == NON_DEPENDENT_EXPR)
    8784             :     {
    8785           0 :       if (complain & tf_error)
    8786           0 :         error ("not enough type information");
    8787           0 :       return error_mark_node;
    8788             :     }
    8789             : 
    8790             :   /* There are only a few kinds of expressions that may have a type
    8791             :      dependent on overload resolution.  */
    8792      128164 :   gcc_assert (TREE_CODE (rhs) == ADDR_EXPR
    8793             :               || TREE_CODE (rhs) == COMPONENT_REF
    8794             :               || is_overloaded_fn (rhs)
    8795             :               || (flag_ms_extensions && TREE_CODE (rhs) == FUNCTION_DECL));
    8796             : 
    8797             :   /* This should really only be used when attempting to distinguish
    8798             :      what sort of a pointer to function we have.  For now, any
    8799             :      arithmetic operation which is not supported on pointers
    8800             :      is rejected as an error.  */
    8801             : 
    8802      128164 :   switch (TREE_CODE (rhs))
    8803             :     {
    8804         595 :     case COMPONENT_REF:
    8805         595 :       {
    8806         595 :         tree member = TREE_OPERAND (rhs, 1);
    8807             : 
    8808         595 :         member = instantiate_type (lhstype, member, complain);
    8809         595 :         if (member != error_mark_node
    8810         595 :             && TREE_SIDE_EFFECTS (TREE_OPERAND (rhs, 0)))
    8811             :           /* Do not lose object's side effects.  */
    8812          36 :           return build2 (COMPOUND_EXPR, TREE_TYPE (member),
    8813          72 :                          TREE_OPERAND (rhs, 0), member);
    8814             :         return member;
    8815             :       }
    8816             : 
    8817        1584 :     case OFFSET_REF:
    8818        1584 :       rhs = TREE_OPERAND (rhs, 1);
    8819        1584 :       if (BASELINK_P (rhs))
    8820             :         return instantiate_type (lhstype, rhs, complain_in);
    8821             : 
    8822             :       /* This can happen if we are forming a pointer-to-member for a
    8823             :          member template.  */
    8824           0 :       gcc_assert (TREE_CODE (rhs) == TEMPLATE_ID_EXPR);
    8825             : 
    8826             :       /* Fall through.  */
    8827             : 
    8828       15805 :     case TEMPLATE_ID_EXPR:
    8829       15805 :       {
    8830       15805 :         tree fns = TREE_OPERAND (rhs, 0);
    8831       15805 :         tree args = TREE_OPERAND (rhs, 1);
    8832             : 
    8833       15805 :         return
    8834       15805 :           resolve_address_of_overloaded_function (lhstype, fns, complain_in,
    8835             :                                                   /*template_only=*/true,
    8836       15805 :                                                   args, access_path);
    8837             :       }
    8838             : 
    8839      107257 :     case OVERLOAD:
    8840      107257 :     case FUNCTION_DECL:
    8841      107257 :       return
    8842      107257 :         resolve_address_of_overloaded_function (lhstype, rhs, complain_in,
    8843             :                                                 /*template_only=*/false,
    8844             :                                                 /*explicit_targs=*/NULL_TREE,
    8845      107257 :                                                 access_path);
    8846             : 
    8847        2923 :     case ADDR_EXPR:
    8848        2923 :     {
    8849        2923 :       if (PTRMEM_OK_P (rhs))
    8850        1584 :         complain |= tf_ptrmem_ok;
    8851             : 
    8852        2923 :       return instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
    8853             :     }
    8854             : 
    8855           0 :     case ERROR_MARK:
    8856           0 :       return error_mark_node;
    8857             : 
    8858           0 :     default:
    8859           0 :       gcc_unreachable ();
    8860             :     }
    8861             :   return error_mark_node;
    8862             : }
    8863             : 
    8864             : /* Return the name of the virtual function pointer field
    8865             :    (as an IDENTIFIER_NODE) for the given TYPE.  Note that
    8866             :    this may have to look back through base types to find the
    8867             :    ultimate field name.  (For single inheritance, these could
    8868             :    all be the same name.  Who knows for multiple inheritance).  */
    8869             : 
    8870             : static tree
    8871      173804 : get_vfield_name (tree type)
    8872             : {
    8873      173804 :   tree binfo, base_binfo;
    8874             : 
    8875      173804 :   for (binfo = TYPE_BINFO (type);
    8876      173804 :        BINFO_N_BASE_BINFOS (binfo);
    8877             :        binfo = base_binfo)
    8878             :     {
    8879       55424 :       base_binfo = BINFO_BASE_BINFO (binfo, 0);
    8880             : 
    8881      110848 :       if (BINFO_VIRTUAL_P (base_binfo)
    8882       55424 :           || !TYPE_CONTAINS_VPTR_P (BINFO_TYPE (base_binfo)))
    8883             :         break;
    8884             :     }
    8885             : 
    8886      173804 :   type = BINFO_TYPE (binfo);
    8887      173804 :   tree ctor_name = constructor_name (type);
    8888      173804 :   char *buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
    8889             :                                + IDENTIFIER_LENGTH (ctor_name) + 2);
    8890      173804 :   sprintf (buf, VFIELD_NAME_FORMAT, IDENTIFIER_POINTER (ctor_name));
    8891      173804 :   return get_identifier (buf);
    8892             : }
    8893             : 
    8894             : /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
    8895             :    according to [class]:
    8896             :                                           The class-name is also inserted
    8897             :    into  the scope of the class itself.  For purposes of access checking,
    8898             :    the inserted class name is treated as if it were a public member name.  */
    8899             : 
    8900             : void
    8901    17932208 : build_self_reference (void)
    8902             : {
    8903    17932208 :   tree name = DECL_NAME (TYPE_NAME (current_class_type));
    8904    17932208 :   tree decl = build_lang_decl (TYPE_DECL, name, current_class_type);
    8905             : 
    8906    17932208 :   DECL_NONLOCAL (decl) = 1;
    8907    17932208 :   DECL_CONTEXT (decl) = current_class_type;
    8908    17932208 :   DECL_ARTIFICIAL (decl) = 1;
    8909    17932208 :   SET_DECL_SELF_REFERENCE_P (decl);
    8910    17932208 :   set_underlying_type (decl);
    8911    17932208 :   set_instantiating_module (decl);  
    8912             : 
    8913    17932208 :   if (processing_template_decl)
    8914    12007515 :     decl = push_template_decl (decl);
    8915             : 
    8916    17932208 :   tree saved_cas = current_access_specifier;
    8917    17932208 :   current_access_specifier = access_public_node;
    8918    17932208 :   finish_member_declaration (decl);
    8919    17932208 :   current_access_specifier = saved_cas;
    8920    17932208 : }
    8921             : 
    8922             : /* Returns 1 if TYPE contains only padding bytes.  */
    8923             : 
    8924             : int
    8925   289952540 : is_empty_class (tree type)
    8926             : {
    8927   289952540 :   if (type == error_mark_node)
    8928             :     return 0;
    8929             : 
    8930   289952536 :   if (! CLASS_TYPE_P (type))
    8931             :     return 0;
    8932             : 
    8933   200637378 :   return CLASSTYPE_EMPTY_P (type);
    8934             : }
    8935             : 
    8936             : /* Returns true if TYPE contains no actual data, just various
    8937             :    possible combinations of empty classes.  If IGNORE_VPTR is true,
    8938             :    a vptr doesn't prevent the class from being considered empty.  Typically
    8939             :    we want to ignore the vptr on assignment, and not on initialization.  */
    8940             : 
    8941             : bool
    8942   251469728 : is_really_empty_class (tree type, bool ignore_vptr)
    8943             : {
    8944   251469728 :   if (CLASS_TYPE_P (type))
    8945             :     {
    8946    50055223 :       tree field;
    8947    50055223 :       tree binfo;
    8948    50055223 :       tree base_binfo;
    8949    50055223 :       int i;
    8950             : 
    8951             :       /* CLASSTYPE_EMPTY_P isn't set properly until the class is actually laid
    8952             :          out, but we'd like to be able to check this before then.  */
    8953    50055223 :       if (COMPLETE_TYPE_P (type) && is_empty_class (type))
    8954             :         return true;
    8955             : 
    8956    33529834 :       if (!ignore_vptr && TYPE_CONTAINS_VPTR_P (type))
    8957             :         return false;
    8958             : 
    8959    46807468 :       for (binfo = TYPE_BINFO (type), i = 0;
    8960    46807468 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    8961    15411045 :         if (!is_really_empty_class (BINFO_TYPE (base_binfo), ignore_vptr))
    8962             :           return false;
    8963   189973260 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    8964   171444791 :         if (TREE_CODE (field) == FIELD_DECL
    8965    14598905 :             && !DECL_ARTIFICIAL (field)
    8966             :             /* An unnamed bit-field is not a data member.  */
    8967    13015174 :             && !DECL_UNNAMED_BIT_FIELD (field)
    8968   184457205 :             && !is_really_empty_class (TREE_TYPE (field), ignore_vptr))
    8969             :           return false;
    8970             :       return true;
    8971             :     }
    8972   201414505 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    8973     1172150 :     return (integer_zerop (array_type_nelts_top (type))
    8974     1172150 :             || is_really_empty_class (TREE_TYPE (type), ignore_vptr));
    8975             :   return false;
    8976             : }
    8977             : 
    8978             : /* Note that NAME was looked up while the current class was being
    8979             :    defined and that the result of that lookup was DECL.  */
    8980             : 
    8981             : void
    8982  1228407271 : maybe_note_name_used_in_class (tree name, tree decl)
    8983             : {
    8984             :   /* If we're not defining a class, there's nothing to do.  */
    8985  1228407271 :   if (!(innermost_scope_kind() == sk_class
    8986   172859979 :         && TYPE_BEING_DEFINED (current_class_type)
    8987   298481337 :         && !LAMBDA_TYPE_P (current_class_type)))
    8988             :     return;
    8989             : 
    8990   149620978 :   const cp_binding_level *blev = nullptr;
    8991   149620978 :   if (const cxx_binding *binding = IDENTIFIER_BINDING (name))
    8992   125467543 :     blev = binding->scope;
    8993   149620978 :   const cp_binding_level *lev = current_binding_level;
    8994             : 
    8995             :   /* Record the binding in the names_used tables for classes inside blev.  */
    8996   220289725 :   for (int i = current_class_depth; i > 0; --i)
    8997             :     {
    8998   314918480 :       tree type = (i == current_class_depth
    8999   157459240 :                    ? current_class_type
    9000     7838262 :                    : current_class_stack[i].type);
    9001             : 
    9002   167573863 :       for (; lev; lev = lev->level_chain)
    9003             :         {
    9004   167573863 :           if (lev == blev)
    9005             :             /* We found the declaration.  */
    9006             :             return;
    9007    80783370 :           if (lev->kind == sk_class && lev->this_entity == type)
    9008             :             /* This class is inside the declaration scope.  */
    9009             :             break;
    9010             :         }
    9011             : 
    9012    70668747 :       auto &names_used = current_class_stack[i-1].names_used;
    9013    70668747 :       if (!names_used)
    9014     9731765 :         names_used = splay_tree_new (splay_tree_compare_pointers, 0, 0);
    9015             : 
    9016    70668747 :       tree use = build1_loc (input_location, VIEW_CONVERT_EXPR,
    9017    70668747 :                              TREE_TYPE (decl), decl);
    9018    70668747 :       EXPR_LOCATION_WRAPPER_P (use) = 1;
    9019    70668747 :       splay_tree_insert (names_used,
    9020             :                          (splay_tree_key) name,
    9021             :                          (splay_tree_value) use);
    9022             :     }
    9023             : }
    9024             : 
    9025             : /* Note that NAME was declared (as DECL) in the current class.  Check
    9026             :    to see that the declaration is valid under [class.member.lookup]:
    9027             : 
    9028             :    If [the result of a search in T for N at point P] differs from the result of
    9029             :    a search in T for N from immediately after the class-specifier of T, the
    9030             :    program is ill-formed, no diagnostic required.  */
    9031             : 
    9032             : void
    9033   179126504 : note_name_declared_in_class (tree name, tree decl)
    9034             : {
    9035   179126504 :   splay_tree names_used;
    9036   179126504 :   splay_tree_node n;
    9037             : 
    9038             :   /* Look to see if we ever used this name.  */
    9039   179126504 :   names_used
    9040   179126504 :     = current_class_stack[current_class_depth - 1].names_used;
    9041   179126504 :   if (!names_used)
    9042             :     return;
    9043             :   /* The C language allows members to be declared with a type of the same
    9044             :      name, and the C++ standard says this diagnostic is not required.  So
    9045             :      allow it in extern "C" blocks unless pedantic is specified.
    9046             :      Allow it in all cases if -ms-extensions is specified.  */
    9047    57705204 :   if ((!pedantic && current_lang_name == lang_name_c)
    9048    56193053 :       || flag_ms_extensions)
    9049             :     return;
    9050    56193045 :   n = splay_tree_lookup (names_used, (splay_tree_key) name);
    9051    56193045 :   if (n)
    9052             :     {
    9053          80 :       tree use = (tree) n->value;
    9054          80 :       location_t loc = EXPR_LOCATION (use);
    9055          80 :       tree olddecl = OVL_FIRST (TREE_OPERAND (use, 0));
    9056             :       /* [basic.scope.class]
    9057             : 
    9058             :          A name N used in a class S shall refer to the same declaration
    9059             :          in its context and when re-evaluated in the completed scope of
    9060             :          S.  */
    9061          80 :       auto ov = make_temp_override (global_dc->pedantic_errors);
    9062          80 :       if (TREE_CODE (decl) == TYPE_DECL
    9063          28 :           && TREE_CODE (olddecl) == TYPE_DECL
    9064         108 :           && same_type_p (TREE_TYPE (decl), TREE_TYPE (olddecl)))
    9065             :         /* Different declaration, but same meaning; just warn.  */;
    9066          72 :       else if (flag_permissive)
    9067             :         /* Let -fpermissive make it a warning like past versions.  */;
    9068             :       else
    9069             :         /* Make it an error.  */
    9070          44 :         global_dc->pedantic_errors = 1;
    9071         160 :       if (pedwarn (location_of (decl), OPT_Wchanges_meaning,
    9072             :                    "declaration of %q#D changes meaning of %qD",
    9073          80 :                    decl, OVL_NAME (decl)))
    9074             :         {
    9075          68 :           inform (loc, "used here to mean %q#D", olddecl);
    9076          68 :           inform (location_of (olddecl), "declared here" );
    9077             :         }
    9078          80 :     }
    9079             : }
    9080             : 
    9081             : /* Returns the VAR_DECL for the complete vtable associated with BINFO.
    9082             :    Secondary vtables are merged with primary vtables; this function
    9083             :    will return the VAR_DECL for the primary vtable.  */
    9084             : 
    9085             : tree
    9086     3906758 : get_vtbl_decl_for_binfo (tree binfo)
    9087             : {
    9088     3906758 :   tree decl;
    9089             : 
    9090     3906758 :   decl = BINFO_VTABLE (binfo);
    9091     3906758 :   if (decl && TREE_CODE (decl) == POINTER_PLUS_EXPR)
    9092             :     {
    9093     3906754 :       gcc_assert (TREE_CODE (TREE_OPERAND (decl, 0)) == ADDR_EXPR);
    9094     3906754 :       decl = TREE_OPERAND (TREE_OPERAND (decl, 0), 0);
    9095             :     }
    9096     3906754 :   if (decl)
    9097     3906754 :     gcc_assert (VAR_P (decl));
    9098     3906758 :   return decl;
    9099             : }
    9100             : 
    9101             : 
    9102             : /* Returns the binfo for the primary base of BINFO.  If the resulting
    9103             :    BINFO is a virtual base, and it is inherited elsewhere in the
    9104             :    hierarchy, then the returned binfo might not be the primary base of
    9105             :    BINFO in the complete object.  Check BINFO_PRIMARY_P or
    9106             :    BINFO_LOST_PRIMARY_P to be sure.  */
    9107             : 
    9108             : static tree
    9109    28758153 : get_primary_binfo (tree binfo)
    9110             : {
    9111    28758153 :   tree primary_base;
    9112             : 
    9113    28758153 :   primary_base = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (binfo));
    9114    28758153 :   if (!primary_base)
    9115             :     return NULL_TREE;
    9116             : 
    9117     8495898 :   return copied_binfo (primary_base, binfo);
    9118             : }
    9119             : 
    9120             : /* As above, but iterate until we reach the binfo that actually provides the
    9121             :    vptr for BINFO.  */
    9122             : 
    9123             : static tree
    9124     1807060 : most_primary_binfo (tree binfo)
    9125             : {
    9126     1807060 :   tree b = binfo;
    9127     5596472 :   while (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (b))
    9128     7578824 :          && !BINFO_LOST_PRIMARY_P (b))
    9129             :     {
    9130     1982352 :       tree primary_base = get_primary_binfo (b);
    9131     1982352 :       gcc_assert (BINFO_PRIMARY_P (primary_base)
    9132             :                   && BINFO_INHERITANCE_CHAIN (primary_base) == b);
    9133             :       b = primary_base;
    9134             :     }
    9135     1807060 :   return b;
    9136             : }
    9137             : 
    9138             : /* Returns true if BINFO gets its vptr from a virtual base of the most derived
    9139             :    type.  Note that the virtual inheritance might be above or below BINFO in
    9140             :    the hierarchy.  */
    9141             : 
    9142             : bool
    9143         144 : vptr_via_virtual_p (tree binfo)
    9144             : {
    9145         144 :   if (TYPE_P (binfo))
    9146           0 :     binfo = TYPE_BINFO (binfo);
    9147         144 :   tree primary = most_primary_binfo (binfo);
    9148             :   /* Don't limit binfo_via_virtual, we want to return true when BINFO itself is
    9149             :      a morally virtual base.  */
    9150         144 :   tree virt = binfo_via_virtual (primary, NULL_TREE);
    9151         144 :   return virt != NULL_TREE;
    9152             : }
    9153             : 
    9154             : /* If INDENTED_P is zero, indent to INDENT. Return nonzero.  */
    9155             : 
    9156             : static int
    9157         172 : maybe_indent_hierarchy (FILE * stream, int indent, int indented_p)
    9158             : {
    9159           0 :   if (!indented_p)
    9160          52 :     fprintf (stream, "%*s", indent, "");
    9161         172 :   return 1;
    9162             : }
    9163             : 
    9164             : /* Dump the offsets of all the bases rooted at BINFO to STREAM.
    9165             :    INDENT should be zero when called from the top level; it is
    9166             :    incremented recursively.  IGO indicates the next expected BINFO in
    9167             :    inheritance graph ordering.  */
    9168             : 
    9169             : static tree
    9170         136 : dump_class_hierarchy_r (FILE *stream,
    9171             :                         dump_flags_t flags,
    9172             :                         tree binfo,
    9173             :                         tree igo,
    9174             :                         int indent)
    9175             : {
    9176         136 :   int indented = 0;
    9177         136 :   tree base_binfo;
    9178         136 :   int i;
    9179             : 
    9180         272 :   fprintf (stream, "%s (0x" HOST_WIDE_INT_PRINT_HEX ") ",
    9181         136 :            type_as_string (BINFO_TYPE (binfo), TFF_PLAIN_IDENTIFIER),
    9182             :            (HOST_WIDE_INT) (uintptr_t) binfo);
    9183         136 :   if (binfo != igo)
    9184             :     {
    9185          36 :       fprintf (stream, "alternative-path\n");
    9186          36 :       return igo;
    9187             :     }
    9188         100 :   igo = TREE_CHAIN (binfo);
    9189             : 
    9190         100 :   fprintf (stream, HOST_WIDE_INT_PRINT_DEC,
    9191         100 :            tree_to_shwi (BINFO_OFFSET (binfo)));
    9192         100 :   if (is_empty_class (BINFO_TYPE (binfo)))
    9193          24 :     fprintf (stream, " empty");
    9194          76 :   else if (CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (binfo)))
    9195          16 :     fprintf (stream, " nearly-empty");
    9196         100 :   if (BINFO_VIRTUAL_P (binfo))
    9197          36 :     fprintf (stream, " virtual");
    9198         100 :   fprintf (stream, "\n");
    9199             : 
    9200         100 :   if (BINFO_PRIMARY_P (binfo))
    9201             :     {
    9202          20 :       indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9203          40 :       fprintf (stream, " primary-for %s (0x" HOST_WIDE_INT_PRINT_HEX ")",
    9204          20 :                type_as_string (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo)),
    9205             :                                TFF_PLAIN_IDENTIFIER),
    9206          20 :                (HOST_WIDE_INT) (uintptr_t) BINFO_INHERITANCE_CHAIN (binfo));
    9207             :     }
    9208         100 :   if (BINFO_LOST_PRIMARY_P (binfo))
    9209             :     {
    9210          12 :       indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9211          12 :       fprintf (stream, " lost-primary");
    9212             :     }
    9213         100 :   if (indented)
    9214          32 :     fprintf (stream, "\n");
    9215             : 
    9216         100 :   if (!(flags & TDF_SLIM))
    9217             :     {
    9218         100 :       int indented = 0;
    9219             : 
    9220         100 :       if (BINFO_SUBVTT_INDEX (binfo))
    9221             :         {
    9222          28 :           indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9223          56 :           fprintf (stream, " subvttidx=%s",
    9224          28 :                    expr_as_string (BINFO_SUBVTT_INDEX (binfo),
    9225             :                                    TFF_PLAIN_IDENTIFIER));
    9226             :         }
    9227         100 :       if (BINFO_VPTR_INDEX (binfo))
    9228             :         {
    9229          40 :           indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9230          80 :           fprintf (stream, " vptridx=%s",
    9231          40 :                    expr_as_string (BINFO_VPTR_INDEX (binfo),
    9232             :                                    TFF_PLAIN_IDENTIFIER));
    9233             :         }
    9234         100 :       if (BINFO_VPTR_FIELD (binfo))
    9235             :         {
    9236          36 :           indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9237          72 :           fprintf (stream, " vbaseoffset=%s",
    9238          36 :                    expr_as_string (BINFO_VPTR_FIELD (binfo),
    9239             :                                    TFF_PLAIN_IDENTIFIER));
    9240             :         }
    9241         100 :       if (BINFO_VTABLE (binfo))
    9242             :         {
    9243          36 :           indented = maybe_indent_hierarchy (stream, indent + 3, indented);
    9244          36 :           fprintf (stream, " vptr=%s",
    9245          36 :                    expr_as_string (BINFO_VTABLE (binfo),
    9246             :                                    TFF_PLAIN_IDENTIFIER));
    9247             :         }
    9248             : 
    9249         100 :       if (indented)
    9250          68 :         fprintf (stream, "\n");
    9251             :     }
    9252             : 
    9253         204 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    9254         104 :     igo = dump_class_hierarchy_r (stream, flags, base_binfo, igo, indent + 2);
    9255             : 
    9256             :   return igo;
    9257             : }
    9258             : 
    9259             : /* Dump the BINFO hierarchy for T.  */
    9260             : 
    9261             : static void
    9262          32 : dump_class_hierarchy_1 (FILE *stream, dump_flags_t flags, tree t)
    9263             : {
    9264          32 :   fprintf (stream, "Class %s\n", type_as_string (t, TFF_PLAIN_IDENTIFIER));
    9265         128 :   fprintf (stream, "   size=%lu align=%lu\n",
    9266          32 :            (unsigned long)(tree_to_shwi (TYPE_SIZE (t)) / BITS_PER_UNIT),
    9267          32 :            (unsigned long)(TYPE_ALIGN (t) / BITS_PER_UNIT));
    9268          32 :   if (tree as_base = CLASSTYPE_AS_BASE (t))
    9269         128 :     fprintf (stream, "   base size=%lu base align=%lu\n",
    9270          32 :              (unsigned long)(tree_to_shwi (TYPE_SIZE (as_base))
    9271          32 :                              / BITS_PER_UNIT),
    9272          32 :              (unsigned long)(TYPE_ALIGN (as_base) / BITS_PER_UNIT));
    9273          32 :   dump_class_hierarchy_r (stream, flags, TYPE_BINFO (t), TYPE_BINFO (t), 0);
    9274          32 :   fprintf (stream, "\n");
    9275          32 : }
    9276             : 
    9277             : /* Debug interface to hierarchy dumping.  */
    9278             : 
    9279             : void
    9280           0 : debug_class (tree t)
    9281             : {
    9282           0 :   dump_class_hierarchy_1 (stderr, TDF_SLIM, t);
    9283           0 : }
    9284             : 
    9285             : static void
    9286    25156660 : dump_class_hierarchy (tree t)
    9287             : {
    9288    25156660 :   dump_flags_t flags;
    9289    25156660 :   if (FILE *stream = dump_begin (class_dump_id, &flags))
    9290             :     {
    9291          32 :       dump_class_hierarchy_1 (stream, flags, t);
    9292          32 :       dump_end (class_dump_id, stream);
    9293             :     }
    9294    25156660 : }
    9295             : 
    9296             : static void
    9297          68 : dump_array (FILE * stream, tree decl)
    9298             : {
    9299          68 :   tree value;
    9300          68 :   unsigned HOST_WIDE_INT ix;
    9301          68 :   HOST_WIDE_INT elt;
    9302          68 :   tree size = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (decl)));
    9303             : 
    9304          68 :   elt = (tree_to_shwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))))
    9305             :          / BITS_PER_UNIT);
    9306          68 :   fprintf (stream, "%s:", decl_as_string (decl, TFF_PLAIN_IDENTIFIER));
    9307          68 :   fprintf (stream, " %s entries",
    9308             :            expr_as_string (size_binop (PLUS_EXPR, size, size_one_node),
    9309             :                            TFF_PLAIN_IDENTIFIER));
    9310          68 :   fprintf (stream, "\n");
    9311             : 
    9312         692 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)),
    9313             :                               ix, value)
    9314         556 :     fprintf (stream, "%-4ld  %s\n", (long)(ix * elt),
    9315             :              expr_as_string (value, TFF_PLAIN_IDENTIFIER));
    9316          68 : }
    9317             : 
    9318             : static void
    9319     1336036 : dump_vtable (tree t, tree binfo, tree vtable)
    9320             : {
    9321     1336036 :   dump_flags_t flags;
    9322     1336036 :   FILE *stream = dump_begin (class_dump_id, &flags);
    9323             : 
    9324     1336036 :   if (!stream)
    9325     1335984 :     return;
    9326             : 
    9327          52 :   if (!(flags & TDF_SLIM))
    9328             :     {
    9329          52 :       int ctor_vtbl_p = TYPE_BINFO (t) != binfo;
    9330             : 
    9331         128 :       fprintf (stream, "%s for %s",
    9332             :                ctor_vtbl_p ? "Construction vtable" : "Vtable",
    9333          52 :                type_as_string (BINFO_TYPE (binfo), TFF_PLAIN_IDENTIFIER));
    9334          52 :       if (ctor_vtbl_p)
    9335             :         {
    9336          28 :           if (!BINFO_VIRTUAL_P (binfo))
    9337           8 :             fprintf (stream, " (0x" HOST_WIDE_INT_PRINT_HEX " instance)",
    9338             :                      (HOST_WIDE_INT) (uintptr_t) binfo);
    9339          28 :           fprintf (stream, " in %s", type_as_string (t, TFF_PLAIN_IDENTIFIER));
    9340             :         }
    9341          52 :       fprintf (stream, "\n");
    9342          52 :       dump_array (stream, vtable);
    9343          52 :       fprintf (stream, "\n");
    9344             :     }
    9345             : 
    9346          52 :   dump_end (class_dump_id, stream);
    9347             : }
    9348             : 
    9349             : static void
    9350      137473 : dump_vtt (tree t, tree vtt)
    9351             : {
    9352      137473 :   dump_flags_t flags;
    9353      137473 :   FILE *stream = dump_begin (class_dump_id, &flags);
    9354             : 
    9355      137473 :   if (!stream)
    9356      137457 :     return;
    9357             : 
    9358          16 :   if (!(flags & TDF_SLIM))
    9359             :     {
    9360          16 :       fprintf (stream, "VTT for %s\n",
    9361             :                type_as_string (t, TFF_PLAIN_IDENTIFIER));
    9362          16 :       dump_array (stream, vtt);
    9363          16 :       fprintf (stream, "\n");
    9364             :     }
    9365             : 
    9366          16 :   dump_end (class_dump_id, stream);
    9367             : }
    9368             : 
    9369             : /* Dump a function or thunk and its thunkees.  */
    9370             : 
    9371             : static void
    9372           0 : dump_thunk (FILE *stream, int indent, tree thunk)
    9373             : {
    9374           0 :   static const char spaces[] = "        ";
    9375           0 :   tree name = DECL_NAME (thunk);
    9376           0 :   tree thunks;
    9377             : 
    9378           0 :   fprintf (stream, "%.*s%p %s %s", indent, spaces,
    9379             :            (void *)thunk,
    9380           0 :            !DECL_THUNK_P (thunk) ? "function"
    9381           0 :            : DECL_THIS_THUNK_P (thunk) ? "this-thunk" : "covariant-thunk",
    9382           0 :            name ? IDENTIFIER_POINTER (name) : "<unset>");
    9383           0 :   if (DECL_THUNK_P (thunk))
    9384             :     {
    9385           0 :       HOST_WIDE_INT fixed_adjust = THUNK_FIXED_OFFSET (thunk);
    9386           0 :       tree virtual_adjust = THUNK_VIRTUAL_OFFSET (thunk);
    9387             : 
    9388           0 :       fprintf (stream, " fixed=" HOST_WIDE_INT_PRINT_DEC, fixed_adjust);
    9389           0 :       if (!virtual_adjust)
    9390             :         /*NOP*/;
    9391           0 :       else if (DECL_THIS_THUNK_P (thunk))
    9392           0 :         fprintf (stream, " vcall="  HOST_WIDE_INT_PRINT_DEC,
    9393             :                  tree_to_shwi (virtual_adjust));
    9394             :       else
    9395           0 :         fprintf (stream, " vbase=" HOST_WIDE_INT_PRINT_DEC "(%s)",
    9396           0 :                  tree_to_shwi (BINFO_VPTR_FIELD (virtual_adjust)),
    9397           0 :                  type_as_string (BINFO_TYPE (virtual_adjust), TFF_SCOPE));
    9398           0 :       if (THUNK_ALIAS (thunk))
    9399           0 :         fprintf (stream, " alias to %p", (void *)THUNK_ALIAS (thunk));
    9400             :     }
    9401           0 :   fprintf (stream, "\n");
    9402           0 :   for (thunks = DECL_THUNKS (thunk); thunks; thunks = TREE_CHAIN (thunks))
    9403           0 :     dump_thunk (stream, indent + 2, thunks);
    9404           0 : }
    9405             : 
    9406             : /* Dump the thunks for FN.  */
    9407             : 
    9408             : void
    9409           0 : debug_thunks (tree fn)
    9410             : {
    9411           0 :   dump_thunk (stderr, 0, fn);
    9412           0 : }
    9413             : 
    9414             : /* Virtual function table initialization.  */
    9415             : 
    9416             : /* Create all the necessary vtables for T and its base classes.  */
    9417             : 
    9418             : static void
    9419    25156660 : finish_vtbls (tree t)
    9420             : {
    9421    25156660 :   tree vbase;
    9422    25156660 :   vec<constructor_elt, va_gc> *v = NULL;
    9423    25156660 :   tree vtable = BINFO_VTABLE (TYPE_BINFO (t));
    9424             : 
    9425             :   /* We lay out the primary and secondary vtables in one contiguous
    9426             :      vtable.  The primary vtable is first, followed by the non-virtual
    9427             :      secondary vtables in inheritance graph order.  */
    9428    25156660 :   accumulate_vtbl_inits (TYPE_BINFO (t), TYPE_BINFO (t), TYPE_BINFO (t),
    9429             :                          vtable, t, &v);
    9430             : 
    9431             :   /* Then come the virtual bases, also in inheritance graph order.  */
    9432    67477222 :   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
    9433             :     {
    9434    42320562 :       if (!BINFO_VIRTUAL_P (vbase))
    9435    42168990 :         continue;
    9436      151572 :       accumulate_vtbl_inits (vbase, vbase, TYPE_BINFO (t), vtable, t, &v);
    9437             :     }
    9438             : 
    9439    25156660 :   if (BINFO_VTABLE (TYPE_BINFO (t)))
    9440     1144766 :     initialize_vtable (TYPE_BINFO (t), v);
    9441    25156660 : }
    9442             : 
    9443             : /* Initialize the vtable for BINFO with the INITS.  */
    9444             : 
    9445             : static void
    9446     1144766 : initialize_vtable (tree binfo, vec<constructor_elt, va_gc> *inits)
    9447             : {
    9448     1144766 :   tree decl;
    9449             : 
    9450     2289532 :   layout_vtable_decl (binfo, vec_safe_length (inits));
    9451     1144766 :   decl = get_vtbl_decl_for_binfo (binfo);
    9452     1144766 :   initialize_artificial_var (decl, inits);
    9453     1144766 :   dump_vtable (BINFO_TYPE (binfo), binfo, decl);
    9454     1144766 : }
    9455             : 
    9456             : /* Build the VTT (virtual table table) for T.
    9457             :    A class requires a VTT if it has virtual bases.
    9458             : 
    9459             :    This holds
    9460             :    1 - primary virtual pointer for complete object T
    9461             :    2 - secondary VTTs for each direct non-virtual base of T which requires a
    9462             :        VTT
    9463             :    3 - secondary virtual pointers for each direct or indirect base of T which
    9464             :        has virtual bases or is reachable via a virtual path from T.
    9465             :    4 - secondary VTTs for each direct or indirect virtual base of T.
    9466             : 
    9467             :    Secondary VTTs look like complete object VTTs without part 4.  */
    9468             : 
    9469             : static void
    9470    25156660 : build_vtt (tree t)
    9471             : {
    9472    25156660 :   tree type;
    9473    25156660 :   tree vtt;
    9474    25156660 :   tree index;
    9475    25156660 :   vec<constructor_elt, va_gc> *inits;
    9476             : 
    9477             :   /* Build up the initializers for the VTT.  */
    9478    25156660 :   inits = NULL;
    9479    25156660 :   index = size_zero_node;
    9480    25156660 :   build_vtt_inits (TYPE_BINFO (t), t, &inits, &index);
    9481             : 
    9482             :   /* If we didn't need a VTT, we're done.  */
    9483    25156660 :   if (!inits)
    9484    25019187 :     return;
    9485             : 
    9486             :   /* Figure out the type of the VTT.  */
    9487      274946 :   type = build_array_of_n_type (const_ptr_type_node,
    9488      137473 :                                 inits->length ());
    9489             : 
    9490             :   /* Now, build the VTT object itself.  */
    9491      137473 :   vtt = build_vtable (t, mangle_vtt_for_type (t), type);
    9492      137473 :   initialize_artificial_var (vtt, inits);
    9493             :   /* Add the VTT to the vtables list.  */
    9494      137473 :   DECL_CHAIN (vtt) = DECL_CHAIN (CLASSTYPE_VTABLES (t));
    9495      137473 :   DECL_CHAIN (CLASSTYPE_VTABLES (t)) = vtt;
    9496             : 
    9497      137473 :   dump_vtt (t, vtt);
    9498             : }
    9499             : 
    9500             : /* When building a secondary VTT, BINFO_VTABLE is set to a TREE_LIST with
    9501             :    PURPOSE the RTTI_BINFO, VALUE the real vtable pointer for this binfo,
    9502             :    and CHAIN the vtable pointer for this binfo after construction is
    9503             :    complete.  VALUE can also be another BINFO, in which case we recurse.  */
    9504             : 
    9505             : static tree
    9506      870209 : binfo_ctor_vtable (tree binfo)
    9507             : {
    9508      942726 :   tree vt;
    9509             : 
    9510      942726 :   while (1)
    9511             :     {
    9512      942726 :       vt = BINFO_VTABLE (binfo);
    9513      942726 :       if (TREE_CODE (vt) == TREE_LIST)
    9514      611649 :         vt = TREE_VALUE (vt);
    9515      942726 :       if (TREE_CODE (vt) == TREE_BINFO)
    9516             :         binfo = vt;
    9517             :       else
    9518             :         break;
    9519             :     }
    9520             : 
    9521      870209 :   return vt;
    9522             : }
    9523             : 
    9524             : /* Data for secondary VTT initialization.  */
    9525             : struct secondary_vptr_vtt_init_data
    9526             : {
    9527             :   /* Is this the primary VTT? */
    9528             :   bool top_level_p;
    9529             : 
    9530             :   /* Current index into the VTT.  */
    9531             :   tree index;
    9532             : 
    9533             :   /* Vector of initializers built up.  */
    9534             :   vec<constructor_elt, va_gc> *inits;
    9535             : 
    9536             :   /* The type being constructed by this secondary VTT.  */
    9537             :   tree type_being_constructed;
    9538             : };
    9539             : 
    9540             : /* Recursively build the VTT-initializer for BINFO (which is in the
    9541             :    hierarchy dominated by T).  INITS points to the end of the initializer
    9542             :    list to date.  INDEX is the VTT index where the next element will be
    9543             :    replaced.  Iff BINFO is the binfo for T, this is the top level VTT (i.e.
    9544             :    not a subvtt for some base of T).  When that is so, we emit the sub-VTTs
    9545             :    for virtual bases of T. When it is not so, we build the constructor
    9546             :    vtables for the BINFO-in-T variant.  */
    9547             : 
    9548             : static void
    9549    25488166 : build_vtt_inits (tree binfo, tree t, vec<constructor_elt, va_gc> **inits,
    9550             :                  tree *index)
    9551             : {
    9552    25488166 :   int i;
    9553    25488166 :   tree b;
    9554    25488166 :   tree init;
    9555    25488166 :   secondary_vptr_vtt_init_data data;
    9556    25488166 :   int top_level_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
    9557             : 
    9558             :   /* We only need VTTs for subobjects with virtual bases.  */
    9559    25488166 :   if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
    9560    25159423 :     return;
    9561             : 
    9562             :   /* We need to use a construction vtable if this is not the primary
    9563             :      VTT.  */
    9564      328743 :   if (!top_level_p)
    9565             :     {
    9566      191270 :       build_ctor_vtbl_group (binfo, t);
    9567             : 
    9568             :       /* Record the offset in the VTT where this sub-VTT can be found.  */
    9569      191270 :       BINFO_SUBVTT_INDEX (binfo) = *index;
    9570             :     }
    9571             : 
    9572             :   /* Add the address of the primary vtable for the complete object.  */
    9573      328743 :   init = binfo_ctor_vtable (binfo);
    9574      328743 :   CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init);
    9575      328743 :   if (top_level_p)
    9576             :     {
    9577      137473 :       gcc_assert (!BINFO_VPTR_INDEX (binfo));
    9578      137473 :       BINFO_VPTR_INDEX (binfo) = *index;
    9579             :     }
    9580      328743 :   *index = size_binop (PLUS_EXPR, *index, TYPE_SIZE_UNIT (ptr_type_node));
    9581             : 
    9582             :   /* Recursively add the secondary VTTs for non-virtual bases.  */
    9583      714775 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, b); ++i)
    9584      386032 :     if (!BINFO_VIRTUAL_P (b))
    9585      179934 :       build_vtt_inits (b, t, inits, index);
    9586             : 
    9587             :   /* Add secondary virtual pointers for all subobjects of BINFO with
    9588             :      either virtual bases or reachable along a virtual path, except
    9589             :      subobjects that are non-virtual primary bases.  */
    9590      328743 :   data.top_level_p = top_level_p;
    9591      328743 :   data.index = *index;
    9592      328743 :   data.inits = *inits;
    9593      328743 :   data.type_being_constructed = BINFO_TYPE (binfo);
    9594             : 
    9595      328743 :   dfs_walk_once (binfo, dfs_build_secondary_vptr_vtt_inits, NULL, &data);
    9596             : 
    9597      328743 :   *index = data.index;
    9598             : 
    9599             :   /* data.inits might have grown as we added secondary virtual pointers.
    9600             :      Make sure our caller knows about the new vector.  */
    9601      328743 :   *inits = data.inits;
    9602             : 
    9603      328743 :   if (top_level_p)
    9604             :     /* Add the secondary VTTs for virtual bases in inheritance graph
    9605             :        order.  */
    9606      740603 :     for (b = TYPE_BINFO (BINFO_TYPE (binfo)); b; b = TREE_CHAIN (b))
    9607             :       {
    9608      603130 :         if (!BINFO_VIRTUAL_P (b))
    9609      451558 :           continue;
    9610             : 
    9611      151572 :         build_vtt_inits (b, t, inits, index);
    9612             :       }
    9613             :   else
    9614             :     /* Remove the ctor vtables we created.  */
    9615      191270 :     dfs_walk_all (binfo, dfs_fixup_binfo_vtbls, NULL, binfo);
    9616             : }
    9617             : 
    9618             : /* Called from build_vtt_inits via dfs_walk.  BINFO is the binfo for the base
    9619             :    in most derived. DATA is a SECONDARY_VPTR_VTT_INIT_DATA structure.  */
    9620             : 
    9621             : static tree
    9622     1372737 : dfs_build_secondary_vptr_vtt_inits (tree binfo, void *data_)
    9623             : {
    9624     1372737 :   secondary_vptr_vtt_init_data *data = (secondary_vptr_vtt_init_data *)data_;
    9625             : 
    9626             :   /* We don't care about bases that don't have vtables.  */
    9627     1372737 :   if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
    9628             :     return dfs_skip_bases;
    9629             : 
    9630             :   /* We're only interested in proper subobjects of the type being
    9631             :      constructed.  */
    9632     1346590 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->type_being_constructed))
    9633             :     return NULL_TREE;
    9634             : 
    9635             :   /* We're only interested in bases with virtual bases or reachable
    9636             :      via a virtual path from the type being constructed.  */
    9637     1634896 :   if (!(CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
    9638      617049 :         || binfo_via_virtual (binfo, data->type_being_constructed)))
    9639             :     return dfs_skip_bases;
    9640             : 
    9641             :   /* We're not interested in non-virtual primary bases.  */
    9642     1017208 :   if (!BINFO_VIRTUAL_P (binfo) && BINFO_PRIMARY_P (binfo))
    9643             :     return NULL_TREE;
    9644             : 
    9645             :   /* Record the index where this secondary vptr can be found.  */
    9646      541466 :   if (data->top_level_p)
    9647             :     {
    9648      193604 :       gcc_assert (!BINFO_VPTR_INDEX (binfo));
    9649      193604 :       BINFO_VPTR_INDEX (binfo) = data->index;
    9650             : 
    9651      193604 :       if (BINFO_VIRTUAL_P (binfo))
    9652             :         {
    9653             :           /* It's a primary virtual base, and this is not a
    9654             :              construction vtable.  Find the base this is primary of in
    9655             :              the inheritance graph, and use that base's vtable
    9656             :              now.  */
    9657      158506 :           while (BINFO_PRIMARY_P (binfo))
    9658       10281 :             binfo = BINFO_INHERITANCE_CHAIN (binfo);
    9659             :         }
    9660             :     }
    9661             : 
    9662             :   /* Add the initializer for the secondary vptr itself.  */
    9663      541466 :   CONSTRUCTOR_APPEND_ELT (data->inits, NULL_TREE, binfo_ctor_vtable (binfo));
    9664             : 
    9665             :   /* Advance the vtt index.  */
    9666      541466 :   data->index = size_binop (PLUS_EXPR, data->index,
    9667             :                             TYPE_SIZE_UNIT (ptr_type_node));
    9668             : 
    9669      541466 :   return NULL_TREE;
    9670             : }
    9671             : 
    9672             : /* Called from build_vtt_inits via dfs_walk. After building
    9673             :    constructor vtables and generating the sub-vtt from them, we need
    9674             :    to restore the BINFO_VTABLES that were scribbled on.  DATA is the
    9675             :    binfo of the base whose sub vtt was generated.  */
    9676             : 
    9677             : static tree
    9678      910854 : dfs_fixup_binfo_vtbls (tree binfo, void* data)
    9679             : {
    9680      910854 :   tree vtable = BINFO_VTABLE (binfo);
    9681             : 
    9682      910854 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
    9683             :     /* If this class has no vtable, none of its bases do.  */
    9684             :     return dfs_skip_bases;
    9685             : 
    9686      812053 :   if (!vtable)
    9687             :     /* This might be a primary base, so have no vtable in this
    9688             :        hierarchy.  */
    9689             :     return NULL_TREE;
    9690             : 
    9691             :   /* If we scribbled the construction vtable vptr into BINFO, clear it
    9692             :      out now.  */
    9693      569322 :   if (TREE_CODE (vtable) == TREE_LIST
    9694      569322 :       && (TREE_PURPOSE (vtable) == (tree) data))
    9695      539132 :     BINFO_VTABLE (binfo) = TREE_CHAIN (vtable);
    9696             : 
    9697             :   return NULL_TREE;
    9698             : }
    9699             : 
    9700             : /* Build the construction vtable group for BINFO which is in the
    9701             :    hierarchy dominated by T.  */
    9702             : 
    9703             : static void
    9704      191270 : build_ctor_vtbl_group (tree binfo, tree t)
    9705             : {
    9706      191270 :   tree type;
    9707      191270 :   tree vtbl;
    9708      191270 :   tree id;
    9709      191270 :   tree vbase;
    9710      191270 :   vec<constructor_elt, va_gc> *v;
    9711             : 
    9712             :   /* See if we've already created this construction vtable group.  */
    9713      191270 :   id = mangle_ctor_vtbl_for_type (t, binfo);
    9714      191270 :   if (get_global_binding (id))
    9715           0 :     return;
    9716             : 
    9717      191270 :   gcc_assert (!SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t));
    9718             :   /* Build a version of VTBL (with the wrong type) for use in
    9719             :      constructing the addresses of secondary vtables in the
    9720             :      construction vtable group.  */
    9721      191270 :   vtbl = build_vtable (t, id, ptr_type_node);
    9722             : 
    9723             :   /* Don't export construction vtables from shared libraries.  Even on
    9724             :      targets that don't support hidden visibility, this tells
    9725             :      can_refer_decl_in_current_unit_p not to assume that it's safe to
    9726             :      access from a different compilation unit (bz 54314).  */
    9727      191270 :   DECL_VISIBILITY (vtbl) = VISIBILITY_HIDDEN;
    9728      191270 :   DECL_VISIBILITY_SPECIFIED (vtbl) = true;
    9729             : 
    9730      191270 :   v = NULL;
    9731      191270 :   accumulate_vtbl_inits (binfo, TYPE_BINFO (TREE_TYPE (binfo)),
    9732             :                          binfo, vtbl, t, &v);
    9733             : 
    9734             :   /* Add the vtables for each of our virtual bases using the vbase in T
    9735             :      binfo.  */
    9736      191270 :   for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
    9737      965914 :        vbase;
    9738      774644 :        vbase = TREE_CHAIN (vbase))
    9739             :     {
    9740      774644 :       tree b;
    9741             : 
    9742      774644 :       if (!BINFO_VIRTUAL_P (vbase))
    9743      440198 :         continue;
    9744      334446 :       b = copied_binfo (vbase, binfo);
    9745             : 
    9746      334446 :       accumulate_vtbl_inits (b, vbase, binfo, vtbl, t, &v);
    9747             :     }
    9748             : 
    9749             :   /* Figure out the type of the construction vtable.  */
    9750      191270 :   type = build_array_of_n_type (vtable_entry_type, v->length ());
    9751      191270 :   layout_type (type);
    9752      191270 :   TREE_TYPE (vtbl) = type;
    9753      191270 :   DECL_SIZE (vtbl) = DECL_SIZE_UNIT (vtbl) = NULL_TREE;
    9754      191270 :   layout_decl (vtbl, 0);
    9755             : 
    9756             :   /* Initialize the construction vtable.  */
    9757      191270 :   CLASSTYPE_VTABLES (t) = chainon (CLASSTYPE_VTABLES (t), vtbl);
    9758      191270 :   initialize_artificial_var (vtbl, v);
    9759      191270 :   dump_vtable (t, binfo, vtbl);
    9760             : }
    9761             : 
    9762             : /* Add the vtbl initializers for BINFO (and its bases other than
    9763             :    non-virtual primaries) to the list of INITS.  BINFO is in the
    9764             :    hierarchy dominated by T.  RTTI_BINFO is the binfo within T of
    9765             :    the constructor the vtbl inits should be accumulated for. (If this
    9766             :    is the complete object vtbl then RTTI_BINFO will be TYPE_BINFO (T).)
    9767             :    ORIG_BINFO is the binfo for this object within BINFO_TYPE (RTTI_BINFO).
    9768             :    BINFO is the active base equivalent of ORIG_BINFO in the inheritance
    9769             :    graph of T. Both BINFO and ORIG_BINFO will have the same BINFO_TYPE,
    9770             :    but are not necessarily the same in terms of layout.  */
    9771             : 
    9772             : static void
    9773    28209618 : accumulate_vtbl_inits (tree binfo,
    9774             :                        tree orig_binfo,
    9775             :                        tree rtti_binfo,
    9776             :                        tree vtbl,
    9777             :                        tree t,
    9778             :                        vec<constructor_elt, va_gc> **inits)
    9779             : {
    9780    28209618 :   int i;
    9781    28209618 :   tree base_binfo;
    9782    28209618 :   int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
    9783             : 
    9784    28209618 :   gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (orig_binfo)));
    9785             : 
    9786             :   /* If it doesn't have a vptr, we don't do anything.  */
    9787    28209618 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
    9788             :     return;
    9789             : 
    9790             :   /* If we're building a construction vtable, we're not interested in
    9791             :      subobjects that don't require construction vtables.  */
    9792     3779423 :   if (ctor_vtbl_p
    9793      750609 :       && !CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
    9794     4129234 :       && !binfo_via_virtual (orig_binfo, BINFO_TYPE (rtti_binfo)))
    9795             :     return;
    9796             : 
    9797             :   /* Build the initializers for the BINFO-in-T vtable.  */
    9798     3779169 :   dfs_accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, vtbl, t, inits);
    9799             : 
    9800             :   /* Walk the BINFO and its bases.  We walk in preorder so that as we
    9801             :      initialize each vtable we can figure out at what offset the
    9802             :      secondary vtable lies from the primary vtable.  We can't use
    9803             :      dfs_walk here because we need to iterate through bases of BINFO
    9804             :      and RTTI_BINFO simultaneously.  */
    9805    10579089 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    9806             :     {
    9807             :       /* Skip virtual bases.  */
    9808     3020751 :       if (BINFO_VIRTUAL_P (base_binfo))
    9809      645081 :         continue;
    9810     4751340 :       accumulate_vtbl_inits (base_binfo,
    9811     2375670 :                              BINFO_BASE_BINFO (orig_binfo, i),
    9812             :                              rtti_binfo, vtbl, t,
    9813             :                              inits);
    9814             :     }
    9815             : }
    9816             : 
    9817             : /* Called from accumulate_vtbl_inits.  Adds the initializers for the
    9818             :    BINFO vtable to L.  */
    9819             : 
    9820             : static void
    9821     3779169 : dfs_accumulate_vtbl_inits (tree binfo,
    9822             :                            tree orig_binfo,
    9823             :                            tree rtti_binfo,
    9824             :                            tree orig_vtbl,
    9825             :                            tree t,
    9826             :                            vec<constructor_elt, va_gc> **l)
    9827             : {
    9828     3779169 :   tree vtbl = NULL_TREE;
    9829     3779169 :   int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
    9830     3779169 :   int n_inits;
    9831             : 
    9832     3779169 :   if (ctor_vtbl_p
    9833     4529524 :       && BINFO_VIRTUAL_P (orig_binfo) && BINFO_PRIMARY_P (orig_binfo))
    9834             :     {
    9835             :       /* In the hierarchy of BINFO_TYPE (RTTI_BINFO), this is a
    9836             :          primary virtual base.  If it is not the same primary in
    9837             :          the hierarchy of T, we'll need to generate a ctor vtable
    9838             :          for it, to place at its location in T.  If it is the same
    9839             :          primary, we still need a VTT entry for the vtable, but it
    9840             :          should point to the ctor vtable for the base it is a
    9841             :          primary for within the sub-hierarchy of RTTI_BINFO.
    9842             : 
    9843             :          There are three possible cases:
    9844             : 
    9845             :          1) We are in the same place.
    9846             :          2) We are a primary base within a lost primary virtual base of
    9847             :          RTTI_BINFO.
    9848             :          3) We are primary to something not a base of RTTI_BINFO.  */
    9849             : 
    9850             :       tree b;
    9851             :       tree last = NULL_TREE;
    9852             : 
    9853             :       /* First, look through the bases we are primary to for RTTI_BINFO
    9854             :          or a virtual base.  */
    9855             :       b = binfo;
    9856       74441 :       while (BINFO_PRIMARY_P (b))
    9857             :         {
    9858       73906 :           b = BINFO_INHERITANCE_CHAIN (b);
    9859       73906 :           last = b;
    9860      146431 :           if (BINFO_VIRTUAL_P (b) || b == rtti_binfo)
    9861       72525 :             goto found;
    9862             :         }
    9863             :       /* If we run out of primary links, keep looking down our
    9864             :          inheritance chain; we might be an indirect primary.  */
    9865        1114 :       for (b = last; b; b = BINFO_INHERITANCE_CHAIN (b))
    9866         595 :         if (BINFO_VIRTUAL_P (b) || b == rtti_binfo)
    9867             :           break;
    9868         519 :     found:
    9869             : 
    9870             :       /* If we found RTTI_BINFO, this is case 1.  If we found a virtual
    9871             :          base B and it is a base of RTTI_BINFO, this is case 2.  In
    9872             :          either case, we share our vtable with LAST, i.e. the
    9873             :          derived-most base within B of which we are a primary.  */
    9874       73060 :       if (b == rtti_binfo
    9875       73060 :           || (b && binfo_for_vbase (BINFO_TYPE (b), BINFO_TYPE (rtti_binfo))))
    9876             :         /* Just set our BINFO_VTABLE to point to LAST, as we may not have
    9877             :            set LAST's BINFO_VTABLE yet.  We'll extract the actual vptr in
    9878             :            binfo_ctor_vtable after everything's been set up.  */
    9879             :         vtbl = last;
    9880             : 
    9881             :       /* Otherwise, this is case 3 and we get our own.  */
    9882             :     }
    9883     3706109 :   else if (!BINFO_NEW_VTABLE_MARKED (orig_binfo))
    9884             :     return;
    9885             : 
    9886     1878825 :   n_inits = vec_safe_length (*l);
    9887             : 
    9888     1878825 :   if (!vtbl)
    9889             :     {
    9890     1806916 :       tree index;
    9891     1806916 :       int non_fn_entries;
    9892             : 
    9893             :       /* Add the initializer for this vtable.  */
    9894     1806916 :       build_vtbl_initializer (binfo, orig_binfo, t, rtti_binfo,
    9895             :                               &non_fn_entries, l);
    9896             : 
    9897             :       /* Figure out the position to which the VPTR should point.  */
    9898     1806916 :       vtbl = build1 (ADDR_EXPR, vtbl_ptr_type_node, orig_vtbl);
    9899     1806916 :       index = size_binop (MULT_EXPR,
    9900             :                           TYPE_SIZE_UNIT (vtable_entry_type),
    9901             :                           size_int (non_fn_entries + n_inits));
    9902     1806916 :       vtbl = fold_build_pointer_plus (vtbl, index);
    9903             :     }
    9904             : 
    9905     1878825 :   if (ctor_vtbl_p)
    9906             :     /* For a construction vtable, we can't overwrite BINFO_VTABLE.
    9907             :        So, we make a TREE_LIST.  Later, dfs_fixup_binfo_vtbls will
    9908             :        straighten this out.  */
    9909      539132 :     BINFO_VTABLE (binfo) = tree_cons (rtti_binfo, vtbl, BINFO_VTABLE (binfo));
    9910     1339693 :   else if (BINFO_PRIMARY_P (binfo) && BINFO_VIRTUAL_P (binfo))
    9911             :     /* Throw away any unneeded intializers.  */
    9912        8575 :     (*l)->truncate (n_inits);
    9913             :   else
    9914             :      /* For an ordinary vtable, set BINFO_VTABLE.  */
    9915     1331118 :     BINFO_VTABLE (binfo) = vtbl;
    9916             : }
    9917             : 
    9918             : static GTY(()) tree abort_fndecl_addr;
    9919             : static GTY(()) tree dvirt_fn;
    9920             : 
    9921             : /* Construct the initializer for BINFO's virtual function table.  BINFO
    9922             :    is part of the hierarchy dominated by T.  If we're building a
    9923             :    construction vtable, the ORIG_BINFO is the binfo we should use to
    9924             :    find the actual function pointers to put in the vtable - but they
    9925             :    can be overridden on the path to most-derived in the graph that
    9926             :    ORIG_BINFO belongs.  Otherwise,
    9927             :    ORIG_BINFO should be the same as BINFO.  The RTTI_BINFO is the
    9928             :    BINFO that should be indicated by the RTTI information in the
    9929             :    vtable; it will be a base class of T, rather than T itself, if we
    9930             :    are building a construction vtable.
    9931             : 
    9932             :    The value returned is a TREE_LIST suitable for wrapping in a
    9933             :    CONSTRUCTOR to use as the DECL_INITIAL for a vtable.  If
    9934             :    NON_FN_ENTRIES_P is not NULL, *NON_FN_ENTRIES_P is set to the
    9935             :    number of non-function entries in the vtable.
    9936             : 
    9937             :    It might seem that this function should never be called with a
    9938             :    BINFO for which BINFO_PRIMARY_P holds, the vtable for such a
    9939             :    base is always subsumed by a derived class vtable.  However, when
    9940             :    we are building construction vtables, we do build vtables for
    9941             :    primary bases; we need these while the primary base is being
    9942             :    constructed.  */
    9943             : 
    9944             : static void
    9945     1806916 : build_vtbl_initializer (tree binfo,
    9946             :                         tree orig_binfo,
    9947             :                         tree t,
    9948             :                         tree rtti_binfo,
    9949             :                         int* non_fn_entries_p,
    9950             :                         vec<constructor_elt, va_gc> **inits)
    9951             : {
    9952     1806916 :   tree v;
    9953     1806916 :   vtbl_init_data vid;
    9954     1806916 :   unsigned ix, jx;
    9955     1806916 :   tree vbinfo;
    9956     1806916 :   vec<tree, va_gc> *vbases;
    9957     1806916 :   constructor_elt *e;
    9958             : 
    9959             :   /* Initialize VID.  */
    9960     1806916 :   memset (&vid, 0, sizeof (vid));
    9961     1806916 :   vid.binfo = binfo;
    9962     1806916 :   vid.derived = t;
    9963     1806916 :   vid.rtti_binfo = rtti_binfo;
    9964     1806916 :   vid.primary_vtbl_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
    9965     1806916 :   vid.ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
    9966     1806916 :   vid.generate_vcall_entries = true;
    9967             :   /* The first vbase or vcall offset is at index -3 in the vtable.  */
    9968     1806916 :   vid.index = ssize_int(-3 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
    9969             : 
    9970             :   /* Add entries to the vtable for RTTI.  */
    9971     1806916 :   build_rtti_vtbl_entries (binfo, &vid);
    9972             : 
    9973             :   /* Create an array for keeping track of the functions we've
    9974             :      processed.  When we see multiple functions with the same
    9975             :      signature, we share the vcall offsets.  */
    9976     1806916 :   vec_alloc (vid.fns, 32);
    9977             :   /* Add the vcall and vbase offset entries.  */
    9978     1806916 :   build_vcall_and_vbase_vtbl_entries (binfo, &vid);
    9979             : 
    9980             :   /* Clear BINFO_VTABLE_PATH_MARKED; it's set by
    9981             :      build_vbase_offset_vtbl_entries.  */
    9982     1806916 :   for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
    9983     7963223 :        vec_safe_iterate (vbases, ix, &vbinfo); ix++)
    9984     6156307 :     BINFO_VTABLE_PATH_MARKED (vbinfo) = 0;
    9985             : 
    9986             :   /* If the target requires padding between data entries, add that now.  */
    9987     1806916 :   if (TARGET_VTABLE_DATA_ENTRY_DISTANCE > 1)
    9988             :     {
    9989             :       int n_entries = vec_safe_length (vid.inits);
    9990             : 
    9991             :       vec_safe_grow (vid.inits, TARGET_VTABLE_DATA_ENTRY_DISTANCE * n_entries,
    9992             :                      true);
    9993             : 
    9994             :       /* Move data entries into their new positions and add padding
    9995             :          after the new positions.  Iterate backwards so we don't
    9996             :          overwrite entries that we would need to process later.  */
    9997             :       for (ix = n_entries - 1;
    9998             :            vid.inits->iterate (ix, &e);
    9999             :            ix--)
   10000             :         {
   10001             :           int j;
   10002             :           int new_position = (TARGET_VTABLE_DATA_ENTRY_DISTANCE * ix
   10003             :                               + (TARGET_VTABLE_DATA_ENTRY_DISTANCE - 1));
   10004             : 
   10005             :           (*vid.inits)[new_position] = *e;
   10006             : 
   10007             :           for (j = 1; j < TARGET_VTABLE_DATA_ENTRY_DISTANCE; ++j)
   10008             :             {
   10009             :               constructor_elt *f = &(*vid.inits)[new_position - j];
   10010             :               f->index = NULL_TREE;
   10011             :               f->value = build1 (NOP_EXPR, vtable_entry_type,
   10012             :                                  null_pointer_node);
   10013             :             }
   10014             :         }
   10015             :     }
   10016             : 
   10017     1806916 :   if (non_fn_entries_p)
   10018     3613832 :     *non_fn_entries_p = vec_safe_length (vid.inits);
   10019             : 
   10020             :   /* The initializers for virtual functions were built up in reverse
   10021             :      order.  Straighten them out and add them to the running list in one
   10022             :      step.  */
   10023     1806916 :   jx = vec_safe_length (*inits);
   10024     1806916 :   vec_safe_grow (*inits, jx + vid.inits->length (), true);
   10025             : 
   10026     1806916 :   for (ix = vid.inits->length () - 1;
   10027     7816274 :        vid.inits->iterate (ix, &e);
   10028     6009358 :        ix--, jx++)
   10029     6009358 :     (**inits)[jx] = *e;
   10030             : 
   10031             :   /* Go through all the ordinary virtual functions, building up
   10032             :      initializers.  */
   10033     9529706 :   for (v = BINFO_VIRTUALS (orig_binfo); v; v = TREE_CHAIN (v))
   10034             :     {
   10035     7722790 :       tree delta;
   10036     7722790 :       tree vcall_index;
   10037     7722790 :       tree fn, fn_original;
   10038     7722790 :       tree init = NULL_TREE;
   10039             : 
   10040     7722790 :       fn = BV_FN (v);
   10041     7722790 :       fn_original = fn;
   10042     7722790 :       if (DECL_THUNK_P (fn))
   10043             :         {
   10044         617 :           if (!DECL_NAME (fn))
   10045         270 :             finish_thunk (fn);
   10046         617 :           if (THUNK_ALIAS (fn))
   10047             :             {
   10048           0 :               fn = THUNK_ALIAS (fn);
   10049           0 :               BV_FN (v) = fn;
   10050             :             }
   10051         617 :           fn_original = THUNK_TARGET (fn);
   10052             :         }
   10053             : 
   10054             :       /* If the only definition of this function signature along our
   10055             :          primary base chain is from a lost primary, this vtable slot will
   10056             :          never be used, so just zero it out.  This is important to avoid
   10057             :          requiring extra thunks which cannot be generated with the function.
   10058             : 
   10059             :          We first check this in update_vtable_entry_for_fn, so we handle
   10060             :          restored primary bases properly; we also need to do it here so we
   10061             :          zero out unused slots in ctor vtables, rather than filling them
   10062             :          with erroneous values (though harmless, apart from relocation
   10063             :          costs).  */
   10064     7722790 :       if (BV_LOST_PRIMARY (v))
   10065         868 :         init = size_zero_node;
   10066             : 
   10067         868 :       if (! init)
   10068             :         {
   10069             :           /* Pull the offset for `this', and the function to call, out of
   10070             :              the list.  */
   10071     7721922 :           delta = BV_DELTA (v);
   10072     7721922 :           vcall_index = BV_VCALL_INDEX (v);
   10073             : 
   10074     7721922 :           gcc_assert (TREE_CODE (delta) == INTEGER_CST);
   10075     7721922 :           gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
   10076             : 
   10077             :           /* You can't call an abstract virtual function; it's abstract.
   10078             :              So, we replace these functions with __pure_virtual.  */
   10079     7721922 :           if (DECL_PURE_VIRTUAL_P (fn_original))
   10080             :             {
   10081      425386 :               fn = abort_fndecl;
   10082      425386 :               if (!TARGET_VTABLE_USES_DESCRIPTORS)
   10083             :                 {
   10084      425386 :                   if (abort_fndecl_addr == NULL)
   10085       10532 :                     abort_fndecl_addr
   10086       10532 :                       = fold_convert (vfunc_ptr_type_node,
   10087             :                                       build_fold_addr_expr (fn));
   10088      425386 :                   init = abort_fndecl_addr;
   10089             :                 }
   10090             :             }
   10091             :           /* Likewise for deleted virtuals.  */
   10092     7296536 :           else if (DECL_DELETED_FN (fn_original))
   10093             :             {
   10094          41 :               if (!dvirt_fn)
   10095             :                 {
   10096          17 :                   tree name = get_identifier ("__cxa_deleted_virtual");
   10097          17 :                   dvirt_fn = get_global_binding (name);
   10098          17 :                   if (!dvirt_fn)
   10099          17 :                     dvirt_fn = push_library_fn
   10100          17 :                       (name,
   10101             :                        build_function_type_list (void_type_node, NULL_TREE),
   10102             :                        NULL_TREE, ECF_NORETURN | ECF_COLD);
   10103             :                 }
   10104          41 :               fn = dvirt_fn;
   10105          41 :               if (!TARGET_VTABLE_USES_DESCRIPTORS)
   10106          41 :                 init = fold_convert (vfunc_ptr_type_node,
   10107             :                                      build_fold_addr_expr (fn));
   10108             :             }
   10109             :           else
   10110             :             {
   10111     7296495 :               if (!integer_zerop (delta) || vcall_index)
   10112             :                 {
   10113      763991 :                   fn = make_thunk (fn, /*this_adjusting=*/1,
   10114             :                                    delta, vcall_index);
   10115      763991 :                   if (!DECL_NAME (fn))
   10116      356585 :                     finish_thunk (fn);
   10117             :                 }
   10118             :               /* Take the address of the function, considering it to be of an
   10119             :                  appropriate generic type.  */
   10120     7296495 :               if (!TARGET_VTABLE_USES_DESCRIPTORS)
   10121     7296495 :                 init = fold_convert (vfunc_ptr_type_node,
   10122             :                                      build_fold_addr_expr (fn));
   10123             :               /* Don't refer to a virtual destructor from a constructor
   10124             :                  vtable or a vtable for an abstract class, since destroying
   10125             :                  an object under construction is undefined behavior and we
   10126             :                  don't want it to be considered a candidate for speculative
   10127             :                  devirtualization.  But do create the thunk for ABI
   10128             :                  compliance.  */
   10129     7296495 :               if (DECL_DESTRUCTOR_P (fn_original)
   10130     7296495 :                   && (CLASSTYPE_PURE_VIRTUALS (DECL_CONTEXT (fn_original))
   10131     3161298 :                       || orig_binfo != binfo))
   10132      950900 :                 init = size_zero_node;
   10133             :             }
   10134             :         }
   10135             : 
   10136             :       /* And add it to the chain of initializers.  */
   10137     7722790 :       if (TARGET_VTABLE_USES_DESCRIPTORS)
   10138             :         {
   10139             :           int i;
   10140             :           if (init == size_zero_node)
   10141             :             for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
   10142             :               CONSTRUCTOR_APPEND_ELT (*inits, size_int (jx++), init);
   10143             :           else
   10144             :             for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
   10145             :               {
   10146             :                 tree fdesc = build2 (FDESC_EXPR, vfunc_ptr_type_node,
   10147             :                                      fn, build_int_cst (NULL_TREE, i));
   10148             :                 TREE_CONSTANT (fdesc) = 1;
   10149             : 
   10150             :                 CONSTRUCTOR_APPEND_ELT (*inits, size_int (jx++), fdesc);
   10151             :               }
   10152             :         }
   10153             :       else
   10154     7722790 :         CONSTRUCTOR_APPEND_ELT (*inits, size_int (jx++), init);
   10155             :     }
   10156     1806916 : }
   10157             : 
   10158             : /* Adds to vid->inits the initializers for the vbase and vcall
   10159             :    offsets in BINFO, which is in the hierarchy dominated by T.  */
   10160             : 
   10161             : static void
   10162     3793016 : build_vcall_and_vbase_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10163             : {
   10164     3793016 :   tree b;
   10165             : 
   10166             :   /* If this is a derived class, we must first create entries
   10167             :      corresponding to the primary base class.  */
   10168     3793016 :   b = get_primary_binfo (binfo);
   10169     3793016 :   if (b)
   10170     1986100 :     build_vcall_and_vbase_vtbl_entries (b, vid);
   10171             : 
   10172             :   /* Add the vbase entries for this base.  */
   10173     3793016 :   build_vbase_offset_vtbl_entries (binfo, vid);
   10174             :   /* Add the vcall entries for this base.  */
   10175     3793016 :   build_vcall_offset_vtbl_entries (binfo, vid);
   10176     3793016 : }
   10177             : 
   10178             : /* Returns the initializers for the vbase offset entries in the vtable
   10179             :    for BINFO (which is part of the class hierarchy dominated by T), in
   10180             :    reverse order.  VBASE_OFFSET_INDEX gives the vtable index
   10181             :    where the next vbase offset will go.  */
   10182             : 
   10183             : static void
   10184     3793016 : build_vbase_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10185             : {
   10186     3793016 :   tree vbase;
   10187     3793016 :   tree t;
   10188     3793016 :   tree non_primary_binfo;
   10189             : 
   10190             :   /* If there are no virtual baseclasses, then there is nothing to
   10191             :      do.  */
   10192     3793016 :   if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
   10193             :     return;
   10194             : 
   10195      738734 :   t = vid->derived;
   10196             : 
   10197             :   /* We might be a primary base class.  Go up the inheritance hierarchy
   10198             :      until we find the most derived class of which we are a primary base:
   10199             :      it is the offset of that which we need to use.  */
   10200      738734 :   non_primary_binfo = binfo;
   10201     1128701 :   while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
   10202             :     {
   10203      700801 :       tree b;
   10204             : 
   10205             :       /* If we have reached a virtual base, then it must be a primary
   10206             :          base (possibly multi-level) of vid->binfo, or we wouldn't
   10207             :          have called build_vcall_and_vbase_vtbl_entries for it.  But it
   10208             :          might be a lost primary, so just skip down to vid->binfo.  */
   10209      700801 :       if (BINFO_VIRTUAL_P (non_primary_binfo))
   10210             :         {
   10211      187555 :           non_primary_binfo = vid->binfo;
   10212      187555 :           break;
   10213             :         }
   10214             : 
   10215      513246 :       b = BINFO_INHERITANCE_CHAIN (non_primary_binfo);
   10216      513246 :       if (get_primary_binfo (b) != non_primary_binfo)
   10217             :         break;
   10218             :       non_primary_binfo = b;
   10219             :     }
   10220             : 
   10221             :   /* Go through the virtual bases, adding the offsets.  */
   10222      738734 :   for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
   10223     4757539 :        vbase;
   10224     4018805 :        vbase = TREE_CHAIN (vbase))
   10225             :     {
   10226     4018805 :       tree b;
   10227     4018805 :       tree delta;
   10228             : 
   10229     4018805 :       if (!BINFO_VIRTUAL_P (vbase))
   10230     1693934 :         continue;
   10231             : 
   10232             :       /* Find the instance of this virtual base in the complete
   10233             :          object.  */
   10234     2324871 :       b = copied_binfo (vbase, binfo);
   10235             : 
   10236             :       /* If we've already got an offset for this virtual base, we
   10237             :          don't need another one.  */
   10238     2324871 :       if (BINFO_VTABLE_PATH_MARKED (b))
   10239      254137 :         continue;
   10240     2070734 :       BINFO_VTABLE_PATH_MARKED (b) = 1;
   10241             : 
   10242             :       /* Figure out where we can find this vbase offset.  */
   10243     2070734 :       delta = size_binop (MULT_EXPR,
   10244             :                           vid->index,
   10245             :                           fold_convert (ssizetype,
   10246             :                                    TYPE_SIZE_UNIT (vtable_entry_type)));
   10247     2070734 :       if (vid->primary_vtbl_p)
   10248      151572 :         BINFO_VPTR_FIELD (b) = delta;
   10249             : 
   10250     2070734 :       if (binfo != TYPE_BINFO (t))
   10251             :         /* The vbase offset had better be the same.  */
   10252     2023185 :         gcc_assert (tree_int_cst_equal (delta, BINFO_VPTR_FIELD (vbase)));
   10253             : 
   10254             :       /* The next vbase will come at a more negative offset.  */
   10255     2070734 :       vid->index = size_binop (MINUS_EXPR, vid->index,
   10256             :                                ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
   10257             : 
   10258             :       /* The initializer is the delta from BINFO to this virtual base.
   10259             :          The vbase offsets go in reverse inheritance-graph order, and
   10260             :          we are walking in inheritance graph order so these end up in
   10261             :          the right order.  */
   10262     2070734 :       delta = size_diffop_loc (input_location,
   10263     2070734 :                            BINFO_OFFSET (b), BINFO_OFFSET (non_primary_binfo));
   10264             : 
   10265     6089539 :       CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE,
   10266             :                               fold_build1_loc (input_location, NOP_EXPR,
   10267             :                                                vtable_entry_type, delta));
   10268             :     }
   10269             : }
   10270             : 
   10271             : /* Adds the initializers for the vcall offset entries in the vtable
   10272             :    for BINFO (which is part of the class hierarchy dominated by VID->DERIVED)
   10273             :    to VID->INITS.  */
   10274             : 
   10275             : static void
   10276     3793016 : build_vcall_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10277             : {
   10278             :   /* We only need these entries if this base is a virtual base.  We
   10279             :      compute the indices -- but do not add to the vtable -- when
   10280             :      building the main vtable for a class.  */
   10281     3793016 :   if (binfo == TYPE_BINFO (vid->derived)
   10282     6441266 :       || (BINFO_VIRTUAL_P (binfo) 
   10283             :           /* If BINFO is RTTI_BINFO, then (since BINFO does not
   10284             :              correspond to VID->DERIVED), we are building a primary
   10285             :              construction virtual table.  Since this is a primary
   10286             :              virtual table, we do not need the vcall offsets for
   10287             :              BINFO.  */
   10288      493338 :           && binfo != vid->rtti_binfo))
   10289             :     {
   10290             :       /* We need a vcall offset for each of the virtual functions in this
   10291             :          vtable.  For example:
   10292             : 
   10293             :            class A { virtual void f (); };
   10294             :            class B1 : virtual public A { virtual void f (); };
   10295             :            class B2 : virtual public A { virtual void f (); };
   10296             :            class C: public B1, public B2 { virtual void f (); };
   10297             : 
   10298             :          A C object has a primary base of B1, which has a primary base of A.  A
   10299             :          C also has a secondary base of B2, which no longer has a primary base
   10300             :          of A.  So the B2-in-C construction vtable needs a secondary vtable for
   10301             :          A, which will adjust the A* to a B2* to call f.  We have no way of
   10302             :          knowing what (or even whether) this offset will be when we define B2,
   10303             :          so we store this "vcall offset" in the A sub-vtable and look it up in
   10304             :          a "virtual thunk" for B2::f.
   10305             : 
   10306             :          We need entries for all the functions in our primary vtable and
   10307             :          in our non-virtual bases' secondary vtables.  */
   10308     1624427 :       vid->vbase = binfo;
   10309             :       /* If we are just computing the vcall indices -- but do not need
   10310             :          the actual entries -- not that.  */
   10311     1624427 :       if (!BINFO_VIRTUAL_P (binfo))
   10312     1144766 :         vid->generate_vcall_entries = false;
   10313             :       /* Now, walk through the non-virtual bases, adding vcall offsets.  */
   10314     1624427 :       add_vcall_offset_vtbl_entries_r (binfo, vid);
   10315             :     }
   10316     3793016 : }
   10317             : 
   10318             : /* Build vcall offsets, starting with those for BINFO.  */
   10319             : 
   10320             : static void
   10321     4380585 : add_vcall_offset_vtbl_entries_r (tree binfo, vtbl_init_data* vid)
   10322             : {
   10323     4380585 :   int i;
   10324     4380585 :   tree primary_binfo;
   10325     4380585 :   tree base_binfo;
   10326             : 
   10327             :   /* Don't walk into virtual bases -- except, of course, for the
   10328             :      virtual base for which we are building vcall offsets.  Any
   10329             :      primary virtual base will have already had its offsets generated
   10330             :      through the recursion in build_vcall_and_vbase_vtbl_entries.  */
   10331     4380585 :   if (BINFO_VIRTUAL_P (binfo) && vid->vbase != binfo)
   10332     4380585 :     return;
   10333             : 
   10334             :   /* If BINFO has a primary base, process it first.  */
   10335     3955827 :   primary_binfo = get_primary_binfo (binfo);
   10336     3955827 :   if (primary_binfo)
   10337     1946381 :     add_vcall_offset_vtbl_entries_r (primary_binfo, vid);
   10338             : 
   10339             :   /* Add BINFO itself to the list.  */
   10340     3955827 :   add_vcall_offset_vtbl_entries_1 (binfo, vid);
   10341             : 
   10342             :   /* Scan the non-primary bases of BINFO.  */
   10343    10667605 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
   10344     2755951 :     if (base_binfo != primary_binfo)
   10345      809777 :       add_vcall_offset_vtbl_entries_r (base_binfo, vid);
   10346             : }
   10347             : 
   10348             : /* Called from build_vcall_offset_vtbl_entries_r.  */
   10349             : 
   10350             : static void
   10351     3955827 : add_vcall_offset_vtbl_entries_1 (tree binfo, vtbl_init_data* vid)
   10352             : {
   10353             :   /* Make entries for the rest of the virtuals.  */
   10354     3955827 :   tree orig_fn;
   10355             : 
   10356             :   /* The ABI requires that the methods be processed in declaration
   10357             :      order.  */
   10358     3955827 :   for (orig_fn = TYPE_FIELDS (BINFO_TYPE (binfo));
   10359   137908810 :        orig_fn;
   10360   133952983 :        orig_fn = DECL_CHAIN (orig_fn))
   10361   133952983 :     if (TREE_CODE (orig_fn) == FUNCTION_DECL && DECL_VINDEX (orig_fn))
   10362    16841373 :       add_vcall_offset (orig_fn, binfo, vid);
   10363     3955827 : }
   10364             : 
   10365             : /* Add a vcall offset entry for ORIG_FN to the vtable.  */
   10366             : 
   10367             : static void
   10368    16841373 : add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
   10369             : {
   10370    16841373 :   size_t i;
   10371    16841373 :   tree vcall_offset;
   10372    16841373 :   tree derived_entry;
   10373             : 
   10374             :   /* If there is already an entry for a function with the same
   10375             :      signature as FN, then we do not need a second vcall offset.
   10376             :      Check the list of functions already present in the derived
   10377             :      class vtable.  */
   10378    46937273 :   FOR_EACH_VEC_SAFE_ELT (vid->fns, i, derived_entry)
   10379             :     {
   10380    41144035 :       if (same_signature_p (derived_entry, orig_fn)
   10381             :           /* We only use one vcall offset for virtual destructors,
   10382             :              even though there are two virtual table entries.  */
   10383    77908203 :           || (DECL_DESTRUCTOR_P (derived_entry)
   10384    26856400 :               && DECL_DESTRUCTOR_P (orig_fn)))
   10385    16841373 :         return;
   10386             :     }
   10387             : 
   10388             :   /* If we are building these vcall offsets as part of building
   10389             :      the vtable for the most derived class, remember the vcall
   10390             :      offset.  */
   10391     5793238 :   if (vid->binfo == TYPE_BINFO (vid->derived))
   10392             :     {
   10393     5470942 :       tree_pair_s elt = {orig_fn, vid->index};
   10394     5470942 :       vec_safe_push (CLASSTYPE_VCALL_INDICES (vid->derived), elt);
   10395             :     }
   10396             : 
   10397             :   /* The next vcall offset will be found at a more negative
   10398             :      offset.  */
   10399     5793238 :   vid->index = size_binop (MINUS_EXPR, vid->index,
   10400             :                            ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
   10401             : 
   10402             :   /* Keep track of this function.  */
   10403     5793238 :   vec_safe_push (vid->fns, orig_fn);
   10404             : 
   10405     5793238 :   if (vid->generate_vcall_entries)
   10406             :     {
   10407      324792 :       tree base;
   10408      324792 :       tree fn;
   10409             : 
   10410             :       /* Find the overriding function.  */
   10411      324792 :       fn = find_final_overrider (vid->rtti_binfo, binfo, orig_fn);
   10412      324792 :       if (fn == error_mark_node)
   10413          36 :         vcall_offset = build_zero_cst (vtable_entry_type);
   10414             :       else
   10415             :         {
   10416      324756 :           base = TREE_VALUE (fn);
   10417             : 
   10418             :           /* The vbase we're working on is a primary base of
   10419             :              vid->binfo.  But it might be a lost primary, so its
   10420             :              BINFO_OFFSET might be wrong, so we just use the
   10421             :              BINFO_OFFSET from vid->binfo.  */
   10422     1299024 :           vcall_offset = size_diffop_loc (input_location,
   10423      324756 :                                       BINFO_OFFSET (base),
   10424      324756 :                                       BINFO_OFFSET (vid->binfo));
   10425      324756 :           vcall_offset = fold_build1_loc (input_location,
   10426             :                                       NOP_EXPR, vtable_entry_type,
   10427             :                                       vcall_offset);
   10428             :         }
   10429             :       /* Add the initializer to the vtable.  */
   10430      324792 :       CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, vcall_offset);
   10431             :     }
   10432             : }
   10433             : 
   10434             : /* Return vtbl initializers for the RTTI entries corresponding to the
   10435             :    BINFO's vtable.  The RTTI entries should indicate the object given
   10436             :    by VID->rtti_binfo.  */
   10437             : 
   10438             : static void
   10439     1806916 : build_rtti_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10440             : {
   10441     1806916 :   tree b;
   10442     1806916 :   tree t;
   10443     1806916 :   tree offset;
   10444     1806916 :   tree decl;
   10445     1806916 :   tree init;
   10446             : 
   10447     1806916 :   t = BINFO_TYPE (vid->rtti_binfo);
   10448             : 
   10449             :   /* To find the complete object, we will first convert to our most
   10450             :      primary base, and then add the offset in the vtbl to that value.  */
   10451     1806916 :   b = most_primary_binfo (binfo);
   10452     1806916 :   offset = size_diffop_loc (input_location,
   10453     1806916 :                         BINFO_OFFSET (vid->rtti_binfo), BINFO_OFFSET (b));
   10454             : 
   10455             :   /* The second entry is the address of the typeinfo object.  */
   10456     1806916 :   if (flag_rtti)
   10457     1803129 :     decl = build_address (get_tinfo_decl (t));
   10458             :   else
   10459        3787 :     decl = integer_zero_node;
   10460             : 
   10461             :   /* Convert the declaration to a type that can be stored in the
   10462             :      vtable.  */
   10463     1806916 :   init = build_nop (vfunc_ptr_type_node, decl);
   10464     1806916 :   CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, init);
   10465             : 
   10466             :   /* Add the offset-to-top entry.  It comes earlier in the vtable than
   10467             :      the typeinfo entry.  Convert the offset to look like a
   10468             :      function pointer, so that we can put it in the vtable.  */
   10469     1806916 :   init = build_nop (vfunc_ptr_type_node, offset);
   10470     1806916 :   CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, init);
   10471     1806916 : }
   10472             : 
   10473             : /* TRUE iff TYPE is uniquely derived from PARENT.  Ignores
   10474             :    accessibility.  */
   10475             : 
   10476             : bool
   10477        3218 : uniquely_derived_from_p (tree parent, tree type)
   10478             : {
   10479        3218 :   tree base = lookup_base (type, parent, ba_unique, NULL, tf_none);
   10480        3218 :   return base && base != error_mark_node;
   10481             : }
   10482             : 
   10483             : /* TRUE iff TYPE is publicly & uniquely derived from PARENT.  */
   10484             : 
   10485             : bool
   10486        3613 : publicly_uniquely_derived_p (tree parent, tree type)
   10487             : {
   10488        3613 :   tree base = lookup_base (type, parent, ba_ignore_scope | ba_check,
   10489             :                            NULL, tf_none);
   10490        3613 :   return base && base != error_mark_node;
   10491             : }
   10492             : 
   10493             : /* CTX1 and CTX2 are declaration contexts.  Return the innermost common
   10494             :    class between them, if any.  */
   10495             : 
   10496             : tree
   10497         187 : common_enclosing_class (tree ctx1, tree ctx2)
   10498             : {
   10499         187 :   if (!TYPE_P (ctx1) || !TYPE_P (ctx2))
   10500             :     return NULL_TREE;
   10501         187 :   gcc_assert (ctx1 == TYPE_MAIN_VARIANT (ctx1)
   10502             :               && ctx2 == TYPE_MAIN_VARIANT (ctx2));
   10503         187 :   if (ctx1 == ctx2)
   10504             :     return ctx1;
   10505         116 :   for (tree t = ctx1; TYPE_P (t); t = TYPE_CONTEXT (t))
   10506          85 :     TYPE_MARKED_P (t) = true;
   10507          52 :   tree found = NULL_TREE;
   10508          52 :   for (tree t = ctx2; TYPE_P (t); t = TYPE_CONTEXT (t))
   10509          52 :     if (TYPE_MARKED_P (t))
   10510             :       {
   10511             :         found = t;
   10512             :         break;
   10513             :       }
   10514         116 :   for (tree t = ctx1; TYPE_P (t); t = TYPE_CONTEXT (t))
   10515          85 :     TYPE_MARKED_P (t) = false;
   10516             :   return found;
   10517             : }
   10518             : 
   10519             : #include "gt-cp-class.h"

Generated by: LCOV version 1.16