LCOV - code coverage report
Current view: top level - gcc/cp - class.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.5 % 4446 4292
Test Date: 2026-10-24 16:24:59 Functions: 98.6 % 209 206
Legend: Lines:     hit not hit

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

Generated by: LCOV version 2.5.0-beta

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