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

Generated by: LCOV version 2.4-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.