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-11-14 16:39:50 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    217526365 : set_current_access_from_decl (tree decl)
     216              : {
     217    217526365 :   if (TREE_PRIVATE (decl))
     218     20802383 :     current_access_specifier = access_private_node;
     219    196723982 :   else if (TREE_PROTECTED (decl))
     220     11989453 :     current_access_specifier = access_protected_node;
     221              :   else
     222    184734529 :     current_access_specifier = access_public_node;
     223    217526365 : }
     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       160735 : build_if_in_charge (tree true_stmt, tree false_stmt)
     231              : {
     232       160735 :   gcc_assert (DECL_HAS_IN_CHARGE_PARM_P (current_function_decl));
     233       321470 :   tree cmp = build2 (NE_EXPR, boolean_type_node,
     234       160735 :                      current_in_charge_parm, integer_zero_node);
     235       160735 :   tree type = unlowered_expr_type (true_stmt);
     236       160735 :   if (VOID_TYPE_P (type))
     237         7755 :     type = unlowered_expr_type (false_stmt);
     238       160735 :   tree cond = build3 (COND_EXPR, type,
     239              :                       cmp, true_stmt, false_stmt);
     240       160735 :   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     61876592 : build_base_path (enum tree_code code,
     255              :                  tree expr,
     256              :                  tree binfo,
     257              :                  int nonnull,
     258              :                  tsubst_flags_t complain)
     259              : {
     260     61876592 :   tree v_binfo = NULL_TREE;
     261     61876592 :   tree d_binfo = NULL_TREE;
     262     61876592 :   tree probe;
     263     61876592 :   tree offset;
     264     61876592 :   tree target_type;
     265     61876592 :   tree null_test = NULL;
     266     61876592 :   tree ptr_target_type;
     267     61876592 :   int fixed_type_p;
     268     61876592 :   int want_pointer = TYPE_PTR_P (TREE_TYPE (expr));
     269     61876592 :   bool has_empty = false;
     270     61876592 :   bool virtual_access;
     271     61876592 :   bool rvalue = false;
     272              : 
     273     61876592 :   if (expr == error_mark_node || binfo == error_mark_node || !binfo)
     274              :     return error_mark_node;
     275              : 
     276    132988302 :   for (probe = binfo; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
     277              :     {
     278     71111734 :       d_binfo = probe;
     279     71111734 :       if (is_empty_class (BINFO_TYPE (probe)))
     280      9910670 :         has_empty = true;
     281    142124564 :       if (!v_binfo && BINFO_VIRTUAL_P (probe))
     282              :         v_binfo = probe;
     283              :     }
     284              : 
     285     61876568 :   probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
     286     61876568 :   if (want_pointer)
     287     57865532 :     probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
     288     61876568 :   if (dependent_type_p (probe))
     289       289535 :     if (tree open = currently_open_class (probe))
     290     61876568 :       probe = open;
     291              : 
     292     61876568 :   if (code == PLUS_EXPR
     293    120188398 :       && !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     65441296 :   gcc_assert ((code == MINUS_EXPR
     310              :                && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), probe))
     311              :               || code == PLUS_EXPR);
     312              : 
     313     61876558 :   if (binfo == d_binfo)
     314              :     /* Nothing to do.  */
     315              :     return expr;
     316              : 
     317      8518317 :   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     24407491 :   bool uneval = (cp_unevaluated_operand != 0
     349      7723026 :                  || processing_template_decl
     350     15889426 :                  || in_template_context);
     351              : 
     352      7370887 :   if (!uneval)
     353      7370887 :     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      8518302 :   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      8518302 :   if (code == PLUS_EXPR
     363      8518302 :       && !want_pointer
     364              :       && !has_empty
     365      4010569 :       && !uneval
     366      2374580 :       && !virtual_access)
     367      2368053 :     return build_simple_base_path (expr, binfo);
     368              : 
     369      6150249 :   if (!want_pointer)
     370              :     {
     371      1642516 :       rvalue = !lvalue_p (expr);
     372              :       /* This must happen before the call to save_expr.  */
     373      1642516 :       expr = cp_build_addr_expr (expr, complain);
     374              :     }
     375              :   else
     376      4507733 :     expr = mark_rvalue_use (expr);
     377              : 
     378      6150249 :   offset = BINFO_OFFSET (binfo);
     379      6202241 :   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      6150249 :   target_type = cp_build_qualified_type
     384      6150249 :     (target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr))));
     385      6150249 :   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      6150249 :   if (uneval)
     393              :     {
     394      1147415 :       expr = build_nop (ptr_target_type, expr);
     395      1147415 :       goto indout;
     396              :     }
     397              : 
     398      5002834 :   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      5002828 :   if (virtual_access && fixed_type_p < 0
     411      5002828 :       && 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      5002795 :   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        69685 :       if (!virtual_access && integer_zerop (offset))
     427        67654 :         return build_nop (ptr_target_type, expr);
     428         2031 :       null_test = error_mark_node;
     429              :     }
     430              : 
     431              :   /* Protect against multiple evaluation if necessary.  */
     432      4935141 :   if (TREE_SIDE_EFFECTS (expr) && (null_test || virtual_access))
     433          975 :     expr = save_expr (expr);
     434              : 
     435              :   /* Store EXPR and build the real null test just before returning.  */
     436      4935141 :   if (null_test)
     437         2031 :     null_test = expr;
     438              : 
     439              :   /* If this is a simple base reference, express it as a COMPONENT_REF.  */
     440      4935141 :   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      4817870 :       && !has_empty)
     444              :     {
     445      2834753 :       expr = cp_build_fold_indirect_ref (expr);
     446      2834753 :       expr = build_simple_base_path (expr, binfo);
     447      2834753 :       if (rvalue && lvalue_p (expr))
     448            0 :         expr = move (expr);
     449      2834753 :       if (want_pointer)
     450      2834753 :         expr = build_address (expr);
     451      2834753 :       target_type = TREE_TYPE (expr);
     452      2834753 :       goto out;
     453              :     }
     454              : 
     455      2100388 :   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        77755 :       tree v_offset;
     461              : 
     462        77755 :       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        77749 :           tree t = expr;
     477        77749 :           if (sanitize_flags_p (SANITIZE_VPTR)
     478        77749 :               && 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        77705 :                 t = expr;
     484              :             }
     485        77749 :           v_offset = build_vfield_ref (cp_build_fold_indirect_ref (t),
     486        77749 :           TREE_TYPE (TREE_TYPE (expr)));
     487              :         }
     488              : 
     489        77755 :       if (v_offset == error_mark_node)
     490              :         return error_mark_node;
     491              : 
     492        77755 :       v_offset = fold_build_pointer_plus (v_offset, BINFO_VPTR_FIELD (v_binfo));
     493        77755 :       v_offset = build1 (NOP_EXPR,
     494              :                          build_pointer_type (ptrdiff_type_node),
     495              :                          v_offset);
     496        77755 :       v_offset = cp_build_fold_indirect_ref (v_offset);
     497        77755 :       TREE_CONSTANT (v_offset) = 1;
     498              : 
     499       155510 :       offset = convert_to_integer (ptrdiff_type_node,
     500              :                                    size_diffop_loc (input_location, offset,
     501        77755 :                                                 BINFO_OFFSET (v_binfo)));
     502              : 
     503        77755 :       if (!integer_zerop (offset))
     504          502 :         v_offset = build2 (code, ptrdiff_type_node, v_offset, offset);
     505              : 
     506        77755 :       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        46073 :         offset = build_if_in_charge
     511        46073 :           (convert_to_integer (ptrdiff_type_node, BINFO_OFFSET (binfo)),
     512              :            v_offset);
     513              :       else
     514              :         offset = v_offset;
     515              :     }
     516              : 
     517      2100388 :   if (want_pointer)
     518      2100388 :     target_type = ptr_target_type;
     519              : 
     520      2100388 :   if (!integer_zerop (offset))
     521              :     {
     522        78848 :       offset = fold_convert (sizetype, offset);
     523        78848 :       if (code == MINUS_EXPR)
     524          538 :         offset = fold_build1_loc (input_location, NEGATE_EXPR, sizetype, offset);
     525        78848 :       expr = fold_build_pointer_plus (expr, offset);
     526              :     }
     527              :   else
     528              :     null_test = NULL;
     529              : 
     530      2100388 :   expr = build1 (NOP_EXPR, ptr_target_type, expr);
     531              : 
     532      3247836 :  indout:
     533      3247836 :   if (!want_pointer)
     534              :     {
     535      1642516 :       expr = cp_build_fold_indirect_ref (expr);
     536      1642516 :       if (rvalue)
     537       249323 :         expr = move (expr);
     538              :     }
     539              : 
     540      1605320 :  out:
     541      6082589 :   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     17759174 : build_simple_base_path (tree expr, tree binfo)
     554              : {
     555     17759174 :   tree type = BINFO_TYPE (binfo);
     556     17759174 :   tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
     557     17759174 :   tree field;
     558              : 
     559     17759174 :   if (d_binfo == NULL_TREE)
     560              :     {
     561      8679460 :       tree temp;
     562              : 
     563      8679460 :       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      8679460 :       temp = unary_complex_lvalue (ADDR_EXPR, expr);
     570      8679460 :       if (temp)
     571            0 :         expr = cp_build_fold_indirect_ref (temp);
     572              : 
     573              :       return expr;
     574              :     }
     575              : 
     576              :   /* Recurse.  */
     577      9079714 :   expr = build_simple_base_path (expr, d_binfo);
     578              : 
     579      9079714 :   for (field = TYPE_FIELDS (BINFO_TYPE (d_binfo));
     580     46249062 :        field; field = DECL_CHAIN (field))
     581              :     /* Is this the base field created by build_base_field?  */
     582     46249062 :     if (TREE_CODE (field) == FIELD_DECL
     583     10306779 :         && DECL_FIELD_IS_BASE (field)
     584     10260095 :         && 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     55328899 :         && (BINFO_INHERITANCE_CHAIN (d_binfo)
     590      8679301 :             || tree_int_cst_equal (byte_position (field),
     591      8679301 :                                    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      9079714 :         auto type_quals = cp_type_quals (TREE_TYPE (expr));
     597              : 
     598      9079714 :         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      9079714 :         if (type_quals & TYPE_QUAL_CONST)
     605       806298 :           TREE_READONLY (expr) = 1;
     606      9079714 :         if (type_quals & TYPE_QUAL_VOLATILE)
     607        29161 :           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      2017763 : convert_to_base (tree object, tree type, bool check_access, bool nonnull,
     625              :                  tsubst_flags_t complain)
     626              : {
     627      2017763 :   tree binfo;
     628      2017763 :   tree object_type;
     629              : 
     630      2017763 :   if (TYPE_PTR_P (TREE_TYPE (object)))
     631              :     {
     632       216140 :       object_type = TREE_TYPE (TREE_TYPE (object));
     633       216140 :       type = TREE_TYPE (type);
     634              :     }
     635              :   else
     636      1801623 :     object_type = TREE_TYPE (object);
     637              : 
     638      2021179 :   binfo = lookup_base (object_type, type, check_access ? ba_check : ba_unique,
     639              :                        NULL, complain);
     640      2017763 :   if (!binfo || binfo == error_mark_node)
     641           87 :     return error_mark_node;
     642              : 
     643      2017676 :   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      1642088 : convert_to_base_statically (tree expr, tree base)
     653              : {
     654      1642088 :   tree expr_type;
     655              : 
     656      1642088 :   expr_type = TREE_TYPE (expr);
     657      1642088 :   if (!SAME_BINFO_TYPE_P (BINFO_TYPE (base), expr_type))
     658              :     {
     659              :       /* If this is a non-empty base, use a COMPONENT_REF.  */
     660      1642088 :       if (!is_empty_class (BINFO_TYPE (base)))
     661      1409449 :         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       232639 :       gcc_assert (!processing_template_decl);
     668       232639 :       expr = cp_build_addr_expr (expr, tf_warning_or_error);
     669       232639 :       if (!integer_zerop (BINFO_OFFSET (base)))
     670          189 :         expr = fold_build_pointer_plus_loc (input_location,
     671          189 :                                             expr, BINFO_OFFSET (base));
     672       232639 :       expr = fold_convert (build_pointer_type (BINFO_TYPE (base)), expr);
     673       232639 :       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     42764584 : is_empty_base_ref (tree expr)
     686              : {
     687     42764584 :   if (INDIRECT_REF_P (expr))
     688     34291102 :     expr = TREE_OPERAND (expr, 0);
     689     42764584 :   if (TREE_CODE (expr) != NOP_EXPR)
     690              :     return false;
     691      1167388 :   tree type = TREE_TYPE (expr);
     692      1167388 :   if (!POINTER_TYPE_P (type))
     693              :     return false;
     694      1167388 :   type = TREE_TYPE (type);
     695      1167388 :   if (!is_empty_class (type))
     696              :     return false;
     697       483584 :   STRIP_NOPS (expr);
     698       483584 :   tree fromtype = TREE_TYPE (expr);
     699       483584 :   if (!POINTER_TYPE_P (fromtype))
     700              :     return false;
     701       483584 :   fromtype = TREE_TYPE (fromtype);
     702       474959 :   return (CLASS_TYPE_P (fromtype)
     703       474959 :           && !same_type_ignoring_top_level_qualifiers_p (fromtype, type)
     704       957655 :           && DERIVED_FROM_P (type, fromtype));
     705              : }
     706              : 
     707              : tree
     708      1751239 : build_vfield_ref (tree datum, tree type)
     709              : {
     710      1751239 :   tree vfield, vcontext;
     711              : 
     712      1751239 :   if (datum == error_mark_node
     713              :       /* Can happen in case of duplicate base types (c++/59082).  */
     714      1751239 :       || !TYPE_VFIELD (type))
     715              :     return error_mark_node;
     716              : 
     717              :   /* First, convert to the requested type.  */
     718      1751239 :   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      1751239 :   vfield = TYPE_VFIELD (type);
     729      1751239 :   vcontext = DECL_CONTEXT (vfield);
     730      3818444 :   while (!same_type_ignoring_top_level_qualifiers_p (vcontext, type))
     731              :     {
     732      2067205 :       datum = build_simple_base_path (datum, CLASSTYPE_PRIMARY_BINFO (type));
     733      2067205 :       type = TREE_TYPE (datum);
     734              :     }
     735              : 
     736      1751239 :   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       495304 : build_vtbl_ref (tree instance, tree idx)
     746              : {
     747       495304 :   tree aref;
     748       495304 :   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       495304 :   int cdtorp = 0;
     754       495304 :   tree fixed_type = fixed_type_or_null (instance, NULL, &cdtorp);
     755              : 
     756       495304 :   tree basetype = non_reference (TREE_TYPE (instance));
     757              : 
     758       495304 :   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       495273 :     vtbl = build_vfield_ref (instance, basetype);
     768              : 
     769       495304 :   aref = build_array_ref (input_location, vtbl, idx);
     770       990577 :   TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
     771              : 
     772       495304 :   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       494176 : build_vfn_ref (tree instance_ptr, tree idx)
     780              : {
     781       494176 :   tree aref;
     782              : 
     783       494176 :   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       494176 :   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       494176 :   aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr,
     793       494176 :                  fold_convert (TREE_TYPE (instance_ptr), idx));
     794              : 
     795       494176 :   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      1824666 : 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     38376424 : set_linkage_according_to_type (tree /*type*/, tree decl)
     817              : {
     818     38376424 :   TREE_PUBLIC (decl) = 1;
     819     38376424 :   determine_visibility (decl);
     820     38376424 : }
     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      2262265 : build_vtable (tree class_type, tree name, tree vtable_type)
     828              : {
     829      2262265 :   tree decl;
     830              : 
     831      2262265 :   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      2262265 :   SET_DECL_ASSEMBLER_NAME (decl, name);
     835      2262265 :   DECL_CONTEXT (decl) = class_type;
     836      2262265 :   DECL_ARTIFICIAL (decl) = 1;
     837      2262265 :   TREE_STATIC (decl) = 1;
     838      2262265 :   TREE_READONLY (decl) = 1;
     839      2262265 :   DECL_VIRTUAL_P (decl) = 1;
     840      2273730 :   SET_DECL_ALIGN (decl, TARGET_VTABLE_ENTRY_ALIGN);
     841      2262265 :   DECL_USER_ALIGN (decl) = true;
     842      2262265 :   DECL_VTABLE_OR_VTT_P (decl) = 1;
     843      2262265 :   set_linkage_according_to_type (class_type, decl);
     844              :   /* The vtable has not been defined -- yet.  */
     845      2262265 :   DECL_EXTERNAL (decl) = 1;
     846      2262265 :   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      2262265 :   DECL_IGNORED_P (decl) = 1;
     869              : 
     870      2262265 :   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      8606520 : get_vtable_decl (tree type, int complete)
     881              : {
     882      8606520 :   tree decl;
     883              : 
     884      8606520 :   if (CLASSTYPE_VTABLES (type))
     885      6781854 :     return CLASSTYPE_VTABLES (type);
     886              : 
     887      1824666 :   decl = build_vtable (type, get_vtable_name (type), vtbl_type_node);
     888      1824666 :   CLASSTYPE_VTABLES (type) = decl;
     889              : 
     890      1824666 :   if (complete)
     891              :     {
     892        40889 :       DECL_EXTERNAL (decl) = 1;
     893        40889 :       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      6771045 : build_primary_vtable (tree binfo, tree type)
     907              : {
     908      6771045 :   tree decl;
     909      6771045 :   tree virtuals;
     910              : 
     911      6771045 :   decl = get_vtable_decl (type, /*complete=*/0);
     912              : 
     913      6771045 :   if (binfo)
     914              :     {
     915      6514579 :       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      1527311 :       virtuals = copy_list (BINFO_VIRTUALS (binfo));
     921      1527311 :       TREE_TYPE (decl) = TREE_TYPE (get_vtbl_decl_for_binfo (binfo));
     922      1527311 :       DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (decl));
     923      1527311 :       DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
     924              :     }
     925              :   else
     926              :     {
     927       256466 :       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      1783777 :   BINFO_VTABLE (TYPE_BINFO (type)) = decl;
     934      1783777 :   BINFO_VIRTUALS (TYPE_BINFO (type)) = virtuals;
     935      1783777 :   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       741120 : build_secondary_vtable (tree binfo)
     955              : {
     956       741120 :   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       257519 :   SET_BINFO_NEW_VTABLE_MARKED (binfo);
     964              : 
     965              :   /* Make fresh virtual list, so we can smash it later.  */
     966       257519 :   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       257519 :   BINFO_VTABLE (binfo) = NULL_TREE;
     971       257519 :   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      7255699 : make_new_vtable (tree t, tree binfo)
     979              : {
     980      7255699 :   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      6514579 :     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       741120 :     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      7646795 : modify_vtable_entry (tree t,
    1001              :                      tree binfo,
    1002              :                      tree fndecl,
    1003              :                      tree delta,
    1004              :                      tree *virtuals)
    1005              : {
    1006      7646795 :   tree v;
    1007              : 
    1008      7646795 :   v = *virtuals;
    1009              : 
    1010      7646795 :   if (fndecl != BV_FN (v)
    1011      7646795 :       || !tree_int_cst_equal (delta, BV_DELTA (v)))
    1012              :     {
    1013              :       /* We need a new vtable for BINFO.  */
    1014      5470869 :       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      5470869 :       BV_DELTA (v) = delta;
    1026      5470869 :       BV_VCALL_INDEX (v) = NULL_TREE;
    1027      5470869 :       BV_FN (v) = fndecl;
    1028              :     }
    1029      7646795 : }
    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       293578 : iobj_parm_corresponds_to (tree iobj_fn, tree xobj_param, tree context)
    1038              : {
    1039       293578 :   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       293578 :   if (!same_type_ignoring_top_level_qualifiers_p
    1109       293578 :       (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       293569 :   cp_ref_qualifier const iobj_ref_qual = type_memfn_rqual (iobj_fn_type);
    1122              :   /* We only care about cv qualifiers when determining correspondence.  */
    1123       293569 :   static constexpr cp_cv_quals cv_bits = TYPE_QUAL_VOLATILE
    1124              :                                        | TYPE_QUAL_CONST;
    1125       293569 :   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       293569 :   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       585822 :       cp_ref_qualifier const xobj_ref_qual = [&](){
    1184       292911 :           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       292911 :         }(); /* 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       292911 :       cp_cv_quals const xobj_cv_quals
    1194       292911 :         = 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       292911 :       if (iobj_ref_qual != xobj_ref_qual
    1199       292335 :           || 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    445124810 : object_parms_correspond (tree fn, tree method, tree context)
    1216              : {
    1217    445124810 :   tree fn_type = TREE_TYPE (fn);
    1218    445124810 :   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    445124810 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    1224    445124810 :       && 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    442833206 :       if ((cxx_dialect >= cxx20
    1229      3499227 :            || (FUNCTION_REF_QUALIFIED (fn_type)
    1230      3499227 :                == FUNCTION_REF_QUALIFIED (method_type)))
    1231    446332425 :           && (type_memfn_quals (fn_type) != type_memfn_quals (method_type)
    1232    423803784 :               || type_memfn_rqual (fn_type) != type_memfn_rqual (method_type)))
    1233     19435157 :         return false;
    1234              :       return true;
    1235              :     }
    1236              :   /* Treat a static member function as corresponding to any object parm.  */
    1237      2291604 :   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        14059 :   else if (DECL_XOBJ_MEMBER_FUNCTION_P (fn)
    1243        27014 :            && DECL_XOBJ_MEMBER_FUNCTION_P (method))
    1244              :     {
    1245        35607 :       auto get_object_param = [] (tree fn)
    1246              :         {
    1247        23738 :           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        11869 :       tree fn_param = get_object_param (fn);
    1252        11869 :       tree method_param = get_object_param (method);
    1253        11869 :       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         8861 :   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    362217749 : add_method (tree type, tree method, bool via_using)
    1274              : {
    1275    362217749 :   if (method == error_mark_node)
    1276              :     return false;
    1277              : 
    1278    362217749 :   gcc_assert (!DECL_EXTERN_C_P (method));
    1279              : 
    1280    362217749 :   tree *slot = find_member_slot (type, DECL_NAME (method));
    1281    362217749 :   tree current_fns = slot ? *slot : NULL_TREE;
    1282              : 
    1283              :   /* See below.  */
    1284    362217749 :   int losem = -1;
    1285              : 
    1286              :   /* Check to see if we've already got this method.  */
    1287   1454320163 :   for (ovl_iterator iter (current_fns); iter; ++iter)
    1288              :     {
    1289    613819379 :       tree fn = *iter;
    1290              : 
    1291    613819379 :       if (TREE_CODE (fn) != TREE_CODE (method))
    1292    167176987 :         continue;
    1293              : 
    1294              :       /* Two using-declarations can coexist, we'll complain about ambiguity in
    1295              :          overload resolution.  */
    1296      4007411 :       if (via_using && iter.using_p ()
    1297              :           /* Except handle inherited constructors specially.  */
    1298    451029488 :           && ! DECL_CONSTRUCTOR_P (fn))
    1299              :         {
    1300      1590471 :           if (fn == method)
    1301              :             /* Don't add the same one twice.  */
    1302        19704 :             return false;
    1303      1590462 :           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    445051921 :       if (!object_parms_correspond (fn, method, type))
    1323     19439770 :         continue;
    1324              : 
    1325    425612151 :       tree fn_type = TREE_TYPE (fn);
    1326    425612151 :       tree method_type = TREE_TYPE (method);
    1327              : 
    1328    425612151 :       tree real_fn = fn;
    1329    425612151 :       tree real_method = method;
    1330              : 
    1331              :       /* Templates and conversion ops must match return types.  */
    1332    851062370 :       if ((DECL_CONV_FN_P (fn) || TREE_CODE (fn) == TEMPLATE_DECL)
    1333    591716677 :           && !same_type_p (TREE_TYPE (fn_type), TREE_TYPE (method_type)))
    1334      4477964 :         continue;
    1335              : 
    1336              :       /* For templates, the template parameters must be identical.  */
    1337    421134187 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    1338              :         {
    1339    323576800 :           if (!comp_template_parms (DECL_TEMPLATE_PARMS (fn),
    1340    161788400 :                                     DECL_TEMPLATE_PARMS (method)))
    1341    112905135 :             continue;
    1342              : 
    1343     48883265 :           real_fn = DECL_TEMPLATE_RESULT (fn);
    1344     48883265 :           real_method = DECL_TEMPLATE_RESULT (method);
    1345              :         }
    1346              : 
    1347    308229052 :       tree parms1 = TYPE_ARG_TYPES (fn_type);
    1348    308229052 :       tree parms2 = TYPE_ARG_TYPES (method_type);
    1349    308229052 :       if (! DECL_STATIC_FUNCTION_P (real_fn))
    1350    306783069 :         parms1 = TREE_CHAIN (parms1);
    1351    308229052 :       if (! DECL_STATIC_FUNCTION_P (real_method))
    1352    306774214 :         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    308229052 :       if (ctor_omit_inherited_parms (real_fn))
    1357          729 :         parms1 = FUNCTION_FIRST_USER_PARMTYPE (DECL_CLONED_FUNCTION (real_fn));
    1358    308229052 :       if (ctor_omit_inherited_parms (real_method))
    1359          330 :         parms2 = (FUNCTION_FIRST_USER_PARMTYPE
    1360              :                   (DECL_CLONED_FUNCTION (real_method)));
    1361              : 
    1362    308229052 :       if (!compparms (parms1, parms2))
    1363    304396768 :         continue;
    1364              : 
    1365      3832284 :       tree fn_constraints = get_constraints (fn);
    1366      3832284 :       tree method_constraints = get_constraints (method);
    1367              : 
    1368      3832284 :       if (fn_constraints && method_constraints
    1369      3233212 :           && DECL_CONTEXT (fn) != type
    1370      3832296 :           && !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      3832284 :       if (!equivalent_constraints (fn_constraints, method_constraints))
    1389              :         {
    1390      3633341 :           if (processing_template_decl)
    1391              :             /* We can't check satisfaction in dependent context, wait until
    1392              :                the class is instantiated.  */
    1393       545992 :             continue;
    1394              : 
    1395      3087349 :           special_function_kind sfk = special_memfn_p (method);
    1396              : 
    1397      6023489 :           if (sfk == sfk_none
    1398       665326 :               || DECL_INHERITED_CTOR (fn)
    1399      3419920 :               || 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      2936140 :             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       151209 :           bool dtor = (sfk == sfk_destructor);
    1412       151209 :           if (losem == -1)
    1413       298469 :             losem = ((!dtor && DECL_DELETED_FN (method))
    1414       298127 :                      || !constraints_satisfied_p (method));
    1415       147816 :           bool losef = ((!dtor && DECL_DELETED_FN (fn))
    1416       165433 :                         || !constraints_satisfied_p (fn));
    1417       151209 :           int win;
    1418       151209 :           if (losem || losef)
    1419       145585 :             win = losem - losef;
    1420              :           else
    1421              :             {
    1422         5624 :               win = more_constrained (fn, method);
    1423         5624 :               if (win)
    1424              :                 {
    1425              :                   /* The winner can't be more explicit.  */
    1426         5621 :                   int ex = (DECL_NONCONVERTING_P (method)
    1427         5621 :                             - DECL_NONCONVERTING_P (fn));
    1428         5621 :                   if (ex && ex != win)
    1429              :                     win = 0;
    1430              :                 }
    1431              :             }
    1432       151197 :           if (win > 0)
    1433              :             /* Leave FN in the method vec, discard METHOD.  */
    1434              :             return false;
    1435       138369 :           else if (win < 0)
    1436              :             {
    1437              :               /* Remove FN, add METHOD.  */
    1438       124732 :               current_fns = iter.remove_node (current_fns);
    1439       124732 :               continue;
    1440              :             }
    1441              :           else
    1442              :             /* Let them coexist for now.  */
    1443        13637 :             continue;
    1444              :         }
    1445              : 
    1446              :       /* If these are versions of the same function, process and
    1447              :          move on.  */
    1448       198970 :       if (TREE_CODE (fn) == FUNCTION_DECL
    1449       198943 :           && maybe_version_functions (method, fn))
    1450           27 :         continue;
    1451              : 
    1452       397832 :       if (DECL_INHERITED_CTOR (method))
    1453              :         {
    1454        12970 :           if (!DECL_INHERITED_CTOR (fn))
    1455              :             /* Defer to the other function.  */
    1456         6404 :             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       192431 :       if (via_using)
    1489              :         /* Defer to the local function.  */
    1490              :         return false;
    1491       192419 :       else if (iter.using_p ()
    1492       192419 :                ||  (flag_new_inheriting_ctors
    1493       242950 :                     && DECL_INHERITED_CTOR (fn)))
    1494              :         {
    1495              :           /* Remove the inherited function.  */
    1496       191980 :           current_fns = iter.remove_node (current_fns);
    1497       191980 :           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    362198045 :   current_fns = ovl_insert (method, current_fns, via_using);
    1511              : 
    1512    654239775 :   if (!COMPLETE_TYPE_P (type) && !DECL_CONV_FN_P (method)
    1513    651436433 :       && !push_class_level_binding (DECL_NAME (method), current_fns))
    1514              :     return false;
    1515              : 
    1516    362198027 :   if (!slot)
    1517    159510523 :     slot = add_member_slot (type, DECL_NAME (method));
    1518              : 
    1519              :   /* Maintain TYPE_HAS_USER_CONSTRUCTOR, etc.  */
    1520    362198027 :   grok_special_member_properties (method);
    1521              : 
    1522    362198027 :   *slot = current_fns;
    1523              : 
    1524    362198027 :   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      3143056 : alter_access (tree t, tree fdecl, tree access)
    1534              : {
    1535      3143056 :   tree elem;
    1536              : 
    1537      3143056 :   retrofit_lang_decl (fdecl);
    1538              : 
    1539      3143056 :   gcc_assert (!DECL_DISCRIMINATOR_P (fdecl));
    1540              : 
    1541      3143056 :   elem = purpose_member (t, DECL_ACCESS (fdecl));
    1542      3143056 :   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      3143056 :       perform_or_defer_access_check (TYPE_BINFO (t), fdecl, fdecl,
    1563              :                                      tf_warning_or_error);
    1564      3143056 :       DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
    1565      3143056 :       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       500140 : declared_access (tree decl)
    1574              : {
    1575       500140 :   return (TREE_PRIVATE (decl) ? access_private_node
    1576       489932 :           : TREE_PROTECTED (decl) ? access_protected_node
    1577       500140 :           : 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    200377945 : maybe_push_used_methods (tree decl)
    1586              : {
    1587    200377945 :   if (TREE_CODE (decl) != USING_DECL)
    1588              :     return false;
    1589      3475527 :   tree used = strip_using_decl (decl);
    1590      3475527 :   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      6465250 :   for (tree f : ovl_range (used))
    1596              :     {
    1597      6115608 :       if (DECL_CONSTRUCTOR_P (f))
    1598              :         /* Inheriting constructors are handled separately.  */
    1599       119096 :         return false;
    1600              : 
    1601      2938708 :       bool added = add_method (current_class_type, f, true);
    1602              : 
    1603      2938708 :       if (added)
    1604      2938687 :         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      1909952 :   return true;
    1619              : }
    1620              : 
    1621              : /* Process the USING_DECL, which is a member of T.  */
    1622              : 
    1623              : static void
    1624      2389788 : handle_using_decl (tree using_decl, tree t)
    1625              : {
    1626      2389788 :   tree decl = USING_DECL_DECLS (using_decl);
    1627              : 
    1628      2389788 :   gcc_assert (!processing_template_decl && decl);
    1629              : 
    1630      2389788 :   cp_emit_debug_info_for_using (decl, t);
    1631              : 
    1632      2389788 :   if (is_overloaded_fn (decl))
    1633              :     /* Handled in maybe_push_used_methods.  */
    1634      2389788 :     return;
    1635              : 
    1636       480009 :   tree name = DECL_NAME (using_decl);
    1637       480009 :   tree old_value = lookup_member (t, name, /*protect=*/0, /*want_type=*/false,
    1638              :                                   tf_warning_or_error);
    1639       480009 :   if (old_value)
    1640              :     {
    1641       480009 :       old_value = OVL_FIRST (old_value);
    1642              : 
    1643       480009 :       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       480009 :   iloc_sentinel ils (DECL_SOURCE_LOCATION (using_decl));
    1673       480009 :   tree access = declared_access (using_decl);
    1674              : 
    1675              :   /* Make type T see field decl FDECL with access ACCESS.  */
    1676       480009 :   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       275640 :       gcc_assert (TREE_CODE (decl) == CONST_DECL);
    1682              : 
    1683       275640 :       auto cas = make_temp_override (current_access_specifier, access);
    1684       275640 :       tree copy = copy_decl (decl);
    1685       275640 :       DECL_CONTEXT (copy) = t;
    1686       275640 :       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       275640 :       DECL_IGNORED_P (copy) = true;
    1690       275640 :       DECL_SOURCE_LOCATION (copy) = DECL_SOURCE_LOCATION (using_decl);
    1691       275640 :       finish_member_declaration (copy);
    1692       275640 :       DECL_ABSTRACT_ORIGIN (copy) = decl;
    1693       275640 :     }
    1694              :   else
    1695       204369 :     alter_access (t, decl, access);
    1696       480009 : }
    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     17752284 : check_tag (tree tag, tree id, tree *tp, abi_tag_data *p)
    1713              : {
    1714     17752284 :   if (!IDENTIFIER_MARKED (id))
    1715              :     {
    1716      6010846 :       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      6010828 :           p->tags = tree_cons (NULL_TREE, tag, p->tags);
    1721              : 
    1722              :           /* Don't inherit this tag multiple times.  */
    1723      6010828 :           IDENTIFIER_MARKED (id) = true;
    1724              : 
    1725      6010828 :           ABI_TAG_INHERITED (p->tags) = true;
    1726      6010828 :           if (TYPE_P (p->t))
    1727              :             {
    1728              :               /* Tags inherited from type template arguments are only used
    1729              :                  to avoid warnings.  */
    1730      5963709 :               ABI_TAG_NOT_MANGLED (p->tags) = true;
    1731      5963709 :               return;
    1732              :             }
    1733              :           /* For functions and variables we want to warn, too.  */
    1734              :         }
    1735              : 
    1736              :       /* Otherwise we're diagnosing missing tags.  */
    1737        47137 :       if (TREE_CODE (p->t) == FUNCTION_DECL)
    1738              :         {
    1739        46717 :           auto_diagnostic_group d;
    1740        46717 :           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        46717 :         }
    1745          420 :       else if (VAR_P (p->t))
    1746              :         {
    1747          402 :           auto_diagnostic_group d;
    1748          402 :           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          402 :         }
    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   2626844212 : mark_or_check_attr_tags (tree attr, tree *tp, abi_tag_data *p, bool val)
    1780              : {
    1781   2626844212 :   if (!attr)
    1782              :     return;
    1783    322467359 :   for (; (attr = lookup_attribute ("abi_tag", attr));
    1784    107964204 :        attr = TREE_CHAIN (attr))
    1785    215928438 :     for (tree list = TREE_VALUE (attr); list;
    1786    107964234 :          list = TREE_CHAIN (list))
    1787              :       {
    1788    107964234 :         tree tag = TREE_VALUE (list);
    1789    107964234 :         tree id = get_identifier (TREE_STRING_POINTER (tag));
    1790    107964234 :         if (tp)
    1791     17752284 :           check_tag (tag, id, tp, p);
    1792              :         else
    1793     90211950 :           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    975263758 : mark_or_check_tags (tree t, tree *tp, abi_tag_data *p, bool val)
    1802              : {
    1803   3602107970 :   while (t != global_namespace)
    1804              :     {
    1805   2626844212 :       tree attr;
    1806   2626844212 :       if (TYPE_P (t))
    1807              :         {
    1808    970851738 :           attr = TYPE_ATTRIBUTES (t);
    1809    970851738 :           t = CP_TYPE_CONTEXT (t);
    1810              :         }
    1811              :       else
    1812              :         {
    1813   1655992474 :           attr = DECL_ATTRIBUTES (t);
    1814   1655992474 :           t = CP_DECL_CONTEXT (t);
    1815              :         }
    1816   2626844212 :       mark_or_check_attr_tags (attr, tp, p, val);
    1817              :     }
    1818    975263758 : }
    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    810527186 : find_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1826              : {
    1827    810527186 :   if (TYPE_P (*tp) && *walk_subtrees == 1 && flag_abi_version != 14)
    1828              :     /* Tell cp_walk_subtrees to look though typedefs. [PR98481] */
    1829    524485258 :     *walk_subtrees = 2;
    1830              : 
    1831    810527186 :   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    147632800 :   *walk_subtrees = false;
    1837              : 
    1838    147632800 :   abi_tag_data *p = static_cast<struct abi_tag_data*>(data);
    1839              : 
    1840    147632800 :   mark_or_check_tags (*tp, tp, p, false);
    1841              : 
    1842    147632800 :   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   1372426388 : mark_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1850              : {
    1851   1372426388 :   if (TYPE_P (*tp) && *walk_subtrees == 1 && flag_abi_version != 14)
    1852              :     /* Tell cp_walk_subtrees to look though typedefs.  */
    1853    973361368 :     *walk_subtrees = 2;
    1854              : 
    1855   1372426388 :   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    185790762 :   *walk_subtrees = false;
    1861              : 
    1862    185790762 :   bool *valp = static_cast<bool*>(data);
    1863              : 
    1864    185790762 :   mark_or_check_tags (*tp, NULL, NULL, *valp);
    1865              : 
    1866    185790762 :   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    641840196 : mark_abi_tags (tree t, bool val)
    1874              : {
    1875    641840196 :   mark_or_check_tags (t, NULL, NULL, val);
    1876    641840196 :   if (DECL_P (t))
    1877              :     {
    1878    827734686 :       if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t)
    1879    714075870 :           && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))
    1880              :         {
    1881              :           /* Template arguments are part of the signature.  */
    1882     33820066 :           tree level = INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t));
    1883    117972188 :           for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1884              :             {
    1885     50332056 :               tree arg = TREE_VEC_ELT (level, j);
    1886     50332056 :               cp_walk_tree_without_duplicates (&arg, mark_abi_tags_r, &val);
    1887              :             }
    1888              :         }
    1889    415142978 :       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   1062458318 :         for (tree arg = FUNCTION_FIRST_USER_PARMTYPE (t); arg;
    1893    714382610 :              arg = TREE_CHAIN (arg))
    1894    714382610 :           cp_walk_tree_without_duplicates (&TREE_VALUE (arg),
    1895              :                                            mark_abi_tags_r, &val);
    1896              :     }
    1897    641840196 : }
    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    251712819 : check_abi_tags (tree t, tree subob, bool just_checking = false)
    1905              : {
    1906    251712819 :   bool inherit = DECL_P (t);
    1907              : 
    1908    251712819 :   if (!inherit && !warn_abi_tag)
    1909              :     return NULL_TREE;
    1910              : 
    1911    207761573 :   tree decl = TYPE_P (t) ? TYPE_NAME (t) : t;
    1912    207761573 :   if (!TREE_PUBLIC (decl))
    1913              :     /* No need to worry about things local to this TU.  */
    1914              :     return NULL_TREE;
    1915              : 
    1916    207571510 :   mark_abi_tags (t, true);
    1917              : 
    1918    207571510 :   tree subtype = TYPE_P (subob) ? subob : TREE_TYPE (subob);
    1919    207571510 :   struct abi_tag_data data = { t, subob, error_mark_node };
    1920    207571510 :   if (inherit)
    1921    207571489 :     data.tags = NULL_TREE;
    1922              : 
    1923    207571510 :   cp_walk_tree_without_duplicates (&subtype, find_abi_tags_r, &data);
    1924              : 
    1925    207571510 :   if (!(inherit && data.tags))
    1926              :     /* We don't need to do anything with data.tags.  */;
    1927        47104 :   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        47071 :       tree attr = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (t));
    1936        47071 :       if (attr)
    1937            0 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1938              :       else
    1939        47071 :         DECL_ATTRIBUTES (t)
    1940        94142 :           = tree_cons (abi_tag_identifier, data.tags, DECL_ATTRIBUTES (t));
    1941              :     }
    1942              : 
    1943    207571510 :   mark_abi_tags (t, false);
    1944              : 
    1945    207571510 :   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    221414926 : check_abi_tags (tree decl)
    1953              : {
    1954    221414926 :   if (VAR_P (decl))
    1955     33649607 :     check_abi_tags (decl, TREE_TYPE (decl));
    1956    187765319 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1957    187761936 :            && !DECL_CONV_FN_P (decl)
    1958    372802362 :            && !mangle_return_type_p (decl))
    1959    174028361 :     check_abi_tags (decl, TREE_TYPE (TREE_TYPE (decl)));
    1960    221414926 : }
    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    113733770 : inherit_targ_abi_tags (tree t)
    1983              : {
    1984    113348588 :   if (!CLASS_TYPE_P (t)
    1985    227082358 :       || CLASSTYPE_TEMPLATE_INFO (t) == NULL_TREE)
    1986       385182 :     return;
    1987              : 
    1988    113348588 :   mark_abi_tags (t, true);
    1989              : 
    1990    113348588 :   tree args = CLASSTYPE_TI_ARGS (t);
    1991    113348588 :   struct abi_tag_data data = { t, NULL_TREE, NULL_TREE };
    1992    680091710 :   for (int i = 0; i < TMPL_ARGS_DEPTH (args); ++i)
    1993              :     {
    1994    232258558 :       tree level = TMPL_ARGS_LEVEL (args, i+1);
    1995    318925321 :       for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1996              :         {
    1997    202796042 :           tree arg = TREE_VEC_ELT (level, j);
    1998    202796042 :           data.subob = arg;
    1999    202796042 :           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    113348588 :   if (data.tags)
    2006              :     {
    2007      5963709 :       tree attr = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (t));
    2008      5963709 :       if (attr)
    2009            3 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    2010              :       else
    2011      5963706 :         TYPE_ATTRIBUTES (t)
    2012     11927412 :           = tree_cons (abi_tag_identifier, data.tags, TYPE_ATTRIBUTES (t));
    2013              :     }
    2014              : 
    2015    113348588 :   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     52492668 : check_bases (tree t,
    2051              :              int* cant_have_const_ctor_p,
    2052              :              int* no_const_asn_ref_p)
    2053              : {
    2054     52492668 :   int i;
    2055     52492668 :   bool seen_non_virtual_nearly_empty_base_p = 0;
    2056     52492668 :   int seen_tm_mask = 0;
    2057     52492668 :   tree base_binfo;
    2058     52492668 :   tree binfo;
    2059     52492668 :   tree field = NULL_TREE;
    2060              : 
    2061     52492668 :   if (!CLASSTYPE_NON_STD_LAYOUT (t))
    2062    236460503 :     for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    2063    191238877 :       if (TREE_CODE (field) == FIELD_DECL)
    2064              :         break;
    2065              : 
    2066     77144568 :   for (binfo = TYPE_BINFO (t), i = 0;
    2067     77144568 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    2068              :     {
    2069     24651900 :       tree basetype = TREE_TYPE (base_binfo);
    2070              : 
    2071     24651900 :       gcc_assert (COMPLETE_TYPE_P (basetype));
    2072              : 
    2073     24651900 :       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     24651900 :       if (!CLASSTYPE_LITERAL_P (basetype))
    2079      1703187 :         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     24651900 :       if (TYPE_HAS_COPY_CTOR (basetype)
    2086     24651900 :           && ! TYPE_HAS_CONST_COPY_CTOR (basetype))
    2087           60 :         *cant_have_const_ctor_p = 1;
    2088     24651900 :       if (TYPE_HAS_COPY_ASSIGN (basetype)
    2089     24651900 :           && !TYPE_HAS_CONST_COPY_ASSIGN (basetype))
    2090           18 :         *no_const_asn_ref_p = 1;
    2091              : 
    2092     24651900 :       if (BINFO_VIRTUAL_P (base_binfo))
    2093              :         /* A virtual base does not effect nearly emptiness.  */
    2094              :         ;
    2095     24604113 :       else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
    2096              :         {
    2097       279291 :           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     24324822 :       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      2178570 :         CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    2109              : 
    2110              :       /* A lot of properties from the bases also apply to the derived
    2111              :          class.  */
    2112     24651900 :       TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
    2113     73955700 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    2114     24651900 :         |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
    2115     24651900 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    2116     24651900 :         |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (basetype)
    2117     24651900 :             || !TYPE_HAS_COPY_ASSIGN (basetype));
    2118     49303800 :       TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (basetype)
    2119     24651900 :                                          || !TYPE_HAS_COPY_CTOR (basetype));
    2120     73955700 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
    2121     24651900 :         |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (basetype);
    2122     24651900 :       TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (basetype);
    2123     24651900 :       TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
    2124     73955700 :       CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
    2125     24651900 :         |= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
    2126     49303800 :       TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
    2127     24651900 :                                     || TYPE_HAS_COMPLEX_DFLT (basetype));
    2128     24651900 :       SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT
    2129              :         (t, CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
    2130              :          | CLASSTYPE_READONLY_FIELDS_NEED_INIT (basetype));
    2131     24651900 :       SET_CLASSTYPE_REF_FIELDS_NEED_INIT
    2132              :         (t, CLASSTYPE_REF_FIELDS_NEED_INIT (t)
    2133              :          | CLASSTYPE_REF_FIELDS_NEED_INIT (basetype));
    2134     24651900 :       if (TYPE_HAS_MUTABLE_P (basetype))
    2135       988513 :         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     24651900 :       CLASSTYPE_NON_STD_LAYOUT (t) |= CLASSTYPE_NON_STD_LAYOUT (basetype);
    2141     24651900 :       if (!CLASSTYPE_NON_STD_LAYOUT (t))
    2142              :         {
    2143     22669074 :           tree basefield;
    2144              :           /* ...has no base classes of the same type as the first non-static
    2145              :              data member...  */
    2146       534976 :           if (field && DECL_CONTEXT (field) == t
    2147     23147472 :               && (same_type_ignoring_top_level_qualifiers_p
    2148       478398 :                   (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     22668944 :           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    328306364 :             for (basefield = TYPE_FIELDS (basetype); basefield;
    2158    305637816 :                  basefield = DECL_CHAIN (basefield))
    2159    306610301 :               if (TREE_CODE (basefield) == FIELD_DECL
    2160    307925493 :                   && !(DECL_FIELD_IS_BASE (basefield)
    2161      1315192 :                        && is_empty_field (basefield)))
    2162              :                 {
    2163       972485 :                   if (field)
    2164       132842 :                     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     24651900 :       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     24651900 :       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     52492668 :   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     52492668 : }
    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     52492668 : determine_primary_bases (tree t)
    2200              : {
    2201     52492668 :   unsigned i;
    2202     52492668 :   tree primary = NULL_TREE;
    2203     52492668 :   tree type_binfo = TYPE_BINFO (t);
    2204     52492668 :   tree base_binfo;
    2205              : 
    2206              :   /* Determine the primary bases of our bases.  */
    2207     80950781 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    2208     28458113 :        base_binfo = TREE_CHAIN (base_binfo))
    2209              :     {
    2210     28458113 :       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     28458113 :       if (!BINFO_VIRTUAL_P (base_binfo))
    2215              :         {
    2216     28259653 :           tree parent = BINFO_INHERITANCE_CHAIN (base_binfo);
    2217     28259653 :           tree parent_primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (parent));
    2218              : 
    2219     28259653 :           if (parent_primary
    2220     28259653 :               && SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
    2221              :                                     BINFO_TYPE (parent_primary)))
    2222              :             /* We are the primary binfo.  */
    2223      1127124 :             BINFO_PRIMARY_P (base_binfo) = 1;
    2224              :         }
    2225              :       /* Determine if we have a virtual primary base, and mark it so.
    2226              :        */
    2227     29592434 :       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     75429550 :   for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, base_binfo); i++)
    2257              :     {
    2258     24462506 :       tree basetype = BINFO_TYPE (base_binfo);
    2259              : 
    2260     24462506 :       if (TYPE_CONTAINS_VPTR_P (basetype) && !BINFO_VIRTUAL_P (base_binfo))
    2261              :         {
    2262      1525624 :           primary = base_binfo;
    2263      1525624 :           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     76009287 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    2274     25042243 :        base_binfo = TREE_CHAIN (base_binfo))
    2275     25043849 :     if (BINFO_VIRTUAL_P (base_binfo)
    2276     25043849 :         && 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     25042243 :           primary = base_binfo;
    2287              :       }
    2288              : 
    2289     50965438 :  found:
    2290              :   /* If we've got a primary base, use it.  */
    2291     52492668 :   if (primary)
    2292              :     {
    2293      1527311 :       tree basetype = BINFO_TYPE (primary);
    2294              : 
    2295      1527311 :       CLASSTYPE_PRIMARY_BINFO (t) = primary;
    2296      1527311 :       if (BINFO_PRIMARY_P (primary))
    2297              :         /* We are stealing a primary base.  */
    2298           81 :         BINFO_LOST_PRIMARY_P (BINFO_INHERITANCE_CHAIN (primary)) = 1;
    2299      1527311 :       BINFO_PRIMARY_P (primary) = 1;
    2300      1527311 :       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      1527311 :       primary = TYPE_BINFO (basetype);
    2315              : 
    2316      1527311 :       TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
    2317      1527311 :       BINFO_VTABLE (type_binfo) = BINFO_VTABLE (primary);
    2318      1527311 :       BINFO_VIRTUALS (type_binfo) = BINFO_VIRTUALS (primary);
    2319              :     }
    2320     52492668 : }
    2321              : 
    2322              : /* Update the variant types of T.  If UPDATE_ALIGN is true, also
    2323              :    update variant alignments from TYPE.  */
    2324              : 
    2325              : void
    2326    170490916 : fixup_type_variants (tree type, bool update_align /* = false */)
    2327              : {
    2328    170490916 :   if (!type)
    2329              :     return;
    2330              : 
    2331    170490916 :   for (tree variant = TYPE_NEXT_VARIANT (type);
    2332    342678910 :        variant;
    2333    172187994 :        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    172187994 :       TYPE_HAS_USER_CONSTRUCTOR (variant) = TYPE_HAS_USER_CONSTRUCTOR (type);
    2338    172187994 :       TYPE_NEEDS_CONSTRUCTING (variant) = TYPE_NEEDS_CONSTRUCTING (type);
    2339    344375988 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variant)
    2340    172187994 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    2341              : 
    2342    172187994 :       TYPE_POLYMORPHIC_P (variant) = TYPE_POLYMORPHIC_P (type);
    2343    172187994 :       CLASSTYPE_FINAL (variant) = CLASSTYPE_FINAL (type);
    2344              : 
    2345    172187994 :       TYPE_BINFO (variant) = TYPE_BINFO (type);
    2346              : 
    2347              :       /* Copy whatever these are holding today.  */
    2348    172187994 :       TYPE_VFIELD (variant) = TYPE_VFIELD (type);
    2349    172187994 :       TYPE_FIELDS (variant) = TYPE_FIELDS (type);
    2350              : 
    2351    172187994 :       TYPE_SIZE (variant) = TYPE_SIZE (type);
    2352    172187994 :       TYPE_SIZE_UNIT (variant) = TYPE_SIZE_UNIT (type);
    2353              : 
    2354    172187994 :       if (update_align
    2355    172187994 :           && (!TYPE_USER_ALIGN (variant)
    2356      1786917 :               || TYPE_NAME (variant) == TYPE_NAME (type)
    2357       742182 :               || TYPE_ALIGN_RAW (variant) < TYPE_ALIGN_RAW (type)))
    2358              :         {
    2359     69698357 :           TYPE_ALIGN_RAW (variant) =  TYPE_ALIGN_RAW (type);
    2360     69698357 :           TYPE_USER_ALIGN (variant) = TYPE_USER_ALIGN (type);
    2361              :         }
    2362              : 
    2363    172187994 :       TYPE_PRECISION (variant) = TYPE_PRECISION (type);
    2364    172187994 :       TYPE_MODE_RAW (variant) = TYPE_MODE_RAW (type);
    2365    172187994 :       TYPE_EMPTY_P (variant) = TYPE_EMPTY_P (type);
    2366    172187994 :       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        38740 : fixup_may_alias (tree klass)
    2376              : {
    2377        38740 :   tree t, v;
    2378              : 
    2379        57747 :   for (t = TYPE_POINTER_TO (klass); t; t = TYPE_NEXT_PTR_TO (t))
    2380        57006 :     for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    2381        37999 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    2382        38761 :   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        38740 : }
    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    102111485 : fixup_attribute_variants (tree t)
    2393              : {
    2394    102111485 :   tree variants;
    2395              : 
    2396    102111485 :   if (!t)
    2397              :     return;
    2398              : 
    2399    102111485 :   tree attrs = TYPE_ATTRIBUTES (t);
    2400    102111485 :   unsigned align = TYPE_ALIGN (t);
    2401    102111485 :   bool user_align = TYPE_USER_ALIGN (t);
    2402    102111485 :   bool may_alias = lookup_attribute ("may_alias", attrs);
    2403    102111485 :   bool packed = TYPE_PACKED (t);
    2404              : 
    2405    102111485 :   if (may_alias)
    2406        19481 :     fixup_may_alias (t);
    2407              : 
    2408    102111485 :   for (variants = TYPE_NEXT_VARIANT (t);
    2409    154034379 :        variants;
    2410     51922894 :        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     51922894 :       TYPE_ATTRIBUTES (variants) = attrs;
    2415     51922894 :       unsigned valign = align;
    2416     51922894 :       if (TYPE_USER_ALIGN (variants))
    2417        25931 :         valign = MAX (valign, TYPE_ALIGN (variants));
    2418              :       else
    2419     51896963 :         TYPE_USER_ALIGN (variants) = user_align;
    2420     51922894 :       SET_TYPE_ALIGN (variants, valign);
    2421     51922894 :       TYPE_PACKED (variants) = packed;
    2422     51922894 :       if (may_alias)
    2423        19259 :         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     52492668 : 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     52492668 :   if (!has_trivial_abi_attribute (t)
    2438     52492668 :       && (type_has_nontrivial_copy_init (t)
    2439     47789707 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)))
    2440              :     {
    2441      5230989 :       SET_DECL_MODE (TYPE_MAIN_DECL (t), BLKmode);
    2442      5230989 :       SET_TYPE_MODE (t, BLKmode);
    2443      5230989 :       TREE_ADDRESSABLE (t) = 1;
    2444              :     }
    2445              : 
    2446     52492668 :   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      1598480 :     get_pure_virtuals (t);
    2456              : 
    2457              :   /* Fix up variants (if any).  */
    2458     52492668 :   fixup_type_variants (t, /*update_align=*/true);
    2459     52492668 : }
    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     31336196 : maybe_warn_about_overly_private_class (tree t)
    2470              : {
    2471     31336196 :   int has_member_fn = 0;
    2472     31336196 :   int has_nonprivate_method = 0;
    2473     31336196 :   bool nonprivate_ctor = false;
    2474              : 
    2475     31336196 :   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     31336244 :       || 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      1783777 : layout_vtable_decl (tree binfo, int n)
    2621              : {
    2622      1783777 :   tree atype;
    2623      1783777 :   tree vtable;
    2624              : 
    2625      1783777 :   atype = build_array_of_n_type (vtable_entry_type, n);
    2626      1783777 :   layout_type (atype);
    2627              : 
    2628              :   /* We may have to grow the vtable.  */
    2629      1783777 :   vtable = get_vtbl_decl_for_binfo (binfo);
    2630      1783777 :   if (!same_type_p (TREE_TYPE (vtable), atype))
    2631              :     {
    2632       598515 :       TREE_TYPE (vtable) = atype;
    2633       598515 :       DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE;
    2634       598515 :       layout_decl (vtable, 0);
    2635              :     }
    2636      1783777 : }
    2637              : 
    2638              : /* True iff FNDECL and BASE_FNDECL (both non-static member functions)
    2639              :    have the same signature.  */
    2640              : 
    2641              : int
    2642     80685798 : 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    123776644 :   if (DECL_DESTRUCTOR_P (base_fndecl) && DECL_DESTRUCTOR_P (fndecl)
    2647    102124046 :       && 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    197200531 :   if (DECL_DESTRUCTOR_P (base_fndecl) || DECL_DESTRUCTOR_P (fndecl))
    2654              :     return 0;
    2655              : 
    2656     48985815 :   if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl)
    2657     48985815 :       || (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     17330543 :       tree fntype = TREE_TYPE (fndecl);
    2663     17330543 :       tree base_fntype = TREE_TYPE (base_fndecl);
    2664     17330543 :       if (type_memfn_quals (fntype) == type_memfn_quals (base_fntype)
    2665     17329549 :           && type_memfn_rqual (fntype) == type_memfn_rqual (base_fntype)
    2666     34660089 :           && compparms (FUNCTION_FIRST_USER_PARMTYPE (fndecl),
    2667     17329546 :                         FUNCTION_FIRST_USER_PARMTYPE (base_fndecl)))
    2668     14685176 :         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       235671 : base_derived_from (tree derived, tree base)
    2678              : {
    2679       235671 :   tree probe;
    2680              : 
    2681       235947 :   for (probe = base; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
    2682              :     {
    2683       235842 :       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      8078614 : 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     13307392 : dfs_find_final_overrider_1 (tree binfo,
    2711              :                             find_final_overrider_data *ffod,
    2712              :                             unsigned depth)
    2713              : {
    2714     13307392 :   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     13307392 :   if (depth)
    2719              :     {
    2720      4993647 :       depth--;
    2721      4993647 :       if (dfs_find_final_overrider_1
    2722      4993647 :           (ffod->path[depth], ffod, depth))
    2723              :         return true;
    2724              :     }
    2725              : 
    2726     10657961 :   method = look_for_overrides_here (BINFO_TYPE (binfo), ffod->fn);
    2727     10657961 :   if (method)
    2728              :     {
    2729      8313745 :       tree *candidate = &ffod->candidates;
    2730              : 
    2731              :       /* Remove any candidates overridden by this new function.  */
    2732      8314267 :       while (*candidate)
    2733              :         {
    2734              :           /* If *CANDIDATE overrides METHOD, then METHOD
    2735              :              cannot override anything else on the list.  */
    2736       235149 :           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      8079118 :       ffod->candidates = tree_cons (method, binfo, ffod->candidates);
    2747      8079118 :       return true;
    2748              :     }
    2749              : 
    2750              :   return false;
    2751              : }
    2752              : 
    2753              : /* Called from find_final_overrider via dfs_walk.  */
    2754              : 
    2755              : static tree
    2756     30522891 : dfs_find_final_overrider_pre (tree binfo, void *data)
    2757              : {
    2758     30522891 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2759              : 
    2760     30522891 :   if (binfo == ffod->declaring_base)
    2761     16627490 :     dfs_find_final_overrider_1 (binfo, ffod, ffod->path.length ());
    2762     30522891 :   ffod->path.safe_push (binfo);
    2763              : 
    2764     30522891 :   return NULL_TREE;
    2765              : }
    2766              : 
    2767              : static tree
    2768     30522891 : dfs_find_final_overrider_post (tree /*binfo*/, void *data)
    2769              : {
    2770     30522891 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2771     30522891 :   ffod->path.pop ();
    2772              : 
    2773     30522891 :   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      8078614 : find_final_overrider (tree derived, tree binfo, tree fn)
    2783              : {
    2784      8078614 :   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      8078614 :   if (DECL_THUNK_P (fn))
    2805            0 :     fn = THUNK_TARGET (fn);
    2806              : 
    2807              :   /* Determine the depth of the hierarchy.  */
    2808      8078614 :   ffod.fn = fn;
    2809      8078614 :   ffod.declaring_base = binfo;
    2810      8078614 :   ffod.candidates = NULL_TREE;
    2811      8078614 :   ffod.path.create (30);
    2812              : 
    2813      8078614 :   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      8078614 :   if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
    2818           36 :     return error_mark_node;
    2819              : 
    2820              :   return ffod.candidates;
    2821      8078614 : }
    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       363111 : get_vcall_index (tree fn, tree type)
    2828              : {
    2829       363111 :   vec<tree_pair_s, va_gc> *indices = CLASSTYPE_VCALL_INDICES (type);
    2830       363111 :   tree_pair_p p;
    2831       363111 :   unsigned ix;
    2832              : 
    2833       369070 :   FOR_EACH_VEC_SAFE_ELT (indices, ix, p)
    2834      1103814 :     if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (p->purpose))
    2835       374724 :         || same_signature_p (fn, p->purpose))
    2836       363111 :       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      7646804 : update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
    2867              :                             unsigned ix)
    2868              : {
    2869      7646804 :   tree b;
    2870      7646804 :   tree overrider;
    2871      7646804 :   tree delta;
    2872      7646804 :   tree virtual_base;
    2873      7646804 :   tree first_defn;
    2874      7646804 :   tree overrider_fn, overrider_target;
    2875      7646804 :   tree target_fn = DECL_THUNK_P (fn) ? THUNK_TARGET (fn) : fn;
    2876      7646804 :   tree over_return, base_return;
    2877      7646804 :   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      9929843 :   for (b = binfo; ; b = get_primary_binfo (b))
    2883              :     {
    2884      9929843 :       gcc_assert (b);
    2885      9929843 :       if (look_for_overrides_here (BINFO_TYPE (b), target_fn))
    2886              :         break;
    2887              : 
    2888              :       /* The nearest definition is from a lost primary.  */
    2889      2283039 :       if (BINFO_LOST_PRIMARY_P (b))
    2890          412 :         lost = true;
    2891              :     }
    2892      7646804 :   first_defn = b;
    2893              : 
    2894              :   /* Find the final overrider.  */
    2895      7646804 :   overrider = find_final_overrider (TYPE_BINFO (t), b, target_fn);
    2896      7646804 :   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      7646795 :   overrider_target = overrider_fn = TREE_PURPOSE (overrider);
    2902              : 
    2903              :   /* Check for adjusting covariant return types.  */
    2904      7646795 :   over_return = TREE_TYPE (TREE_TYPE (overrider_target));
    2905      7646795 :   base_return = TREE_TYPE (TREE_TYPE (target_fn));
    2906              : 
    2907      7646795 :   if (INDIRECT_TYPE_P (over_return)
    2908       667085 :       && TREE_CODE (over_return) == TREE_CODE (base_return)
    2909       667076 :       && CLASS_TYPE_P (TREE_TYPE (over_return))
    2910        42303 :       && CLASS_TYPE_P (TREE_TYPE (base_return))
    2911              :       /* If the overrider is invalid, don't even try.  */
    2912      7689092 :       && !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        42264 :       tree fixed_offset, virtual_offset;
    2919              : 
    2920        42264 :       over_return = TREE_TYPE (over_return);
    2921        42264 :       base_return = TREE_TYPE (base_return);
    2922              : 
    2923        42264 :       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        42210 :       else if (!same_type_ignoring_top_level_qualifiers_p
    2939        42210 :                (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        42264 :       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      7604531 :     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      7646795 :   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      7646795 :   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      7846091 :   for (; b; b = BINFO_INHERITANCE_CHAIN (b))
    3048              :     {
    3049              :       /* If we find the final overrider, then we can stop
    3050              :          walking.  */
    3051      7846091 :       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       562407 :       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      7646795 :   if (virtual_base)
    3069              :     /* The `this' pointer needs to be adjusted from the declaration to
    3070              :        the nearest virtual base.  */
    3071      1089333 :     delta = size_diffop_loc (input_location,
    3072       363111 :                          fold_convert (ssizetype, BINFO_OFFSET (virtual_base)),
    3073       363111 :                          fold_convert (ssizetype, BINFO_OFFSET (first_defn)));
    3074      7283684 :   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     21849951 :     delta = size_diffop_loc (input_location,
    3085      7283317 :                          fold_convert (ssizetype,
    3086              :                                   BINFO_OFFSET (TREE_VALUE (overrider))),
    3087      7283317 :                          fold_convert (ssizetype, BINFO_OFFSET (binfo)));
    3088              : 
    3089      7646795 :   modify_vtable_entry (t, binfo, overrider_fn, delta, virtuals);
    3090              : 
    3091      7646795 :   if (virtual_base)
    3092       726222 :     BV_VCALL_INDEX (*virtuals)
    3093       726222 :       = get_vcall_index (overrider_target, BINFO_TYPE (virtual_base));
    3094              :   else
    3095      7283684 :     BV_VCALL_INDEX (*virtuals) = NULL_TREE;
    3096              : 
    3097      7646795 :   BV_LOST_PRIMARY (*virtuals) = lost;
    3098              : }
    3099              : 
    3100              : /* Called from modify_all_vtables via dfs_walk.  */
    3101              : 
    3102              : static tree
    3103     56014118 : dfs_modify_vtables (tree binfo, void* data)
    3104              : {
    3105     56014118 :   tree t = (tree) data;
    3106     56014118 :   tree virtuals;
    3107     56014118 :   tree old_virtuals;
    3108     56014118 :   unsigned ix;
    3109              : 
    3110     56014118 :   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      4694044 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t)
    3116      4694044 :       && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    3117              :     /* Don't do the primary vtable, if it's new.  */
    3118              :     return NULL_TREE;
    3119              : 
    3120      4437578 :   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      1784830 :   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      1784830 :   for (ix = 0, virtuals = BINFO_VIRTUALS (binfo),
    3133      1784830 :          old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
    3134      9431634 :        virtuals;
    3135      7646804 :        ix++, virtuals = TREE_CHAIN (virtuals),
    3136      7646804 :          old_virtuals = TREE_CHAIN (old_virtuals))
    3137      7646804 :     update_vtable_entry_for_fn (t,
    3138              :                                 binfo,
    3139      7646804 :                                 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     52492668 : modify_all_vtables (tree t, tree virtuals)
    3156              : {
    3157     52492668 :   tree binfo = TYPE_BINFO (t);
    3158     52492668 :   tree *fnsp;
    3159              : 
    3160              :   /* Mangle the vtable name before entering dfs_walk (c++/51884).  */
    3161     52492668 :   if (TYPE_CONTAINS_VPTR_P (t))
    3162      1783777 :     get_vtable_decl (t, false);
    3163              : 
    3164              :   /* Update all of the vtables.  */
    3165     52492668 :   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    113041866 :   for (fnsp = &virtuals; *fnsp; )
    3172              :     {
    3173      8056530 :       tree fn = TREE_VALUE (*fnsp);
    3174              : 
    3175      8056530 :       if (!value_member (fn, BINFO_VIRTUALS (binfo))
    3176     13043623 :           || DECL_VINDEX (fn) == error_mark_node)
    3177              :         {
    3178              :           /* We don't need to adjust the `this' pointer when
    3179              :              calling this function.  */
    3180      3069437 :           BV_DELTA (*fnsp) = integer_zero_node;
    3181      3069437 :           BV_VCALL_INDEX (*fnsp) = NULL_TREE;
    3182              : 
    3183              :           /* This is a function not already in our vtable.  Keep it.  */
    3184      3069437 :           fnsp = &TREE_CHAIN (*fnsp);
    3185              :         }
    3186              :       else
    3187              :         /* We've already got an entry for this function.  Skip it.  */
    3188      4987093 :         *fnsp = TREE_CHAIN (*fnsp);
    3189              :     }
    3190              : 
    3191     52492668 :   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    152899320 : check_for_override (tree decl, tree ctype)
    3229              : {
    3230    152899320 :   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    124540459 :   if ((IDENTIFIER_VIRTUAL_P (DECL_NAME (decl))
    3243    109556036 :        || DECL_CONV_FN_P (decl))
    3244     16621095 :       && look_for_overrides (ctype, decl)
    3245              :       /* Check staticness after we've checked if we 'override'.  */
    3246    128135767 :       && !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      3595302 :       DECL_VINDEX (decl) = decl;
    3252              : 
    3253      3595302 :       if (warn_override
    3254            6 :           && !DECL_OVERRIDE_P (decl)
    3255            5 :           && !DECL_FINAL_P (decl)
    3256      3595306 :           && !DECL_DESTRUCTOR_P (decl))
    3257            3 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
    3258              :                     "%qD can be marked override", decl);
    3259              :     }
    3260    120945157 :   else if (DECL_OVERRIDE_P (decl))
    3261           24 :     error ("%q+#D marked %<override%>, but does not override", decl);
    3262              : 
    3263    124540459 :   if (DECL_VIRTUAL_P (decl))
    3264              :     {
    3265              :       /* Remember this identifier is virtual name.  */
    3266      6395981 :       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = true;
    3267              : 
    3268      6395981 :       if (!DECL_VINDEX (decl))
    3269              :         /* It's a new vfunc.  */
    3270      2800703 :         DECL_VINDEX (decl) = error_mark_node;
    3271              : 
    3272      6395981 :       if (DECL_DESTRUCTOR_P (decl))
    3273      1660513 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
    3274              : 
    3275      6395981 :       if (DECL_HAS_CONTRACTS_P (decl))
    3276           18 :         error_at (DECL_SOURCE_LOCATION (decl),
    3277              :                   "contracts cannot be added to virtual functions");
    3278              :     }
    3279    118144478 :   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       427110 : warn_hidden (tree t)
    3288              : {
    3289       427110 :   if (vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (t))
    3290      2125775 :     for (unsigned ix = member_vec->length (); ix--;)
    3291              :       {
    3292      1982003 :         tree fns = (*member_vec)[ix];
    3293              : 
    3294      1982003 :         if (!OVL_P (fns))
    3295      1981845 :           continue;
    3296              : 
    3297      1087677 :         tree name = OVL_NAME (fns);
    3298      1087677 :         size_t num_fns = 0; /* The number of fndecls in fns.  */
    3299      1087677 :         auto_vec<tree, 20> base_fndecls;
    3300      1087677 :         tree base_binfo;
    3301      1087677 :         tree binfo;
    3302      1087677 :         unsigned j;
    3303      1087677 :         size_t num_overriders = 0;
    3304      1087677 :         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      1087677 :         hash_map<tree, tree> hidden_base_fndecls;
    3308              : 
    3309      1087677 :         if (IDENTIFIER_CDTOR_P (name))
    3310       359710 :           continue;
    3311              : 
    3312              :         /* Iterate through all of the base classes looking for possibly
    3313              :            hidden functions.  */
    3314       727967 :         for (binfo = TYPE_BINFO (t), j = 0;
    3315       936571 :              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       727967 :         if (base_fndecls.is_empty ())
    3323       708527 :           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      1087677 :       }
    3385       427110 : }
    3386              : 
    3387              : /* Recursive helper for finish_struct_anon.  */
    3388              : 
    3389              : static void
    3390       244853 : finish_struct_anon_r (tree field)
    3391              : {
    3392      1411994 :   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      1167141 :       if (DECL_ARTIFICIAL (elt)
    3402      1167141 :           && (!DECL_IMPLICIT_TYPEDEF_P (elt)
    3403       114960 :               || TYPE_UNNAMED_P (TREE_TYPE (elt))))
    3404       283172 :         continue;
    3405              : 
    3406       883969 :       TREE_PRIVATE (elt) = TREE_PRIVATE (field);
    3407       883969 :       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       883969 :       if (DECL_NAME (elt) == NULL_TREE
    3422       883969 :           && ANON_AGGR_TYPE_P (TREE_TYPE (elt)))
    3423        37525 :         finish_struct_anon_r (elt);
    3424              :     }
    3425       244853 : }
    3426              : 
    3427              : /* Fix up any anonymous union/struct members of T.  */
    3428              : 
    3429              : static void
    3430     52492668 : finish_struct_anon (tree t)
    3431              : {
    3432    339082885 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3433              :     {
    3434    286590217 :       if (TREE_STATIC (field))
    3435     14731936 :         continue;
    3436    271858281 :       if (TREE_CODE (field) != FIELD_DECL)
    3437    253440961 :         continue;
    3438              : 
    3439     18417320 :       if (DECL_NAME (field) == NULL_TREE
    3440     18417320 :           && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    3441       207328 :         finish_struct_anon_r (field);
    3442              :     }
    3443     52492668 : }
    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    469255164 : maybe_add_class_template_decl_list (tree type, tree t, int friend_p)
    3457              : {
    3458    469255164 :   if (CLASSTYPE_TEMPLATE_INFO (type)
    3459    469255164 :       && TREE_CODE (t) != CONST_DECL)
    3460              :     {
    3461    407379812 :       tree purpose = friend_p ? NULL_TREE : type;
    3462              : 
    3463    407379812 :       CLASSTYPE_DECL_LIST (type)
    3464    814759624 :         = tree_cons (purpose, t, CLASSTYPE_DECL_LIST (type));
    3465              :     }
    3466    469255164 : }
    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      3750439 : dfs_declare_virt_assop_and_dtor (tree binfo, void *data)
    3478              : {
    3479      3750439 :   tree bv, fn, t = (tree)data;
    3480      3750439 :   tree opname = assign_op_identifier;
    3481              : 
    3482      3750439 :   gcc_assert (t && CLASS_TYPE_P (t));
    3483      3750439 :   gcc_assert (binfo && TREE_CODE (binfo) == TREE_BINFO);
    3484              : 
    3485      3750439 :   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      3172762 :   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     12541535 :   for (bv = BINFO_VIRTUALS (binfo); bv; bv = TREE_CHAIN (bv))
    3496              :     {
    3497      9368773 :       fn = BV_FN (bv);
    3498              : 
    3499      9368773 :       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      9368752 :       else if (DECL_DESTRUCTOR_P (fn)
    3507      9368752 :                && CLASSTYPE_LAZY_DESTRUCTOR (t))
    3508       189107 :         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     52492668 : declare_virt_assop_and_dtor (tree t)
    3520              : {
    3521     52492668 :   if (!(TYPE_POLYMORPHIC_P (t)
    3522      1781236 :         && (CLASSTYPE_LAZY_COPY_ASSIGN (t)
    3523       639220 :             || CLASSTYPE_LAZY_MOVE_ASSIGN (t)
    3524       639220 :             || CLASSTYPE_LAZY_DESTRUCTOR (t))))
    3525              :     return;
    3526              : 
    3527      1211134 :   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       472116 : one_inherited_ctor (tree ctor, tree t, tree using_decl)
    3570              : {
    3571       472116 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (ctor);
    3572              : 
    3573       472116 :   if (flag_new_inheriting_ctors)
    3574              :     {
    3575       472026 :       ctor = implicitly_declare_fn (sfk_inheriting_constructor,
    3576              :                                     t, /*const*/false, ctor, parms);
    3577       472026 :       add_method (t, ctor, using_decl != NULL_TREE);
    3578       472026 :       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     45381047 : add_implicit_default_ctor (tree t)
    3603              : {
    3604     45381047 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 1;
    3605     45381047 :   CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1;
    3606     45381047 :   if (cxx_dialect >= cxx11)
    3607     45296368 :     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     90592736 :       = type_maybe_constexpr_default_constructor (t);
    3613     45381047 : }
    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     52492668 : 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     52492668 :   if (!CLASSTYPE_DESTRUCTOR (t))
    3629              :     /* In general, we create destructors lazily.  */
    3630     48737608 :     CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
    3631              : 
    3632     52492668 :   bool move_ok = false;
    3633     52380761 :   if (cxx_dialect >= cxx11 && CLASSTYPE_LAZY_DESTRUCTOR (t)
    3634     48646098 :       && !TYPE_HAS_COPY_CTOR (t) && !TYPE_HAS_COPY_ASSIGN (t)
    3635     99708684 :       && !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     52492668 :   if (! TYPE_HAS_USER_CONSTRUCTOR (t))
    3643     45322646 :     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     52492668 :   if (! TYPE_HAS_COPY_CTOR (t))
    3650              :     {
    3651     48914340 :       TYPE_HAS_COPY_CTOR (t) = 1;
    3652     48914340 :       TYPE_HAS_CONST_COPY_CTOR (t) = !cant_have_const_cctor;
    3653     48914340 :       CLASSTYPE_LAZY_COPY_CTOR (t) = 1;
    3654     48914340 :       if (move_ok)
    3655     46894284 :         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     52492668 :   if (!TYPE_HAS_COPY_ASSIGN (t))
    3663              :     {
    3664     49055298 :       TYPE_HAS_COPY_ASSIGN (t) = 1;
    3665     49055298 :       TYPE_HAS_CONST_COPY_ASSIGN (t) = !cant_have_const_assignment;
    3666     49055298 :       CLASSTYPE_LAZY_COPY_ASSIGN (t) = 1;
    3667     95514291 :       if (move_ok && !LAMBDA_TYPE_P (t))
    3668     46490116 :         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     52492668 :   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     52492668 :   if (!classtype_has_op (t, EQ_EXPR))
    3679     51159119 :     if (tree space = classtype_has_defaulted_op (t, SPACESHIP_EXPR))
    3680              :       {
    3681         1170 :         tree eq = implicitly_declare_fn (sfk_comparison, t, false, space,
    3682              :                                          NULL_TREE);
    3683         1170 :         bool is_friend = DECL_CONTEXT (space) != t;
    3684         1170 :         if (is_friend)
    3685           90 :           do_friend (NULL_TREE, DECL_NAME (eq), eq,
    3686              :                      NO_SPECIAL, true);
    3687              :         else
    3688              :           {
    3689         1080 :             add_method (t, eq, false);
    3690         1080 :             DECL_CHAIN (eq) = TYPE_FIELDS (t);
    3691         1080 :             TYPE_FIELDS (t) = eq;
    3692              :           }
    3693         1170 :         maybe_add_class_template_decl_list (t, eq, is_friend);
    3694              :       }
    3695              : 
    3696     54990729 :   while (*access_decls)
    3697              :     {
    3698      2498061 :       tree using_decl = TREE_VALUE (*access_decls);
    3699      2498061 :       tree decl = USING_DECL_DECLS (using_decl);
    3700      2498061 :       if (DECL_NAME (using_decl) == ctor_identifier)
    3701              :         {
    3702              :           /* declare, then remove the decl */
    3703       108273 :           tree ctor_list = decl;
    3704       108273 :           location_t loc = input_location;
    3705       108273 :           input_location = DECL_SOURCE_LOCATION (using_decl);
    3706       945362 :           for (tree fn : ovl_range (ctor_list))
    3707              :             {
    3708       472116 :               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        58401 :                 add_implicit_default_ctor (t);
    3712       472116 :               one_inherited_ctor (fn, t, using_decl);
    3713              :             }
    3714       108273 :           *access_decls = TREE_CHAIN (*access_decls);
    3715       108273 :           input_location = loc;
    3716              :         }
    3717              :       else
    3718      2389788 :         access_decls = &TREE_CHAIN (*access_decls);
    3719              :     }
    3720     52492668 : }
    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       104752 : enum_min_precision (tree type)
    3730              : {
    3731       104752 :   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       104752 :   if (UNSCOPED_ENUM_P (type)
    3735        47054 :       && !ENUM_FIXED_UNDERLYING_TYPE_P (type)
    3736       113543 :       && !lookup_attribute ("mode", TYPE_ATTRIBUTES (type)))
    3737         8779 :     return TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type));
    3738              : 
    3739        95973 :   if (enum_to_min_precision == NULL)
    3740         9643 :     enum_to_min_precision = hash_map<tree, int>::create_ggc (37);
    3741              : 
    3742        95973 :   bool existed;
    3743        95973 :   int &prec = enum_to_min_precision->get_or_insert (type, &existed);
    3744        95973 :   if (existed)
    3745        57642 :     return prec;
    3746              : 
    3747        38331 :   tree minnode, maxnode;
    3748        38331 :   if (TYPE_VALUES (type))
    3749              :     {
    3750              :       minnode = maxnode = NULL_TREE;
    3751       296673 :       for (tree values = TYPE_VALUES (type);
    3752       335001 :            values; values = TREE_CHAIN (values))
    3753              :         {
    3754       296673 :           tree decl = TREE_VALUE (values);
    3755       296673 :           tree value = DECL_INITIAL (decl);
    3756       296673 :           if (value == error_mark_node)
    3757            0 :             value = integer_zero_node;
    3758       296673 :           if (!minnode)
    3759              :             minnode = maxnode = value;
    3760       258345 :           else if (tree_int_cst_lt (maxnode, value))
    3761              :             maxnode = value;
    3762        76456 :           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        38331 :   signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
    3770        38331 :   int lowprec = tree_int_cst_min_precision (minnode, sgn);
    3771        38331 :   int highprec = tree_int_cst_min_precision (maxnode, sgn);
    3772        38331 :   prec = MAX (lowprec, highprec);
    3773        38331 :   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       659172 : check_bitfield_decl (tree field)
    3782              : {
    3783       659172 :   tree type = TREE_TYPE (field);
    3784       659172 :   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       659172 :   w = DECL_BIT_FIELD_REPRESENTATIVE (field);
    3789       659172 :   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       659172 :   DECL_BIT_FIELD_REPRESENTATIVE (field) = NULL_TREE;
    3793              : 
    3794              :   /* Detect invalid bit-field type.  */
    3795       659172 :   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       659169 :       location_t loc = input_location;
    3804              :       /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs.  */
    3805       659169 :       STRIP_NOPS (w);
    3806              : 
    3807              :       /* detect invalid field size.  */
    3808       659169 :       input_location = DECL_SOURCE_LOCATION (field);
    3809       659169 :       w = cxx_constant_value (w);
    3810       659169 :       input_location = loc;
    3811              : 
    3812       659169 :       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       659154 :       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       659154 :       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       659139 :       else if ((TREE_CODE (type) != ENUMERAL_TYPE
    3828       659139 :                 && TREE_CODE (type) != BOOLEAN_TYPE
    3829       552899 :                 && compare_tree_int (w, TYPE_PRECISION (type)) > 0)
    3830       659139 :                || ((TREE_CODE (type) == ENUMERAL_TYPE
    3831       658705 :                     || TREE_CODE (type) == BOOLEAN_TYPE)
    3832       106240 :                    && 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       658365 :       else if (TREE_CODE (type) == ENUMERAL_TYPE)
    3836              :         {
    3837       104752 :           int prec = enum_min_precision (type);
    3838       104752 :           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       659172 :   if (w != error_mark_node)
    3846              :     {
    3847       659139 :       DECL_SIZE (field) = fold_convert (bitsizetype, w);
    3848       659139 :       DECL_BIT_FIELD (field) = 1;
    3849       659139 :       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     19299367 : check_field_decl (tree field,
    3866              :                   tree t,
    3867              :                   int* cant_have_const_ctor,
    3868              :                   int* no_const_asn_ref)
    3869              : {
    3870     19299367 :   tree type = strip_array_types (TREE_TYPE (field));
    3871     19299367 :   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     19299367 :   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     19298490 :   else if (ANON_AGGR_TYPE_P (type))
    3880              :     {
    3881      1408453 :       for (tree fields = TYPE_FIELDS (type); fields;
    3882      1164478 :            fields = DECL_CHAIN (fields))
    3883      1164478 :         if (TREE_CODE (fields) == FIELD_DECL)
    3884       882213 :           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     19054515 :   else if (CLASS_TYPE_P (type))
    3891              :     {
    3892              :       /* Never let anything with uninheritable virtuals
    3893              :          make it through without complaint.  */
    3894      3626808 :       abstract_virtuals_error (field, type);
    3895              : 
    3896      3626808 :       if (TREE_CODE (t) == UNION_TYPE && cxx_dialect < cxx11)
    3897              :         {
    3898         3017 :           static bool warned;
    3899         3017 :           auto_diagnostic_group d;
    3900         3017 :           int oldcount = errorcount;
    3901         3017 :           if (TYPE_NEEDS_CONSTRUCTING (type))
    3902            2 :             error ("member %q+#D with constructor not allowed in union",
    3903              :                    field);
    3904         3017 :           if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    3905            0 :             error ("member %q+#D with destructor not allowed in union", field);
    3906         3017 :           if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    3907            3 :             error ("member %q+#D with copy assignment operator not allowed in union",
    3908              :                    field);
    3909         3017 :           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         3017 :         }
    3916              :       else
    3917              :         {
    3918      3623791 :           TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
    3919      3623791 :           TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    3920      3623791 :             |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (type)
    3921      3623791 :                 || !TYPE_HAS_COPY_ASSIGN (type));
    3922      7247582 :           TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (type)
    3923      3623791 :                                              || !TYPE_HAS_COPY_CTOR (type));
    3924     10871373 :           TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
    3925      3623791 :             |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (type);
    3926      3623791 :           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      3623791 :           if (TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
    3934              :             {
    3935      9813795 :               TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    3936      3271265 :                 |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    3937      3271265 :               TYPE_HAS_COMPLEX_DFLT (t)
    3938      6542530 :                 |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type)
    3939      3271265 :                     || TYPE_HAS_COMPLEX_DFLT (type));
    3940              :             }
    3941              :         }
    3942              : 
    3943      3626808 :       if (TYPE_HAS_COPY_CTOR (type)
    3944      3626808 :           && !TYPE_HAS_CONST_COPY_CTOR (type))
    3945         9555 :         *cant_have_const_ctor = 1;
    3946              : 
    3947      3626808 :       if (TYPE_HAS_COPY_ASSIGN (type)
    3948      3626808 :           && !TYPE_HAS_CONST_COPY_ASSIGN (type))
    3949           94 :         *no_const_asn_ref = 1;
    3950              :     }
    3951              : 
    3952     19299367 :   check_abi_tags (t, field);
    3953              : 
    3954     19299367 :   if (DECL_INITIAL (field) != NULL_TREE)
    3955              :     /* `build_class_init_list' does not recognize
    3956              :        non-FIELD_DECLs.  */
    3957      1467040 :     any_default_members = true;
    3958              : 
    3959     19299367 :   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     52492668 : check_field_decls (tree t, tree *access_decls,
    3986              :                    int *cant_have_const_ctor_p,
    3987              :                    int *no_const_asn_ref_p)
    3988              : {
    3989     52492668 :   int cant_pack = 0;
    3990              : 
    3991              :   /* Assume there are no access declarations.  */
    3992     52492668 :   *access_decls = NULL_TREE;
    3993              :   /* Effective C has things to say about classes with pointer members.  */
    3994     52492668 :   tree pointer_member = NULL_TREE;
    3995              :   /* Default initialized members affect the whole class.  */
    3996     52492668 :   tree default_init_member = NULL_TREE;
    3997              :   /* Lack of any non-static data member of non-volatile literal
    3998              :      type affects a union.  */
    3999     52492668 :   bool found_nv_literal_p = false;
    4000              :   /* Standard layout requires all FIELDS have same access.  */
    4001     52492668 :   int field_access = -1;
    4002              : 
    4003    339082885 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    4004              :     {
    4005    286590217 :       tree type = TREE_TYPE (field);
    4006              : 
    4007    286590217 :       switch (TREE_CODE (field))
    4008              :         {
    4009            0 :         default:
    4010            0 :           gcc_unreachable ();
    4011              : 
    4012      2498061 :         case USING_DECL:
    4013              :           /* Save the access declarations for our caller.  */
    4014      2498061 :           *access_decls = tree_cons (NULL_TREE, field, *access_decls);
    4015      2498061 :           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      1752576 :         case CONST_DECL:
    4026      1752576 :           DECL_NONLOCAL (field) = 1;
    4027      1752576 :           break;
    4028              : 
    4029     14332181 :         case VAR_DECL:
    4030     14332181 :           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     14332181 :           goto data_member;
    4042              : 
    4043     18417320 :         case FIELD_DECL:
    4044     18417320 :           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      1452627 :               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     16964693 :         data_member:
    4056              :           /* Common VAR_DECL & FIELD_DECL processing.  */
    4057     32749501 :           DECL_CONTEXT (field) = t;
    4058     32749501 :           DECL_NONLOCAL (field) = 1;
    4059              : 
    4060              :           /* Template instantiation can cause this.  Perhaps this
    4061              :              should be a specific instantiation check?  */
    4062     32749501 :           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     32749490 :           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    286590217 :       if (TREE_CODE (field) != FIELD_DECL)
    4079    268172897 :         continue;
    4080              : 
    4081     18417320 :       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     18417154 :       if (COMPLETE_TYPE_P (type))
    4091              :         {
    4092     18415765 :           if (!literal_type_p (type) || CP_TYPE_VOLATILE_P (type))
    4093      1007637 :             CLASSTYPE_LITERAL_P (t) = false;
    4094              :           else
    4095              :             found_nv_literal_p = true;
    4096              :         }
    4097              : 
    4098     18417154 :       int this_field_access = (TREE_PROTECTED (field) ? 1
    4099     16653210 :                                : TREE_PRIVATE (field) ? 2 : 0);
    4100     18417154 :       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      7311414 :           if (field_access < 0)
    4107              :             field_access = this_field_access;
    4108              :           else
    4109        40508 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4110              : 
    4111              :           /* Aggregates must be public.  */
    4112      7311414 :           if (this_field_access)
    4113      3491697 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    4114              :         }
    4115              : 
    4116              :       /* If this is of reference type, check if it needs an init.  */
    4117     18417154 :       if (TYPE_REF_P (type))
    4118              :         {
    4119       442627 :           CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4120       442627 :           CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4121       442627 :           if (DECL_INITIAL (field) == NULL_TREE)
    4122       442450 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    4123       442627 :           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         1053 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    4130         1053 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    4131              :             }
    4132              :         }
    4133              : 
    4134     18417154 :       type = strip_array_types (type);
    4135              : 
    4136     18417154 :       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     18417154 :       if (DECL_C_BIT_FIELD (field)
    4151     18417154 :           && integer_zerop (DECL_BIT_FIELD_REPRESENTATIVE (field)))
    4152              :         /* We don't treat zero-width bitfields as making a class
    4153              :            non-empty.  */
    4154              :         ;
    4155     18415953 :       else if (field_poverlapping_p (field)
    4156     18415953 :                && is_empty_class (TREE_TYPE (field)))
    4157              :         /* Empty data members also don't make a class non-empty.  */
    4158       234328 :         CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    4159              :       else
    4160              :         {
    4161              :           /* The class is non-empty.  */
    4162     18181625 :           CLASSTYPE_EMPTY_P (t) = 0;
    4163              :           /* The class is not even nearly empty.  */
    4164     18181625 :           CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4165              :           /* If one of the data members contains an empty class, so
    4166              :              does T.  */
    4167      3520571 :           if (CLASS_TYPE_P (type)
    4168     21690958 :               && CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    4169      1024467 :             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     18417154 :       if (TYPE_PTR_P (type)
    4176     18417154 :           && !TYPE_PTRFN_P (type))
    4177              :         pointer_member = field;
    4178              : 
    4179     18417154 :       if (CLASS_TYPE_P (type))
    4180              :         {
    4181      3743661 :           if (CLASSTYPE_REF_FIELDS_NEED_INIT (type))
    4182         3057 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    4183      3743661 :           if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (type))
    4184        28987 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    4185              :         }
    4186              : 
    4187     18417154 :       if (DECL_MUTABLE_P (field) || TYPE_HAS_MUTABLE_P (type))
    4188       211985 :         CLASSTYPE_HAS_MUTABLE (t) = 1;
    4189              : 
    4190     18417154 :       if (DECL_MUTABLE_P (field))
    4191              :         {
    4192       131617 :           if (TYPE_REF_P (type))
    4193            3 :             error ("member %q+D cannot be declared as a %<mutable%> "
    4194              :                    "reference", field);
    4195       131614 :           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     18417154 :       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      3143887 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4204              : 
    4205     18417154 :       if (field_poverlapping_p (field))
    4206              :         /* A potentially-overlapping non-static data member makes the class
    4207              :            non-layout-POD.  */
    4208       300461 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4209              : 
    4210     18417154 :       if (!std_layout_type_p (type))
    4211       673602 :         CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4212              : 
    4213     18417154 :       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     18417154 :       if (DECL_C_BIT_FIELD (field))
    4219       659172 :         check_bitfield_decl (field);
    4220              : 
    4221     18417154 :       if (check_field_decl (field, t,
    4222              :                             cant_have_const_ctor_p, no_const_asn_ref_p))
    4223              :         {
    4224      1467019 :           if (default_init_member
    4225       588930 :               && 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     18417154 :       if (DECL_INITIAL (field))
    4240              :         {
    4241      1448055 :           if (cxx_dialect < cxx14)
    4242         1056 :             CLASSTYPE_NON_AGGREGATE (t) = true;
    4243              :           else
    4244      1446999 :             CLASSTYPE_NON_POD_AGGREGATE (t) = true;
    4245              :         }
    4246              : 
    4247     18417154 :       if (CP_TYPE_CONST_P (type))
    4248              :         {
    4249              :           /* If any field is const, the structure type is pseudo-const.  */
    4250       284747 :           C_TYPE_FIELDS_READONLY (t) = 1;
    4251       284747 :           if (DECL_INITIAL (field) == NULL_TREE)
    4252       237004 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    4253       284747 :           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          709 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    4260          709 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    4261              :             }
    4262              :         }
    4263              :       /* A field that is pseudo-const makes the structure likewise.  */
    4264     18132407 :       else if (CLASS_TYPE_P (type))
    4265              :         {
    4266      3695563 :           C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type);
    4267      3695563 :           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     18417154 :       if (constructor_name_p (DECL_NAME (field), t)
    4276     18417154 :           && 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     52492668 :   if (TREE_CODE (t) == UNION_TYPE && found_nv_literal_p)
    4284       454712 :     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     52492668 :   if (warn_ecpp
    4301          138 :       && pointer_member
    4302           15 :       && TYPE_HAS_USER_CONSTRUCTOR (t)
    4303           15 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    4304     52492680 :       && !(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     52492668 :   if (default_init_member)
    4327              :     {
    4328       878089 :       TYPE_NEEDS_CONSTRUCTING (t) = true;
    4329       878089 :       TYPE_HAS_COMPLEX_DFLT (t) = true;
    4330              :     }
    4331              : 
    4332              :   /* If any of the fields couldn't be packed, unset TYPE_PACKED.  */
    4333     52492668 :   if (cant_pack)
    4334           12 :     TYPE_PACKED (t) = 0;
    4335              : 
    4336              :   /* Check anonymous struct/anonymous union fields.  */
    4337     52492668 :   finish_struct_anon (t);
    4338              : 
    4339              :   /* We've built up the list of access declarations in reverse order.
    4340              :      Fix that now.  */
    4341     52492668 :   *access_decls = nreverse (*access_decls);
    4342     52492668 : }
    4343              : 
    4344              : /* If TYPE is an empty class type, records its OFFSET in the table of
    4345              :    OFFSETS.  */
    4346              : 
    4347              : static int
    4348     30868705 : record_subobject_offset (tree type, tree offset, splay_tree offsets)
    4349              : {
    4350     30868705 :   splay_tree_node n;
    4351              : 
    4352     30868705 :   if (!is_empty_class (type))
    4353              :     return 0;
    4354              : 
    4355              :   /* Record the location of this empty object in OFFSETS.  */
    4356     27896718 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    4357     27896718 :   if (!n)
    4358     23605313 :     n = splay_tree_insert (offsets,
    4359              :                            (splay_tree_key) offset,
    4360              :                            (splay_tree_value) NULL_TREE);
    4361     55793436 :   n->value = ((splay_tree_value)
    4362     27896718 :               tree_cons (NULL_TREE,
    4363              :                          type,
    4364     27896718 :                          (tree) n->value));
    4365              : 
    4366     27896718 :   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       671346 : check_subobject_offset (tree type, tree offset, splay_tree offsets)
    4374              : {
    4375       671346 :   splay_tree_node n;
    4376       671346 :   tree t;
    4377              : 
    4378       671346 :   if (!is_empty_class (type))
    4379              :     return 0;
    4380              : 
    4381              :   /* Record the location of this empty object in OFFSETS.  */
    4382       569011 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    4383       569011 :   if (!n)
    4384              :     return 0;
    4385              : 
    4386       568907 :   enum { ignore, fast, slow, warn }
    4387       568907 :   cv_check = (abi_version_crosses (19) ? slow
    4388       568874 :               : abi_version_at_least (19) ? fast
    4389            0 :               : ignore);
    4390      4038060 :   for (t = (tree) n->value; t; t = TREE_CHAIN (t))
    4391              :     {
    4392      3473037 :       tree elt = TREE_VALUE (t);
    4393              : 
    4394      3473037 :       if (same_type_p (elt, type))
    4395              :         return 1;
    4396              : 
    4397      3469153 :       if (cv_check != ignore
    4398      3469153 :           && similar_type_p (elt, type))
    4399              :         {
    4400           12 :           if (cv_check == fast)
    4401              :             return 1;
    4402              :           cv_check = warn;
    4403              :         }
    4404              :     }
    4405              : 
    4406       565023 :   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     57565244 : 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     57565244 :   int r = 0;
    4437     57565244 :   tree type_binfo = NULL_TREE;
    4438              : 
    4439              :   /* If this OFFSET is bigger than the MAX_OFFSET, then we should
    4440              :      stop.  */
    4441     57565244 :   if (max_offset && tree_int_cst_lt (max_offset, offset))
    4442              :     return 0;
    4443              : 
    4444     48823202 :   if (type == error_mark_node)
    4445              :     return 0;
    4446              : 
    4447     48823202 :   if (!TYPE_P (type))
    4448              :     {
    4449      6087068 :       type_binfo = type;
    4450      6087068 :       type = BINFO_TYPE (type);
    4451              :     }
    4452              : 
    4453     48823202 :   if (CLASS_TYPE_P (type))
    4454              :     {
    4455     36548860 :       tree field;
    4456     36548860 :       tree binfo;
    4457     36548860 :       int i;
    4458              : 
    4459              :       /* Avoid recursing into objects that are not interesting.  */
    4460     36548860 :       if (!CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    4461     57565244 :         return 0;
    4462              : 
    4463              :       /* Record the location of TYPE.  */
    4464     31540488 :       r = (*f) (type, offset, offsets);
    4465     31540488 :       if (r)
    4466              :         return r;
    4467              : 
    4468              :       /* Iterate through the direct base classes of TYPE.  */
    4469     31536592 :       if (!type_binfo)
    4470     26485003 :         type_binfo = TYPE_BINFO (type);
    4471     37461717 :       for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, binfo); i++)
    4472              :         {
    4473      5926532 :           tree binfo_offset;
    4474              : 
    4475      5926532 :           if (BINFO_VIRTUAL_P (binfo))
    4476         1767 :             continue;
    4477              : 
    4478      5924765 :           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      5924765 :           orig_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
    4483      5924765 :           binfo_offset = size_binop (PLUS_EXPR,
    4484              :                                      offset,
    4485              :                                      BINFO_OFFSET (orig_binfo));
    4486              : 
    4487      5924765 :           r = walk_subobject_offsets (binfo,
    4488              :                                       f,
    4489              :                                       binfo_offset,
    4490              :                                       offsets,
    4491              :                                       max_offset,
    4492              :                                       /*vbases_p=*/0);
    4493      5924765 :           if (r)
    4494              :             return r;
    4495              :         }
    4496              : 
    4497     31535185 :       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    610605567 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    4544    579073370 :         if (TREE_CODE (field) == FIELD_DECL
    4545     11907168 :             && TREE_TYPE (field) != error_mark_node
    4546    590980494 :             && !DECL_ARTIFICIAL (field))
    4547              :           {
    4548      5955139 :             tree field_offset;
    4549              : 
    4550      5955139 :             field_offset = byte_position (field);
    4551              : 
    4552      5955139 :             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      5955139 :             if (r)
    4561              :               return r;
    4562              :           }
    4563              :     }
    4564     12274342 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    4565              :     {
    4566       700235 :       tree element_type = strip_array_types (type);
    4567       700235 :       tree domain = TYPE_DOMAIN (type);
    4568       700235 :       tree index;
    4569              : 
    4570              :       /* Avoid recursing into objects that are not interesting.  */
    4571        27349 :       if (!CLASS_TYPE_P (element_type)
    4572        27337 :           || !CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type)
    4573        12549 :           || !domain
    4574       712765 :           || integer_minus_onep (TYPE_MAX_VALUE (domain)))
    4575              :         return 0;
    4576              : 
    4577              :       /* Step through each of the elements in the array.  */
    4578        12313 :       for (index = size_zero_node;
    4579        35815 :            !tree_int_cst_lt (TYPE_MAX_VALUE (domain), index);
    4580        23502 :            index = size_binop (PLUS_EXPR, index, size_one_node))
    4581              :         {
    4582        34680 :           r = walk_subobject_offsets (TREE_TYPE (type),
    4583              :                                       f,
    4584              :                                       offset,
    4585              :                                       offsets,
    4586              :                                       max_offset,
    4587              :                                       /*vbases_p=*/1);
    4588        34680 :           if (r)
    4589              :             return r;
    4590        34680 :           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        34680 :           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     91312529 : 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     91312529 :   if (DECL_FIELD_IS_BASE (decl))
    4612              :     {
    4613            0 :       gcc_checking_assert (c_dialect_objc ());
    4614              :       return false;
    4615              :     }
    4616              : 
    4617     91312529 :   return lookup_attribute ("no_unique_address",
    4618    182625058 :                            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    539530984 : is_empty_field (tree decl)
    4626              : {
    4627    539530984 :   if (!decl || TREE_CODE (decl) != FIELD_DECL)
    4628              :     return false;
    4629              : 
    4630    129445209 :   bool r = (is_empty_class (TREE_TYPE (decl))
    4631    134693283 :             && (DECL_FIELD_IS_BASE (decl)
    4632      1016589 :                 || field_poverlapping_p (decl)));
    4633              : 
    4634              :   /* Empty fields should have size zero.  */
    4635      5036313 :   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     43213253 : record_subobject_offsets (tree decl_or_binfo,
    4644              :                           splay_tree offsets)
    4645              : {
    4646     43213253 :   tree type, offset;
    4647     43213253 :   bool overlapping, vbases_p;
    4648              : 
    4649     43213253 :   if (DECL_P (decl_or_binfo))
    4650              :     {
    4651     18417154 :       tree decl = decl_or_binfo;
    4652     18417154 :       type = TREE_TYPE (decl);
    4653     18417154 :       offset = byte_position (decl);
    4654     18417154 :       overlapping = field_poverlapping_p (decl);
    4655     18417154 :       vbases_p = true;
    4656              :     }
    4657              :   else
    4658              :     {
    4659     24796099 :       type = BINFO_TYPE (decl_or_binfo);
    4660     24796099 :       offset = BINFO_OFFSET (decl_or_binfo);
    4661     24796099 :       overlapping = true;
    4662     24796099 :       vbases_p = false;
    4663              :     }
    4664              : 
    4665     43213253 :   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     24796099 :   if (!overlapping
    4680     43213253 :       || !is_empty_class (type))
    4681     20830403 :     max_offset = sizeof_biggest_empty_class;
    4682              :   else
    4683              :     max_offset = NULL_TREE;
    4684     43213253 :   walk_subobject_offsets (type, record_subobject_offset, offset,
    4685              :                           offsets, max_offset, vbases_p);
    4686     43213253 : }
    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     41765232 : layout_conflict_p (tree type,
    4694              :                    tree offset,
    4695              :                    splay_tree offsets,
    4696              :                    int vbases_p)
    4697              : {
    4698     41765232 :   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     41765232 :   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     41765232 :   if (!max_node)
    4706              :     return 0;
    4707              : 
    4708      2436802 :   return walk_subobject_offsets (type, check_subobject_offset, offset,
    4709      2436802 :                                  offsets, (tree) (max_node->key),
    4710      2436802 :                                  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     20831171 : layout_nonempty_base_or_field (record_layout_info rli,
    4721              :                                tree decl,
    4722              :                                tree binfo,
    4723              :                                splay_tree offsets)
    4724              : {
    4725     20831171 :   tree offset = NULL_TREE;
    4726     20831171 :   bool field_p;
    4727     20831171 :   tree type;
    4728              : 
    4729     20831171 :   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      2647577 :       type = TREE_TYPE (binfo);
    4736      2647577 :       field_p = false;
    4737              :     }
    4738              :   else
    4739              :     {
    4740     18183594 :       type = TREE_TYPE (decl);
    4741     18183594 :       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     20831639 :   while (1)
    4748              :     {
    4749     20831405 :       struct record_layout_info_s old_rli = *rli;
    4750              : 
    4751              :       /* Place this field.  */
    4752     20831405 :       place_field (rli, decl);
    4753     20831405 :       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     20831405 :       if (TREE_CODE (rli->t) == UNION_TYPE)
    4773              :         break;
    4774     22027634 :       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     19379764 :       else if (TREE_CODE (type) == NULLPTR_TYPE
    4791        86155 :                && 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     23478748 :   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      2647577 :     propagate_binfo_offsets (binfo,
    4823              :                              size_diffop_loc (input_location,
    4824              :                                           fold_convert (ssizetype, offset),
    4825      2647577 :                                           fold_convert (ssizetype,
    4826              :                                                    BINFO_OFFSET (binfo))));
    4827     20831171 : }
    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     22382850 : layout_empty_base_or_field (record_layout_info rli, tree binfo_or_decl,
    4847              :                             splay_tree offsets)
    4848              : {
    4849     22382850 :   tree alignment;
    4850     22382850 :   bool atend = false;
    4851     22382850 :   tree binfo = NULL_TREE;
    4852     22382850 :   tree decl = NULL_TREE;
    4853     22382850 :   tree type;
    4854     22382850 :   if (TREE_CODE (binfo_or_decl) == TREE_BINFO)
    4855              :     {
    4856     22148522 :       binfo = binfo_or_decl;
    4857     22148522 :       type = BINFO_TYPE (binfo);
    4858              :     }
    4859              :   else
    4860              :     {
    4861       234328 :       decl = binfo_or_decl;
    4862       234328 :       type = TREE_TYPE (decl);
    4863              :     }
    4864              : 
    4865              :   /* On some platforms (ARM), even empty classes will not be
    4866              :      byte-aligned.  */
    4867     22382850 :   tree eoc = round_up_loc (input_location,
    4868              :                            rli_size_unit_so_far (rli),
    4869     22382850 :                            CLASSTYPE_ALIGN_UNIT (type));
    4870              : 
    4871              :   /* This routine should only be used for empty classes.  */
    4872     22382850 :   gcc_assert (is_empty_class (type));
    4873              : 
    4874     22382850 :   if (decl && DECL_USER_ALIGN (decl))
    4875            3 :     alignment = size_int (DECL_ALIGN_UNIT (decl));
    4876              :   else
    4877     22382847 :     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     22382850 :   tree offset = size_zero_node;
    4882     22382850 :   if (TREE_CODE (rli->t) != UNION_TYPE
    4883     22382850 :       && 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     22382850 :   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     22382847 :   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     22382850 :   if (binfo)
    4922              :     /* Adjust BINFO_OFFSET (binfo) to be exactly OFFSET.  */
    4923     44297044 :     propagate_binfo_offsets (binfo,
    4924     22148522 :                              size_diffop (offset, BINFO_OFFSET (binfo)));
    4925              :   else
    4926              :     {
    4927       234328 :       DECL_FIELD_OFFSET (decl) = offset;
    4928       234328 :       DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    4929       234328 :       SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    4930              :     }
    4931              : 
    4932     22382850 :   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     24717823 : build_base_field_1 (tree t, tree binfo, tree access, tree *&next_field)
    4940              : {
    4941              :   /* Create the FIELD_DECL.  */
    4942     24717823 :   tree basetype = BINFO_TYPE (binfo);
    4943     24717823 :   tree as_base = CLASSTYPE_AS_BASE (basetype);
    4944     24717823 :   gcc_assert (as_base);
    4945     24717823 :   tree decl = build_decl (input_location, FIELD_DECL, NULL_TREE, as_base);
    4946              : 
    4947     24717823 :   DECL_ARTIFICIAL (decl) = 1;
    4948     24717823 :   DECL_IGNORED_P (decl) = 1;
    4949     24717823 :   DECL_FIELD_CONTEXT (decl) = t;
    4950     24717823 :   if (is_empty_class (basetype))
    4951              :     /* CLASSTYPE_SIZE is one byte, but the field needs to have size zero.  */
    4952     22070246 :     DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = size_zero_node;
    4953              :   else
    4954              :     {
    4955      2647577 :       DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
    4956      2647577 :       DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
    4957              :     }
    4958     24717823 :   SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype));
    4959     24717823 :   DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
    4960     24717823 :   SET_DECL_MODE (decl, TYPE_MODE (basetype));
    4961     24717823 :   DECL_FIELD_IS_BASE (decl) = 1;
    4962              : 
    4963     24717823 :   if (access == access_private_node)
    4964       462991 :     TREE_PRIVATE (decl) = true;
    4965     24254832 :   else if (access == access_protected_node)
    4966        89934 :     TREE_PROTECTED (decl) = true;
    4967              : 
    4968              :   /* Add the new FIELD_DECL to the list of fields for T.  */
    4969     24717823 :   DECL_CHAIN (decl) = *next_field;
    4970     24717823 :   *next_field = decl;
    4971     24717823 :   next_field = &DECL_CHAIN (decl);
    4972              : 
    4973     24717823 :   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     24796099 : build_base_field (record_layout_info rli, tree binfo, tree access,
    4987              :                   splay_tree offsets, tree *next_field)
    4988              : {
    4989     24796099 :   tree t = rli->t;
    4990     24796099 :   tree basetype = BINFO_TYPE (binfo);
    4991              : 
    4992     24796099 :   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     24796099 :   if (!is_empty_class (basetype))
    4999              :     {
    5000      2647577 :       tree decl;
    5001              : 
    5002              :       /* The containing class is non-empty because it has a non-empty
    5003              :          base class.  */
    5004      2647577 :       CLASSTYPE_EMPTY_P (t) = 0;
    5005              : 
    5006              :       /* Create the FIELD_DECL.  */
    5007      2647577 :       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      2647577 :       layout_nonempty_base_or_field (rli, decl, binfo, offsets);
    5013              :     }
    5014              :   else
    5015              :     {
    5016     22148522 :       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     22148522 :       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     44220515 :       if (cxx_dialect >= cxx17 && !BINFO_VIRTUAL_P (binfo))
    5040              :         {
    5041     22070246 :           tree decl = build_base_field_1 (t, binfo, access, next_field);
    5042     22070246 :           DECL_FIELD_OFFSET (decl) = BINFO_OFFSET (binfo);
    5043     22070246 :           DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    5044     22070246 :           SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    5045     22070246 :           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     24796099 :   record_subobject_offsets (binfo, offsets);
    5056              : 
    5057     24796099 :   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     52492668 : 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     52492668 :   tree t = rli->t;
    5073     52492668 :   tree binfo = TYPE_BINFO (t);
    5074     52492668 :   int n_baseclasses = BINFO_N_BASE_BINFOS (binfo);
    5075              : 
    5076              :   /* The primary base class is always allocated first.  */
    5077     52492668 :   const tree primary_binfo = CLASSTYPE_PRIMARY_BINFO (t);
    5078     52492668 :   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      1527311 :       tree primary_access = access_private_node;
    5083      1528345 :       for (int i = 0; i < n_baseclasses; ++i)
    5084              :         {
    5085      1528272 :           tree base_binfo = BINFO_BASE_BINFO (binfo, i);
    5086      1528272 :           if (base_binfo == primary_binfo)
    5087              :             {
    5088      1527238 :               primary_access = BINFO_BASE_ACCESS (binfo, i);
    5089      1527238 :               break;
    5090              :             }
    5091              :         }
    5092      1527311 :       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     77144568 :   for (int i = 0; i < n_baseclasses; ++i)
    5099              :     {
    5100     24651900 :       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     24651900 :       if (base_binfo == primary_binfo)
    5105      1527238 :        continue;
    5106              : 
    5107              :       /* Virtual bases are added at the end (a primary virtual base
    5108              :          will have already been added).  */
    5109     23124662 :       if (BINFO_VIRTUAL_P (base_binfo))
    5110        46173 :         continue;
    5111              : 
    5112     23078489 :       next_field = build_base_field (rli, base_binfo,
    5113     23078489 :                                      BINFO_BASE_ACCESS (binfo, i),
    5114              :                                      offsets, next_field);
    5115              :     }
    5116     52492668 : }
    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     52492668 : check_methods (tree t)
    5124              : {
    5125    339082885 :   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    5126    286590217 :     if (DECL_DECLARES_FUNCTION_P (x))
    5127              :       {
    5128    142654133 :         check_for_override (x, t);
    5129              : 
    5130    142654133 :         if (DECL_PURE_VIRTUAL_P (x)
    5131    142654133 :             && (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    142654133 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_VINDEX (x))
    5136              :           {
    5137      6206895 :             TYPE_POLYMORPHIC_P (t) = 1;
    5138      6206895 :             if (DECL_PURE_VIRTUAL_P (x))
    5139       750077 :               vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    5140              :           }
    5141              : 
    5142    142654133 :         if (!DECL_VIRTUAL_P (x)
    5143    279101395 :             && lookup_attribute ("transaction_safe_dynamic",
    5144    136447262 :                                  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     52492668 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    5157              :     {
    5158      3755060 :       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      3755054 :       else if (user_provided_p (dtor))
    5184      2912799 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = true;
    5185              :     }
    5186              : 
    5187    104100983 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5188              :     {
    5189     29300211 :       if (!user_provided_p (fn))
    5190              :         /* Might be trivial.  */;
    5191     22976271 :       else if (TREE_CODE (fn) == TEMPLATE_DECL)
    5192              :         /* Templates are never special members.  */;
    5193     14778453 :       else if (copy_fn_p (fn)
    5194     14778453 :                && constraints_satisfied_p (fn))
    5195      1062301 :         TYPE_HAS_COMPLEX_COPY_CTOR (t) = true;
    5196     13716152 :       else if (move_fn_p (fn)
    5197     13716152 :                && constraints_satisfied_p (fn))
    5198       942309 :         TYPE_HAS_COMPLEX_MOVE_CTOR (t) = true;
    5199              :     }
    5200              : 
    5201     65492558 :   for (tree fn : ovl_range (get_class_binding_direct (t, assign_op_identifier)))
    5202              :     {
    5203      8336155 :       if (!user_provided_p (fn))
    5204              :         /* Might be trivial.  */;
    5205      4347264 :       else if (TREE_CODE (fn) == TEMPLATE_DECL)
    5206              :         /* Templates are never special members.  */;
    5207      3175972 :       else if (copy_fn_p (fn)
    5208      3175972 :                && constraints_satisfied_p (fn))
    5209       672821 :         TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = true;
    5210      2503151 :       else if (move_fn_p (fn)
    5211      2503151 :                && constraints_satisfied_p (fn))
    5212       893334 :         TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = true;
    5213              :     }
    5214     52492668 : }
    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    134751352 : 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    134751352 :   tree clone = copy_decl (fn);
    5226              :   /* Reset the function name.  */
    5227    134751352 :   DECL_NAME (clone) = name;
    5228              : 
    5229    134751352 :   if (flag_concepts)
    5230              :     /* Clone constraints.  */
    5231    133448023 :     if (tree ci = get_constraints (fn))
    5232     13026812 :       set_constraints (clone, copy_node (ci));
    5233              : 
    5234    134751352 :   SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
    5235    134751352 :   DECL_ABSTRACT_P (clone) = false;
    5236              :   /* There's no pending inline data for this function.  */
    5237    134751352 :   DECL_PENDING_INLINE_INFO (clone) = NULL;
    5238    134751352 :   DECL_PENDING_INLINE_P (clone) = 0;
    5239              : 
    5240    134751352 :   if (name == base_dtor_identifier)
    5241              :     {
    5242              :       /* The base-class destructor is not virtual.  */
    5243     11234267 :       DECL_VIRTUAL_P (clone) = 0;
    5244     11234267 :       DECL_VINDEX (clone) = NULL_TREE;
    5245              :     }
    5246    123517085 :   else if (code != ERROR_MARK)
    5247              :     {
    5248              :       /* Set the operator code.  */
    5249         1170 :       const ovl_op_info_t *ovl_op = OVL_OP_INFO (false, code);
    5250         1170 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (clone) = ovl_op->ovl_op_code;
    5251              : 
    5252              :       /* The operator could be virtual.  */
    5253         1170 :       if (DECL_VIRTUAL_P (clone))
    5254           12 :         IDENTIFIER_VIRTUAL_P (name) = true;
    5255              :    }
    5256              : 
    5257    134751352 :   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    134751352 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    5263              :     {
    5264      2498212 :       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
    5265      2498212 :       tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
    5266              :       /* Skip the `this' parameter.  */
    5267      2498212 :       parmtypes = TREE_CHAIN (parmtypes);
    5268              :       /* Skip the in-charge parameter.  */
    5269      2498212 :       parmtypes = TREE_CHAIN (parmtypes);
    5270              :       /* And the VTT parm, in a complete [cd]tor.  */
    5271      2498212 :       if (DECL_HAS_VTT_PARM_P (fn) && !need_vtt_parm_p)
    5272      1339263 :         parmtypes = TREE_CHAIN (parmtypes);
    5273      2498212 :       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      2498212 :       TREE_TYPE (clone)
    5280      2498212 :         = build_method_type_directly (basetype,
    5281      2498212 :                                       TREE_TYPE (TREE_TYPE (clone)),
    5282              :                                       parmtypes);
    5283      2498212 :       TREE_TYPE (clone)
    5284      2498212 :         = cp_build_type_attribute_variant (TREE_TYPE (clone),
    5285      2498212 :                                            TYPE_ATTRIBUTES (TREE_TYPE (fn)));
    5286      2498212 :       TREE_TYPE (clone)
    5287      4996424 :         = cxx_copy_lang_qualifiers (TREE_TYPE (clone), TREE_TYPE (fn));
    5288              :     }
    5289              : 
    5290              :   /* Copy the function parameters.  */
    5291    134751352 :   DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
    5292              : 
    5293              :   /* Remove the in-charge parameter.  */
    5294    134751352 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    5295              :     {
    5296      2498212 :       DECL_CHAIN (DECL_ARGUMENTS (clone))
    5297      2498212 :         = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    5298      2498212 :       DECL_HAS_IN_CHARGE_PARM_P (clone) = 0;
    5299              :     }
    5300              : 
    5301              :   /* And the VTT parm, in a complete [cd]tor.  */
    5302    134751352 :   if (DECL_HAS_VTT_PARM_P (fn))
    5303              :     {
    5304      2498212 :       if (need_vtt_parm_p)
    5305      1158949 :         DECL_HAS_VTT_PARM_P (clone) = 1;
    5306              :       else
    5307              :         {
    5308      2678526 :           DECL_CHAIN (DECL_ARGUMENTS (clone))
    5309      1339263 :             = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    5310      1339263 :           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    134751352 :   if (omit_inherited_parms_p)
    5317          120 :     DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone))) = NULL_TREE;
    5318              : 
    5319    414457414 :   for (tree parms = DECL_ARGUMENTS (clone); parms; parms = DECL_CHAIN (parms))
    5320              :     {
    5321    279706062 :       DECL_CONTEXT (parms) = clone;
    5322    279706062 :       cxx_dup_lang_specific_decl (parms);
    5323              :     }
    5324              : 
    5325              :   /* Create the RTL for this function.  */
    5326    134751352 :   SET_DECL_RTL (clone, NULL);
    5327              : 
    5328              :   /* Regardless of the current scope, this is a member function, so
    5329              :      not at namespace scope.  */
    5330    134751352 :   rest_of_decl_compilation (clone, /*top_level=*/0, at_eof);
    5331              : 
    5332    134751352 :   return clone;
    5333              : }
    5334              : 
    5335              : /* FN is an operator function, create a variant for CODE.  */
    5336              : 
    5337              : tree
    5338         1170 : copy_operator_fn (tree fn, tree_code code)
    5339              : {
    5340         1170 :   return copy_fndecl_with_name (fn, ovl_op_identifier (code),
    5341         1170 :                                 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    153286752 : build_clone (tree fn, tree name, bool need_vtt_parm_p,
    5350              :              bool omit_inherited_parms_p)
    5351              : {
    5352    153286752 :   tree clone;
    5353              : 
    5354              :   /* If this is a template, do the rest on the DECL_TEMPLATE_RESULT.  */
    5355    153286752 :   if (TREE_CODE (fn) == TEMPLATE_DECL)
    5356              :     {
    5357     18536570 :       clone = copy_decl (fn);
    5358     18536570 :       DECL_NAME (clone) = name;
    5359              : 
    5360     18536570 :       tree result = build_clone (DECL_TEMPLATE_RESULT (clone), name,
    5361              :                                  need_vtt_parm_p, omit_inherited_parms_p);
    5362     18536570 :       DECL_TEMPLATE_RESULT (clone) = result;
    5363              : 
    5364     18536570 :       DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
    5365     18536570 :       DECL_TI_TEMPLATE (result) = clone;
    5366              : 
    5367     18536570 :       TREE_TYPE (clone) = TREE_TYPE (result);
    5368              :     }
    5369              :   else
    5370              :     {
    5371    134750182 :       clone = copy_fndecl_with_name (fn, name, ERROR_MARK,
    5372              :                                      need_vtt_parm_p, omit_inherited_parms_p);
    5373    134750182 :       DECL_CLONED_FUNCTION (clone) = fn;
    5374              : 
    5375    134750182 :       maybe_prepare_return_this (clone);
    5376              :     }
    5377              : 
    5378              :   /* Remember where this function came from.  */
    5379    153286752 :   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    153286752 :   DECL_CHAIN (clone) = DECL_CHAIN (fn);
    5384    153286752 :   DECL_CHAIN (fn) = clone;
    5385              : 
    5386    153286752 :   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     66544118 : build_cdtor_clones (tree fn, bool needs_vtt_p, bool base_omits_inherited_p,
    5394              :                     bool update_methods)
    5395              : {
    5396     66544118 :   unsigned count = 0;
    5397              : 
    5398     66544118 :   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     55309851 :       build_clone (fn, complete_ctor_identifier, false, false);
    5403     55309851 :       build_clone (fn, base_ctor_identifier, needs_vtt_p,
    5404              :                    base_omits_inherited_p);
    5405     55309851 :       count += 2;
    5406              :     }
    5407              :   else
    5408              :     {
    5409     11234267 :       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     11234267 :       if (DECL_VIRTUAL_P (fn))
    5421              :         {
    5422      1661946 :           build_clone (fn, deleting_dtor_identifier, false, false);
    5423      1661946 :           count++;
    5424              :         }
    5425     11234267 :       build_clone (fn, complete_dtor_identifier, false, false);
    5426     11234267 :       build_clone (fn, base_dtor_identifier, needs_vtt_p, false);
    5427     11234267 :       count += 2;
    5428              :     }
    5429              : 
    5430              :   /* The original is now an abstract function that is never
    5431              :      emitted.  */
    5432     66544118 :   DECL_ABSTRACT_P (fn) = true;
    5433              : 
    5434     66544118 :   if (update_methods)
    5435    170171557 :     for (tree clone = fn; count--;)
    5436              :       {
    5437    114001209 :         clone = DECL_CHAIN (clone);
    5438    114001209 :         add_method (DECL_CONTEXT (clone), clone, false);
    5439              :       }
    5440     66544118 : }
    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     66870881 : clone_cdtor (tree fn, bool update_methods)
    5448              : {
    5449              :   /* Avoid inappropriate cloning.  */
    5450     66870881 :   if (DECL_CHAIN (fn)
    5451     66870881 :       && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn)))
    5452              :     return;
    5453              : 
    5454              :   /* Base cdtors need a vtt parm if there are virtual bases.  */
    5455     66498460 :   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     66498460 :   bool base_omits_inherited = (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
    5460     66498460 :                                && base_ctor_omit_inherited_parms (fn));
    5461              : 
    5462     66498460 :   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     20815271 : adjust_clone_args (tree decl)
    5474              : {
    5475     20815271 :   tree clone;
    5476              : 
    5477     34242431 :   for (clone = DECL_CHAIN (decl); clone && DECL_CLONED_FUNCTION_P (clone);
    5478     13427160 :        clone = DECL_CHAIN (clone))
    5479              :     {
    5480     13427160 :       tree orig_clone_parms = TYPE_ARG_TYPES (TREE_TYPE (clone));
    5481     13427160 :       tree orig_decl_parms = TYPE_ARG_TYPES (TREE_TYPE (decl));
    5482     13427160 :       tree decl_parms, clone_parms;
    5483              : 
    5484              :       /* Skip the 'this' parameter.  */
    5485     13427160 :       orig_clone_parms = TREE_CHAIN (orig_clone_parms);
    5486     13427160 :       orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5487              : 
    5488     13427160 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl))
    5489        20482 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5490     13427160 :       if (DECL_HAS_VTT_PARM_P (decl))
    5491        20482 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5492              : 
    5493     13427160 :       clone_parms = orig_clone_parms;
    5494     13427160 :       if (DECL_HAS_VTT_PARM_P (clone))
    5495        10241 :         clone_parms = TREE_CHAIN (clone_parms);
    5496              : 
    5497     27112672 :       for (decl_parms = orig_decl_parms; decl_parms;
    5498     13685512 :            decl_parms = TREE_CHAIN (decl_parms),
    5499     13685512 :              clone_parms = TREE_CHAIN (clone_parms))
    5500              :         {
    5501     27110998 :           if (clone_parms == void_list_node)
    5502              :             {
    5503     13425462 :               gcc_assert (decl_parms == clone_parms
    5504              :                           || ctor_omit_inherited_parms (clone));
    5505              :               break;
    5506              :             }
    5507              : 
    5508     13685536 :           gcc_checking_assert (same_type_p (TREE_VALUE (decl_parms),
    5509              :                                             TREE_VALUE (clone_parms)));
    5510              : 
    5511     14860248 :           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     13427160 :       gcc_assert (!clone_parms || clone_parms == void_list_node);
    5540              :     }
    5541     20815271 : }
    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     52492668 : 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    105032290 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5552     29765869 :     clone_cdtor (fn, /*update_methods=*/true);
    5553              : 
    5554     52492668 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    5555      3944167 :     clone_cdtor (dtor, /*update_methods=*/true);
    5556     52492668 : }
    5557              : 
    5558              : /* Deduce noexcept for a destructor DTOR.  */
    5559              : 
    5560              : void
    5561      3820229 : deduce_noexcept_on_destructor (tree dtor)
    5562              : {
    5563      3820229 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (dtor)))
    5564      2569001 :     TREE_TYPE (dtor) = build_exception_variant (TREE_TYPE (dtor),
    5565              :                                                 noexcept_deferred_spec);
    5566      3820229 : }
    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     52492668 : set_method_tm_attributes (tree t)
    5673              : {
    5674     52492668 :   tree class_tm_attr, fndecl;
    5675              : 
    5676              :   /* Don't bother collecting tm attributes if transactional memory
    5677              :      support is not enabled.  */
    5678     52492668 :   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     12715300 : default_ctor_p (const_tree fn)
    5713              : {
    5714     12715300 :   return (DECL_CONSTRUCTOR_P (fn)
    5715     12715300 :           && 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    124173375 : user_provided_p (tree fn)
    5765              : {
    5766    124173375 :   fn = STRIP_TEMPLATE (fn);
    5767    124173375 :   return (!DECL_ARTIFICIAL (fn)
    5768    110113668 :           && !(DECL_INITIALIZED_IN_CLASS_P (fn)
    5769    100037650 :                && (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    212313184 :           && !(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     52501187 : type_has_user_provided_constructor (tree t)
    5781              : {
    5782     52501187 :   if (!CLASS_TYPE_P (t))
    5783              :     return false;
    5784              : 
    5785     52501129 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5786              :     return false;
    5787              : 
    5788     10117926 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5789      8420667 :     if (user_provided_p (*iter))
    5790      6723900 :       return true;
    5791              : 
    5792       450546 :   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      1758217 : type_has_converting_constructor (tree t)
    5804              : {
    5805      1758217 :   if (!CLASS_TYPE_P (t))
    5806              :     return false;
    5807              : 
    5808      1758217 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5809              :     return false;
    5810              : 
    5811      5483670 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5812              :     {
    5813      3234741 :       tree fn = *iter;
    5814      3234741 :       tree parm = FUNCTION_FIRST_USER_PARMTYPE (fn);
    5815      3234741 :       if (parm == NULL_TREE)
    5816              :         /* Varargs.  */
    5817       985812 :         return true;
    5818      4121674 :       if (parm == void_list_node
    5819      3234739 :           || !sufficient_parms_p (TREE_CHAIN (parm)))
    5820              :         /* Can't accept a single argument, so won't be considered for
    5821              :            conversion.  */
    5822       886935 :         continue;
    5823      2347804 :       if (TREE_CODE (fn) == TEMPLATE_DECL
    5824      2347804 :           || TREE_CHAIN (parm) != void_list_node)
    5825              :         /* Not a simple single parameter.  */
    5826              :         return true;
    5827      1812730 :       if (TYPE_MAIN_VARIANT (non_reference (TREE_VALUE (parm)))
    5828      1812730 :           != DECL_CONTEXT (fn))
    5829              :         /* The single parameter has the wrong type.  */
    5830              :         return true;
    5831      1361994 :       if (get_constraints (fn))
    5832              :         /* Constrained.  */
    5833              :         return true;
    5834              :     }
    5835              : 
    5836       335054 :   return false;
    5837              : }
    5838              : 
    5839              : /* Returns true iff class T has a user-provided or explicit constructor.  */
    5840              : 
    5841              : bool
    5842     52930357 : type_has_user_provided_or_explicit_constructor (tree t)
    5843              : {
    5844     52930357 :   if (!CLASS_TYPE_P (t))
    5845              :     return false;
    5846              : 
    5847     52930357 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5848              :     return false;
    5849              : 
    5850      9967859 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5851              :     {
    5852      8433773 :       tree fn = *iter;
    5853      8433773 :       if (user_provided_p (fn) || DECL_NONCONVERTING_P (fn))
    5854      6900180 :         return true;
    5855              :     }
    5856              : 
    5857       291575 :   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      3367435 : type_has_non_user_provided_default_constructor (tree t)
    5866              : {
    5867      3367435 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t))
    5868              :     return false;
    5869      3367409 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5870              :     return true;
    5871              : 
    5872     24255678 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5873              :     {
    5874     12794542 :       tree fn = *iter;
    5875     12794542 :       if (TREE_CODE (fn) == FUNCTION_DECL
    5876      8766957 :           && default_ctor_p (fn)
    5877     16159683 :           && !user_provided_p (fn))
    5878      1334620 :         return true;
    5879              :     }
    5880              : 
    5881      2031811 :   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       809620 : default_init_uninitialized_part (tree type)
    5925              : {
    5926       809620 :   tree t, r, binfo;
    5927       809620 :   int i;
    5928              : 
    5929       809620 :   type = strip_array_types (type);
    5930       809620 :   if (!CLASS_TYPE_P (type))
    5931              :     return type;
    5932       802646 :   if (!type_has_non_user_provided_default_constructor (type))
    5933              :     return NULL_TREE;
    5934       744916 :   for (binfo = TYPE_BINFO (type), i = 0;
    5935       744916 :        BINFO_BASE_ITERATE (binfo, i, t); ++i)
    5936              :     {
    5937       145647 :       r = default_init_uninitialized_part (BINFO_TYPE (t));
    5938       145647 :       if (r)
    5939              :         return r;
    5940              :     }
    5941       745480 :   for (t = next_aggregate_field (TYPE_FIELDS (type)); t;
    5942       146211 :        t = next_aggregate_field (DECL_CHAIN (t)))
    5943       146445 :     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     48902710 : trivial_default_constructor_is_constexpr (tree t)
    5958              : {
    5959              :   /* A defaulted trivial default constructor is constexpr
    5960              :      if there is nothing to initialize.  */
    5961     48902710 :   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     48902710 :   return (cxx_dialect >= cxx20
    5969     48902710 :           || 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     44864571 : type_has_constexpr_default_constructor (tree t)
    5976              : {
    5977     44864571 :   tree fns;
    5978              : 
    5979     44864571 :   if (!CLASS_TYPE_P (t))
    5980              :     {
    5981              :       /* The caller should have stripped an enclosing array.  */
    5982           78 :       gcc_assert (TREE_CODE (t) != ARRAY_TYPE);
    5983              :       return false;
    5984              :     }
    5985     44864493 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5986              :     {
    5987     44862976 :       if (!TYPE_HAS_COMPLEX_DFLT (t))
    5988     44862911 :         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     45296368 : type_maybe_constexpr_default_constructor (tree t)
    6003              : {
    6004     45296368 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DEFAULT_CTOR (t)
    6005     90592736 :       && TYPE_HAS_COMPLEX_DFLT (t))
    6006              :     /* Assume it's constexpr.  */
    6007              :     return true;
    6008     44862911 :   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     50173015 : type_maybe_constexpr_destructor (tree t)
    6032              : {
    6033              :   /* Until C++20, only trivial destruction is constexpr.  */
    6034     50173015 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (t))
    6035              :     return true;
    6036      1710617 :   if (cxx_dialect < cxx20)
    6037              :     return false;
    6038      1686973 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DESTRUCTOR (t))
    6039              :     /* Assume it's constexpr.  */
    6040              :     return true;
    6041      1438387 :   tree fn = CLASSTYPE_DESTRUCTOR (t);
    6042      1438387 :   return (fn && maybe_constexpr_fn (fn));
    6043              : }
    6044              : 
    6045              : /* Returns true iff class TYPE has a virtual destructor.  */
    6046              : 
    6047              : bool
    6048      3569628 : type_has_virtual_destructor (tree type)
    6049              : {
    6050      3569628 :   tree dtor;
    6051              : 
    6052      3569628 :   if (!NON_UNION_CLASS_TYPE_P (type))
    6053              :     return false;
    6054              : 
    6055      3569472 :   gcc_assert (COMPLETE_TYPE_P (type));
    6056      3569472 :   dtor = CLASSTYPE_DESTRUCTOR (type);
    6057      3569472 :   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        20474 : type_has_non_deleted_trivial_default_ctor (tree type)
    6065              : {
    6066        20474 :   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     55620000 : classtype_has_move_assign_or_move_ctor_p (tree t, bool user_p)
    6080              : {
    6081     55620000 :   gcc_assert (user_p
    6082              :               || (!CLASSTYPE_LAZY_MOVE_CTOR (t)
    6083              :                   && !CLASSTYPE_LAZY_MOVE_ASSIGN (t)));
    6084              : 
    6085     55620000 :   if (!CLASSTYPE_LAZY_MOVE_CTOR (t))
    6086     66192040 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    6087     11096410 :       if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter))
    6088      1271148 :         return true;
    6089              : 
    6090     54348852 :   if (!CLASSTYPE_LAZY_MOVE_ASSIGN (t))
    6091      1114653 :     for (ovl_iterator iter (get_class_binding_direct
    6092     48746387 :                             (t, assign_op_identifier));
    6093     49861040 :          iter; ++iter)
    6094       948609 :       if ((!user_p || !DECL_ARTIFICIAL (*iter))
    6095       370569 :           && DECL_CONTEXT (*iter) == t
    6096      1268625 :           && 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      6893511 : classtype_has_depr_implicit_copy (tree t)
    6138              : {
    6139      6893511 :   if (!CLASSTYPE_LAZY_COPY_CTOR (t))
    6140     19073991 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    6141              :       {
    6142      9503185 :         tree fn = *iter;
    6143      9503185 :         if (user_provided_p (fn) && copy_fn_p (fn))
    6144          865 :           return fn;
    6145              :       }
    6146              : 
    6147      6892646 :   if (!CLASSTYPE_LAZY_COPY_ASSIGN (t))
    6148       779361 :     for (ovl_iterator iter (get_class_binding_direct
    6149      1508803 :                             (t, assign_op_identifier));
    6150      2288164 :          iter; ++iter)
    6151              :       {
    6152       779807 :         tree fn = *iter;
    6153       779807 :         if (DECL_CONTEXT (fn) == t
    6154       779807 :             && user_provided_p (fn) && copy_fn_p (fn))
    6155          446 :           return fn;
    6156              :       }
    6157              : 
    6158      6892200 :   if (!CLASSTYPE_LAZY_DESTRUCTOR (t))
    6159              :     {
    6160      2198993 :       tree fn = CLASSTYPE_DESTRUCTOR (t);
    6161      2198993 :       if (user_provided_p (fn))
    6162       675155 :         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     52492668 : classtype_has_op (tree t, tree_code op)
    6172              : {
    6173     52492668 :   tree name = ovl_op_identifier (op);
    6174     52492668 :   if (get_class_binding (t, name))
    6175              :     return true;
    6176     54619713 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    6177      3460594 :     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     51159119 : classtype_has_defaulted_op (tree t, tree_code op)
    6187              : {
    6188     51159119 :   tree name = ovl_op_identifier (op);
    6189     51159174 :   for (ovl_iterator oi (get_class_binding (t, name)); oi; ++oi)
    6190              :     {
    6191         1124 :       tree fn = *oi;
    6192         1124 :       if (DECL_DEFAULTED_FN (fn))
    6193         1080 :         return fn;
    6194              :     }
    6195     52073311 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    6196       915362 :     if (FRIEND_NAME (f) == name)
    6197         2015 :       for (tree l = FRIEND_DECLS (f); l; l = TREE_CHAIN (l))
    6198              :         {
    6199         1142 :           tree fn = TREE_VALUE (l);
    6200         1142 :           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     71419975 : type_build_ctor_call (tree t)
    6218              : {
    6219     71419975 :   tree inner;
    6220     71419975 :   if (TYPE_NEEDS_CONSTRUCTING (t))
    6221              :     return true;
    6222     63661004 :   inner = strip_array_types (t);
    6223     63661004 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner))
    6224              :     return false;
    6225      5747195 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (inner))
    6226              :     return true;
    6227      5303836 :   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     20374476 :   for (ovl_iterator iter (get_class_binding (inner, complete_ctor_identifier));
    6232     20374476 :        iter; ++iter)
    6233              :     {
    6234     15621662 :       tree fn = *iter;
    6235     15621662 :       if (!DECL_ARTIFICIAL (fn)
    6236     15366750 :           || TREE_DEPRECATED (fn)
    6237     15237144 :           || TREE_UNAVAILABLE (fn)
    6238     30858806 :           || DECL_DELETED_FN (fn))
    6239       541528 :         return true;
    6240              :     }
    6241      4752814 :   return false;
    6242              : }
    6243              : 
    6244              : /* Like type_build_ctor_call, but for destructors.  */
    6245              : 
    6246              : bool
    6247    134401563 : type_build_dtor_call (tree t)
    6248              : {
    6249    134401563 :   tree inner;
    6250    134401563 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    6251              :     return true;
    6252    106850981 :   inner = strip_array_types (t);
    6253     46977918 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner)
    6254    153652933 :       || !COMPLETE_TYPE_P (inner))
    6255              :     return false;
    6256     46801917 :   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     81191662 :   for (ovl_iterator iter (get_class_binding (inner, complete_dtor_identifier));
    6261     81191662 :        iter; ++iter)
    6262              :     {
    6263     46324718 :       tree fn = *iter;
    6264     46324718 :       if (!DECL_ARTIFICIAL (fn)
    6265     34427061 :           || TREE_DEPRECATED (fn)
    6266     34427061 :           || TREE_UNAVAILABLE (fn)
    6267     80751779 :           || DECL_DELETED_FN (fn))
    6268     11897714 :         return true;
    6269              :     }
    6270     34866944 :   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     52492668 : type_requires_array_cookie (tree type)
    6278              : {
    6279     52492668 :   tree fns;
    6280     52492668 :   bool has_two_argument_delete_p = false;
    6281              : 
    6282     52492668 :   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     52492668 :   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     48718705 :   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     48718705 :   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     52492668 : finalize_literal_type_property (tree t)
    6336              : {
    6337     52492668 :   tree fn;
    6338              : 
    6339     52492668 :   if (cxx_dialect < cxx11)
    6340       111907 :     CLASSTYPE_LITERAL_P (t) = false;
    6341     52380761 :   else if (CLASSTYPE_LITERAL_P (t)
    6342     52380761 :            && !type_maybe_constexpr_destructor (t))
    6343       729149 :     CLASSTYPE_LITERAL_P (t) = false;
    6344    100648208 :   else if (CLASSTYPE_LITERAL_P (t) && LAMBDA_TYPE_P (t))
    6345       403984 :     CLASSTYPE_LITERAL_P (t) = (cxx_dialect >= cxx17);
    6346    100287492 :   else if (CLASSTYPE_LITERAL_P (t) && !TYPE_HAS_TRIVIAL_DFLT (t)
    6347      4003357 :            && CLASSTYPE_NON_AGGREGATE (t)
    6348     55090287 :            && !TYPE_HAS_CONSTEXPR_CTOR (t))
    6349       579038 :     CLASSTYPE_LITERAL_P (t) = false;
    6350              : 
    6351              :   /* C++14 DR 1684 removed this restriction.  */
    6352     52492668 :   if (cxx_dialect < cxx14
    6353     52619497 :       && !CLASSTYPE_LITERAL_P (t) && !LAMBDA_TYPE_P (t))
    6354      1344543 :     for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6355      1211530 :       if (TREE_CODE (fn) == FUNCTION_DECL
    6356       580221 :           && DECL_DECLARED_CONSTEXPR_P (fn)
    6357         2741 :           && DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    6358      1213336 :           && !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     52492668 : }
    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     52492668 : check_bases_and_members (tree t)
    6476              : {
    6477              :   /* Nonzero if the implicitly generated copy constructor should take
    6478              :      a non-const reference argument.  */
    6479     52492668 :   int cant_have_const_ctor;
    6480              :   /* Nonzero if the implicitly generated assignment operator
    6481              :      should take a non-const reference argument.  */
    6482     52492668 :   int no_const_asn_ref;
    6483     52492668 :   tree access_decls;
    6484     52492668 :   bool saved_complex_asn_ref;
    6485     52492668 :   bool saved_nontrivial_dtor;
    6486     52492668 :   tree fn;
    6487              : 
    6488              :   /* By default, we use const reference arguments and generate default
    6489              :      constructors.  */
    6490     52492668 :   cant_have_const_ctor = 0;
    6491     52492668 :   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     52492668 :   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     52492668 :   if (cxx_dialect >= cxx11)
    6501     52380761 :     if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    6502      7469338 :       for (tree fn : ovl_range (dtor))
    6503      3734669 :         deduce_noexcept_on_destructor (fn);
    6504              : 
    6505              :   /* Check all the method declarations.  */
    6506     52492668 :   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     52492668 :   saved_complex_asn_ref = TYPE_HAS_COMPLEX_COPY_ASSIGN (t);
    6512     52492668 :   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     52492668 :   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     52492668 :   if (!TYPE_CONTAINS_VPTR_P (t))
    6525     50708891 :     CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    6526              : 
    6527              :   /* Do some bookkeeping that will guide the generation of implicitly
    6528              :      declared member functions.  */
    6529     54276445 :   TYPE_HAS_COMPLEX_COPY_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
    6530     54276445 :   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     52492668 :   TYPE_NEEDS_CONSTRUCTING (t)
    6537     52492668 :     |= (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     52492668 :   CLASSTYPE_NON_AGGREGATE (t)
    6546     52492668 :     |= (type_has_user_provided_or_explicit_constructor (t)
    6547     52492668 :         || 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     52492668 :   CLASSTYPE_NON_LAYOUT_POD_P (t)
    6551     52492668 :     |= (CLASSTYPE_NON_AGGREGATE (t)
    6552     52492668 :         || saved_nontrivial_dtor || saved_complex_asn_ref);
    6553     54276445 :   CLASSTYPE_NON_STD_LAYOUT (t) |= TYPE_CONTAINS_VPTR_P (t);
    6554     54276445 :   TYPE_HAS_COMPLEX_COPY_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    6555     54276445 :   TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    6556     54276445 :   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     52492668 :   if (CLASSTYPE_NON_POD_AGGREGATE (t))
    6560              :     {
    6561       867854 :       if (CLASSTYPE_NON_LAYOUT_POD_P (t))
    6562              :         /* It's non-POD for another reason.  */
    6563       796863 :         CLASSTYPE_NON_POD_AGGREGATE (t) = false;
    6564        70991 :       else if (abi_version_at_least (17))
    6565        70989 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = true;
    6566              :     }
    6567              : 
    6568              :   /* P1008: Prohibit aggregates with user-declared constructors.  */
    6569     52492668 :   if (cxx_dialect >= cxx20 && TYPE_HAS_USER_CONSTRUCTOR (t))
    6570              :     {
    6571      7067441 :       CLASSTYPE_NON_AGGREGATE (t) = true;
    6572      7067441 :       if (!CLASSTYPE_NON_LAYOUT_POD_P (t))
    6573              :         {
    6574              :           /* c++/120012: The C++20 aggregate change affected layout.  */
    6575         4893 :           if (!abi_version_at_least (21))
    6576            6 :             CLASSTYPE_NON_LAYOUT_POD_P (t) = true;
    6577        10351 :           if (abi_version_crosses (21))
    6578         4328 :             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     52492668 :   if (!TYPE_HAS_COMPLEX_DFLT (t)
    6585     47737273 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (t)
    6586     54624666 :       && !type_has_non_user_provided_default_constructor (t))
    6587      1541511 :     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     52492668 :   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     52492668 :   if (warn_uninitialized
    6617              :       /* Classes with user-declared constructors are presumed to
    6618              :          initialize these members.  */
    6619       436614 :       && !TYPE_HAS_USER_CONSTRUCTOR (t)
    6620              :       /* Aggregates can be initialized with brace-enclosed
    6621              :          initializers.  */
    6622     52860960 :       && 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     52492668 :   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    339840455 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6656    172294954 :     if (DECL_DECLARES_FUNCTION_P (fn)
    6657    143411703 :         && !DECL_ARTIFICIAL (fn)
    6658    142300219 :         && DECL_DEFAULTED_IN_CLASS_P (fn)
    6659              :         /* ...except handle comparisons later, in finish_struct_1.  */
    6660    293939882 :         && special_function_p (fn) != sfk_comparison)
    6661              :       {
    6662      6552901 :         bool imp_const_p
    6663     13105802 :           = (DECL_CONSTRUCTOR_P (fn) ? !cant_have_const_ctor
    6664      6552901 :              : !no_const_asn_ref);
    6665      6553016 :         defaulted_late_check (fn, imp_const_p);
    6666              :       }
    6667              : 
    6668    104527656 :   if (LAMBDA_TYPE_P (t))
    6669              :     /* "This class type is not an aggregate."  */
    6670       404172 :     CLASSTYPE_NON_AGGREGATE (t) = 1;
    6671              : 
    6672              :   /* Compute the 'literal type' property before we
    6673              :      do anything with non-static member functions.  */
    6674     52492668 :   finalize_literal_type_property (t);
    6675              : 
    6676              :   /* Create the in-charge and not-in-charge variants of constructors
    6677              :      and destructors.  */
    6678     52492668 :   clone_constructors_and_destructors (t);
    6679              : 
    6680              :   /* Process the using-declarations.  */
    6681    107375124 :   for (; access_decls; access_decls = TREE_CHAIN (access_decls))
    6682      2389788 :     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     52492668 :   LANG_TYPE_CLASS_CHECK (t)->vec_new_uses_cookie
    6687     52492668 :     = 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     52492668 :   propagate_class_warmth_attribute (t);
    6694     52492668 : }
    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     52492668 : create_vtable_ptr (tree t, tree* virtuals_p)
    6705              : {
    6706     52492668 :   tree fn;
    6707              : 
    6708              :   /* Collect the virtual functions declared in T.  */
    6709    407698097 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6710    355205429 :     if (TREE_CODE (fn) == FUNCTION_DECL
    6711    164258011 :         && DECL_VINDEX (fn) && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)
    6712    363261959 :         && TREE_CODE (DECL_VINDEX (fn)) != INTEGER_CST)
    6713              :       {
    6714      8056530 :         tree new_virtual = make_node (TREE_LIST);
    6715              : 
    6716      8056530 :         BV_FN (new_virtual) = fn;
    6717      8056530 :         BV_DELTA (new_virtual) = integer_zero_node;
    6718      8056530 :         BV_VCALL_INDEX (new_virtual) = NULL_TREE;
    6719              : 
    6720      8056530 :         TREE_CHAIN (new_virtual) = *virtuals_p;
    6721      8056530 :         *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     52492668 :   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       256466 :       tree field;
    6750              : 
    6751       256466 :       field = build_decl (input_location,
    6752              :                           FIELD_DECL, get_vfield_name (t), vtbl_ptr_type_node);
    6753       256466 :       DECL_VIRTUAL_P (field) = 1;
    6754       256466 :       DECL_ARTIFICIAL (field) = 1;
    6755       256466 :       DECL_FIELD_CONTEXT (field) = t;
    6756       256466 :       DECL_FCONTEXT (field) = t;
    6757       256466 :       if (TYPE_PACKED (t))
    6758            3 :         DECL_PACKED (field) = 1;
    6759              : 
    6760       256466 :       TYPE_VFIELD (t) = field;
    6761              : 
    6762              :       /* This class is non-empty.  */
    6763       256466 :       CLASSTYPE_EMPTY_P (t) = 0;
    6764              : 
    6765       256466 :       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     28467279 : propagate_binfo_offsets (tree binfo, tree offset)
    6778              : {
    6779     28467279 :   int i;
    6780     28467279 :   tree primary_binfo;
    6781     28467279 :   tree base_binfo;
    6782              : 
    6783              :   /* Update BINFO's offset.  */
    6784     28467279 :   BINFO_OFFSET (binfo)
    6785     28467279 :     = 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     28467279 :   primary_binfo = get_primary_binfo (binfo);
    6792              : 
    6793     29602626 :   if (primary_binfo && BINFO_INHERITANCE_CHAIN (primary_binfo) == binfo)
    6794      1134335 :     propagate_binfo_offsets (primary_binfo, offset);
    6795              : 
    6796              :   /* Scan all of the bases, pushing the BINFO_OFFSET adjust
    6797              :      downwards.  */
    6798     32350887 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6799              :     {
    6800              :       /* Don't do the primary base twice.  */
    6801      3883608 :       if (base_binfo == primary_binfo)
    6802      1135253 :         continue;
    6803              : 
    6804      2748355 :       if (BINFO_VIRTUAL_P (base_binfo))
    6805       219752 :         continue;
    6806              : 
    6807      2528603 :       propagate_binfo_offsets (base_binfo, offset);
    6808              :     }
    6809     28467279 : }
    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     52492668 : layout_virtual_bases (record_layout_info rli, splay_tree offsets)
    6817              : {
    6818     52492668 :   tree vbase;
    6819     52492668 :   tree t = rli->t;
    6820     52492668 :   tree *next_field;
    6821              : 
    6822     52492668 :   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     24075185 :   next_field = &TYPE_FIELDS (t);
    6828    183295036 :   while (*next_field)
    6829    159219851 :     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     76608483 :   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
    6835              :     {
    6836     52533298 :       if (!BINFO_VIRTUAL_P (vbase))
    6837     52334838 :         continue;
    6838              : 
    6839       198460 :       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       190299 :           tree access = access_private_node;
    6844       190299 :           if (publicly_virtually_derived_p (BINFO_TYPE (vbase), t))
    6845       189230 :             access = access_public_node;
    6846       190299 :           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     49412434 : end_of_base (tree binfo)
    6857              : {
    6858     49412434 :   tree size;
    6859              : 
    6860     49412434 :   if (!CLASSTYPE_AS_BASE (BINFO_TYPE (binfo)))
    6861            0 :     size = TYPE_SIZE_UNIT (char_type_node);
    6862     49412434 :   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     44296371 :     size = TYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6867              :   else
    6868      5116063 :     size = CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6869              : 
    6870     49412434 :   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    103091450 : end_of_class (tree t, eoc_mode mode)
    6884              : {
    6885    103091450 :   tree result = size_zero_node;
    6886    103091450 :   vec<tree, va_gc> *vbases;
    6887    103091450 :   tree binfo;
    6888    103091450 :   tree base_binfo;
    6889    103091450 :   tree offset;
    6890    103091450 :   int i;
    6891              : 
    6892    103091450 :   for (binfo = TYPE_BINFO (t), i = 0;
    6893    152397779 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6894              :     {
    6895     49306329 :       if (BINFO_VIRTUAL_P (base_binfo)
    6896     49306329 :           && (!BINFO_PRIMARY_P (base_binfo)
    6897         3466 :               || BINFO_INHERITANCE_CHAIN (base_binfo) != TYPE_BINFO (t)))
    6898        92355 :         continue;
    6899              : 
    6900     49213974 :       offset = end_of_base (base_binfo);
    6901     49213974 :       if (tree_int_cst_lt (result, offset))
    6902     49306329 :         result = offset;
    6903              :     }
    6904              : 
    6905    853726884 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6906    750635434 :     if (TREE_CODE (field) == FIELD_DECL
    6907    750635434 :         && !DECL_FIELD_IS_BASE (field))
    6908              :       {
    6909     30446583 :         tree size = DECL_SIZE_UNIT (field);
    6910     30446583 :         if (!size)
    6911              :           /* DECL_SIZE_UNIT can be null for a flexible array.  */
    6912         1996 :           continue;
    6913              : 
    6914     30444587 :         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       469354 :           size = TYPE_SIZE_UNIT (TREE_TYPE (field));
    6918              : 
    6919     30444587 :         if (DECL_BIT_FIELD_TYPE (field))
    6920              :           {
    6921       934157 :             offset = size_binop (PLUS_EXPR, bit_position (field),
    6922              :                                  DECL_SIZE (field));
    6923       934157 :             offset = size_binop (CEIL_DIV_EXPR, offset, bitsize_unit_node);
    6924       934157 :             offset = fold_convert (sizetype, offset);
    6925              :           }
    6926              :         else
    6927     29510430 :           offset = size_binop (PLUS_EXPR, byte_position (field), size);
    6928     30444587 :         if (tree_int_cst_lt (result, offset))
    6929    750635434 :           result = offset;
    6930              :       }
    6931              : 
    6932    103091450 :   if (mode != eoc_nvsize)
    6933     52726842 :     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    6934     52726842 :          vec_safe_iterate (vbases, i, &base_binfo); i++)
    6935              :       {
    6936       198469 :         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       198460 :           offset = end_of_base (base_binfo);
    6942       198469 :         if (tree_int_cst_lt (result, offset))
    6943       187911 :           result = offset;
    6944              :       }
    6945              : 
    6946    103091450 :   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    379991689 : check_non_pod_aggregate (tree field)
    6955              : {
    6956   1139806584 :   if ((!abi_version_crosses (17) || cxx_dialect < cxx14)
    6957    783700252 :       && (!abi_version_crosses (21) || cxx_dialect < cxx20))
    6958              :     return;
    6959    354244681 :   if (TREE_CODE (field) != FIELD_DECL
    6960    354244681 :       || (!DECL_FIELD_IS_BASE (field)
    6961     16628525 :           && !field_poverlapping_p (field)))
    6962              :     return;
    6963     23308411 :   tree next = DECL_CHAIN (field);
    6964    116732497 :   while (next && TREE_CODE (next) != FIELD_DECL) next = DECL_CHAIN (next);
    6965     23308411 :   if (!next)
    6966              :     return;
    6967      1737396 :   tree type = TREE_TYPE (field);
    6968      1737396 :   if (TYPE_IDENTIFIER (type) == as_base_identifier)
    6969       945600 :     type = TYPE_CONTEXT (type);
    6970      1713292 :   if (!CLASS_TYPE_P (type)
    6971      1713291 :       || is_empty_class (type)
    6972      2623938 :       || (!CLASSTYPE_NON_POD_AGGREGATE (type)
    6973       884402 :           && !CLASSTYPE_NON_AGGREGATE_POD (type)))
    6974              :     return;
    6975         2164 :   tree size = end_of_class (type, (DECL_FIELD_IS_BASE (field)
    6976              :                                    ? eoc_nvsize : eoc_nv_or_dsize));
    6977         2148 :   tree rounded = round_up_loc (input_location, size, DECL_ALIGN_UNIT (next));
    6978         2148 :   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     52492668 : maybe_warn_about_inaccessible_bases (tree t)
    7022              : {
    7023     52492668 :   int i;
    7024     52492668 :   vec<tree, va_gc> *vbases;
    7025     52492668 :   tree basetype;
    7026     52492668 :   tree binfo;
    7027     52492668 :   tree base_binfo;
    7028              : 
    7029              :   /* If not checking for warning then return early.  */
    7030     52492668 :   if (!warn_inaccessible_base)
    7031              :     return;
    7032              : 
    7033              :   /* If there are no repeated bases, nothing can be ambiguous.  */
    7034     52492512 :   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     10035242 : splay_tree_compare_integer_csts (splay_tree_key k1, splay_tree_key k2)
    7065              : {
    7066     10035242 :   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     52492668 : include_empty_classes (record_layout_info rli)
    7074              : {
    7075     52492668 :   tree eoc;
    7076     52492668 :   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     52492668 :   eoc = end_of_class (rli->t, eoc_vsize);
    7084     52492668 :   rli_size = rli_size_unit_so_far (rli);
    7085     52492668 :   if (TREE_CODE (rli_size) == INTEGER_CST
    7086     52492668 :       && tree_int_cst_lt (rli_size, eoc))
    7087              :     {
    7088              :       /* The size should have been rounded to a whole byte.  */
    7089     21380532 :       gcc_assert (tree_int_cst_equal
    7090              :                   (rli->bitpos, round_down (rli->bitpos, BITS_PER_UNIT)));
    7091     21380532 :       rli->bitpos
    7092     21380532 :         = 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     21380532 :       normalize_rli (rli);
    7100              :     }
    7101     52492668 : }
    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     52492668 : layout_class_type (tree t, tree *virtuals_p)
    7109              : {
    7110     52492668 :   tree non_static_data_members;
    7111     52492668 :   tree field;
    7112     52492668 :   tree vptr;
    7113     52492668 :   record_layout_info rli;
    7114              :   /* Maps offsets (represented as INTEGER_CSTs) to a TREE_LIST of
    7115              :      types that appear at that offset.  */
    7116     52492668 :   splay_tree empty_base_offsets;
    7117              :   /* True if the last field laid out was a bit-field.  */
    7118     52492668 :   bool last_field_was_bitfield = false;
    7119              :   /* The location at which the next field should be inserted.  */
    7120     52492668 :   tree *next_field;
    7121              : 
    7122              :   /* Keep track of the first non-static data member.  */
    7123     52492668 :   non_static_data_members = TYPE_FIELDS (t);
    7124              : 
    7125              :   /* Start laying out the record.  */
    7126     52492668 :   rli = start_record_layout (t);
    7127              : 
    7128              :   /* Mark all the primary bases in the hierarchy.  */
    7129     52492668 :   determine_primary_bases (t);
    7130              : 
    7131              :   /* Create a pointer to our virtual function table.  */
    7132     52492668 :   vptr = create_vtable_ptr (t, virtuals_p);
    7133              : 
    7134              :   /* The vptr is always the first thing in the class.  */
    7135     52492668 :   if (vptr)
    7136              :     {
    7137       256466 :       DECL_CHAIN (vptr) = TYPE_FIELDS (t);
    7138       256466 :       TYPE_FIELDS (t) = vptr;
    7139       256466 :       next_field = &DECL_CHAIN (vptr);
    7140       256466 :       place_field (rli, vptr);
    7141              :     }
    7142              :   else
    7143     52236202 :     next_field = &TYPE_FIELDS (t);
    7144              : 
    7145              :   /* Build FIELD_DECLs for all of the non-virtual base-types.  */
    7146     52492668 :   empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
    7147              :                                        NULL, NULL);
    7148     52492668 :   build_base_fields (rli, empty_base_offsets, next_field);
    7149              : 
    7150              :   /* Layout the non-static data members.  */
    7151    460190765 :   for (field = non_static_data_members; field; field = DECL_CHAIN (field))
    7152              :     {
    7153    355205429 :       tree type;
    7154    355205429 :       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    355205429 :       if (TREE_CODE (field) != FIELD_DECL)
    7159              :         {
    7160    336788109 :           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    336788109 :           if (VAR_P (field))
    7172              :             {
    7173     14332181 :               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     14332181 :               determine_visibility (field);
    7178              :             }
    7179    336788109 :           continue;
    7180              :         }
    7181              : 
    7182     18417320 :       type = TREE_TYPE (field);
    7183     18417320 :       if (type == error_mark_node)
    7184          166 :         continue;
    7185              : 
    7186     18417154 :       padding = NULL_TREE;
    7187              : 
    7188     18417154 :       bool might_overlap = field_poverlapping_p (field);
    7189              : 
    7190       300461 :       if (might_overlap && CLASS_TYPE_P (type)
    7191     18687305 :           && (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       270017 :           if (CLASSTYPE_EMPTY_P (type))
    7196       234328 :             DECL_SIZE (field) = DECL_SIZE_UNIT (field) = size_zero_node;
    7197              :           else
    7198              :             {
    7199        35689 :               tree size = end_of_class (type, eoc_nv_or_dsize);
    7200        35689 :               DECL_SIZE_UNIT (field) = size;
    7201        35689 :               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     18417154 :       if (DECL_C_BIT_FIELD (field)
    7209     18417154 :           && 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     18416380 :       else if (might_overlap && is_empty_class (type))
    7272              :         {
    7273       234328 :           SET_DECL_FIELD_ABI_IGNORED (field, 1);
    7274       234328 :           layout_empty_base_or_field (rli, field, empty_base_offsets);
    7275              :         }
    7276              :       else
    7277     18182052 :         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     18417154 :       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     18417154 :       if (warn_abi
    7287     16545515 :           && 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       605689 :           && !warning_suppressed_p (field, OPT_Wabi)
    7293       605689 :           && !last_field_was_bitfield
    7294     18545912 :           && !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     18417154 :       if (DECL_C_BIT_FIELD (field))
    7313              :         {
    7314       659139 :           unsigned HOST_WIDE_INT width;
    7315       659139 :           tree ftype = TREE_TYPE (field);
    7316       659139 :           width = tree_to_uhwi (DECL_SIZE (field));
    7317       659139 :           if (width != TYPE_PRECISION (ftype))
    7318              :             {
    7319       520464 :               TREE_TYPE (field)
    7320      1040928 :                 = c_build_bitfield_integer_type (width,
    7321       520464 :                                                  TYPE_UNSIGNED (ftype));
    7322       520464 :               TREE_TYPE (field)
    7323      1040928 :                 = 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     18417154 :       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     18417154 :       last_field_was_bitfield = DECL_C_BIT_FIELD (field);
    7350              :     }
    7351              : 
    7352     52492668 :   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      5586276 :       rli->bitpos = round_up_loc (input_location, rli->bitpos, BITS_PER_UNIT);
    7358      5586276 :       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    432484357 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7367              :     {
    7368    379991689 :       if (TREE_CODE (field) == FIELD_DECL
    7369     43203580 :           && 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       659139 :           && (DECL_SIZE (field) == NULL_TREE
    7376       659139 :               || integer_zerop (DECL_SIZE (field)))
    7377    379992890 :           && TREE_TYPE (field) != error_mark_node)
    7378         1201 :         SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field, 1);
    7379    379991689 :       check_non_pod_aggregate (field);
    7380              :     }
    7381              : 
    7382     52492668 :   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     50560945 :       tree base_t = make_node (TREE_CODE (t));
    7387     50560945 :       tree base_d = create_implicit_typedef (as_base_identifier, base_t);
    7388              : 
    7389     50560945 :       TYPE_CONTEXT (base_t) = t;
    7390     50560945 :       DECL_CONTEXT (base_d) = t;
    7391              : 
    7392     50560945 :       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     50560945 :       tree eoc = end_of_class (t, eoc_nvsize);
    7404     50560945 :       TYPE_SIZE_UNIT (base_t)
    7405     50560945 :         = 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     50560945 :       TYPE_SIZE (base_t)
    7412     50560945 :         = 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     50560945 :       SET_TYPE_ALIGN (base_t, rli->record_align);
    7418     50560945 :       TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t);
    7419     50560945 :       TYPE_TYPELESS_STORAGE (base_t) = TYPE_TYPELESS_STORAGE (t);
    7420     50560945 :       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     50560945 :       next_field = &TYPE_FIELDS (base_t);
    7425    420148657 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7426    369587712 :         if (TREE_CODE (field) == FIELD_DECL)
    7427              :           {
    7428     36255356 :             *next_field = copy_node (field);
    7429              :             /* Zap any NSDMI, it's not needed and might be a deferred
    7430              :                parse.  */
    7431     36255356 :             DECL_INITIAL (*next_field) = NULL_TREE;
    7432     36255356 :             DECL_CONTEXT (*next_field) = base_t;
    7433     36255356 :             next_field = &DECL_CHAIN (*next_field);
    7434              :           }
    7435     50560945 :       *next_field = NULL_TREE;
    7436              : 
    7437              :       /* We use the base type for trivial assignments, and hence it
    7438              :          needs a mode.  */
    7439     50560945 :       compute_record_mode (base_t);
    7440              : 
    7441              :       /* Record the base version of the type.  */
    7442     50560945 :       CLASSTYPE_AS_BASE (t) = base_t;
    7443              :     }
    7444              :   else
    7445      1931723 :     CLASSTYPE_AS_BASE (t) = t;
    7446              : 
    7447              :   /* Every empty class contains an empty class.  */
    7448     52492668 :   if (CLASSTYPE_EMPTY_P (t))
    7449     43660617 :     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     52492668 :   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     52492668 :   layout_virtual_bases (rli, empty_base_offsets);
    7461              : 
    7462              :   /* Make sure that empty classes are reflected in RLI at this
    7463              :      point.  */
    7464     52492668 :   include_empty_classes (rli);
    7465              : 
    7466              :   /* Make sure not to create any structures with zero size.  */
    7467     52492668 :   if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
    7468     22280466 :     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     52492668 :   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     52492668 :   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     52492668 :   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     50560945 :       && TYPE_USER_ALIGN (t) == TYPE_USER_ALIGN (CLASSTYPE_AS_BASE (t))
    7486    103053579 :       && tree_int_cst_equal (TYPE_SIZE (t),
    7487     50560911 :                              TYPE_SIZE (CLASSTYPE_AS_BASE (t))))
    7488     27223084 :     CLASSTYPE_AS_BASE (t) = t;
    7489              : 
    7490     52492668 :   if (TYPE_SIZE_UNIT (t)
    7491     52492668 :       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
    7492     52492668 :       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
    7493    104985327 :       && !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     52492668 :   maybe_warn_about_inaccessible_bases (t);
    7498              : 
    7499              :   /* Now that we're done with layout, give the base fields the real types.  */
    7500    432672386 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7501    380179718 :     if (DECL_ARTIFICIAL (field) && IS_FAKE_BASE_TYPE (TREE_TYPE (field)))
    7502     21658012 :       TREE_TYPE (field) = TYPE_CONTEXT (TREE_TYPE (field));
    7503              : 
    7504              :   /* Clean up.  */
    7505     52492668 :   splay_tree_delete (empty_base_offsets);
    7506              : 
    7507     52492668 :   if (CLASSTYPE_EMPTY_P (t)
    7508     96153285 :       && tree_int_cst_lt (sizeof_biggest_empty_class,
    7509     43660617 :                           TYPE_SIZE_UNIT (t)))
    7510        63457 :     sizeof_biggest_empty_class = TYPE_SIZE_UNIT (t);
    7511     52492668 : }
    7512              : 
    7513              : /* Determine the "key method" for the class type indicated by TYPE,
    7514              :    and set CLASSTYPE_KEY_METHOD accordingly.  */
    7515              : 
    7516              : void
    7517      1783777 : determine_key_method (tree type)
    7518              : {
    7519      1783777 :   tree method;
    7520              : 
    7521      1783777 :   if (processing_template_decl
    7522      1783777 :       || CLASSTYPE_TEMPLATE_INSTANTIATION (type)
    7523      2572602 :       || 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      8014691 :   for (method = TYPE_FIELDS (type); method; method = DECL_CHAIN (method))
    7531      7817094 :     if (TREE_CODE (method) == FUNCTION_DECL
    7532      6382717 :         && 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      1298162 :         && ! DECL_NONGNU_INLINE_P (method)
    7538      8430137 :         && ! DECL_PURE_VIRTUAL_P (method))
    7539              :       {
    7540       591199 :         SET_CLASSTYPE_KEY_METHOD (type, method);
    7541       591199 :         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     44082639 : field_nonempty_p (const_tree fld)
    7552              : {
    7553     44082639 :   if (TREE_CODE (fld) == ERROR_MARK)
    7554              :     return false;
    7555              : 
    7556     44082639 :   tree type = TREE_TYPE (fld);
    7557     44082639 :   if (TREE_CODE (fld) == FIELD_DECL
    7558     44082639 :       && TREE_CODE (type) != ERROR_MARK
    7559     88165278 :       && (DECL_NAME (fld) || RECORD_OR_UNION_TYPE_P (type)))
    7560     43948356 :     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     87512122 : 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     87512122 :   if (TREE_CODE (t) == UNION_TYPE)
    7609      1367007 :     pun = true;
    7610              : 
    7611     87512122 :   tree fld = TYPE_FIELDS (t);
    7612     87512122 :   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     59255407 :       for (; (fld = next_subobject_field (fld)); fld = DECL_CHAIN (fld))
    7630     25191127 :         if (DECL_ARTIFICIAL (fld))
    7631      7499284 :           continue;
    7632     17691843 :         else if (TREE_TYPE (fld) == error_mark_node)
    7633              :           return;
    7634     17691816 :         else if (TREE_CODE (TREE_TYPE (fld)) == ARRAY_TYPE
    7635     17691816 :                  || field_nonempty_p (fld))
    7636              :           last_fld = fld;
    7637     87512095 :       fld = last_fld;
    7638              :     }
    7639    665424712 :   for (; fld; fld = DECL_CHAIN (fld))
    7640              :     {
    7641    577913191 :       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    578852873 :       if (TREE_CODE (fld) == TYPE_DECL
    7653    134874841 :           && DECL_IMPLICIT_TYPEDEF_P (fld)
    7654      8436050 :           && CLASS_TYPE_P (TREE_TYPE (fld))
    7655    584337427 :           && (IDENTIFIER_ANON_P (DECL_NAME (fld))
    7656      5484576 :               || 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       939682 :           check_flexarrays (TREE_TYPE (fld));
    7662       939682 :           continue;
    7663              :         }
    7664              : 
    7665              :       /* Skip anything that's GCC-generated or not a (non-static) data
    7666              :          member.  */
    7667    576973509 :       if (DECL_ARTIFICIAL (fld) || TREE_CODE (fld) != FIELD_DECL)
    7668    548759695 :         continue;
    7669              : 
    7670              :       /* Type of the member.  */
    7671     28213814 :       tree fldtype = TREE_TYPE (fld);
    7672     28213814 :       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     38476824 :       while (TREE_CODE (eltype) == ARRAY_TYPE
    7680     38476824 :              || INDIRECT_TYPE_P (eltype))
    7681     10263156 :         eltype = TREE_TYPE (eltype);
    7682              : 
    7683     28213668 :       if (RECORD_OR_UNION_TYPE_P (eltype))
    7684              :         {
    7685     10491973 :           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     14107859 :           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      6910574 :               bool first = fmem->first;
    7704      6910574 :               tree array = fmem->array;
    7705     14698720 :               bool maybe_anon_p = TYPE_UNNAMED_P (eltype);
    7706       905622 :               if (tree ctx = maybe_anon_p ? TYPE_CONTEXT (eltype) : NULL_TREE)
    7707       905622 :                 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      6910574 :               if (first && !array && !ANON_AGGR_TYPE_P (eltype))
    7714      2147953 :                 fmem->first = false;
    7715              : 
    7716     11836232 :               find_flexarrays (eltype, fmem, false, !maybe_anon_p, pun,
    7717      4925658 :                                !pstr && TREE_CODE (t) == RECORD_TYPE
    7718              :                                ? fld : pstr);
    7719              : 
    7720      6910574 :               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      6909535 :               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      2147571 :                 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      6909535 :               if (base_p)
    7742      1187266 :                 continue;
    7743              :             }
    7744              :         }
    7745              : 
    7746     27024935 :       if (field_nonempty_p (fld))
    7747              :         {
    7748              :           /* Remember the first non-static data member.  */
    7749     26886282 :           if (!fmem->first)
    7750     10265866 :             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     26886282 :           if (fmem->array && !fmem->after[pun])
    7756         1508 :             fmem->after[pun] = fld;
    7757              :         }
    7758              : 
    7759              :       /* Skip non-arrays.  */
    7760     27024935 :       if (TREE_CODE (fldtype) != ARRAY_TYPE)
    7761     25033962 :         continue;
    7762              : 
    7763              :       /* Determine the upper bound of the array if it has one.  */
    7764      1990973 :       if (TYPE_DOMAIN (fldtype))
    7765              :         {
    7766      1989351 :           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      1988311 :           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         2441 :               fmem->array = fld;
    7780         2441 :               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         2134 : diagnose_invalid_flexarray (const flexmems_t *fmem)
    7814              : {
    7815         2134 :   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         2134 : }
    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     52131236 : diagnose_flexarrays (tree t, const flexmems_t *fmem)
    7836              : {
    7837     52131236 :   if (!fmem->array)
    7838              :     return;
    7839              : 
    7840         3984 :   if (fmem->first && !fmem->after[0])
    7841              :     {
    7842         1852 :       diagnose_invalid_flexarray (fmem);
    7843         1852 :       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     81902662 : 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     81902662 :   flexmems_t flexmems = flexmems_t ();
    7927     81902662 :   if (!fmem)
    7928              :     fmem = &flexmems;
    7929     28470312 :   else if (fmem->array && fmem->first && fmem->after[0])
    7930            0 :     return;
    7931              : 
    7932     81902662 :   tree fam = fmem->array;
    7933              : 
    7934              :   /* Recursively check the primary base class first.  */
    7935     81902662 :   if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    7936              :     {
    7937      2663040 :       tree basetype = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (t));
    7938      2663040 :       check_flexarrays (basetype, fmem, true);
    7939              :     }
    7940              : 
    7941              :   /* Recursively check the base classes.  */
    7942     81902662 :   int nbases = TYPE_BINFO (t) ? BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) : 0;
    7943    110440562 :   for (int i = 0; i < nbases; ++i)
    7944              :     {
    7945     28537900 :       tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (t), i);
    7946              : 
    7947              :       /* The primary base class was already checked above.  */
    7948     28537900 :       if (base_binfo == CLASSTYPE_PRIMARY_BINFO (t))
    7949      2662873 :         continue;
    7950              : 
    7951              :       /* Virtual base classes are at the end.  */
    7952     25875027 :       if (BINFO_VIRTUAL_P (base_binfo))
    7953       266218 :         continue;
    7954              : 
    7955              :       /* Check the base class.  */
    7956     25608809 :       check_flexarrays (BINFO_TYPE (base_binfo), fmem, /*base_p=*/true);
    7957              :     }
    7958              : 
    7959     81902662 :   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     53432350 :       int i;
    7965     53432350 :       tree base_binfo;
    7966     53432350 :       vec<tree, va_gc> *vbases;
    7967     53630813 :       for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    7968     53630813 :            vec_safe_iterate (vbases, i, &base_binfo); i++)
    7969              :         {
    7970              :           /* Check the virtual base class.  */
    7971       198463 :           tree basetype = TREE_TYPE (base_binfo);
    7972              : 
    7973       198463 :           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    165925982 :   bool maybe_anon_p = TYPE_UNNAMED_P (t);
    7980      1704413 :   if (tree ctx = maybe_anon_p ? TYPE_CONTEXT (t) : NULL_TREE)
    7981      1704413 :     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     81902662 :   if (fmem != &flexmems || !maybe_anon_p)
    7986    109072038 :     find_flexarrays (t, fmem, base_p || fam != fmem->array);
    7987              : 
    7988     81902662 :   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     52131236 :     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     52492668 : finish_struct_1 (tree t)
    8003              : {
    8004     52492668 :   tree x;
    8005              :   /* A TREE_LIST.  The TREE_VALUE of each node is a FUNCTION_DECL.  */
    8006     52492668 :   tree virtuals = NULL_TREE;
    8007              : 
    8008     52492668 :   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     52492668 :   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     52492668 :   TYPE_SIZE (t) = NULL_TREE;
    8030     52492668 :   CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
    8031              : 
    8032              :   /* Make assumptions about the class; we'll reset the flags if
    8033              :      necessary.  */
    8034     52492668 :   CLASSTYPE_EMPTY_P (t) = 1;
    8035     52492668 :   CLASSTYPE_NEARLY_EMPTY_P (t) = 1;
    8036     52492668 :   CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 0;
    8037     52492668 :   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     52492668 :   check_bases_and_members (t);
    8042              : 
    8043              :   /* Find the key method.  */
    8044     52492668 :   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      1783777 :       if (targetm.cxx.key_method_may_be_inline ())
    8055      1783777 :         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      1783777 :       if (!CLASSTYPE_KEY_METHOD (t) || module_attach_p ())
    8065      1192623 :         vec_safe_push (keyed_classes, t);
    8066              :     }
    8067              : 
    8068              :   /* Layout the class itself.  */
    8069     52492668 :   layout_class_type (t, &virtuals);
    8070              :   /* COMPLETE_TYPE_P is now true.  */
    8071              : 
    8072     52492668 :   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     52492668 :   check_flexarrays (t);
    8078              : 
    8079     52492668 :   virtuals = modify_all_vtables (t, nreverse (virtuals));
    8080              : 
    8081              :   /* If necessary, create the primary vtable for this class.  */
    8082     52492668 :   if (virtuals || TYPE_CONTAINS_VPTR_P (t))
    8083              :     {
    8084              :       /* We must enter these virtuals into the table.  */
    8085      1783777 :       if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    8086       256466 :         build_primary_vtable (NULL_TREE, t);
    8087      1527311 :       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      1783777 :       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     52492668 :   if (TYPE_CONTAINS_VPTR_P (t))
    8100              :     {
    8101      1783777 :       int vindex;
    8102      1783777 :       tree fn;
    8103              : 
    8104      1783777 :       if (BINFO_VTABLE (TYPE_BINFO (t)))
    8105      1783777 :         gcc_assert (DECL_VIRTUAL_P (BINFO_VTABLE (TYPE_BINFO (t))));
    8106      1783777 :       if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    8107       256466 :         gcc_assert (BINFO_VIRTUALS (TYPE_BINFO (t)) == NULL_TREE);
    8108              : 
    8109              :       /* Add entries for virtual functions introduced by this class.  */
    8110      1783777 :       BINFO_VIRTUALS (TYPE_BINFO (t))
    8111      1783777 :         = chainon (BINFO_VIRTUALS (TYPE_BINFO (t)), virtuals);
    8112              : 
    8113              :       /* Set DECL_VINDEX for all functions declared in this class.  */
    8114      1783777 :       for (vindex = 0, fn = BINFO_VIRTUALS (TYPE_BINFO (t));
    8115     12010392 :            fn;
    8116     10226615 :            fn = TREE_CHAIN (fn),
    8117     10226615 :              vindex += (TARGET_VTABLE_USES_DESCRIPTORS
    8118              :                         ? TARGET_VTABLE_USES_DESCRIPTORS : 1))
    8119              :         {
    8120     10226615 :           tree fndecl = BV_FN (fn);
    8121              : 
    8122     10226615 :           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     10226489 :           else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
    8128      8056530 :             DECL_VINDEX (fndecl) = build_int_cst (integer_type_node, vindex);
    8129              :         }
    8130              :     }
    8131              : 
    8132     52492668 :   validate_trivial_abi_attribute (t);
    8133              : 
    8134     52492668 :   finish_struct_bits (t);
    8135              : 
    8136     52492668 :   set_method_tm_attributes (t);
    8137     52492668 :   if (flag_openmp || flag_openmp_simd)
    8138       120201 :     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    432672794 :   for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    8143    380180126 :     if (DECL_DECLARES_FUNCTION_P (x))
    8144              :       {
    8145              :         /* Synthesize constexpr defaulted comparisons.  */
    8146    210994113 :         if (!DECL_ARTIFICIAL (x)
    8147    209882167 :             && DECL_DEFAULTED_IN_CLASS_P (x)
    8148    227275991 :             && special_function_p (x) == sfk_comparison)
    8149        39194 :           defaulted_late_check (x);
    8150    210994113 :         DECL_IN_AGGR_P (x) = false;
    8151              :       }
    8152     14332181 :     else if (VAR_P (x) && TREE_STATIC (x)
    8153     14332181 :              && TREE_TYPE (x) != error_mark_node
    8154    183518129 :              && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t))
    8155       151500 :       SET_DECL_MODE (x, TYPE_MODE (t));
    8156              : 
    8157              :   /* Complain if one of the field types requires lower visibility.  */
    8158     52492668 :   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     52492668 :   finish_vtbls (t);
    8163              : 
    8164              :   /* Build the VTT for T.  */
    8165     52492668 :   build_vtt (t);
    8166              : 
    8167     52492668 :   if (warn_nonvdtor
    8168          147 :       && TYPE_POLYMORPHIC_P (t) && accessible_nvdtor_p (t)
    8169     52492704 :       && !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     52492668 :   complete_vars (t);
    8175              : 
    8176     52492668 :   if (warn_overloaded_virtual)
    8177       427110 :     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     52492668 :   targetm.cxx.adjust_class_at_definition (t);
    8183              : 
    8184     52492668 :   maybe_suppress_debug_info (t);
    8185              : 
    8186     52492668 :   if (flag_vtable_verify)
    8187           12 :     vtv_save_class_info (t);
    8188              : 
    8189     52492668 :   dump_class_hierarchy (t);
    8190              : 
    8191              :   /* Finish debugging output for this type.  */
    8192     52492668 :   rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
    8193              : 
    8194     52492668 :   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     72443572 : unreverse_member_declarations (tree t)
    8228              : {
    8229     72443572 :   tree next;
    8230     72443572 :   tree prev;
    8231     72443572 :   tree x;
    8232              : 
    8233              :   /* The following lists are all in reverse order.  Put them in
    8234              :      declaration order now.  */
    8235     72443572 :   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     72443572 :   prev = NULL_TREE;
    8241     72443572 :   for (x = TYPE_FIELDS (t);
    8242    350155295 :        x && TREE_CODE (x) != TYPE_DECL;
    8243    277711723 :        x = next)
    8244              :     {
    8245    277711723 :       next = DECL_CHAIN (x);
    8246    277711723 :       DECL_CHAIN (x) = prev;
    8247    277711723 :       prev = x;
    8248              :     }
    8249              : 
    8250     72443572 :   if (prev)
    8251              :     {
    8252     29025133 :       DECL_CHAIN (TYPE_FIELDS (t)) = x;
    8253     29025133 :       TYPE_FIELDS (t) = prev;
    8254              :     }
    8255     72443572 : }
    8256              : 
    8257              : /* Classes, structs or unions T marked with hotness attributes propagate
    8258              :    the attribute to all methods.  */
    8259              : 
    8260              : void
    8261     52492668 : propagate_class_warmth_attribute (tree t)
    8262              : {
    8263     52492668 :   if (t == NULL_TREE
    8264     52492668 :       || !(TREE_CODE (t) == RECORD_TYPE
    8265              :            || TREE_CODE (t) == UNION_TYPE))
    8266              :     return;
    8267              : 
    8268     52492668 :   tree class_has_cold_attr
    8269     52492668 :     = lookup_attribute ("cold", TYPE_ATTRIBUTES (t));
    8270     52492668 :   tree class_has_hot_attr
    8271     52492668 :     = lookup_attribute ("hot", TYPE_ATTRIBUTES (t));
    8272              : 
    8273     52492668 :   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     31336196 : finish_struct (tree t, tree attributes)
    8281              : {
    8282     31336196 :   location_t saved_loc = input_location;
    8283              : 
    8284              :   /* Now that we've got all the field declarations, reverse everything
    8285              :      as necessary.  */
    8286     31336196 :   unreverse_member_declarations (t);
    8287              : 
    8288     31336196 :   cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8289     31336196 :   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     31336196 :   input_location = DECL_SOURCE_LOCATION (TYPE_NAME (t));
    8294              : 
    8295     31336196 :   if (processing_template_decl)
    8296              :     {
    8297     19950904 :       tree x;
    8298              : 
    8299    155836045 :       for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    8300    135885141 :         if (DECL_DECLARES_FUNCTION_P (x))
    8301              :           {
    8302     75800057 :             DECL_IN_AGGR_P (x) = false;
    8303     75800057 :             if (DECL_VIRTUAL_P (x))
    8304      1872626 :               CLASSTYPE_NON_AGGREGATE (t) = true;
    8305              :           }
    8306     60085084 :         else if (TREE_CODE (x) == FIELD_DECL)
    8307              :           {
    8308     12740071 :             if (TREE_PROTECTED (x) || TREE_PRIVATE (x))
    8309      6527829 :               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     19950904 :       tree ass_op = build_lang_decl (USING_DECL, assign_op_identifier,
    8318              :                                      NULL_TREE);
    8319     19950904 :       DECL_CONTEXT (ass_op) = t;
    8320     19950904 :       USING_DECL_SCOPE (ass_op) = t;
    8321     19950904 :       DECL_DEPENDENT_P (ass_op) = true;
    8322     19950904 :       DECL_ARTIFICIAL (ass_op) = true;
    8323     19950904 :       DECL_CHAIN (ass_op) = TYPE_FIELDS (t);
    8324     19950904 :       TYPE_FIELDS (t) = ass_op;
    8325              : 
    8326     19950904 :       TYPE_SIZE (t) = bitsize_zero_node;
    8327     19950904 :       TYPE_SIZE_UNIT (t) = size_zero_node;
    8328              :       /* COMPLETE_TYPE_P is now true.  */
    8329              : 
    8330     19950904 :       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     19950904 :       CLASSTYPE_PURE_VIRTUALS (t) = NULL;
    8340    175786949 :       for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    8341    155836045 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_PURE_VIRTUAL_P (x))
    8342       273580 :           vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    8343     19950904 :       complete_vars (t);
    8344              : 
    8345              :       /* Remember current #pragma pack value.  */
    8346     19950904 :       TYPE_PRECISION (t) = maximum_field_alignment;
    8347              : 
    8348     19950904 :       if (cxx_dialect < cxx20)
    8349              :         {
    8350       589550 :           if (!CLASSTYPE_NON_AGGREGATE (t)
    8351       589550 :               && type_has_user_provided_or_explicit_constructor (t))
    8352        19159 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    8353              :         }
    8354     19361354 :       else if (TYPE_HAS_USER_CONSTRUCTOR (t))
    8355      5874956 :         CLASSTYPE_NON_AGGREGATE (t) = 1;
    8356              : 
    8357              :       /* Fix up any variants we've already built.  */
    8358     19950904 :       fixup_type_variants (t);
    8359              :     }
    8360              :   else
    8361     11385292 :     finish_struct_1 (t);
    8362              :   /* COMPLETE_TYPE_P is now true.  */
    8363              : 
    8364     31336196 :   maybe_warn_about_overly_private_class (t);
    8365              : 
    8366     31336196 :   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        14683 :       bool ok = false;
    8373        14683 :       if (processing_template_decl)
    8374              :         {
    8375        14683 :           tree f = next_aggregate_field (TYPE_FIELDS (t));
    8376        14683 :           if (f && TYPE_PTR_P (TREE_TYPE (f)))
    8377              :             {
    8378        14680 :               f = next_aggregate_field (DECL_CHAIN (f));
    8379        14680 :               if (f && same_type_p (TREE_TYPE (f), size_type_node))
    8380              :                 ok = true;
    8381              :             }
    8382              :         }
    8383              :       /* It also cannot be a union.  */
    8384        14683 :       ok &= NON_UNION_CLASS_TYPE_P (t);
    8385        14683 :       if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
    8386              :         ok = false;
    8387        14680 :       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     31336184 :   input_location = saved_loc;
    8393              : 
    8394     31336184 :   TYPE_BEING_DEFINED (t) = 0;
    8395              : 
    8396     31336184 :   if (current_class_type)
    8397     31336184 :     popclass ();
    8398              :   else
    8399            0 :     error ("trying to finish struct, but kicked out due to previous parse errors");
    8400              : 
    8401     31336184 :   if (flag_openmp)
    8402       738767 :     for (tree decl = TYPE_FIELDS (t); decl; decl = DECL_CHAIN (decl))
    8403       621841 :       if (TREE_CODE (decl) == FUNCTION_DECL
    8404       621841 :           && DECL_OBJECT_MEMBER_FUNCTION_P (decl))
    8405       130264 :         if (tree attr = lookup_attribute ("omp declare variant base",
    8406       130264 :                                           DECL_ATTRIBUTES (decl)))
    8407          120 :           omp_declare_variant_finalize (decl, attr);
    8408              : 
    8409     19950892 :   if (processing_template_decl && at_function_scope_p ()
    8410              :       /* Lambdas are defined by the LAMBDA_EXPR.  */
    8411     34034297 :       && !LAMBDA_TYPE_P (t))
    8412       254007 :     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     33083153 :   if (at_function_scope_p () && !LAMBDA_TYPE_P (t))
    8417       261728 :     maybe_key_decl (current_scope (), TYPE_NAME (t));
    8418              : 
    8419     31336184 :   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     16335683 : fixed_type_or_null (tree instance, int *nonnull, int *cdtorp)
    8435              : {
    8436              : #define RECUR(T) fixed_type_or_null((T), nonnull, cdtorp)
    8437              : 
    8438     16335683 :   switch (TREE_CODE (instance))
    8439              :     {
    8440      2395107 :     case INDIRECT_REF:
    8441      2395107 :       if (INDIRECT_TYPE_P (TREE_TYPE (instance)))
    8442              :         return NULL_TREE;
    8443              :       else
    8444      2381230 :         return RECUR (TREE_OPERAND (instance, 0));
    8445              : 
    8446       142513 :     case CALL_EXPR:
    8447              :       /* This is a call to a constructor, hence it's never zero.  */
    8448       142513 :       if (CALL_EXPR_FN (instance)
    8449       142513 :           && TREE_HAS_CONSTRUCTOR (instance))
    8450              :         {
    8451            0 :           if (nonnull)
    8452            0 :             *nonnull = 1;
    8453            0 :           return TREE_TYPE (instance);
    8454              :         }
    8455       142513 :       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        47353 :     case SAVE_EXPR:
    8467              :       /* This is a call to a constructor, hence it's never zero.  */
    8468        47353 :       if (TREE_HAS_CONSTRUCTOR (instance))
    8469              :         {
    8470            0 :           if (nonnull)
    8471            0 :             *nonnull = 1;
    8472            0 :           return TREE_TYPE (instance);
    8473              :         }
    8474        47353 :       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      3102867 :     CASE_CONVERT:
    8488      3102867 :       return RECUR (TREE_OPERAND (instance, 0));
    8489              : 
    8490       849159 :     case ADDR_EXPR:
    8491       849159 :       instance = TREE_OPERAND (instance, 0);
    8492       849159 :       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       847078 :           tree t = get_base_address (instance);
    8497              :           /* ??? Probably should check DECL_WEAK here.  */
    8498       847078 :           if (t && DECL_P (t))
    8499       125745 :             *nonnull = 1;
    8500              :         }
    8501       849159 :       return RECUR (instance);
    8502              : 
    8503      1182276 :     case COMPONENT_REF:
    8504              :       /* If this component is really a base class reference, then the field
    8505              :          itself isn't definitive.  */
    8506      1182276 :       if (DECL_FIELD_IS_BASE (TREE_OPERAND (instance, 1)))
    8507         1945 :         return RECUR (TREE_OPERAND (instance, 0));
    8508      1180331 :       return RECUR (TREE_OPERAND (instance, 1));
    8509              : 
    8510      1597951 :     case VAR_DECL:
    8511      1597951 :     case FIELD_DECL:
    8512      1597951 :       if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
    8513      1597951 :           && 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      7998986 :     case TARGET_EXPR:
    8521      7998986 :     case PARM_DECL:
    8522      7998986 :     case RESULT_DECL:
    8523      7998986 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (instance)))
    8524              :         {
    8525      1969906 :           if (nonnull)
    8526      1968058 :             *nonnull = 1;
    8527      1969906 :           return TREE_TYPE (instance);
    8528              :         }
    8529      6029080 :       else if (instance == current_class_ptr)
    8530              :         {
    8531      5109091 :           if (nonnull)
    8532      4428805 :             *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      5109091 :           if (current_scope () != current_function_decl
    8538      5109091 :               || (DECL_LANG_SPECIFIC (current_function_decl)
    8539     10217902 :                   && (DECL_CONSTRUCTOR_P (current_function_decl)
    8540      2497047 :                       || DECL_DESTRUCTOR_P (current_function_decl))))
    8541              :             {
    8542      2705910 :               if (cdtorp)
    8543      2705910 :                 *cdtorp = 1;
    8544      2705910 :               return TREE_TYPE (TREE_TYPE (instance));
    8545              :             }
    8546              :         }
    8547       919989 :       else if (TYPE_REF_P (TREE_TYPE (instance)))
    8548              :         {
    8549              :           /* We only need one hash table because it is always left empty.  */
    8550       719529 :           if (!fixed_type_or_null_ref_ht)
    8551        14248 :             fixed_type_or_null_ref_ht
    8552        14248 :               = new hash_table<nofree_ptr_hash<tree_node> > (37);
    8553              : 
    8554              :           /* Reference variables should be references to objects.  */
    8555       719529 :           if (nonnull)
    8556       716284 :             *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       719529 :           if (VAR_P (instance)
    8562        25240 :               && DECL_INITIAL (instance)
    8563         2917 :               && !type_dependent_expression_p_push (DECL_INITIAL (instance))
    8564       722446 :               && !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       375982 :     case VIEW_CONVERT_EXPR:
    8580       375982 :       if (location_wrapper_p (instance))
    8581       375982 :         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      7898600 : resolves_to_fixed_type_p (tree instance, int* nonnull)
    8609              : {
    8610      7898600 :   tree t = TREE_TYPE (instance);
    8611      7898600 :   int cdtorp = 0;
    8612      7898600 :   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      7898600 :   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      7898576 :   fixed = fixed_type_or_null (instance, nonnull, &cdtorp);
    8626      7898576 :   if (INDIRECT_TYPE_P (t))
    8627      4890827 :     t = TREE_TYPE (t);
    8628      7898576 :   if (CLASS_TYPE_P (t) && CLASSTYPE_FINAL (t))
    8629              :     return 1;
    8630      7829421 :   if (fixed == NULL_TREE)
    8631              :     return 0;
    8632      4636720 :   if (!same_type_ignoring_top_level_qualifiers_p (t, fixed))
    8633              :     return 0;
    8634      4636092 :   return cdtorp ? -1 : 1;
    8635              : }
    8636              : 
    8637              : 
    8638              : void
    8639       100969 : init_class_processing (void)
    8640              : {
    8641       100969 :   current_class_depth = 0;
    8642       100969 :   current_class_stack_size = 10;
    8643       100969 :   current_class_stack
    8644       100969 :     = XNEWVEC (struct class_stack_node, current_class_stack_size);
    8645       100969 :   sizeof_biggest_empty_class = size_zero_node;
    8646              : 
    8647       100969 :   ridpointers[(int) RID_PUBLIC] = access_public_node;
    8648       100969 :   ridpointers[(int) RID_PRIVATE] = access_private_node;
    8649       100969 :   ridpointers[(int) RID_PROTECTED] = access_protected_node;
    8650       100969 : }
    8651              : 
    8652              : /* Restore the cached PREVIOUS_CLASS_LEVEL.  */
    8653              : 
    8654              : static void
    8655    211782144 : restore_class_cache (void)
    8656              : {
    8657    211782144 :   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    211782144 :   push_binding_level (previous_class_level);
    8664    211782144 :   class_binding_level = previous_class_level;
    8665              :   /* Restore IDENTIFIER_TYPE_VALUE.  */
    8666    211782144 :   for (type = class_binding_level->type_shadowed;
    8667   1091921165 :        type;
    8668    880139021 :        type = TREE_CHAIN (type))
    8669    880139021 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (type), TREE_TYPE (type));
    8670    211782144 : }
    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    464329683 : pushclass (tree type)
    8683              : {
    8684    464329683 :   class_stack_node_t csn;
    8685              : 
    8686    464329683 :   type = TYPE_MAIN_VARIANT (type);
    8687              : 
    8688              :   /* Make sure there is enough room for the new entry on the stack.  */
    8689    464329683 :   if (current_class_depth + 1 >= current_class_stack_size)
    8690              :     {
    8691        11999 :       current_class_stack_size *= 2;
    8692        11999 :       current_class_stack
    8693        11999 :         = 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    464329683 :   csn = current_class_stack + current_class_depth;
    8699    464329683 :   csn->name = current_class_name;
    8700    464329683 :   csn->type = current_class_type;
    8701    464329683 :   csn->access = current_access_specifier;
    8702    464329683 :   csn->names_used = 0;
    8703    464329683 :   csn->hidden = 0;
    8704    464329683 :   current_class_depth++;
    8705              : 
    8706              :   /* Now set up the new type.  */
    8707    464329683 :   current_class_name = TYPE_NAME (type);
    8708    464329683 :   if (TREE_CODE (current_class_name) == TYPE_DECL)
    8709    464329683 :     current_class_name = DECL_NAME (current_class_name);
    8710    464329683 :   current_class_type = type;
    8711              : 
    8712              :   /* By default, things in classes are private, while things in
    8713              :      structures or unions are public.  */
    8714    464329683 :   current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
    8715    464329683 :                               ? access_private_node
    8716              :                               : access_public_node);
    8717              : 
    8718    464329683 :   if (previous_class_level
    8719    275086773 :       && type != previous_class_level->this_entity
    8720     58354665 :       && current_class_depth == 1)
    8721              :     {
    8722              :       /* Forcibly remove any old class remnants.  */
    8723     30945225 :       invalidate_class_lookup_cache ();
    8724              :     }
    8725              : 
    8726    464329683 :   if (!previous_class_level
    8727    244141548 :       || type != previous_class_level->this_entity
    8728    216732108 :       || current_class_depth > 1)
    8729    252547539 :     pushlevel_class ();
    8730              :   else
    8731    211782144 :     restore_class_cache ();
    8732    464329683 : }
    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    464313413 : popclass (void)
    8739              : {
    8740    464313413 :   poplevel_class ();
    8741              : 
    8742    464313410 :   current_class_depth--;
    8743    464313410 :   current_class_name = current_class_stack[current_class_depth].name;
    8744    464313410 :   current_class_type = current_class_stack[current_class_depth].type;
    8745    464313410 :   current_access_specifier = current_class_stack[current_class_depth].access;
    8746    464313410 :   if (current_class_stack[current_class_depth].names_used)
    8747     17434790 :     splay_tree_delete (current_class_stack[current_class_depth].names_used);
    8748    464313410 : }
    8749              : 
    8750              : /* Mark the top of the class stack as hidden.  */
    8751              : 
    8752              : void
    8753    548797732 : push_class_stack (void)
    8754              : {
    8755    548797732 :   if (current_class_depth)
    8756    383864784 :     ++current_class_stack[current_class_depth - 1].hidden;
    8757    548797732 : }
    8758              : 
    8759              : /* Mark the top of the class stack as un-hidden.  */
    8760              : 
    8761              : void
    8762    548669671 : pop_class_stack (void)
    8763              : {
    8764    548669671 :   if (current_class_depth)
    8765    383851248 :     --current_class_stack[current_class_depth - 1].hidden;
    8766    548669671 : }
    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   5343641576 : currently_open_class (tree t)
    8775              : {
    8776   5343641576 :   int i;
    8777              : 
    8778   5343641576 :   if (!CLASS_TYPE_P (t))
    8779              :     return NULL_TREE;
    8780              : 
    8781   5153124420 :   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   6433001353 :   for (i = current_class_depth; i > 0; --i)
    8786              :     {
    8787   5411062903 :       tree c;
    8788   5411062903 :       if (i == current_class_depth)
    8789   4740898884 :         c = current_class_type;
    8790              :       else
    8791              :         {
    8792    670164019 :           if (current_class_stack[i].hidden)
    8793              :             break;
    8794    499351795 :           c = current_class_stack[i].type;
    8795              :         }
    8796   5240250679 :       if (!c)
    8797    324519065 :         continue;
    8798   4915731614 :       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    167206165 : currently_open_derived_class (tree t)
    8810              : {
    8811    167206165 :   int i;
    8812              : 
    8813              :   /* The bases of a dependent type are unknown.  */
    8814    167206165 :   if (dependent_type_p (t))
    8815              :     return NULL_TREE;
    8816              : 
    8817    160611178 :   if (!current_class_type)
    8818              :     return NULL_TREE;
    8819              : 
    8820    159248270 :   if (DERIVED_FROM_P (t, current_class_type))
    8821    145403806 :     return current_class_type;
    8822              : 
    8823     18494928 :   for (i = current_class_depth - 1; i > 0; --i)
    8824              :     {
    8825      7913600 :       if (current_class_stack[i].hidden)
    8826              :         break;
    8827      7913600 :       if (DERIVED_FROM_P (t, current_class_stack[i].type))
    8828      3263136 :         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   1400422765 : current_nonlambda_class_type (void)
    8861              : {
    8862   1400422765 :   tree type = current_class_type;
    8863   2502596172 :   while (type && LAMBDA_TYPE_P (type))
    8864      3563679 :     type = decl_type_context (TYPE_NAME (type));
    8865   1400422765 :   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    682439502 : push_nested_class (tree type)
    8876              : {
    8877              :   /* A namespace might be passed in error cases, like A::B:C.  */
    8878    682439502 :   if (type == NULL_TREE
    8879    682439502 :       || !CLASS_TYPE_P (type))
    8880              :     return;
    8881              : 
    8882    350855155 :   push_nested_class (DECL_CONTEXT (TYPE_MAIN_DECL (type)));
    8883              : 
    8884    350855155 :   pushclass (type);
    8885              : }
    8886              : 
    8887              : /* Undoes a push_nested_class call.  */
    8888              : 
    8889              : void
    8890    331573548 : pop_nested_class (void)
    8891              : {
    8892    350841656 :   tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
    8893              : 
    8894    350841656 :   popclass ();
    8895    350841656 :   if (context && CLASS_TYPE_P (context))
    8896              :     pop_nested_class ();
    8897    331573548 : }
    8898              : 
    8899              : /* Returns the number of extern "LANG" blocks we are nested within.  */
    8900              : 
    8901              : int
    8902         3466 : current_lang_depth (void)
    8903              : {
    8904         3466 :   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      1209753 : push_lang_context (tree name)
    8912              : {
    8913      1209753 :   vec_safe_push (current_lang_base, current_lang_name);
    8914              : 
    8915      1209753 :   if (name == lang_name_cplusplus)
    8916       641350 :     current_lang_name = name;
    8917       568403 :   else if (name == lang_name_c)
    8918       568403 :     current_lang_name = name;
    8919              :   else
    8920            0 :     error ("language string %<\"%E\"%> not recognized", name);
    8921      1209753 : }
    8922              : 
    8923              : /* Get out of the current language scope.  */
    8924              : 
    8925              : void
    8926      1209753 : pop_lang_context (void)
    8927              : {
    8928      1209753 :   current_lang_name = current_lang_base->pop ();
    8929      1209753 : }
    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        94672 : 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        94672 :   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        94672 :   tree matches = NULL_TREE;
    8985        94672 :   tree fn;
    8986        94672 :   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        94672 :   gcc_assert (!TYPE_PTR_P (target_type)
    8992              :               || TREE_CODE (TREE_TYPE (target_type)) != METHOD_TYPE);
    8993              : 
    8994        94672 :   gcc_assert (is_overloaded_fn (overload));
    8995              : 
    8996              :   /* Check that the TARGET_TYPE is reasonable.  */
    8997        93192 :   if (TYPE_PTRFN_P (target_type)
    8998        94676 :       || 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        94623 :   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        94623 :   if (!template_only)
    9030       144119 :     for (lkp_iterator iter (overload); iter; ++iter)
    9031              :       {
    9032        74945 :         tree fn = *iter;
    9033              : 
    9034        74945 :         if (TREE_CODE (fn) == TEMPLATE_DECL)
    9035              :           /* We're not looking for templates just yet.  */
    9036        67870 :           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        69174 :   if (!matches)
    9079              :     {
    9080        92590 :       tree target_arg_types;
    9081        92590 :       tree target_ret_type;
    9082        92590 :       tree *args;
    9083        92590 :       unsigned int nargs, ia;
    9084        92590 :       tree arg;
    9085              : 
    9086        92590 :       target_arg_types = TYPE_ARG_TYPES (target_fn_type);
    9087        92590 :       target_ret_type = TREE_TYPE (target_fn_type);
    9088              : 
    9089        92590 :       nargs = list_length (target_arg_types);
    9090        92590 :       args = XALLOCAVEC (tree, nargs);
    9091        92590 :       for (arg = target_arg_types, ia = 0;
    9092       284930 :            arg != NULL_TREE;
    9093       192340 :            arg = TREE_CHAIN (arg), ++ia)
    9094       192340 :         args[ia] = TREE_VALUE (arg);
    9095        92590 :       nargs = ia;
    9096              : 
    9097       186330 :       for (lkp_iterator iter (overload); iter; ++iter)
    9098              :         {
    9099        93740 :           tree fn = *iter;
    9100        93740 :           tree instantiation;
    9101        93740 :           tree targs;
    9102              : 
    9103        93740 :           if (TREE_CODE (fn) != TEMPLATE_DECL)
    9104              :             /* We're only looking for templates.  */
    9105          671 :             continue;
    9106              : 
    9107        93069 :           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        93057 :           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        93057 :           if (undeduced_auto_decl (fn))
    9118          330 :             ret = NULL_TREE;
    9119              : 
    9120              :           /* Try to do argument deduction.  */
    9121        93057 :           targs = make_tree_vec (DECL_NTPARMS (fn));
    9122        93057 :           instantiation = fn_type_unification (fn, explicit_targs, targs, args,
    9123              :                                                nargs, ret,
    9124              :                                               DEDUCE_EXACT, LOOKUP_NORMAL,
    9125              :                                                NULL, false, false);
    9126        93057 :           if (instantiation == error_mark_node)
    9127              :             /* Instantiation failed.  */
    9128        21094 :             continue;
    9129              : 
    9130              :           /* Constraints must be satisfied. This is done before
    9131              :              return type deduction since that instantiates the
    9132              :              function. */
    9133        71963 :           if (flag_concepts && !constraints_satisfied_p (instantiation))
    9134            0 :             continue;
    9135              : 
    9136              :           /* And now force instantiation to do return type deduction.  */
    9137        71963 :           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        71963 :           if (flag_noexcept_type)
    9148        71117 :             maybe_instantiate_noexcept (instantiation, complain);
    9149              : 
    9150              :           /* See if there's a match.  */
    9151        71963 :           tree fntype = static_fn_type (instantiation);
    9152        71963 :           if (same_type_p (target_fn_type, fntype)
    9153        71963 :               || fnptr_conv_p (target_fn_type, fntype))
    9154        71945 :             matches = tree_cons (instantiation, fn, matches);
    9155              :         }
    9156              : 
    9157              :       /* Now, remove all but the most specialized of the matches.  */
    9158        92590 :       if (matches)
    9159              :         {
    9160        71825 :           tree match = most_specialized_instantiation (matches);
    9161              : 
    9162        71825 :           if (match != error_mark_node)
    9163              :             {
    9164        71789 :               matches = match;
    9165        71789 :               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        73858 :   if (matches == NULL_TREE)
    9178              :     {
    9179              :       /* There were *no* matches.  */
    9180        20765 :       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        20765 :       return error_mark_node;
    9189              :     }
    9190        73858 :   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        73822 :   fn = TREE_PURPOSE (matches);
    9227              : 
    9228       146401 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (fn)
    9229        74218 :       && !(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        73609 :   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        73528 :   if (!(complain & tf_conv))
    9298              :     {
    9299              :       /* Make =delete work with SFINAE.  */
    9300        33293 :       if (DECL_DELETED_FN (fn) && !(complain & tf_error))
    9301            0 :         return error_mark_node;
    9302        33293 :       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        73600 :   if (DECL_FUNCTION_MEMBER_P (fn))
    9310              :     {
    9311         7013 :       gcc_assert (access_path);
    9312         7013 :       perform_or_defer_access_check (access_path, fn, fn, complain);
    9313              :     }
    9314              : 
    9315        73600 :   if (TYPE_PTRFN_P (target_type) || TYPE_PTRMEMFUNC_P (target_type))
    9316        73485 :     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        98608 : instantiate_type (tree lhstype, tree rhs, tsubst_flags_t complain)
    9340              : {
    9341       108961 :   tsubst_flags_t complain_in = complain;
    9342       108961 :   tree access_path = NULL_TREE;
    9343              : 
    9344       108961 :   complain &= ~tf_ptrmem_ok;
    9345              : 
    9346       108961 :   STRIP_ANY_LOCATION_WRAPPER (rhs);
    9347              : 
    9348       108961 :   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       108961 :   if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
    9356              :     {
    9357         3290 :       tree fntype = non_reference (lhstype);
    9358         3290 :       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       105689 :   if (TREE_CODE (rhs) == SAVE_EXPR)
    9380            9 :     rhs = TREE_OPERAND (rhs, 0);
    9381              : 
    9382       105689 :   if (BASELINK_P (rhs))
    9383              :     {
    9384         7408 :       access_path = BASELINK_ACCESS_BINFO (rhs);
    9385         7408 :       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       105689 :   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       105689 :   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         2324 :     case OFFSET_REF:
    9416         2324 :       rhs = TREE_OPERAND (rhs, 1);
    9417         2324 :       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        25461 :     case TEMPLATE_ID_EXPR:
    9427        25461 :       {
    9428        25461 :         tree fns = TREE_OPERAND (rhs, 0);
    9429        25461 :         tree args = TREE_OPERAND (rhs, 1);
    9430              : 
    9431        25461 :         return
    9432        25461 :           resolve_address_of_overloaded_function (lhstype, fns, complain_in,
    9433              :                                                   /*template_only=*/true,
    9434        25461 :                                                   args, access_path);
    9435              :       }
    9436              : 
    9437        69211 :     case OVERLOAD:
    9438        69211 :     case FUNCTION_DECL:
    9439        69211 :       return
    9440        69211 :         resolve_address_of_overloaded_function (lhstype, rhs, complain_in,
    9441              :                                                 /*template_only=*/false,
    9442              :                                                 /*explicit_targs=*/NULL_TREE,
    9443        69211 :                                                 access_path);
    9444              : 
    9445         8029 :     case ADDR_EXPR:
    9446         8029 :     {
    9447         8029 :       if (PTRMEM_OK_P (rhs))
    9448         2324 :         complain |= tf_ptrmem_ok;
    9449              : 
    9450         8029 :       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       256466 : get_vfield_name (tree type)
    9470              : {
    9471       256466 :   tree binfo, base_binfo;
    9472              : 
    9473       256466 :   for (binfo = TYPE_BINFO (type);
    9474       256466 :        BINFO_N_BASE_BINFOS (binfo);
    9475              :        binfo = base_binfo)
    9476              :     {
    9477        73710 :       base_binfo = BINFO_BASE_BINFO (binfo, 0);
    9478              : 
    9479       147420 :       if (BINFO_VIRTUAL_P (base_binfo)
    9480        73710 :           || !TYPE_CONTAINS_VPTR_P (BINFO_TYPE (base_binfo)))
    9481              :         break;
    9482              :     }
    9483              : 
    9484       256466 :   type = BINFO_TYPE (binfo);
    9485       256466 :   tree ctor_name = constructor_name (type);
    9486       256466 :   char *buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
    9487              :                                + IDENTIFIER_LENGTH (ctor_name) + 2);
    9488       256466 :   sprintf (buf, VFIELD_NAME_FORMAT, IDENTIFIER_POINTER (ctor_name));
    9489       256466 :   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     31336207 : build_self_reference (void)
    9500              : {
    9501     31336207 :   tree name = DECL_NAME (TYPE_NAME (current_class_type));
    9502     31336207 :   tree decl = build_lang_decl (TYPE_DECL, name, current_class_type);
    9503              : 
    9504     31336207 :   DECL_NONLOCAL (decl) = 1;
    9505     31336207 :   DECL_CONTEXT (decl) = current_class_type;
    9506     31336207 :   DECL_ARTIFICIAL (decl) = 1;
    9507     31336207 :   SET_DECL_SELF_REFERENCE_P (decl);
    9508     31336207 :   set_underlying_type (decl);
    9509     31336207 :   set_instantiating_module (decl);
    9510              : 
    9511     31336207 :   if (processing_template_decl)
    9512     19950904 :     decl = push_template_decl (decl);
    9513              : 
    9514     31336207 :   tree saved_cas = current_access_specifier;
    9515     31336207 :   current_access_specifier = access_public_node;
    9516     31336207 :   finish_member_declaration (decl);
    9517     31336207 :   current_access_specifier = saved_cas;
    9518     31336207 : }
    9519              : 
    9520              : /* Returns 1 if TYPE contains only padding bytes.  */
    9521              : 
    9522              : int
    9523    668267881 : is_empty_class (tree type)
    9524              : {
    9525    668267881 :   if (type == error_mark_node)
    9526              :     return 0;
    9527              : 
    9528    668267878 :   if (! CLASS_TYPE_P (type))
    9529              :     return 0;
    9530              : 
    9531    397445835 :   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    453579134 : is_really_empty_class (tree type, bool ignore_vptr)
    9541              : {
    9542    453579134 :   if (CLASS_TYPE_P (type))
    9543              :     {
    9544     38623968 :       tree field;
    9545     38623968 :       tree binfo;
    9546     38623968 :       tree base_binfo;
    9547     38623968 :       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     38623968 :       if (COMPLETE_TYPE_P (type) && is_empty_class (type))
    9552              :         return true;
    9553              : 
    9554     30079976 :       if (!ignore_vptr && TYPE_CONTAINS_VPTR_P (type))
    9555              :         return false;
    9556              : 
    9557     33224040 :       for (binfo = TYPE_BINFO (type), i = 0;
    9558     33224040 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    9559      4869877 :         if (!is_really_empty_class (BINFO_TYPE (base_binfo), ignore_vptr))
    9560              :           return false;
    9561    557683265 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    9562    557209441 :         if (TREE_CODE (field) == FIELD_DECL
    9563     31013625 :             && !DECL_ARTIFICIAL (field)
    9564              :             /* An unnamed bit-field is not a data member.  */
    9565     28029787 :             && !DECL_UNNAMED_BIT_FIELD (field)
    9566    585236888 :             && !is_really_empty_class (TREE_TYPE (field), ignore_vptr))
    9567              :           return false;
    9568              :       return true;
    9569              :     }
    9570    414955166 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    9571      3796290 :     return (integer_zerop (array_type_nelts_top (type))
    9572      3796290 :             || 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   2238782819 : 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   2238782819 :   if (!(innermost_scope_kind() == sk_class
    9584    305818175 :         && TYPE_BEING_DEFINED (current_class_type)
    9585    543689555 :         && !LAMBDA_TYPE_P (current_class_type)))
    9586              :     return;
    9587              : 
    9588    272774438 :   const cp_binding_level *blev = nullptr;
    9589    272774438 :   if (const cxx_binding *binding = IDENTIFIER_BINDING (name))
    9590    225857429 :     blev = binding->scope;
    9591    272774438 :   const cp_binding_level *lev = current_binding_level;
    9592              : 
    9593              :   /* Record the binding in the names_used tables for classes inside blev.  */
    9594    406801855 :   for (int i = current_class_depth; i > 0; --i)
    9595              :     {
    9596    580048338 :       tree type = (i == current_class_depth
    9597    290024169 :                    ? current_class_type
    9598     17249731 :                    : current_class_stack[i].type);
    9599              : 
    9600    313940666 :       for (; lev; lev = lev->level_chain)
    9601              :         {
    9602    313940666 :           if (lev == blev)
    9603              :             /* We found the declaration.  */
    9604              :             return;
    9605    157943914 :           if (lev->kind == sk_class && lev->this_entity == type)
    9606              :             /* This class is inside the declaration scope.  */
    9607              :             break;
    9608              :         }
    9609              : 
    9610    134027417 :       auto &names_used = current_class_stack[i-1].names_used;
    9611    134027417 :       if (!names_used)
    9612     17434802 :         names_used = splay_tree_new (splay_tree_compare_pointers, 0, 0);
    9613              : 
    9614    134027417 :       tree use = build1_loc (input_location, VIEW_CONVERT_EXPR,
    9615    134027417 :                              TREE_TYPE (decl), decl);
    9616    134027417 :       EXPR_LOCATION_WRAPPER_P (use) = 1;
    9617    134027417 :       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    341245447 : note_name_declared_in_class (tree name, tree decl)
    9632              : {
    9633    341245447 :   splay_tree names_used;
    9634    341245447 :   splay_tree_node n;
    9635              : 
    9636              :   /* Look to see if we ever used this name.  */
    9637    341245447 :   names_used
    9638    341245447 :     = current_class_stack[current_class_depth - 1].names_used;
    9639    341245447 :   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    104804294 :   if ((!pedantic && current_lang_name == lang_name_c)
    9646    102672854 :       || flag_ms_extensions)
    9647              :     return;
    9648    102672848 :   n = splay_tree_lookup (names_used, (splay_tree_key) name);
    9649    102672848 :   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      6268373 : get_vtbl_decl_for_binfo (tree binfo)
    9687              : {
    9688      6268373 :   tree decl;
    9689              : 
    9690      6268373 :   decl = BINFO_VTABLE (binfo);
    9691      6268373 :   if (decl && TREE_CODE (decl) == POINTER_PLUS_EXPR)
    9692              :     {
    9693      6268370 :       gcc_assert (TREE_CODE (TREE_OPERAND (decl, 0)) == ADDR_EXPR);
    9694      6268370 :       decl = TREE_OPERAND (TREE_OPERAND (decl, 0), 0);
    9695              :     }
    9696      6268370 :   if (decl)
    9697      6268370 :     gcc_assert (VAR_P (decl));
    9698      6268373 :   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     46081625 : get_primary_binfo (tree binfo)
    9710              : {
    9711     46081625 :   tree primary_base;
    9712              : 
    9713     46081625 :   primary_base = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (binfo));
    9714     46081625 :   if (!primary_base)
    9715              :     return NULL_TREE;
    9716              : 
    9717     13114523 :   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      2643172 : most_primary_binfo (tree binfo)
    9725              : {
    9726      2643172 :   tree b = binfo;
    9727      8303556 :   while (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (b))
    9728     11320768 :          && !BINFO_LOST_PRIMARY_P (b))
    9729              :     {
    9730      3017212 :       tree primary_base = get_primary_binfo (b);
    9731      3017212 :       gcc_assert (BINFO_PRIMARY_P (primary_base)
    9732              :                   && BINFO_INHERITANCE_CHAIN (primary_base) == b);
    9733              :       b = primary_base;
    9734              :     }
    9735      2643172 :   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     52492668 : dump_class_hierarchy (tree t)
    9887              : {
    9888     52492668 :   dump_flags_t flags;
    9889     52492668 :   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     52492668 : }
    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      2036956 : dump_vtable (tree t, tree binfo, tree vtable)
    9940              : {
    9941      2036956 :   dump_flags_t flags;
    9942      2036956 :   FILE *stream = dump_begin (class_dump_id, &flags);
    9943              : 
    9944      2036956 :   if (!stream)
    9945      2036917 :     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       184420 : dump_vtt (tree t, tree vtt)
    9971              : {
    9972       184420 :   dump_flags_t flags;
    9973       184420 :   FILE *stream = dump_begin (class_dump_id, &flags);
    9974              : 
    9975       184420 :   if (!stream)
    9976       184408 :     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     52492668 : finish_vtbls (tree t)
   10040              : {
   10041     52492668 :   tree vbase;
   10042     52492668 :   vec<constructor_elt, va_gc> *v = NULL;
   10043     52492668 :   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     52492668 :   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    133443449 :   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
   10053              :     {
   10054     80950781 :       if (!BINFO_VIRTUAL_P (vbase))
   10055     80752321 :         continue;
   10056       198460 :       accumulate_vtbl_inits (vbase, vbase, TYPE_BINFO (t), vtable, t, &v);
   10057              :     }
   10058              : 
   10059     52492668 :   if (BINFO_VTABLE (TYPE_BINFO (t)))
   10060      1783777 :     initialize_vtable (TYPE_BINFO (t), v);
   10061     52492668 : }
   10062              : 
   10063              : /* Initialize the vtable for BINFO with the INITS.  */
   10064              : 
   10065              : static void
   10066      1783777 : initialize_vtable (tree binfo, vec<constructor_elt, va_gc> *inits)
   10067              : {
   10068      1783777 :   tree decl;
   10069              : 
   10070      3567554 :   layout_vtable_decl (binfo, vec_safe_length (inits));
   10071      1783777 :   decl = get_vtbl_decl_for_binfo (binfo);
   10072      1783777 :   initialize_artificial_var (decl, inits);
   10073      1783777 :   dump_vtable (BINFO_TYPE (binfo), binfo, decl);
   10074      1783777 : }
   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     52492668 : build_vtt (tree t)
   10091              : {
   10092     52492668 :   tree type;
   10093     52492668 :   tree vtt;
   10094     52492668 :   tree index;
   10095     52492668 :   vec<constructor_elt, va_gc> *inits;
   10096              : 
   10097              :   /* Build up the initializers for the VTT.  */
   10098     52492668 :   inits = NULL;
   10099     52492668 :   index = size_zero_node;
   10100     52492668 :   build_vtt_inits (TYPE_BINFO (t), t, &inits, &index);
   10101              : 
   10102              :   /* If we didn't need a VTT, we're done.  */
   10103     52492668 :   if (!inits)
   10104              :     return;
   10105              : 
   10106              :   /* Figure out the type of the VTT.  */
   10107       368840 :   type = build_array_of_n_type (const_ptr_type_node,
   10108       184420 :                                 inits->length ());
   10109              : 
   10110              :   /* Now, build the VTT object itself.  */
   10111       184420 :   vtt = build_vtable (t, mangle_vtt_for_type (t), type);
   10112       184420 :   initialize_artificial_var (vtt, inits);
   10113              :   /* Add the VTT to the vtables list.  */
   10114       184420 :   DECL_CHAIN (vtt) = DECL_CHAIN (CLASSTYPE_VTABLES (t));
   10115       184420 :   DECL_CHAIN (CLASSTYPE_VTABLES (t)) = vtt;
   10116              : 
   10117       184420 :   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      1113966 : binfo_ctor_vtable (tree binfo)
   10127              : {
   10128      1186068 :   tree vt;
   10129              : 
   10130      1186068 :   while (1)
   10131              :     {
   10132      1186068 :       vt = BINFO_VTABLE (binfo);
   10133      1186068 :       if (TREE_CODE (vt) == TREE_LIST)
   10134       745357 :         vt = TREE_VALUE (vt);
   10135      1186068 :       if (TREE_CODE (vt) == TREE_BINFO)
   10136              :         binfo = vt;
   10137              :       else
   10138              :         break;
   10139              :     }
   10140              : 
   10141      1113966 :   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     52932600 : build_vtt_inits (tree binfo, tree t, vec<constructor_elt, va_gc> **inits,
   10170              :                  tree *index)
   10171              : {
   10172     52932600 :   int i;
   10173     52932600 :   tree b;
   10174     52932600 :   tree init;
   10175     52932600 :   secondary_vptr_vtt_init_data data;
   10176     52932600 :   int top_level_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
   10177              : 
   10178              :   /* We only need VTTs for subobjects with virtual bases.  */
   10179     52932600 :   if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
   10180     52495001 :     return;
   10181              : 
   10182              :   /* We need to use a construction vtable if this is not the primary
   10183              :      VTT.  */
   10184       437599 :   if (!top_level_p)
   10185              :     {
   10186       253179 :       build_ctor_vtbl_group (binfo, t);
   10187              : 
   10188              :       /* Record the offset in the VTT where this sub-VTT can be found.  */
   10189       253179 :       BINFO_SUBVTT_INDEX (binfo) = *index;
   10190              :     }
   10191              : 
   10192              :   /* Add the address of the primary vtable for the complete object.  */
   10193       437599 :   init = binfo_ctor_vtable (binfo);
   10194       437599 :   CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init);
   10195       437599 :   if (top_level_p)
   10196              :     {
   10197       184420 :       gcc_assert (!BINFO_VPTR_INDEX (binfo));
   10198       184420 :       BINFO_VPTR_INDEX (binfo) = *index;
   10199              :     }
   10200       437599 :   *index = size_binop (PLUS_EXPR, *index, TYPE_SIZE_UNIT (ptr_type_node));
   10201              : 
   10202              :   /* Recursively add the secondary VTTs for non-virtual bases.  */
   10203       947448 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, b); ++i)
   10204       509849 :     if (!BINFO_VIRTUAL_P (b))
   10205       241472 :       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       437599 :   data.top_level_p = top_level_p;
   10211       437599 :   data.index = *index;
   10212       437599 :   data.inits = *inits;
   10213       437599 :   data.type_being_constructed = BINFO_TYPE (binfo);
   10214              : 
   10215       437599 :   dfs_walk_once (binfo, dfs_build_secondary_vptr_vtt_inits, NULL, &data);
   10216              : 
   10217       437599 :   *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       437599 :   *inits = data.inits;
   10222              : 
   10223       437599 :   if (top_level_p)
   10224              :     /* Add the secondary VTTs for virtual bases in inheritance graph
   10225              :        order.  */
   10226       989658 :     for (b = TYPE_BINFO (BINFO_TYPE (binfo)); b; b = TREE_CHAIN (b))
   10227              :       {
   10228       805238 :         if (!BINFO_VIRTUAL_P (b))
   10229       606778 :           continue;
   10230              : 
   10231       198460 :         build_vtt_inits (b, t, inits, index);
   10232              :       }
   10233              :   else
   10234              :     /* Remove the ctor vtables we created.  */
   10235       253179 :     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      1779700 : dfs_build_secondary_vptr_vtt_inits (tree binfo, void *data_)
   10243              : {
   10244      1779700 :   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      1779700 :   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      1755867 :   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      2154474 :   if (!(CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
   10258       836206 :         || 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      1317726 :   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       676367 :   if (data->top_level_p)
   10267              :     {
   10268       256291 :       gcc_assert (!BINFO_VPTR_INDEX (binfo));
   10269       256291 :       BINFO_VPTR_INDEX (binfo) = data->index;
   10270              : 
   10271       256291 :       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       205036 :           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       676367 :   CONSTRUCTOR_APPEND_ELT (data->inits, NULL_TREE, binfo_ctor_vtable (binfo));
   10284              : 
   10285              :   /* Advance the vtt index.  */
   10286       676367 :   data->index = size_binop (PLUS_EXPR, data->index,
   10287              :                             TYPE_SIZE_UNIT (ptr_type_node));
   10288              : 
   10289       676367 :   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      1133686 : dfs_fixup_binfo_vtbls (tree binfo, void* data)
   10299              : {
   10300      1133686 :   tree vtable = BINFO_VTABLE (binfo);
   10301              : 
   10302      1133686 :   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      1038231 :   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       713597 :   if (TREE_CODE (vtable) == TREE_LIST
   10314       713597 :       && (TREE_PURPOSE (vtable) == (tree) data))
   10315       673255 :     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       253179 : build_ctor_vtbl_group (tree binfo, tree t)
   10325              : {
   10326       253179 :   tree type;
   10327       253179 :   tree vtbl;
   10328       253179 :   tree id;
   10329       253179 :   tree vbase;
   10330       253179 :   vec<constructor_elt, va_gc> *v;
   10331              : 
   10332              :   /* See if we've already created this construction vtable group.  */
   10333       253179 :   id = mangle_ctor_vtbl_for_type (t, binfo);
   10334       253179 :   if (get_global_binding (id))
   10335            0 :     return;
   10336              : 
   10337       253179 :   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       253179 :   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       253179 :   DECL_VISIBILITY (vtbl) = VISIBILITY_HIDDEN;
   10348       253179 :   DECL_VISIBILITY_SPECIFIED (vtbl) = true;
   10349              : 
   10350       253179 :   v = NULL;
   10351       253179 :   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       253179 :   for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
   10357      1231698 :        vbase;
   10358       978519 :        vbase = TREE_CHAIN (vbase))
   10359              :     {
   10360       978519 :       tree b;
   10361              : 
   10362       978519 :       if (!BINFO_VIRTUAL_P (vbase))
   10363       582770 :         continue;
   10364       395749 :       b = copied_binfo (vbase, binfo);
   10365              : 
   10366       395749 :       accumulate_vtbl_inits (b, vbase, binfo, vtbl, t, &v);
   10367              :     }
   10368              : 
   10369              :   /* Figure out the type of the construction vtable.  */
   10370       253179 :   type = build_array_of_n_type (vtable_entry_type, v->length ());
   10371       253179 :   layout_type (type);
   10372       253179 :   TREE_TYPE (vtbl) = type;
   10373       253179 :   DECL_SIZE (vtbl) = DECL_SIZE_UNIT (vtbl) = NULL_TREE;
   10374       253179 :   layout_decl (vtbl, 0);
   10375              : 
   10376              :   /* Initialize the construction vtable.  */
   10377       253179 :   CLASSTYPE_VTABLES (t) = chainon (CLASSTYPE_VTABLES (t), vtbl);
   10378       253179 :   initialize_artificial_var (vtbl, v);
   10379       253179 :   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     56989973 : 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     56989973 :   int i;
   10401     56989973 :   tree base_binfo;
   10402     56989973 :   int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
   10403              : 
   10404     56989973 :   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     56989973 :   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      5650860 :   if (ctor_vtbl_p
   10413       956816 :       && !CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
   10414      6125614 :       && !binfo_via_virtual (orig_binfo, BINFO_TYPE (rtti_binfo)))
   10415              :     return;
   10416              : 
   10417              :   /* Build the initializers for the BINFO-in-T vtable.  */
   10418      5650659 :   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     15729114 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
   10426              :     {
   10427              :       /* Skip virtual bases.  */
   10428      4427796 :       if (BINFO_VIRTUAL_P (base_binfo))
   10429       777879 :         continue;
   10430      7299834 :       accumulate_vtbl_inits (base_binfo,
   10431      3649917 :                              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      5650659 : 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      5650659 :   tree vtbl = NULL_TREE;
   10449      5650659 :   int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
   10450      5650659 :   int n_inits;
   10451              : 
   10452      5650659 :   if (ctor_vtbl_p
   10453      6607274 :       && 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      5578182 :   else if (!BINFO_NEW_VTABLE_MARKED (orig_binfo))
   10504              :     return;
   10505              : 
   10506      2714551 :   n_inits = vec_safe_length (*l);
   10507              : 
   10508      2714551 :   if (!vtbl)
   10509              :     {
   10510      2643007 :       tree index;
   10511      2643007 :       int non_fn_entries;
   10512              : 
   10513              :       /* Add the initializer for this vtable.  */
   10514      2643007 :       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      2643007 :       vtbl = build1 (ADDR_EXPR, vtbl_ptr_type_node, orig_vtbl);
   10519      2643007 :       index = size_binop (MULT_EXPR,
   10520              :                           TYPE_SIZE_UNIT (vtable_entry_type),
   10521              :                           size_int (non_fn_entries + n_inits));
   10522      2643007 :       vtbl = fold_build_pointer_plus (vtbl, index);
   10523              :     }
   10524              : 
   10525      2714551 :   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       673255 :     BINFO_VTABLE (binfo) = tree_cons (rtti_binfo, vtbl, BINFO_VTABLE (binfo));
   10530      2041296 :   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      2033135 :     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      2643007 : 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      2643007 :   tree v;
   10573      2643007 :   vtbl_init_data vid;
   10574      2643007 :   unsigned ix, jx;
   10575      2643007 :   tree vbinfo;
   10576      2643007 :   vec<tree, va_gc> *vbases;
   10577      2643007 :   constructor_elt *e;
   10578              : 
   10579              :   /* Initialize VID.  */
   10580      2643007 :   memset (&vid, 0, sizeof (vid));
   10581      2643007 :   vid.binfo = binfo;
   10582      2643007 :   vid.derived = t;
   10583      2643007 :   vid.rtti_binfo = rtti_binfo;
   10584      2643007 :   vid.primary_vtbl_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
   10585      2643007 :   vid.ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
   10586      2643007 :   vid.generate_vcall_entries = true;
   10587              :   /* The first vbase or vcall offset is at index -3 in the vtable.  */
   10588      2643007 :   vid.index = ssize_int(-3 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
   10589              : 
   10590              :   /* Add entries to the vtable for RTTI.  */
   10591      2643007 :   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      2643007 :   vec_alloc (vid.fns, 32);
   10597              :   /* Add the vcall and vbase offset entries.  */
   10598      2643007 :   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      2643007 :   for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
   10603      9035730 :        vec_safe_iterate (vbases, ix, &vbinfo); ix++)
   10604      6392723 :     BINFO_VTABLE_PATH_MARKED (vbinfo) = 0;
   10605              : 
   10606              :   /* If the target requires padding between data entries, add that now.  */
   10607      2643007 :   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      2643007 :   if (non_fn_entries_p)
   10638      5286014 :     *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      2643007 :   jx = vec_safe_length (*inits);
   10644      2643007 :   vec_safe_grow (*inits, jx + vid.inits->length (), true);
   10645              : 
   10646      2643007 :   for (ix = vid.inits->length () - 1;
   10647     10564314 :        vid.inits->iterate (ix, &e);
   10648      7921307 :        ix--, jx++)
   10649      7921307 :     (**inits)[jx] = *e;
   10650              : 
   10651              :   /* Go through all the ordinary virtual functions, building up
   10652              :      initializers.  */
   10653     14388528 :   for (v = BINFO_VIRTUALS (orig_binfo); v; v = TREE_CHAIN (v))
   10654              :     {
   10655     11745521 :       tree delta;
   10656     11745521 :       tree vcall_index;
   10657     11745521 :       tree fn, fn_original;
   10658     11745521 :       tree init = NULL_TREE;
   10659              : 
   10660     11745521 :       fn = BV_FN (v);
   10661     11745521 :       fn_original = fn;
   10662     11745521 :       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     11745521 :       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     11744776 :           delta = BV_DELTA (v);
   10692     11744776 :           vcall_index = BV_VCALL_INDEX (v);
   10693              : 
   10694     11744776 :           gcc_assert (TREE_CODE (delta) == INTEGER_CST);
   10695     11744776 :           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     11744776 :           if (DECL_PURE_VIRTUAL_P (fn_original))
   10700              :             {
   10701       771239 :               fn = abort_fndecl;
   10702       771239 :               if (!TARGET_VTABLE_USES_DESCRIPTORS)
   10703              :                 {
   10704       771239 :                   if (abort_fndecl_addr == NULL)
   10705        14306 :                     abort_fndecl_addr
   10706        14306 :                       = fold_convert (vfunc_ptr_type_node,
   10707              :                                       build_fold_addr_expr (fn));
   10708       771239 :                   init = abort_fndecl_addr;
   10709              :                 }
   10710              :             }
   10711              :           /* Likewise for deleted virtuals.  */
   10712     10973537 :           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     10973488 :               if (!integer_zerop (delta) || vcall_index)
   10732              :                 {
   10733      1034677 :                   fn = make_thunk (fn, /*this_adjusting=*/1,
   10734              :                                    delta, vcall_index);
   10735      1034677 :                   if (!DECL_NAME (fn))
   10736       481910 :                     finish_thunk (fn);
   10737              :                 }
   10738              :               /* Take the address of the function, considering it to be of an
   10739              :                  appropriate generic type.  */
   10740     10973488 :               if (!TARGET_VTABLE_USES_DESCRIPTORS)
   10741     10973488 :                 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     10973488 :               if (DECL_DESTRUCTOR_P (fn_original)
   10750     10973488 :                   && (CLASSTYPE_PURE_VIRTUALS (DECL_CONTEXT (fn_original))
   10751      4506792 :                       || orig_binfo != binfo))
   10752      1339842 :                 init = size_zero_node;
   10753              :             }
   10754              :         }
   10755              : 
   10756              :       /* And add it to the chain of initializers.  */
   10757     11745521 :       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     11745521 :         CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init);
   10775              :     }
   10776      2643007 : }
   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      5663243 : build_vcall_and_vbase_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10783              : {
   10784      5663243 :   tree b;
   10785              : 
   10786              :   /* If this is a derived class, we must first create entries
   10787              :      corresponding to the primary base class.  */
   10788      5663243 :   b = get_primary_binfo (binfo);
   10789      5663243 :   if (b)
   10790      3020236 :     build_vcall_and_vbase_vtbl_entries (b, vid);
   10791              : 
   10792              :   /* Add the vbase entries for this base.  */
   10793      5663243 :   build_vbase_offset_vtbl_entries (binfo, vid);
   10794              :   /* Add the vcall entries for this base.  */
   10795      5663243 :   build_vcall_offset_vtbl_entries (binfo, vid);
   10796      5663243 : }
   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      5663243 : build_vbase_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10805              : {
   10806      5663243 :   tree vbase;
   10807      5663243 :   tree t;
   10808      5663243 :   tree non_primary_binfo;
   10809              : 
   10810              :   /* If there are no virtual baseclasses, then there is nothing to
   10811              :      do.  */
   10812      5663243 :   if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
   10813              :     return;
   10814              : 
   10815       928291 :   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       928291 :   non_primary_binfo = binfo;
   10821      1451248 :   while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
   10822              :     {
   10823       872900 :       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       872900 :       if (BINFO_VIRTUAL_P (non_primary_binfo))
   10830              :         {
   10831       186020 :           non_primary_binfo = vid->binfo;
   10832       186020 :           break;
   10833              :         }
   10834              : 
   10835       686880 :       b = BINFO_INHERITANCE_CHAIN (non_primary_binfo);
   10836       686880 :       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       928291 :   for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
   10843      5610756 :        vbase;
   10844      4682465 :        vbase = TREE_CHAIN (vbase))
   10845              :     {
   10846      4682465 :       tree b;
   10847      4682465 :       tree delta;
   10848              : 
   10849      4682465 :       if (!BINFO_VIRTUAL_P (vbase))
   10850      2170234 :         continue;
   10851              : 
   10852              :       /* Find the instance of this virtual base in the complete
   10853              :          object.  */
   10854      2512231 :       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      2512231 :       if (BINFO_VTABLE_PATH_MARKED (b))
   10859       308748 :         continue;
   10860      2203483 :       BINFO_VTABLE_PATH_MARKED (b) = 1;
   10861              : 
   10862              :       /* Figure out where we can find this vbase offset.  */
   10863      2203483 :       delta = size_binop (MULT_EXPR,
   10864              :                           vid->index,
   10865              :                           fold_convert (ssizetype,
   10866              :                                    TYPE_SIZE_UNIT (vtable_entry_type)));
   10867      2203483 :       if (vid->primary_vtbl_p)
   10868       198460 :         BINFO_VPTR_FIELD (b) = delta;
   10869              : 
   10870      2203483 :       if (binfo != TYPE_BINFO (t))
   10871              :         /* The vbase offset had better be the same.  */
   10872      2145119 :         gcc_assert (tree_int_cst_equal (delta, BINFO_VPTR_FIELD (vbase)));
   10873              : 
   10874              :       /* The next vbase will come at a more negative offset.  */
   10875      2203483 :       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      2203483 :       delta = size_diffop_loc (input_location,
   10883      2203483 :                            BINFO_OFFSET (b), BINFO_OFFSET (non_primary_binfo));
   10884              : 
   10885      6885948 :       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      5663243 : 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      5663243 :   if (binfo == TYPE_BINFO (vid->derived)
   10902      9542709 :       || (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       601468 :           && 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      2371575 :       vid->vbase = binfo;
   10929              :       /* If we are just computing the vcall indices -- but do not need
   10930              :          the actual entries -- not that.  */
   10931      2371575 :       if (!BINFO_VIRTUAL_P (binfo))
   10932      1783777 :         vid->generate_vcall_entries = false;
   10933              :       /* Now, walk through the non-virtual bases, adding vcall offsets.  */
   10934      2371575 :       add_vcall_offset_vtbl_entries_r (binfo, vid);
   10935              :     }
   10936      5663243 : }
   10937              : 
   10938              : /* Build vcall offsets, starting with those for BINFO.  */
   10939              : 
   10940              : static void
   10941      6447924 : add_vcall_offset_vtbl_entries_r (tree binfo, vtbl_init_data* vid)
   10942              : {
   10943      6447924 :   int i;
   10944      6447924 :   tree primary_binfo;
   10945      6447924 :   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      6447924 :   if (BINFO_VIRTUAL_P (binfo) && vid->vbase != binfo)
   10952      6447924 :     return;
   10953              : 
   10954              :   /* If BINFO has a primary base, process it first.  */
   10955      5962391 :   primary_binfo = get_primary_binfo (binfo);
   10956      5962391 :   if (primary_binfo)
   10957      2971196 :     add_vcall_offset_vtbl_entries_r (primary_binfo, vid);
   10958              : 
   10959              :   /* Add BINFO itself to the list.  */
   10960      5962391 :   add_vcall_offset_vtbl_entries_1 (binfo, vid);
   10961              : 
   10962              :   /* Scan the non-primary bases of BINFO.  */
   10963     16000935 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
   10964      4076153 :     if (base_binfo != primary_binfo)
   10965      1105153 :       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      5962391 : add_vcall_offset_vtbl_entries_1 (tree binfo, vtbl_init_data* vid)
   10972              : {
   10973              :   /* Make entries for the rest of the virtuals.  */
   10974      5962391 :   tree orig_fn;
   10975              : 
   10976              :   /* The ABI requires that the methods be processed in declaration
   10977              :      order.  */
   10978      5962391 :   for (orig_fn = TYPE_FIELDS (BINFO_TYPE (binfo));
   10979    203414679 :        orig_fn;
   10980    197452288 :        orig_fn = DECL_CHAIN (orig_fn))
   10981    197452288 :     if (TREE_CODE (orig_fn) == FUNCTION_DECL && DECL_VINDEX (orig_fn))
   10982     25519397 :       add_vcall_offset (orig_fn, binfo, vid);
   10983      5962391 : }
   10984              : 
   10985              : /* Add a vcall offset entry for ORIG_FN to the vtable.  */
   10986              : 
   10987              : static void
   10988     25519397 : add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
   10989              : {
   10990     25519397 :   size_t i;
   10991     25519397 :   tree vcall_offset;
   10992     25519397 :   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     69697242 :   FOR_EACH_VEC_SAFE_ELT (vid->fns, i, derived_entry)
   10999              :     {
   11000     60701283 :       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    114661656 :           || (DECL_DESTRUCTOR_P (derived_entry)
   11004     39862868 :               && DECL_DESTRUCTOR_P (orig_fn)))
   11005     25519397 :         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      8995959 :   if (vid->binfo == TYPE_BINFO (vid->derived))
   11012              :     {
   11013      8566287 :       tree_pair_s elt = {orig_fn, vid->index};
   11014      8566287 :       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      8995959 :   vid->index = size_binop (MINUS_EXPR, vid->index,
   11020              :                            ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
   11021              : 
   11022              :   /* Keep track of this function.  */
   11023      8995959 :   vec_safe_push (vid->fns, orig_fn);
   11024              : 
   11025      8995959 :   if (vid->generate_vcall_entries)
   11026              :     {
   11027       431810 :       tree base;
   11028       431810 :       tree fn;
   11029              : 
   11030              :       /* Find the overriding function.  */
   11031       431810 :       fn = find_final_overrider (vid->rtti_binfo, binfo, orig_fn);
   11032       431810 :       if (fn == error_mark_node)
   11033           27 :         vcall_offset = build_zero_cst (vtable_entry_type);
   11034              :       else
   11035              :         {
   11036       431783 :           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      1727132 :           vcall_offset = size_diffop_loc (input_location,
   11043       431783 :                                       BINFO_OFFSET (base),
   11044       431783 :                                       BINFO_OFFSET (vid->binfo));
   11045       431783 :           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       431810 :       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      2643007 : build_rtti_vtbl_entries (tree binfo, vtbl_init_data* vid)
   11060              : {
   11061      2643007 :   tree b;
   11062      2643007 :   tree t;
   11063      2643007 :   tree offset;
   11064      2643007 :   tree decl;
   11065      2643007 :   tree init;
   11066              : 
   11067      2643007 :   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      2643007 :   b = most_primary_binfo (binfo);
   11072      2643007 :   offset = size_diffop_loc (input_location,
   11073      2643007 :                         BINFO_OFFSET (vid->rtti_binfo), BINFO_OFFSET (b));
   11074              : 
   11075              :   /* The second entry is the address of the typeinfo object.  */
   11076      2643007 :   if (flag_rtti)
   11077      2639898 :     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      2643007 :   init = build_nop (vfunc_ptr_type_node, decl);
   11084      2643007 :   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      2643007 :   init = build_nop (vfunc_ptr_type_node, offset);
   11090      2643007 :   CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, init);
   11091      2643007 : }
   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       190299 : publicly_virtually_derived_p (tree parent, tree type)
   11117              : {
   11118       190299 :   tree base = lookup_base (type, parent,
   11119              :                            ba_ignore_scope | ba_check | ba_require_virtual,
   11120              :                            NULL, tf_none);
   11121       190299 :   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         9695 : common_enclosing_class (tree ctx1, tree ctx2)
   11129              : {
   11130         9695 :   if (!TYPE_P (ctx1) || !TYPE_P (ctx2))
   11131              :     return NULL_TREE;
   11132         9695 :   gcc_assert (ctx1 == TYPE_MAIN_VARIANT (ctx1)
   11133              :               && ctx2 == TYPE_MAIN_VARIANT (ctx2));
   11134         9695 :   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.